From 4985a75c17771f573dc111695692bb9caaaee281 Mon Sep 17 00:00:00 2001 From: Joanna Dyczka Date: Wed, 6 Mar 2024 22:53:52 +0100 Subject: [PATCH] [#220] add styling for DRepCard in default state --- .../frontend/src/components/atoms/Button.tsx | 1 + .../src/components/atoms/StatusPill.tsx | 57 ++++++++ .../frontend/src/components/atoms/index.ts | 1 + .../src/components/organisms/DRepCard.tsx | 130 ++++++++++++++++++ .../src/components/organisms/index.ts | 1 + govtool/frontend/src/i18n/locales/en.ts | 4 + .../src/pages/DRepDirectoryContent.tsx | 99 ++++++++++++- .../src/stories/StatusPill.stories.ts | 33 +++++ 8 files changed, 324 insertions(+), 2 deletions(-) create mode 100644 govtool/frontend/src/components/atoms/StatusPill.tsx create mode 100644 govtool/frontend/src/components/organisms/DRepCard.tsx create mode 100644 govtool/frontend/src/stories/StatusPill.stories.ts diff --git a/govtool/frontend/src/components/atoms/Button.tsx b/govtool/frontend/src/components/atoms/Button.tsx index 97b9f100e..5ce22bf48 100644 --- a/govtool/frontend/src/components/atoms/Button.tsx +++ b/govtool/frontend/src/components/atoms/Button.tsx @@ -19,6 +19,7 @@ export const Button = ({ sx={{ fontSize: size === "extraLarge" ? 16 : 14, height: buttonHeight, + whiteSpace: "nowrap", ...sx, }} variant={variant} diff --git a/govtool/frontend/src/components/atoms/StatusPill.tsx b/govtool/frontend/src/components/atoms/StatusPill.tsx new file mode 100644 index 000000000..60b70d049 --- /dev/null +++ b/govtool/frontend/src/components/atoms/StatusPill.tsx @@ -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) => ( + +); + +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', +})); diff --git a/govtool/frontend/src/components/atoms/index.ts b/govtool/frontend/src/components/atoms/index.ts index b91dec294..ceb4bc8db 100644 --- a/govtool/frontend/src/components/atoms/index.ts +++ b/govtool/frontend/src/components/atoms/index.ts @@ -22,6 +22,7 @@ export * from "./Radio"; export * from "./ScrollToManage"; export * from "./ScrollToTop"; export * from "./Spacer"; +export * from "./StatusPill"; export * from "./StakeRadio"; export * from "./TextArea"; export * from "./Tooltip"; diff --git a/govtool/frontend/src/components/organisms/DRepCard.tsx b/govtool/frontend/src/components/organisms/DRepCard.tsx new file mode 100644 index 000000000..43ce7a599 --- /dev/null +++ b/govtool/frontend/src/components/organisms/DRepCard.tsx @@ -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 ( + + + + + + {name} + + + {id} + + + + + + + + + {t("votingPower")} + + + ₳ + {' '} + {correctAdaFormat(votingPower)} + + + ({ borderColor: palette.lightBlue })} + /> + + + {t("status")} + + + + + + + + + + {status === "active" && isConnected && ( + + )} + {status === "active" && !isConnected && ( + + )} + + + + ); +}; + +const ellipsisStyles = { + overflow: "hidden", + textOverflow: "ellipsis", + whiteSpace: "nowrap", +} as const; diff --git a/govtool/frontend/src/components/organisms/index.ts b/govtool/frontend/src/components/organisms/index.ts index e6cf14e92..3b775bf2e 100644 --- a/govtool/frontend/src/components/organisms/index.ts +++ b/govtool/frontend/src/components/organisms/index.ts @@ -15,6 +15,7 @@ export * from "./DelegateTodRepStepOne"; export * from "./DelegateTodRepStepTwo"; export * from "./Drawer"; export * from "./DrawerMobile"; +export * from "./DRepCard"; export * from "./DRepDirectoryContent"; export * from "./EditDRepInfoSteps"; export * from "./ExternalLinkModal"; diff --git a/govtool/frontend/src/i18n/locales/en.ts b/govtool/frontend/src/i18n/locales/en.ts index e46168178..f47ff1c9f 100644 --- a/govtool/frontend/src/i18n/locales/en.ts +++ b/govtool/frontend/src/i18n/locales/en.ts @@ -254,8 +254,11 @@ export const en = { abstainCardTitle: "Abstain from Every Vote", automatedVotingOptions: "Automated Voting Options", editBtn: "Edit DRep data", + delegationOptions: "Delegation Options", meAsDRep: "This DRep ID is connected to your wallet", + myDelegation: "You have delegated ₳ {{ada}} to:", myDRep: "This is your DRep", + listTitle: "Find a DRep", noConfidenceDescription: "Select this to signal no confidence in the current constitutional committee by voting NO on every proposal and voting YES to no confidence proposals", noConfidenceTitle: "Signal No Confidence on Every Vote", @@ -751,6 +754,7 @@ export const en = { status: "Status", submit: "Submit", thisLink: "this link", + viewDetails: "View details", votingPower: "Voting power", yes: "Yes", }, diff --git a/govtool/frontend/src/pages/DRepDirectoryContent.tsx b/govtool/frontend/src/pages/DRepDirectoryContent.tsx index cb87558cb..b9db91afa 100644 --- a/govtool/frontend/src/pages/DRepDirectoryContent.tsx +++ b/govtool/frontend/src/pages/DRepDirectoryContent.tsx @@ -1,5 +1,8 @@ +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; @@ -7,4 +10,96 @@ interface DRepDirectoryContentProps { export const DRepDirectoryContent: FC = ({ isConnected, -}) => <>{isConnected && }; +}) => { + const { t } = useTranslation(); + + const ada = 1234567; + + return ( + + {isConnected && ( +
+ + + + +
+ )} + + {isConnected && ( +
+ {t("dRepDirectory.delegationOptions")} + +
+ )} + +
+ {t("dRepDirectory.listTitle")} + + {data.map((dRep) => ( + + + + ))} + +
+
+ ); +}; + +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", + }, +]; diff --git a/govtool/frontend/src/stories/StatusPill.stories.ts b/govtool/frontend/src/stories/StatusPill.stories.ts new file mode 100644 index 000000000..a26e09dc7 --- /dev/null +++ b/govtool/frontend/src/stories/StatusPill.stories.ts @@ -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; + +export default meta; +type Story = StoryObj; + +export const StatusPillActive: Story = { + args: { + status: "active", + }, +}; + +export const StatusPillInactive: Story = { + args: { + status: "inactive", + }, +}; + +export const StatusPillRetired: Story = { + args: { + status: "retired", + }, +};