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';
3
3
import { Box } from '../box' ;
4
4
5
5
import * as cx from './amount-input.css' ;
6
+ import { AmountInputAlignments } from './amount-input.css' ;
6
7
7
8
interface Props {
9
+ alignment ?: AmountInputAlignments ;
8
10
onChange ?: ( value : string ) => void ;
9
11
value ?: string ;
10
12
id : string ;
11
13
}
12
14
13
15
export const AmountInput = ( {
16
+ alignment = AmountInputAlignments . right ,
14
17
onChange,
15
18
value,
16
19
id,
17
20
} : Readonly < Props > ) : JSX . Element => {
18
21
return (
19
22
< Box className = { cx . amountInputSizer } data-value = { value } >
20
23
< input
21
- className = { cx . amountInput }
24
+ className = { cx . amountInput [ alignment ] }
22
25
value = { value }
23
26
size = { 1 }
24
27
onChange = { ( { target } ) : void => onChange ?.( target . value ) }
Original file line number Diff line number Diff line change
1
+ import { styleVariants } from '@vanilla-extract/css' ;
2
+
1
3
import { style , vars } from '../../design-tokens' ;
2
4
import { bold } from '../text/text.css' ;
3
5
@@ -20,12 +22,16 @@ export const amountInputSizer = style([
20
22
} ,
21
23
] ) ;
22
24
23
- export const amountInput = style ( [
25
+ export enum AmountInputAlignments {
26
+ left = 'left' ,
27
+ right = 'right' ,
28
+ }
29
+
30
+ const amountInputBase = style ( [
24
31
inputTypography ,
25
32
bold ,
26
33
{
27
34
gridArea : '1 / 2' ,
28
- textAlign : 'right' ,
29
35
border : 'none' ,
30
36
width : 'auto' ,
31
37
background : 'none' ,
@@ -39,3 +45,18 @@ export const amountInput = style([
39
45
} ,
40
46
} ,
41
47
] ) ;
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 {
13
13
ColorSchemaTable ,
14
14
} from '../decorators' ;
15
15
import { Divider } from '../divider' ;
16
- import { Grid } from '../grid' ;
17
- import { Cell } from '../grid/cell.component' ;
16
+ import { Cell , Grid } from '../grid' ;
18
17
19
18
import { AssetInput } from './asset-input.component' ;
20
19
import { invalidState , validState } from './asset-input.fixtures' ;
21
20
import { MaxButton } from './max-button.component' ;
21
+ import { SimpleAssetInput } from './simple-asset-input.component' ;
22
22
23
23
import type { Asset , AssetState } from './asset-input.data' ;
24
24
@@ -61,7 +61,12 @@ export const Overview = (): JSX.Element => (
61
61
< Cell >
62
62
< Section title = "Overview" >
63
63
< 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
+ ] }
65
70
>
66
71
< Variants . Row >
67
72
< Variants . Cell >
@@ -70,6 +75,18 @@ export const Overview = (): JSX.Element => (
70
75
< Variants . Cell >
71
76
< AssetInput state = { invalidState ( '1' ) } />
72
77
</ 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 >
73
90
</ Variants . Row >
74
91
</ Variants . Table >
75
92
</ Section >
Original file line number Diff line number Diff line change 1
1
export { AssetInput } from './asset-input.component' ;
2
+ export { SimpleAssetInput } from './simple-asset-input.component' ;
2
3
export * 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';
6
6
export { Flex } from './flex' ;
7
7
export { Grid , Cell } from './grid' ;
8
8
export { Text } from './text' ;
9
- export { AssetInput } from './asset-input' ;
9
+ export { AssetInput , SimpleAssetInput } from './asset-input' ;
10
10
export { BundleInput } from './bundle-input' ;
11
11
export * as SubNavigation from './sub-navigation' ;
12
12
export * as NavigationButton from './navigation-buttons' ;
You can’t perform that action at this time.
0 commit comments