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

144 lines
3.5 KiB
TypeScript
Raw Normal View History

Bump macaw to 0.3 (#1807) * Update to new design theme (#1631) * Update macaw to 0.3.0 (#1623) * Update macaw to 0.3 * Use proper pagination component * Fix type errors * Remove leftover import * Remove variant and color from confirm button * Remove alias * Update macaw * Fix button type * Random fixes (#1633) * Improve layout components * Use colored svgs * Minor fixes * Fix autocomplete loaders * Fix padding * Fix button variant * Remove codegen file * Fixes after bumping macaw to 0.3 part 2 (#1638) * Fix various visual bugs * Fix type errors * Bump macaw * Random fixes part 3 (#1647) * wip * Fix mismatched paddings * Fix actions container padding * Put story in the right directory * Fix shipping zone picker * Fix minor visual bugs * Remove unused imports * Move styles to separate file * Random fixes part 4 (#1641) * Fix various visual bugs * Fix type errors * Fix last table item padding * Add outline on hover * Fix spaces * Fix spaces * Remove dead code * Fix elevation * Remove dead code * Fix shadows * Add outline to expand button * Fix spacing * Fix spacings * Fix selectable tables hover * Use proper delete icon * Fix ConfirmButtonTransitionState imports * Update src/apps/components/CustomApps/CustomApps.tsx Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> * Rework error page (#1670) * Remake error page * Fix types * Update error id styles * Fix types * Login page rework (#1703) * Rework login page * Remove outline * Fix logo and footer placement * Sort imports * Random fixes part 5 (#1669) * Fix text color in dark mode * Update password reset pages (#1714) * Update password reset pages * Update src/auth/components/ResetPasswordPage/ResetPasswordPage.tsx Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix collection page * Update dark mode logo * Bring back "create app" button * Fix spacings * Fix selects * Fix login e2e test * Fix not found page displaying * Update selector * Add missing package * Let dropdown overflow through card * Fix scroll * Fix scroll * Fix overflow on grid element * Fix e2e tests * Fix data-test-id * Update snapshots * Update messages * Update macaw * Update snapshots * Use stable macaw version Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Update to new design theme (#1631) * Update macaw to 0.3.0 (#1623) * Update macaw to 0.3 * Use proper pagination component * Fix type errors * Remove leftover import * Remove variant and color from confirm button * Remove alias * Update macaw * Fix button type * Random fixes (#1633) * Improve layout components * Use colored svgs * Minor fixes * Fix autocomplete loaders * Fix padding * Fix button variant * Remove codegen file * Fixes after bumping macaw to 0.3 part 2 (#1638) * Fix various visual bugs * Fix type errors * Bump macaw * Random fixes part 3 (#1647) * wip * Fix mismatched paddings * Fix actions container padding * Put story in the right directory * Fix shipping zone picker * Fix minor visual bugs * Remove unused imports * Move styles to separate file * Random fixes part 4 (#1641) * Fix various visual bugs * Fix type errors * Fix last table item padding * Add outline on hover * Fix spaces * Fix spaces * Remove dead code * Fix elevation * Remove dead code * Fix shadows * Add outline to expand button * Fix spacing * Fix spacings * Fix selectable tables hover * Use proper delete icon * Fix ConfirmButtonTransitionState imports * Update src/apps/components/CustomApps/CustomApps.tsx Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> * Rework error page (#1670) * Remake error page * Fix types * Update error id styles * Fix types * Login page rework (#1703) * Rework login page * Remove outline * Fix logo and footer placement * Sort imports * Random fixes part 5 (#1669) * Fix text color in dark mode * Update password reset pages (#1714) * Update password reset pages * Update src/auth/components/ResetPasswordPage/ResetPasswordPage.tsx Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix collection page * Update dark mode logo * Bring back "create app" button * Fix spacings * Fix selects * Fix login e2e test * Fix not found page displaying * Update selector * Add missing package * Let dropdown overflow through card * Fix scroll * Fix scroll * Fix overflow on grid element * Fix e2e tests * Fix data-test-id * Update snapshots * Update messages * Update macaw * Update snapshots * Use stable macaw version Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix visual bugs and artifacts * Fix dropdown menus being clipped (#1762) * wip * Fix clipped select menus * Remove unused import * Fix spacing * Fix tests * Fix select content appearing under dialogs (#1777) * Fix type errors * Fix bulk delete button placement * Fix filter arrow buttons * Fix messages * Remove backling from pages list * Move status above events * Update messages and snapshots Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
2022-01-28 12:34:20 +00:00
import { CircularProgress } from "@material-ui/core";
import { IconButton } from "@saleor/components/IconButton";
import { DeleteIcon, EditIcon, makeStyles } from "@saleor/macaw-ui";
2019-11-28 15:17:39 +00:00
import classNames from "classnames";
import React from "react";
2019-06-19 14:40:52 +00:00
2019-12-03 15:28:40 +00:00
const useStyles = makeStyles(
theme => ({
media: {
2019-12-03 15:28:40 +00:00
height: "100%",
objectFit: "contain",
userSelect: "none",
width: "100%"
},
mediaContainer: {
2019-12-03 15:28:40 +00:00
"&:hover, &.dragged": {
"& $mediaOverlay": {
2019-12-03 15:28:40 +00:00
display: "block"
}
},
background: theme.palette.background.paper,
border: `1px solid ${theme.palette.divider}`,
borderRadius: theme.spacing(),
height: 148,
overflow: "hidden",
padding: theme.spacing(2),
position: "relative",
width: 148
},
mediaOverlay: {
background: theme.palette.background.default,
opacity: 0.8,
2019-12-03 15:28:40 +00:00
cursor: "move",
display: "none",
height: 148,
left: 0,
position: "absolute",
top: 0,
width: 148
},
mediaOverlayShadow: {
"&mediaOverlay": {
2019-12-03 15:28:40 +00:00
alignItems: "center",
display: "flex",
justifyContent: "center"
2019-10-30 14:34:24 +00:00
}
2019-06-19 14:40:52 +00:00
},
mediaOverlayToolbar: {
2019-11-28 15:17:39 +00:00
display: "flex",
2019-12-03 15:28:40 +00:00
justifyContent: "flex-end"
},
controlButton: {
color: theme.palette.saleor.main[1],
backgroundColor: "transparent",
border: "none",
cursor: "pointer",
margin: theme.spacing(2),
padding: 0,
"&:hover": {
color: theme.palette.saleor.active[1]
},
"&:first-child": {
marginRight: 0
}
2019-11-28 15:17:39 +00:00
}
2019-12-03 15:28:40 +00:00
}),
{ name: "MediaTile" }
2019-12-03 15:28:40 +00:00
);
2019-06-19 14:40:52 +00:00
interface MediaTileBaseProps {
media: {
alt: string;
2019-06-19 14:40:52 +00:00
url: string;
type?: string;
oembedData?: string;
2019-06-19 14:40:52 +00:00
};
2019-11-28 15:17:39 +00:00
loading?: boolean;
onDelete?: () => void;
onEdit?: (event: React.ChangeEvent<any>) => void;
2019-06-19 14:40:52 +00:00
}
export type MediaTileProps = MediaTileBaseProps &
(
| {
onEdit?: React.MouseEventHandler<HTMLButtonElement>;
editHref?: never;
}
| {
onEdit?: never;
editHref?: string;
}
);
const MediaTile: React.FC<MediaTileProps> = props => {
const { loading, onDelete, onEdit, editHref, media } = props;
2019-10-30 14:34:24 +00:00
const classes = useStyles(props);
const parsedMediaOembedData = media?.oembedData
? JSON.parse(media.oembedData)
: null;
const mediaUrl = parsedMediaOembedData?.thumbnail_url || media.url;
2019-10-30 14:34:24 +00:00
return (
<div className={classes.mediaContainer} data-test-id="product-image">
2019-11-28 15:17:39 +00:00
<div
className={classNames(classes.mediaOverlay, {
[classes.mediaOverlayShadow]: loading
2019-11-28 15:17:39 +00:00
})}
>
{loading ? (
<CircularProgress size={32} />
) : (
<div className={classes.mediaOverlayToolbar}>
{(onEdit || editHref) && (
<IconButton
href={editHref}
hoverOutline={false}
variant="secondary"
className={classes.controlButton}
onClick={onEdit}
>
2019-11-28 15:17:39 +00:00
<EditIcon />
</IconButton>
2019-11-28 15:17:39 +00:00
)}
{onDelete && (
<IconButton
variant="secondary"
hoverOutline={false}
className={classes.controlButton}
onClick={onDelete}
>
2019-11-28 15:17:39 +00:00
<DeleteIcon />
</IconButton>
2019-11-28 15:17:39 +00:00
)}
</div>
)}
2019-06-19 14:40:52 +00:00
</div>
<img className={classes.media} src={mediaUrl} alt={media.alt} />
2019-06-19 14:40:52 +00:00
</div>
2019-10-30 14:34:24 +00:00
);
};
MediaTile.displayName = "MediaTile";
export default MediaTile;