-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
styles(media): adjustments from design feedback
- Loading branch information
Showing
6 changed files
with
165 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,142 @@ | ||
import { | ||
LinkBox, | ||
LinkOverlay, | ||
Icon, | ||
Text, | ||
Divider, | ||
HStack, | ||
Box, | ||
} from "@chakra-ui/react" | ||
import { Box, Divider, HStack, Icon, Text } from "@chakra-ui/react" | ||
import { Checkbox } from "@opengovsg/design-system-react" | ||
import { BiChevronRight, BiEditAlt, BiFolder, BiTrash } from "react-icons/bi" | ||
import { Link as RouterLink, useRouteMatch } from "react-router-dom" | ||
|
||
import { Card, CardBody } from "components/Card" | ||
import { ContextMenu } from "components/ContextMenu" | ||
|
||
import useRedirectHook from "hooks/useRedirectHook" | ||
|
||
import { BxFileArchiveSolid } from "assets" | ||
|
||
interface FilePreviewCardProps { | ||
name: string | ||
isSelected: boolean | ||
isMenuNeeded?: boolean | ||
onOpen?: () => void | ||
onClick?: () => void | ||
onCheck?: () => void | ||
onDelete?: () => void | ||
onMove?: () => void | ||
} | ||
|
||
export const FilePreviewCard = ({ | ||
name, | ||
isSelected, | ||
isMenuNeeded = true, | ||
onOpen, | ||
onClick, | ||
onCheck, | ||
onDelete, | ||
onMove, | ||
}: FilePreviewCardProps): JSX.Element => { | ||
const { url } = useRouteMatch() | ||
const { setRedirectToPage } = useRedirectHook() | ||
const encodedName = encodeURIComponent(name) | ||
|
||
return ( | ||
<Box position="relative" h="100%"> | ||
<LinkBox position="relative" h="100%"> | ||
<LinkOverlay | ||
as={RouterLink} | ||
to={`${url}/editMediaSettings/${encodedName}`} | ||
<Box position="relative" h="100%" data-group> | ||
{/* Checkbox overlay */} | ||
<Checkbox | ||
position="absolute" | ||
left="1rem" | ||
top="0.5rem" | ||
h="3.25rem" | ||
w="3.25rem" | ||
size="md" | ||
p="1rem" | ||
variant="transparent" | ||
display={isSelected ? "inline-block" : "none"} | ||
_groupHover={{ | ||
bg: "transparent", | ||
display: "inline-block", | ||
}} | ||
_focusWithin={{ | ||
outline: "none", | ||
}} | ||
zIndex={1} | ||
isChecked={isSelected} | ||
onChange={() => { | ||
if (onCheck) onCheck() | ||
}} | ||
/> | ||
|
||
<Box | ||
position="relative" | ||
h="100%" | ||
_hover={{ bg: undefined }} | ||
onClick={(e) => { | ||
// For some weird reason, the onClick event is treated as a submit event | ||
// We can safely disable the default behaviour here since we define the | ||
// onClick behaviour ourselves | ||
e.preventDefault() | ||
|
||
if (onClick) { | ||
onClick() | ||
} else { | ||
setRedirectToPage(`${url}/editMediaSettings/${encodedName}`) | ||
} | ||
}} | ||
> | ||
<Card | ||
variant="multi" | ||
_groupHover={{ bg: "interaction.muted.main-hover" }} | ||
> | ||
<Card variant="multi"> | ||
<CardBody> | ||
<Icon as={BxFileArchiveSolid} fontSize="1.5rem" fill="icon.alt" /> | ||
<Text textStyle="body-1" color="text.label" noOfLines={3}> | ||
{name} | ||
</Text> | ||
</CardBody> | ||
</Card> | ||
</LinkOverlay> | ||
</LinkBox> | ||
<ContextMenu onOpen={onOpen}> | ||
<ContextMenu.Button /> | ||
<ContextMenu.List> | ||
<ContextMenu.Item | ||
icon={<BiEditAlt />} | ||
as={RouterLink} | ||
to={`${url}/editMediaSettings/${encodedName}`} | ||
> | ||
<Text>Edit details</Text> | ||
</ContextMenu.Item> | ||
<ContextMenu.Item icon={<BiFolder />} onClick={onMove}> | ||
<HStack spacing="4rem" alignItems="center"> | ||
<Text>Move to</Text> | ||
<Icon as={BiChevronRight} fontSize="1.25rem" /> | ||
</HStack> | ||
</ContextMenu.Item> | ||
<> | ||
<Divider /> | ||
<CardBody> | ||
{!isSelected && ( | ||
<Icon | ||
as={BxFileArchiveSolid} | ||
fontSize="1.5rem" | ||
fill="icon.alt" | ||
_groupHover={{ | ||
display: "none", | ||
}} | ||
/> | ||
)} | ||
<Text | ||
textStyle="body-1" | ||
color="text.label" | ||
noOfLines={3} | ||
ml={isSelected ? "2.5rem" : 0} | ||
_groupHover={{ marginLeft: "2.5rem" }} | ||
> | ||
{name} | ||
</Text> | ||
</CardBody> | ||
</Card> | ||
</Box> | ||
|
||
{isMenuNeeded && ( | ||
<ContextMenu onOpen={onOpen}> | ||
<ContextMenu.Button /> | ||
<ContextMenu.List> | ||
<ContextMenu.Item | ||
icon={<BiTrash />} | ||
color="interaction.critical.default" | ||
onClick={onDelete} | ||
icon={<BiEditAlt />} | ||
as={RouterLink} | ||
to={`${url}/editMediaSettings/${encodedName}`} | ||
> | ||
Delete file | ||
<Text>Edit details</Text> | ||
</ContextMenu.Item> | ||
<ContextMenu.Item icon={<BiFolder />} onClick={onMove}> | ||
<HStack spacing="4rem" alignItems="center"> | ||
<Text>Move to</Text> | ||
<Icon as={BiChevronRight} fontSize="1.25rem" /> | ||
</HStack> | ||
</ContextMenu.Item> | ||
</> | ||
</ContextMenu.List> | ||
</ContextMenu> | ||
<> | ||
<Divider /> | ||
<ContextMenu.Item | ||
icon={<BiTrash />} | ||
color="interaction.critical.default" | ||
onClick={onDelete} | ||
> | ||
Delete file | ||
</ContextMenu.Item> | ||
</> | ||
</ContextMenu.List> | ||
</ContextMenu> | ||
)} | ||
</Box> | ||
) | ||
} |