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

feature/default_network_editable
George Marshall 2 years ago committed by GitHub
parent 41e3ab189c
commit 7eb93ff74b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 51
      ui/components/component-library/text-field-base/README.mdx
  2. 116
      ui/components/component-library/text-field-base/text-field-base.stories.js

@ -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}
>
<Icon
color={COLORS.PRIMARY_DEFAULT}
name={ICON_NAMES.SCAN_BARCODE_FILLED}
/>
</Box>
} }
/> />
<TextFieldBase <TextFieldBase
placeholder="Enter amount"
type="number"
truncate truncate
leftAccessory={<AvatarToken tokenName="ast" size={SIZES.SM} />} leftAccessory={<SelectTokenComponent />}
rightAccessory={ rightAccessory={<TokenValueInUSDComponent />}
// TODO: replace with ButtonIcon
<button>
<Icon name={ICON_NAMES.CLOSE_OUTLINE} size={SIZES.SM} />
</button>
}
/> />
<TextFieldBase <TextFieldBase
placeholder="Enter amount" placeholder="Public address (0x), or ENS"
type="number" truncate
leftAccessory={ leftAccessory={<AvatarAccount />}
<AvatarToken
tokenName="ast"
tokenImageUrl="./AST.png"
size={SIZES.SM}
/>
}
rightAccessory={ rightAccessory={
// TODO: replace with ButtonLink isAddressValid && (
<button>Max</button> <Icon
name={ICON_NAMES.CHECK_OUTLINE}
color={COLORS.SUCCESS_DEFAULT}
/>
)
} }
/> />
``` ```

@ -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 })} value={value.address}
placeholder="MetaMask" name="address"
onChange={handleOnChange}
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, metaMask: '' })}
> >
<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 address" placeholder="Enter amount"
value={value.address} value={value.amount}
onChange={(e) => setValue({ ...value, address: e.target.value })} name="amount"
onChange={handleOnChange}
type="number"
truncate truncate
leftAccessory={<AvatarToken tokenName="ast" size={SIZES.SM} />} leftAccessory={
rightAccessory={ <Box
<button as="button"
style={{ style={{ padding: 0 }}
padding: 0, backgroundColor={COLORS.TRANSPARENT}
background: 'transparent', gap={1}
margin: 0, display={DISPLAY.FLEX}
display: 'flex', alignItems={ALIGN_ITEMS.CENTER}
}}
onClick={() => setValue({ ...value, address: '' })}
> >
<Icon name={ICON_NAMES.CLOSE_OUTLINE} size={SIZES.SM} /> <AvatarToken
</button> 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={
<Text variant={TEXT.BODY_SM} color={COLORS.TEXT_ALTERNATIVE}>
= ${handleTokenPrice(value.amount, 0.11)}
</Text>
} }
/> />
<TextFieldBase <TextFieldBase
{...args} {...args}
placeholder="Enter amount" placeholder="Public address (0x), or ENS"
value={value.amount} value={value.accountAddress}
onChange={(e) => setValue({ ...value, amount: e.target.value })} name="accountAddress"
type="number" onChange={handleOnChange}
truncate
leftAccessory={ leftAccessory={
<AvatarToken value.accountAddress && (
tokenName="ast" <AvatarAccount size={SIZES.SM} address={value.accountAddress} />
tokenImageUrl="./AST.png" )
size={SIZES.SM}
/>
} }
rightAccessory={ rightAccessory={
<button onClick={() => setValue({ ...value, amount: 100000 })}> value.accountAddress.length === 42 && (
Max <Icon
</button> name={ICON_NAMES.CHECK_OUTLINE}
color={COLORS.SUCCESS_DEFAULT}
/>
)
} }
/> />
</Box> </Box>

Loading…
Cancel
Save