Skip to content

Commit f8ab3ee

Browse files
committed
feat: add simple version of asset input [LW-9231]
1 parent 674f6a6 commit f8ab3ee

File tree

7 files changed

+126
-7
lines changed

7 files changed

+126
-7
lines changed

src/design-system/asset-input/amount-input.component.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,25 @@ import React from 'react';
33
import { Box } from '../box';
44

55
import * as cx from './amount-input.css';
6+
import { AmountInputAlignments } from './amount-input.css';
67

78
interface Props {
9+
alignment?: AmountInputAlignments;
810
onChange?: (value: string) => void;
911
value?: string;
1012
id: string;
1113
}
1214

1315
export const AmountInput = ({
16+
alignment = AmountInputAlignments.right,
1417
onChange,
1518
value,
1619
id,
1720
}: Readonly<Props>): JSX.Element => {
1821
return (
1922
<Box className={cx.amountInputSizer} data-value={value}>
2023
<input
21-
className={cx.amountInput}
24+
className={cx.amountInput[alignment]}
2225
value={value}
2326
size={1}
2427
onChange={({ target }): void => onChange?.(target.value)}

src/design-system/asset-input/amount-input.css.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { styleVariants } from '@vanilla-extract/css';
2+
13
import { style, vars } from '../../design-tokens';
24
import { bold } from '../text/text.css';
35

@@ -20,12 +22,16 @@ export const amountInputSizer = style([
2022
},
2123
]);
2224

23-
export const amountInput = style([
25+
export enum AmountInputAlignments {
26+
left = 'left',
27+
right = 'right',
28+
}
29+
30+
const amountInputBase = style([
2431
inputTypography,
2532
bold,
2633
{
2734
gridArea: '1 / 2',
28-
textAlign: 'right',
2935
border: 'none',
3036
width: 'auto',
3137
background: 'none',
@@ -39,3 +45,18 @@ export const amountInput = style([
3945
},
4046
},
4147
]);
48+
49+
export const amountInput = styleVariants({
50+
left: [
51+
amountInputBase,
52+
{
53+
textAlign: AmountInputAlignments.left,
54+
},
55+
],
56+
right: [
57+
amountInputBase,
58+
{
59+
textAlign: AmountInputAlignments.right,
60+
},
61+
],
62+
});

src/design-system/asset-input/asset-input.stories.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import {
1313
ColorSchemaTable,
1414
} from '../decorators';
1515
import { Divider } from '../divider';
16-
import { Grid } from '../grid';
17-
import { Cell } from '../grid/cell.component';
16+
import { Cell, Grid } from '../grid';
1817

1918
import { AssetInput } from './asset-input.component';
2019
import { invalidState, validState } from './asset-input.fixtures';
2120
import { MaxButton } from './max-button.component';
21+
import { SimpleAssetInput } from './simple-asset-input.component';
2222

2323
import type { Asset, AssetState } from './asset-input.data';
2424

@@ -61,7 +61,12 @@ export const Overview = (): JSX.Element => (
6161
<Cell>
6262
<Section title="Overview">
6363
<Variants.Table
64-
headers={['Browser view — simple', 'Browser view — simple + error']}
64+
headers={[
65+
'Complex — valid',
66+
'Complex — invalid',
67+
'Simple - invalid',
68+
'Simple - invalid',
69+
]}
6570
>
6671
<Variants.Row>
6772
<Variants.Cell>
@@ -70,6 +75,18 @@ export const Overview = (): JSX.Element => (
7075
<Variants.Cell>
7176
<AssetInput state={invalidState('1')} />
7277
</Variants.Cell>
78+
<Variants.Cell>
79+
<SimpleAssetInput
80+
state={validState('1')}
81+
translations={{ balance: 'Balance Available' }}
82+
/>
83+
</Variants.Cell>
84+
<Variants.Cell>
85+
<SimpleAssetInput
86+
state={invalidState('1')}
87+
translations={{ balance: 'Balance Available' }}
88+
/>
89+
</Variants.Cell>
7390
</Variants.Row>
7491
</Variants.Table>
7592
</Section>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { AssetInput } from './asset-input.component';
2+
export { SimpleAssetInput } from './simple-asset-input.component';
23
export * as Data from './asset-input.data';
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import React from 'react';
2+
3+
import { Box } from '../box';
4+
import { Text } from '../text';
5+
6+
import { AmountInput } from './amount-input.component';
7+
import { AmountInputAlignments } from './amount-input.css';
8+
import * as cx from './simple-asset-input.css';
9+
10+
import type { Asset, AssetState } from './asset-input.data';
11+
12+
interface Props {
13+
state: AssetState;
14+
translations: {
15+
balance: string;
16+
};
17+
onAmountChange?: (asset: Readonly<Asset>, amount: string) => void;
18+
}
19+
20+
export const SimpleAssetInput = ({
21+
state,
22+
translations,
23+
onAmountChange,
24+
}: Readonly<Props>): JSX.Element => (
25+
<div className={cx.root}>
26+
<Box className={cx.amountBox}>
27+
<AmountInput
28+
id={state.asset.id}
29+
value={state.asset.amount}
30+
alignment={AmountInputAlignments.left}
31+
onChange={(value): void => {
32+
onAmountChange?.(state.asset, value);
33+
}}
34+
/>
35+
</Box>
36+
<Box className={cx.balance}>
37+
<Text.Body.Normal color="secondary">
38+
{translations.balance}: {state.asset.balance}
39+
</Text.Body.Normal>
40+
</Box>
41+
{state.type === 'invalid' && (
42+
<Box className={cx.error}>
43+
<Text.Label
44+
color="error"
45+
data-testid={`asset-input-error-${state.asset.id}`}
46+
>
47+
{state.error}
48+
</Text.Label>
49+
</Box>
50+
)}
51+
</div>
52+
);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { sx, style, vars } from '../../design-tokens';
2+
3+
export const root = style([
4+
sx({
5+
width: '$fill',
6+
rowGap: '$10',
7+
}),
8+
{
9+
background: vars.colors.$input_container_bgColor,
10+
borderRadius: vars.radius.$medium,
11+
padding: `${vars.spacing.$16} ${vars.spacing.$20}`,
12+
display: 'grid',
13+
gridTemplateAreas: `
14+
"amount amount"
15+
"balance balance"
16+
"error ."
17+
`,
18+
},
19+
]);
20+
21+
export const amountBox = style({ gridArea: 'amount' });
22+
23+
export const balance = style({ gridArea: 'balance' });
24+
25+
export const error = style({ gridArea: 'error' });

src/design-system/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export { Divider } from './divider';
66
export { Flex } from './flex';
77
export { Grid, Cell } from './grid';
88
export { Text } from './text';
9-
export { AssetInput } from './asset-input';
9+
export { AssetInput, SimpleAssetInput } from './asset-input';
1010
export { BundleInput } from './bundle-input';
1111
export * as SubNavigation from './sub-navigation';
1212
export * as NavigationButton from './navigation-buttons';

0 commit comments

Comments
 (0)