1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Update to text-field-base docs (#16170)

This commit is contained in:
George Marshall 2022-10-13 06:32:52 -07:00 committed by GitHub
parent 41e3ab189c
commit 7eb93ff74b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 104 additions and 71 deletions

View File

@ -90,10 +90,10 @@ Use the `leftAccessory` and `rightAccessory` props to add components such as ico
</Canvas> </Canvas>
```jsx ```jsx
import { COLORS, SIZES } from '../../../helpers/constants/design-system'; import { COLORS, SIZES, DISPLAY } from '../../../helpers/constants/design-system';
import { Icon, ICON_NAMES } from '../../ui/component-library/icons'; import { Icon, ICON_NAMES } from '../../ui/component-library/icons';
import { TextFieldBase } from '../../ui/component-library/text-field-base'; import { TextFieldBase } from '../../ui/component-library/text-field';
<TextFieldBase <TextFieldBase
placeholder="Search" placeholder="Search"
@ -106,39 +106,42 @@ import { TextFieldBase } from '../../ui/component-library/text-field-base';
/> />
<TextFieldBase <TextFieldBase
placeholder="MetaMask" placeholder="Public address (0x), or ENS"
rightAccessory={ rightAccessory={
// TODO: replace with ButtonIcon // TODO: replace with ButtonIcon
<button> <Box
<Icon name={ICON_NAMES.CLOSE_OUTLINE} size={SIZES.SM} /> as="button"
</button> display={DISPLAY.FLEX}
} style={{ padding: 0 }}
/> backgroundColor={COLORS.TRANSPARENT}
>
<TextFieldBase <Icon
truncate color={COLORS.PRIMARY_DEFAULT}
leftAccessory={<AvatarToken tokenName="ast" size={SIZES.SM} />} name={ICON_NAMES.SCAN_BARCODE_FILLED}
rightAccessory={ />
// TODO: replace with ButtonIcon </Box>
<button>
<Icon name={ICON_NAMES.CLOSE_OUTLINE} size={SIZES.SM} />
</button>
} }
/> />
<TextFieldBase <TextFieldBase
placeholder="Enter amount" placeholder="Enter amount"
type="number" type="number"
leftAccessory={ truncate
<AvatarToken leftAccessory={<SelectTokenComponent />}
tokenName="ast" rightAccessory={<TokenValueInUSDComponent />}
tokenImageUrl="./AST.png" />
size={SIZES.SM}
/> <TextFieldBase
} placeholder="Public address (0x), or ENS"
truncate
leftAccessory={<AvatarAccount />}
rightAccessory={ rightAccessory={
// TODO: replace with ButtonLink isAddressValid && (
<button>Max</button> <Icon
name={ICON_NAMES.CHECK_OUTLINE}
color={COLORS.SUCCESS_DEFAULT}
/>
)
} }
/> />
``` ```

View File

@ -5,11 +5,15 @@ import {
DISPLAY, DISPLAY,
COLORS, COLORS,
FLEX_DIRECTION, FLEX_DIRECTION,
ALIGN_ITEMS,
TEXT,
} from '../../../helpers/constants/design-system'; } from '../../../helpers/constants/design-system';
import Box from '../../ui/box/box'; import Box from '../../ui/box/box';
import { Icon, ICON_NAMES } from '../icon'; import { Icon, ICON_NAMES } from '../icon';
import { AvatarToken } from '../avatar-token'; import { AvatarToken } from '../avatar-token';
import { AvatarAccount } from '../avatar-account';
import { Text } from '../text';
import { import {
TEXT_FIELD_BASE_SIZES, TEXT_FIELD_BASE_SIZES,
@ -212,10 +216,16 @@ Truncate.args = {
export const LeftAccessoryRightAccessory = (args) => { export const LeftAccessoryRightAccessory = (args) => {
const [value, setValue] = useState({ const [value, setValue] = useState({
search: '', search: '',
metaMask: '', address: '',
address: '0x514910771af9ca656af840dff83e8264ecf986ca',
amount: 1, amount: 1,
accountAddress: '0x514910771af9ca656af840dff83e8264ecf986ca',
}); });
const handleOnChange = (e) => {
setValue({ ...value, [e.target.name]: e.target.value });
};
const handleTokenPrice = (tokenAmount, priceUSD) => {
return tokenAmount * priceUSD;
};
return ( return (
<Box <Box
display={DISPLAY.INLINE_FLEX} display={DISPLAY.INLINE_FLEX}
@ -226,7 +236,9 @@ export const LeftAccessoryRightAccessory = (args) => {
{...args} {...args}
placeholder="Search" placeholder="Search"
value={value.search} value={value.search}
onChange={(e) => setValue({ ...value, search: e.target.value })} name="search"
onChange={handleOnChange}
showClear
leftAccessory={ leftAccessory={
<Icon <Icon
color={COLORS.ICON_ALTERNATIVE} color={COLORS.ICON_ALTERNATIVE}
@ -236,61 +248,79 @@ export const LeftAccessoryRightAccessory = (args) => {
/> />
<TextFieldBase <TextFieldBase
{...args} {...args}
value={value.metaMask} placeholder="Public address (0x), or ENS"
onChange={(e) => setValue({ ...value, metaMask: e.target.value })}
placeholder="MetaMask"
rightAccessory={
<button
style={{
padding: 0,
background: 'transparent',
margin: 0,
display: 'flex',
}}
onClick={() => setValue({ ...value, metaMask: '' })}
>
<Icon name={ICON_NAMES.CLOSE_OUTLINE} size={SIZES.SM} />
</button>
}
/>
<TextFieldBase
{...args}
placeholder="Enter address"
value={value.address} value={value.address}
onChange={(e) => setValue({ ...value, address: e.target.value })} name="address"
truncate onChange={handleOnChange}
leftAccessory={<AvatarToken tokenName="ast" size={SIZES.SM} />}
rightAccessory={ rightAccessory={
<button <Box
style={{ as="button"
padding: 0, display={DISPLAY.FLEX}
background: 'transparent', style={{ padding: 0 }}
margin: 0, backgroundColor={COLORS.TRANSPARENT}
display: 'flex',
}}
onClick={() => setValue({ ...value, address: '' })}
> >
<Icon name={ICON_NAMES.CLOSE_OUTLINE} size={SIZES.SM} /> <Icon
</button> color={COLORS.PRIMARY_DEFAULT}
name={ICON_NAMES.SCAN_BARCODE_FILLED}
/>
</Box>
} }
/> />
<TextFieldBase <TextFieldBase
{...args} {...args}
placeholder="Enter amount" placeholder="Enter amount"
value={value.amount} value={value.amount}
onChange={(e) => setValue({ ...value, amount: e.target.value })} name="amount"
onChange={handleOnChange}
type="number" type="number"
truncate
leftAccessory={ leftAccessory={
<AvatarToken <Box
tokenName="ast" as="button"
tokenImageUrl="./AST.png" style={{ padding: 0 }}
size={SIZES.SM} backgroundColor={COLORS.TRANSPARENT}
/> gap={1}
display={DISPLAY.FLEX}
alignItems={ALIGN_ITEMS.CENTER}
>
<AvatarToken
tokenName="ast"
tokenImageUrl="./AST.png"
size={SIZES.SM}
/>
<Text>AST</Text>
<Icon
name={ICON_NAMES.ARROW_DOWN}
color={COLORS.ICON_DEFAULT}
size={SIZES.SM}
/>
</Box>
} }
rightAccessory={ rightAccessory={
<button onClick={() => setValue({ ...value, amount: 100000 })}> <Text variant={TEXT.BODY_SM} color={COLORS.TEXT_ALTERNATIVE}>
Max = ${handleTokenPrice(value.amount, 0.11)}
</button> </Text>
}
/>
<TextFieldBase
{...args}
placeholder="Public address (0x), or ENS"
value={value.accountAddress}
name="accountAddress"
onChange={handleOnChange}
truncate
leftAccessory={
value.accountAddress && (
<AvatarAccount size={SIZES.SM} address={value.accountAddress} />
)
}
rightAccessory={
value.accountAddress.length === 42 && (
<Icon
name={ICON_NAMES.CHECK_OUTLINE}
color={COLORS.SUCCESS_DEFAULT}
/>
)
} }
/> />
</Box> </Box>