saleor-dashboard/src/components/TableCellAvatar/TableCellAvatar.tsx

81 lines
2 KiB
TypeScript
Raw Normal View History

2019-06-19 14:40:52 +00:00
import Avatar from "@material-ui/core/Avatar";
import {
createStyles,
Theme,
withStyles,
WithStyles
} from "@material-ui/core/styles";
import TableCell from "@material-ui/core/TableCell";
import Cached from "@material-ui/icons/Cached";
2019-08-09 11:14:35 +00:00
import classNames from "classnames";
2019-08-09 10:26:22 +00:00
import React from "react";
2019-06-19 14:40:52 +00:00
import Image from "../../icons/Image";
2019-08-09 11:14:35 +00:00
export const AVATAR_MARGIN = 56;
2019-06-19 14:40:52 +00:00
const styles = (theme: Theme) =>
createStyles({
avatar: {
background: "none",
border: `1px solid ${theme.overrides.MuiCard.root.borderColor}`,
borderRadius: 2,
color: "#bdbdbd",
2019-08-09 11:14:35 +00:00
display: "inline-flex",
2019-06-19 14:40:52 +00:00
padding: theme.spacing.unit / 2
},
2019-08-09 11:14:35 +00:00
children: {
alignSelf: "center",
marginLeft: theme.spacing.unit * 2,
width: "100%"
2019-08-09 11:14:35 +00:00
},
content: {
alignItems: "center",
display: "flex"
},
2019-06-19 14:40:52 +00:00
root: {
paddingRight: theme.spacing.unit * 3,
width: "1%"
}
});
interface TableCellAvatarProps extends WithStyles<typeof styles> {
className?: string;
thumbnail?: string;
avatarProps?: string;
2019-08-09 11:14:35 +00:00
children?: React.ReactNode | React.ReactNodeArray;
2019-06-19 14:40:52 +00:00
}
const TableCellAvatar = withStyles(styles, { name: "TableCellAvatar" })(
2019-08-09 11:14:35 +00:00
({
classes,
children,
className,
thumbnail,
2019-09-27 13:42:16 +00:00
avatarProps,
...props
2019-08-09 11:14:35 +00:00
}: TableCellAvatarProps) => (
2019-09-27 13:42:16 +00:00
<TableCell className={classNames(classes.root, className)} {...props}>
2019-08-09 11:14:35 +00:00
<div className={classes.content}>
{thumbnail === undefined ? (
<Avatar className={classNames(classes.avatar, avatarProps)}>
<Cached color="primary" />
</Avatar>
) : thumbnail === null ? (
<Avatar className={classNames(classes.avatar, avatarProps)}>
<Image color="primary" />
</Avatar>
) : (
<Avatar
className={classNames(classes.avatar, avatarProps)}
src={thumbnail}
/>
)}
<div className={classes.children}>{children}</div>
2019-08-09 11:14:35 +00:00
</div>
2019-06-19 14:40:52 +00:00
</TableCell>
)
);
TableCellAvatar.displayName = "TableCellAvatar";
export default TableCellAvatar;