File tree Expand file tree Collapse file tree 7 files changed +126
-7
lines changed Expand file tree Collapse file tree 7 files changed +126
-7
lines changed Original file line number Diff line number Diff line change @@ -3,22 +3,25 @@ import React from 'react';
33import { Box } from '../box' ;
44
55import * as cx from './amount-input.css' ;
6+ import { AmountInputAlignments } from './amount-input.css' ;
67
78interface Props {
9+ alignment ?: AmountInputAlignments ;
810 onChange ?: ( value : string ) => void ;
911 value ?: string ;
1012 id : string ;
1113}
1214
1315export 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 ) }
Original file line number Diff line number Diff line change 1+ import { styleVariants } from '@vanilla-extract/css' ;
2+
13import { style , vars } from '../../design-tokens' ;
24import { 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+ } ) ;
Original file line number Diff line number Diff line change @@ -13,12 +13,12 @@ import {
1313 ColorSchemaTable ,
1414} from '../decorators' ;
1515import { Divider } from '../divider' ;
16- import { Grid } from '../grid' ;
17- import { Cell } from '../grid/cell.component' ;
16+ import { Cell , Grid } from '../grid' ;
1817
1918import { AssetInput } from './asset-input.component' ;
2019import { invalidState , validState } from './asset-input.fixtures' ;
2120import { MaxButton } from './max-button.component' ;
21+ import { SimpleAssetInput } from './simple-asset-input.component' ;
2222
2323import 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 >
Original file line number Diff line number Diff line change 11export { AssetInput } from './asset-input.component' ;
2+ export { SimpleAssetInput } from './simple-asset-input.component' ;
23export * as Data from './asset-input.data' ;
Original file line number Diff line number Diff line change 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+ ) ;
Original file line number Diff line number Diff line change 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' } ) ;
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ export { Divider } from './divider';
66export { Flex } from './flex' ;
77export { Grid , Cell } from './grid' ;
88export { Text } from './text' ;
9- export { AssetInput } from './asset-input' ;
9+ export { AssetInput , SimpleAssetInput } from './asset-input' ;
1010export { BundleInput } from './bundle-input' ;
1111export * as SubNavigation from './sub-navigation' ;
1212export * as NavigationButton from './navigation-buttons' ;
You can’t perform that action at this time.
0 commit comments