mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-04 23:14:56 +01:00
da4e6d3e37
* Adding TextField component * Fixing lint issues * More linting fixes * Adding more tests * Adding reference to TextFieldBase props * Adding reminder todo comment to styles * Using short hand syntax for conditionally firing event props and removing some css and unused classsNames in favor of box props * Fixing up my sloppy code * Removing text base docs update * More clean up * Adding more stories and docs * Adding new stories to mdx docs |
||
---|---|---|
.. | ||
index.js | ||
README.mdx | ||
text-field.constants.js | ||
text-field.js | ||
text-field.scss | ||
text-field.stories.js | ||
text-field.test.js |
import { Story, Canvas, ArgsTable } from '@storybook/addon-docs'; import { TextField } from './text-field'; # TextField The `TextField` component lets users enter and edit text as well as adding a show clear button option. It wraps `TextFieldBase` and functions only as a controlled input. <Canvas> <Story id="ui-components-component-library-text-field-text-field-stories-js--default-story" /> </Canvas> ## Props The `TextField` accepts all props below as well as all [Box](/docs/ui-components-ui-box-box-stories-js--default-story#props) and [TextFieldBase](/docs/ui-components-component-library-text-field-base-text-field-base-stories-js--default-story#props) component props <ArgsTable of={TextField} /> ### Show Clear Use the `showClear` prop to display a clear button when `TextField` has a value. Clicking the button will clear the value. You can also attach an `onClear` handler to the `TextField` to perform additional actions when the clear button is clicked. <Canvas> <Story id="ui-components-component-library-text-field-text-field-stories-js--show-clear" /> </Canvas> ```jsx import { TextField } from '../../ui/component-library/text-field'; <TextField showClear />; ``` ### On Clear Use the `onClear` prop to perform additional actions when the clear button is clicked. <Canvas> <Story id="ui-components-component-library-text-field-text-field-stories-js--on-clear" /> </Canvas> ```jsx import { TextField } from '../../ui/component-library/text-field'; <TextField showClear onClear={() => console.log('cleared input')} />; ``` ### Clear Button Props and Clear Button Icon Props Use the `clearButtonProps` and `clearButtonIconProps` props to pass props to the clear button and clear button icon respectively. <Canvas> <Story id="ui-components-component-library-text-field-text-field-stories-js--clear-button-props-clear-button-icon-props" /> </Canvas> ```jsx import { SIZES, COLORS, BORDER_RADIUS, } from '../../../helpers/constants/design-system'; import { TextField } from '../../ui/component-library/text-field'; <TextField showClear clearButtonProps={{ backgroundColor: COLORS.BACKGROUND_ALTERNATIVE, borderRadius: BORDER_RADIUS.XS, 'data-testid': 'clear-button', }} clearButtonIconProps={{ size: SIZES.MD }} />; ```