-
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.
[#220] add styling for DRepCard in default state
- Loading branch information
1 parent
906e094
commit 4985a75
Showing
8 changed files
with
324 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Chip, ChipProps, styled } from "@mui/material"; | ||
import { cyan, errorRed, successGreen } from "@/consts"; | ||
|
||
type Status = 'active' | 'retired' | 'inactive'; | ||
|
||
interface StatusPillProps { | ||
status: Status; | ||
label?: string; | ||
size?: 'small' | 'medium'; | ||
sx?: ChipProps['sx']; | ||
} | ||
|
||
export const StatusPill = ({ | ||
status, | ||
label = status, | ||
size = 'small', | ||
sx | ||
}: StatusPillProps) => ( | ||
<StyledChip | ||
status={status} | ||
size={size} | ||
label={label} | ||
sx={sx} | ||
/> | ||
); | ||
|
||
const getBgColor = (status: Status): string => { | ||
switch (status) { | ||
case 'active': | ||
return successGreen.c200; | ||
case 'retired': | ||
return errorRed.c100; | ||
case 'inactive': | ||
return cyan.c100; | ||
// no default | ||
} | ||
}; | ||
|
||
const getTextColor = (status: Status): string => { | ||
switch (status) { | ||
case 'active': | ||
return successGreen.c700; | ||
case 'retired': | ||
return errorRed.c500; | ||
case 'inactive': | ||
return cyan.c500; | ||
// no default | ||
} | ||
}; | ||
|
||
const StyledChip = styled(Chip)<{ status: Status }>(({ theme, status }) => ({ | ||
backgroundColor: getBgColor(status), | ||
color: getTextColor(status), | ||
border: `2px solid ${theme.palette.neutralWhite}`, | ||
fontSize: '0.75rem', | ||
textTransform: 'capitalize', | ||
})); |
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 |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import { useNavigate } from "react-router-dom"; | ||
import { Box, ButtonBase, Divider } from "@mui/material"; | ||
|
||
import { useTranslation } from "@hooks"; | ||
import { Button, StatusPill, Typography } from "@atoms"; | ||
import { Card } from "@molecules"; | ||
import { correctAdaFormat } from "@/utils"; | ||
import { ICONS } from "@/consts"; | ||
|
||
export const DRepCard = ({ | ||
isConnected, | ||
name, | ||
id, | ||
votingPower, | ||
status, | ||
}: any) => { | ||
const navigate = useNavigate(); | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<Card sx={{ container: "root / inline-size", py: 2.5 }}> | ||
<Box | ||
display="flex" | ||
flexDirection="column" | ||
rowGap={4} | ||
columnGap={6} | ||
sx={{ | ||
"@container root (min-width: 480px)": { | ||
flexDirection: "row", | ||
}, | ||
}} | ||
> | ||
<Box flex={2} minWidth={0} sx={{ containerType: "inline-size" }}> | ||
<Box | ||
display="flex" | ||
flexDirection="column" | ||
rowGap={3} | ||
columnGap={6} | ||
sx={{ | ||
"@container (min-width: 480px)": { | ||
flexDirection: "row", | ||
alignItems: "center", | ||
}, | ||
containerType: "inline-size", | ||
}} | ||
> | ||
<Box flex={1} minWidth={0}> | ||
<Typography sx={ellipsisStyles}>{name}</Typography> | ||
<ButtonBase | ||
sx={{ | ||
gap: 1, | ||
maxWidth: "100%", | ||
"&:hover": { | ||
opacity: 0.6, | ||
transition: "opacity 0.3s", | ||
}, | ||
}} | ||
> | ||
<Typography color="primary" variant="body2" sx={ellipsisStyles}> | ||
{id} | ||
</Typography> | ||
<img alt="" src={ICONS.copyBlueIcon} /> | ||
</ButtonBase> | ||
</Box> | ||
|
||
<Box display="flex" gap={3}> | ||
<Box maxWidth={100}> | ||
<Typography | ||
variant="caption" | ||
color="textSecondary" | ||
sx={{ mb: 0.5 }} | ||
> | ||
{t("votingPower")} | ||
</Typography> | ||
<Typography sx={{ whiteSpace: "nowrap" }}> | ||
₳ | ||
{' '} | ||
{correctAdaFormat(votingPower)} | ||
</Typography> | ||
</Box> | ||
<Divider | ||
orientation="vertical" | ||
flexItem | ||
sx={({ palette }) => ({ borderColor: palette.lightBlue })} | ||
/> | ||
<Box> | ||
<Typography | ||
variant="caption" | ||
color="textSecondary" | ||
sx={{ mb: 0.5 }} | ||
> | ||
{t("status")} | ||
</Typography> | ||
<StatusPill status={status} sx={{ width: 80 }} /> | ||
</Box> | ||
</Box> | ||
</Box> | ||
</Box> | ||
|
||
<Box | ||
display="flex" | ||
flex={1} | ||
gap={2.5} | ||
minWidth={isConnected ? 233 : 310} | ||
sx={{ | ||
"@container root (min-width: 480px)": { | ||
justifyContent: "flex-end", | ||
}, | ||
}} | ||
> | ||
<Button variant="outlined" onClick={() => navigate(`/drep/${id}`)}> | ||
{t("viewDetails")} | ||
</Button> | ||
{status === "active" && isConnected && ( | ||
<Button>{t("delegate")}</Button> | ||
)} | ||
{status === "active" && !isConnected && ( | ||
<Button>{t("connectToDelegate")}</Button> | ||
)} | ||
</Box> | ||
</Box> | ||
</Card> | ||
); | ||
}; | ||
|
||
const ellipsisStyles = { | ||
overflow: "hidden", | ||
textOverflow: "ellipsis", | ||
whiteSpace: "nowrap", | ||
} as const; |
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,10 +1,105 @@ | ||
import { Box } from "@mui/material"; | ||
import { FC } from "react"; | ||
import { AutomatedVotingOptions } from "@organisms"; | ||
import { AutomatedVotingOptions, DRepCard } from "@organisms"; | ||
import { Typography } from "@atoms"; | ||
import { Trans, useTranslation } from "react-i18next"; | ||
|
||
interface DRepDirectoryContentProps { | ||
isConnected?: boolean; | ||
} | ||
|
||
export const DRepDirectoryContent: FC<DRepDirectoryContentProps> = ({ | ||
isConnected, | ||
}) => <>{isConnected && <AutomatedVotingOptions />}</>; | ||
}) => { | ||
const { t } = useTranslation(); | ||
|
||
const ada = 1234567; | ||
|
||
return ( | ||
<Box display="flex" flexDirection="column" gap={4}> | ||
{isConnected && ( | ||
<div> | ||
<Typography variant="title2" sx={{ mb: 2 }}> | ||
<Trans i18nKey="dRepDirectory.myDelegation" values={{ ada }} /> | ||
</Typography> | ||
<DRepCard key={data[0]} isConnected={isConnected} {...data[0]} /> | ||
</div> | ||
)} | ||
|
||
{isConnected && ( | ||
<div> | ||
<Typography variant="title2" sx={{ mb: 2 }}>{t("dRepDirectory.delegationOptions")}</Typography> | ||
<AutomatedVotingOptions /> | ||
</div> | ||
)} | ||
|
||
<div> | ||
<Typography fontSize={18} fontWeight={500}>{t("dRepDirectory.listTitle")}</Typography> | ||
<Box component="ul" p={0} display="flex" flexDirection="column" gap={3}> | ||
{data.map((dRep) => ( | ||
<Box key={dRep.id} component="li" sx={{ listStyle: "none" }}> | ||
<DRepCard key={dRep.id} isConnected={isConnected} {...dRep} /> | ||
</Box> | ||
))} | ||
</Box> | ||
</div> | ||
</Box> | ||
); | ||
}; | ||
|
||
const data = [ | ||
{ | ||
name: "DRep 1", | ||
id: "1kejngelrngekngeriogj3io4j3gnd3", | ||
votingPower: 3000000, | ||
status: "active", | ||
}, | ||
{ | ||
name: "DRep 2", | ||
id: "1kejrngelrngekngeriogfrej3io4fj3gn3", | ||
votingPower: 10000000, | ||
status: "active", | ||
}, | ||
{ | ||
name: "DRep 1", | ||
id: "1kejngelrngekngeriogj3io4j3gnd3", | ||
votingPower: 1000000, | ||
status: "active", | ||
}, | ||
{ | ||
name: "DRep 2", | ||
id: "1kejrngelrngekngeriogfrej3io4fj3gn3", | ||
votingPower: 9900000000000000, | ||
status: "active", | ||
}, | ||
{ | ||
name: "DRep 1", | ||
id: "1kejngelrngekngeriogj3io4j3gn3", | ||
votingPower: 12345678, | ||
status: "active", | ||
}, | ||
{ | ||
name: "DRep 2", | ||
id: "1kejrngelrngekngeriogfrej3io4j3gn3", | ||
votingPower: 1234567800, | ||
status: "active", | ||
}, | ||
{ | ||
name: "DRep 4", | ||
id: "1kejrngelkngeriogj3io4j3gn3", | ||
votingPower: 12345678000000, | ||
status: "retired", | ||
}, | ||
{ | ||
name: "DRep 3", | ||
id: "1kejrngelrngekngeriogj3io4j3gn2", | ||
votingPower: 123456, | ||
status: "active", | ||
}, | ||
{ | ||
name: "Some dreps can have a very long name and it will be displayed correctly", | ||
id: "1kejrngelrngekngeriogj3io4j3gn3", | ||
votingPower: 123456, | ||
status: "inactive", | ||
}, | ||
]; |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import { StatusPill } from "@atoms"; | ||
|
||
const meta = { | ||
title: "Example/StatusPill", | ||
component: StatusPill, | ||
parameters: { | ||
layout: "centered", | ||
}, | ||
tags: ["autodocs"], | ||
} satisfies Meta<typeof StatusPill>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const StatusPillActive: Story = { | ||
args: { | ||
status: "active", | ||
}, | ||
}; | ||
|
||
export const StatusPillInactive: Story = { | ||
args: { | ||
status: "inactive", | ||
}, | ||
}; | ||
|
||
export const StatusPillRetired: Story = { | ||
args: { | ||
status: "retired", | ||
}, | ||
}; |