List: move the list widget to use the material ui list.

Fixes #79.
master
Tom Hacohen 5 years ago
parent 6a5d959777
commit 5cb8dda9cc

@ -43,7 +43,7 @@ export default function JournalsList(props: PropsType) {
const keyPair = userInfo.getKeyPair(userInfo.getCryptoManager(derived)); const keyPair = userInfo.getKeyPair(userInfo.getCryptoManager(derived));
const cryptoManager = journal.getCryptoManager(derived, keyPair); const cryptoManager = journal.getCryptoManager(derived, keyPair);
const info = journal.getInfo(cryptoManager); const info = journal.getInfo(cryptoManager);
let colorBox: React.ReactNode; let colorBox: React.ReactElement | undefined;
switch (info.type) { switch (info.type) {
case 'CALENDAR': case 'CALENDAR':
case 'TASKS': case 'TASKS':

@ -31,7 +31,7 @@ export default function JournalsList(props: PropsType) {
const keyPair = userInfo.getKeyPair(userInfo.getCryptoManager(derived)); const keyPair = userInfo.getKeyPair(userInfo.getCryptoManager(derived));
const cryptoManager = journal.getCryptoManager(derived, keyPair); const cryptoManager = journal.getCryptoManager(derived, keyPair);
const info = journal.getInfo(cryptoManager); const info = journal.getInfo(cryptoManager);
let colorBox: React.ReactNode; let colorBox: React.ReactElement | undefined;
switch (info.type) { switch (info.type) {
case 'CALENDAR': case 'CALENDAR':
case 'TASKS': case 'TASKS':

@ -1,82 +0,0 @@
.List {
list-style: none;
padding: 0;
}
.ListItem {
padding: 0 10px;
display: flex;
align-items: center;
height: 60px;
}
.ListItem-href {
display: flex;
align-items: center;
width: 100%;
height: 100%;
color: inherit;
text-decoration: none;
border: none;
}
.ListItem-href:visited, .ListItem-href:active, .ListItem-href:focus {
color: inherit;
outline: 0;
}
.ListItem .ListIconLeft {
margin-left: 5px;
margin-right: 20px;
margin-top: 8px;
margin-bottom: 8px;
}
.ListItem .ListIconRight {
margin-left: auto;
margin-right: 5px;
margin-top: 8px;
margin-bottom: 8px;
}
.ListItem-Item:hover {
background-color: rgba(0, 0, 0, 0.1);
}
.ListItem-inset {
margin-left: 49px;
}
.ListItem-nested-holder {
margin-left: 20px;
}
.ListItem-text-holder {
display: flex;
flex-direction: column;
}
.ListItem-primary-text {
}
.ListItem-secondary-text {
margin-top: 1px;
font-size: 85%;
color: rgba(0, 0, 0, 0.54);
}
.ListSubheader {
font-size: 90%;
color: rgba(0, 0, 0, 0.54);
}
.ListDivider {
height: 1px;
border: medium none;
background-color: rgb(224, 224, 224);
}
.ListDivider.ListDivider-inset {
margin-left: 59px;
}

@ -3,119 +3,98 @@
import * as React from 'react'; import * as React from 'react';
import { createStyles, makeStyles } from '@material-ui/core/styles';
import MuiList from '@material-ui/core/List';
import MuiListItem from '@material-ui/core/ListItem';
import MuiListSubheader from '@material-ui/core/ListSubheader';
import ListItemIcon from '@material-ui/core/ListItemIcon';
import ListItemText from '@material-ui/core/ListItemText';
import Divider from '@material-ui/core/Divider';
import ExternalLink from './ExternalLink'; import ExternalLink from './ExternalLink';
import './List.css'; const useStyles = makeStyles((theme) => (createStyles({
inset: {
marginLeft: 64,
},
nested: {
paddingLeft: theme.spacing(4),
},
})));
export const List = React.memo((props: { children: React.ReactNode[] | React.ReactNode }) => ( export const List = MuiList;
<ul className="List">
{props.children}
</ul>
));
export const ListItemRaw = React.memo((_props: any) => { export const ListSubheader = MuiListSubheader;
const {
href,
children,
nestedItems,
insetChildren,
...props
} = _props;
const inner = href ?
(
<ExternalLink href={href} className="ListItem-href">
{children}
</ExternalLink>
) :
children
;
const nestedContent = nestedItems ?
(
<List>
{nestedItems}
</List>
) :
undefined
;
export const ListDivider = React.memo(function ListDivider(props: { inset?: boolean }) {
const classes = useStyles();
const insetClass = (props.inset) ? classes.inset : undefined;
return ( return (
<React.Fragment> <Divider className={insetClass} />
<li
{...props}
className={'ListItem ListItem-Item ' + ((insetChildren) ? 'ListItem-inset' : '')}
>
{inner}
</li>
<li className="ListItem-nested-holder">
{nestedContent}
</li>
</React.Fragment>
); );
}); });
export const ListSubheader = React.memo((props: any) => ( interface ListItemPropsType {
<li leftIcon?: React.ReactElement;
{...props} rightIcon?: React.ReactElement;
className="ListItem ListSubheader" style?: React.CSSProperties;
> primaryText?: string;
{props.children} secondaryText?: string;
</li> children?: React.ReactNode | React.ReactNode[];
)); onClick?: () => void;
href?: string;
export const ListDivider = React.memo((_props: any) => { insetChildren?: boolean;
const { nestedItems?: React.ReactNode[];
inset, }
...props
} = _props; export const ListItem = React.memo(function ListItem(_props: ListItemPropsType) {
return ( const classes = useStyles();
<li>
<hr className={'ListDivider ' + (inset ? 'ListDivider-inset' : '')} {...props} />
</li>
);
});
export const ListItem = React.memo((_props: any) => {
const { const {
leftIcon, leftIcon,
rightIcon, rightIcon,
primaryText, primaryText,
secondaryText, secondaryText,
children, children,
onClick,
href,
style, style,
...props insetChildren,
nestedItems,
} = _props; } = _props;
const leftIconHolder = (leftIcon) ? ( const extraProps = (onClick || href) ? {
<div className="ListIconLeft">{leftIcon}</div> button: true,
) : undefined; href,
onClick,
const rightIconHolder = (rightIcon) ? ( component: (href) ? ExternalLink : 'div',
<div className="ListIconRight">{rightIcon}</div> } : undefined;
) : undefined;
let textHolder = primaryText;
if (secondaryText) {
textHolder = (
<div className="ListItem-text-holder">
<span className="ListItem-primary-text">{primaryText}</span>
<span className="ListItem-secondary-text">{secondaryText}</span>
</div>
);
}
const pressedStyle = (_props.onClick) ? { cursor: 'pointer' } : undefined;
return ( return (
<ListItemRaw <>
style={{ ...pressedStyle, ...style }} <MuiListItem
{...props} style={style}
> onClick={onClick}
{leftIconHolder} {...(extraProps as any)}
{textHolder} >
{children} {leftIcon && (
{rightIconHolder} <ListItemIcon>
</ListItemRaw> {leftIcon}
</ListItemIcon>
)}
<ListItemText inset={insetChildren} primary={primaryText} secondary={secondaryText}>
{children}
</ListItemText>
{rightIcon && (
<ListItemIcon>
{rightIcon}
</ListItemIcon>
)}
</MuiListItem>
{nestedItems && (
<List className={classes.nested} disablePadding>
{nestedItems}
</List>
)}
</>
); );
}); });

Loading…
Cancel
Save