From e65bd3dafaaf127c280054ee2ac22ed2a438f032 Mon Sep 17 00:00:00 2001 From: Ha Gia Phat Date: Tue, 14 Nov 2023 01:54:28 +0700 Subject: [PATCH] fix: asset list responsive style (#121) --- .../stories/asset/CrossChain.stories.tsx | 23 +- .../stories/asset/SingleChain.stories.tsx | 19 +- .../asset-list-header.css.ts | 33 --- .../asset-list-header.lite.tsx | 275 ++++++++++++------ .../asset-list-header.types.tsx | 31 +- src/ui/asset-list/asset-list.lite.tsx | 90 +++--- src/ui/asset-list/asset-list.types.tsx | 7 +- src/ui/cross-chain/cross-chain.css.ts | 5 - src/ui/cross-chain/cross-chain.lite.tsx | 18 +- src/ui/cross-chain/cross-chain.types.tsx | 12 +- src/ui/single-chain/single-chain.css.ts | 5 - src/ui/single-chain/single-chain.lite.tsx | 21 +- src/ui/single-chain/single-chain.types.tsx | 14 +- 13 files changed, 313 insertions(+), 240 deletions(-) delete mode 100644 src/ui/asset-list-header/asset-list-header.css.ts delete mode 100644 src/ui/cross-chain/cross-chain.css.ts delete mode 100644 src/ui/single-chain/single-chain.css.ts diff --git a/packages/react/stories/asset/CrossChain.stories.tsx b/packages/react/stories/asset/CrossChain.stories.tsx index 2959fde7..1540361f 100644 --- a/packages/react/stories/asset/CrossChain.stories.tsx +++ b/packages/react/stories/asset/CrossChain.stories.tsx @@ -15,16 +15,25 @@ type Story = StoryObj; export const Primary: Story = { args: { - header: { - total: "144.23", - totalOnAll: "732.16", - onDeposit: () => { - console.log("onDeposit"); + title: "Your assets", + multiChainHeader: [ + { + label: "Total on Osmosis", + value: "144.23", }, - onWithdraw: () => { - console.log("onWithdraw"); + { + label: "Total across all chains", + value: "732.16", }, + ], + onDeposit: () => { + console.log("onDeposit"); + }, + onWithdraw: () => { + console.log("onWithdraw"); }, + listTitle: "On Osmosis", + otherListTitle: "On other chains", list: [ { imgSrc: diff --git a/packages/react/stories/asset/SingleChain.stories.tsx b/packages/react/stories/asset/SingleChain.stories.tsx index 35063f7f..d4990196 100644 --- a/packages/react/stories/asset/SingleChain.stories.tsx +++ b/packages/react/stories/asset/SingleChain.stories.tsx @@ -15,14 +15,17 @@ type Story = StoryObj; export const Primary: Story = { args: { - header: { - total: "144.23", - onDeposit: () => { - console.log("onDeposit"); - }, - onWithdraw: () => { - console.log("onWithdraw"); - }, + title: "Your asset", + listTitle: "On Osmosis", + onDeposit: () => { + console.log("onDeposit"); + }, + onWithdraw: () => { + console.log("onWithdraw"); + }, + singleChainHeader: { + label: "Total on Osmosis", + value: "144.23", }, list: [ { diff --git a/src/ui/asset-list-header/asset-list-header.css.ts b/src/ui/asset-list-header/asset-list-header.css.ts deleted file mode 100644 index 74a2f160..00000000 --- a/src/ui/asset-list-header/asset-list-header.css.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { style } from "@vanilla-extract/css"; -import { themeVars } from "../../styles/themes.css"; - -export const assetListHeader = style({ - minWidth: "720px", - boxSizing: "border-box", -}); - -export const crossContainer = style([ - { - minHeight: "103px", - }, -]); - -export const card = style({ - padding: `0 ${themeVars.space[10]}`, - backgroundColor: themeVars.colors.cardBg, - width: "calc(100% / 3)", - borderRadius: themeVars.radii.lg, -}); - -export const crossBtn = style({ - width: "calc(100% / 3)", -}); - -export const singleContainer = style({ - boxSizing: "border-box", - width: "100%", - minHeight: themeVars.space[21], - padding: `0 ${themeVars.space[10]}`, - backgroundColor: themeVars.colors.cardBg, - borderRadius: themeVars.radii.lg, -}); diff --git a/src/ui/asset-list-header/asset-list-header.lite.tsx b/src/ui/asset-list-header/asset-list-header.lite.tsx index e8217d77..68536d2f 100644 --- a/src/ui/asset-list-header/asset-list-header.lite.tsx +++ b/src/ui/asset-list-header/asset-list-header.lite.tsx @@ -3,8 +3,7 @@ import Box from "../box"; import Stack from "../stack"; import Text from "../text"; import Button from "../button"; -import * as styles from "./asset-list-header.css"; -import { AssetListHeaderProps } from "./asset-list-header.types"; +import type { AssetListHeaderProps } from "./asset-list-header.types"; useMetadata({ rsc: { @@ -18,122 +17,214 @@ export default function AssetListHeader(props: AssetListHeaderProps) { }); return ( - - - - Your assets - + + {/* Title */} + + {props.title} + - - - - {(item, index: number) => ( + {/* Multi chain */} + + + + {(item, index: number) => ( + + + {item.label} + - - {item.text} - - - - $ - - - {item.value} - - + $ + + + {item.value} + - )} - + + )} + + + {/* ==== Buttons */} + + + + + + + + + + + + + + + {/* Single chain */} + + + + {props.singleChainHeader.label} - - - - - - + $ + + {props.singleChainHeader.value} + - - - - - Total on Osmosis - + - $ - - {props.total} - - - - - - - + + + + + - - - - - + + + + + ); } diff --git a/src/ui/asset-list-header/asset-list-header.types.tsx b/src/ui/asset-list-header/asset-list-header.types.tsx index 54f1d0e7..b7ad61ca 100644 --- a/src/ui/asset-list-header/asset-list-header.types.tsx +++ b/src/ui/asset-list-header/asset-list-header.types.tsx @@ -1,16 +1,21 @@ -export interface AssetListHeaderProps { - /** - * Sinlge chain or cross chain - */ - isSingle?: boolean; - /** - * Total on Osmosis - */ - total: string; - /** - * Total across all chains - */ - totalOnAll?: string; +import type { BaseComponentProps } from "../../models/components.model"; + +export type HeaderInfo = { + label: string; + value: string; +}; + +export type MultiChainHeader = [HeaderInfo, HeaderInfo]; + +export type SingleChainHeader = HeaderInfo; + +export interface AssetListHeaderProps extends BaseComponentProps { + title: string; + multiChainHeader?: MultiChainHeader; + singleChainHeader?: SingleChainHeader; + depositButtonLabel?: string; + withdrawButtonLabel?: string; onDeposit?: (event?: any) => void; onWithdraw?: (event?: any) => void; + attributes?: any; } diff --git a/src/ui/asset-list/asset-list.lite.tsx b/src/ui/asset-list/asset-list.lite.tsx index b012393c..9fa616c0 100644 --- a/src/ui/asset-list/asset-list.lite.tsx +++ b/src/ui/asset-list/asset-list.lite.tsx @@ -18,50 +18,56 @@ export default function AssetList(props: AssetListProps) { }); return ( - - - - - - Asset - - - - - Chain - - - - - Balance - + + + + + + Asset + + + + + Chain + + + + + Balance + + - - - - {(item: AssetListItemProps, index: number) => ( - - item?.onDeposit()} - onWithdraw={() => item?.onWithdraw()} - /> - - )} - - - + + + + {(item: AssetListItemProps, index: number) => ( + + item?.onDeposit()} + onWithdraw={() => item?.onWithdraw()} + /> + + )} + + + + ); } diff --git a/src/ui/asset-list/asset-list.types.tsx b/src/ui/asset-list/asset-list.types.tsx index 32eb9cd8..998a97da 100644 --- a/src/ui/asset-list/asset-list.types.tsx +++ b/src/ui/asset-list/asset-list.types.tsx @@ -1,6 +1,9 @@ -import { AssetListItemProps } from "../asset-list-item/asset-list-item.types"; -export interface AssetListProps { +import type { BaseComponentProps } from "../../models/components.model"; +import type { AssetListItemProps } from "../asset-list-item/asset-list-item.types"; + +export interface AssetListProps extends BaseComponentProps { isOtherChains: boolean; needChainSpace: boolean; list: AssetListItemProps[]; + attributes?: any; } diff --git a/src/ui/cross-chain/cross-chain.css.ts b/src/ui/cross-chain/cross-chain.css.ts deleted file mode 100644 index 520e581a..00000000 --- a/src/ui/cross-chain/cross-chain.css.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { style } from "@vanilla-extract/css"; - -export const container = style({ - minWidth: "720px", -}); diff --git a/src/ui/cross-chain/cross-chain.lite.tsx b/src/ui/cross-chain/cross-chain.lite.tsx index 70515ce2..776fc237 100644 --- a/src/ui/cross-chain/cross-chain.lite.tsx +++ b/src/ui/cross-chain/cross-chain.lite.tsx @@ -3,7 +3,6 @@ import AssetListHeader from "../asset-list-header"; import AssetList from "../asset-list"; import Box from "../box"; import Text from "../text"; -import * as styles from "./cross-chain.css"; import type { CrossChainProps } from "./cross-chain.types"; useMetadata({ @@ -14,13 +13,14 @@ useMetadata({ export default function CrossChain(props: CrossChainProps) { return ( - + props?.header?.onDeposit?.()} - onWithdraw={() => props?.header?.onWithdraw?.()} + title={props.title} + multiChainHeader={props.multiChainHeader} + depositButtonLabel={props.depositButtonLabel} + withdrawButtonLabel={props.withdrawButtonLabel} + onDeposit={() => props.onDeposit?.()} + onWithdraw={() => props.onWithdraw?.()} /> - On Osmosis + {props.listTitle} - On other chains + {props.otherListTitle} ; +import type { AssetListHeaderProps } from "../asset-list-header/asset-list-header.types"; +import type { AssetListItemProps } from "../asset-list-item/asset-list-item.types"; export type CrossChainListItemProps = Omit; -export interface CrossChainProps { - header: CrossChainHeaderProps; +export interface CrossChainProps + extends Omit { list: Array; + listTitle: string; otherList: Array; + otherListTitle: string; } diff --git a/src/ui/single-chain/single-chain.css.ts b/src/ui/single-chain/single-chain.css.ts deleted file mode 100644 index 520e581a..00000000 --- a/src/ui/single-chain/single-chain.css.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { style } from "@vanilla-extract/css"; - -export const container = style({ - minWidth: "720px", -}); diff --git a/src/ui/single-chain/single-chain.lite.tsx b/src/ui/single-chain/single-chain.lite.tsx index 8e6cc052..971a689f 100644 --- a/src/ui/single-chain/single-chain.lite.tsx +++ b/src/ui/single-chain/single-chain.lite.tsx @@ -4,8 +4,7 @@ import AssetList from "../asset-list"; import Box from "../box"; import Text from "../text"; import ShowMore from "../show-more"; -import * as styles from "./single-chain.css"; -import { SingleChainProps } from "./single-chain.types"; +import type { SingleChainProps } from "./single-chain.types"; useMetadata({ rsc: { @@ -15,22 +14,26 @@ useMetadata({ export default function SingleChain(props: SingleChainProps) { return ( - - + + props?.header?.onDeposit?.()} - onWithdraw={() => props?.header?.onWithdraw?.()} + title={props.title} + singleChainHeader={props.singleChainHeader} + depositButtonLabel={props.depositButtonLabel} + withdrawButtonLabel={props.withdrawButtonLabel} + onDeposit={() => props.onDeposit?.()} + onWithdraw={() => props.onWithdraw?.()} /> + - On Osmosis + {props.listTitle} + ; +import type { AssetListHeaderProps } from "../asset-list-header/asset-list-header.types"; +import type { AssetListItemProps } from "../asset-list-item/asset-list-item.types"; export type SingleChainListItemProps = Omit< AssetListItemProps, "isOtherChains" >; -export interface SingleChainProps { - header: SingleChainHeaderProps; +export interface SingleChainProps + extends Omit { list: Array; + listTitle: string; }