mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
c5368c152b
* added storybook test runner * added test runner in ci * updated test for ci and fixed lint error * updated lavamoat policy * updated test command * updated playwright * changed command to storybook;ci * updated command * updated instance for test-storybook * updated playwright * added playwright step * replaced concurrently with start-server-and-test * updated the static storybook directory * replaced first with last * updated lock file * replaced first with last * updated test-storybook with maxworkers * updated .depchechrc * updated yml * removed id from banner base * replaced broken stories with .stories-to-do.js extesnsion * updated token allowance story * removed duplicacies from yarn * fixed lavamoat * removed filename comment * updated links for docs * fixed file extension for stories * updated path for stories.json * updated stories.json path * yarn updated * updated stories * updated yarn * updated wait on |
||
---|---|---|
.. | ||
__snapshots__ | ||
index.js | ||
README.mdx | ||
text-field.constants.js | ||
text-field.js | ||
text-field.stories.js | ||
text-field.test.js |
import { Story, Canvas, ArgsTable } from '@storybook/addon-docs'; import { TextFieldBase } from '../text-field-base'; 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="components-componentlibrary-textfield--default-story" /> </Canvas> ## Props The `TextField` accepts all props below as well as all [Box](/docs/components-ui-box--default-story#props) component props <ArgsTable of={TextField} /> `TextField` accepts all [TextFieldBase](/docs/components-componentlibrary-textfieldbase--default-story#props) component props <ArgsTable of={TextFieldBase} /> ### Show Clear Button Use the `showClearButton` prop to display a clear button when `TextField` has a value. Use the `clearButtonOnClick` prop to pass an `onClick` event handler to clear the value of the input. Otherwise the clear button will not do anything. The clear button uses [ButtonIcon](/docs/components-componentlibrary-buttonicon--default-story) and accepts all `ButtonIcon` props. **NOTE: The `showClearButton` only works with a controlled input.** <Canvas> <Story id="components-componentlibrary-textfield--show-clear-button" /> </Canvas> ```jsx import { TextField } from '../../component-library'; const [value, setValue] = useState('show clear'); const handleOnChange = (e) => { setValue(e.target.value); }; const handleOnClear = () => { setValue(''); }; <TextField placeholder="Enter text to show clear" value={value} onChange={handleOnChange} showClearButton clearButtonOnClick={handleOnClear} />; ``` ### Clear Button Props Use the `clearButtonProps` to access other props of the clear button. <Canvas> <Story id="components-componentlibrary-textfield--clear-button-props" /> </Canvas> ```jsx import React, { useState } from 'react'; import { SIZES, COLORS, BORDER_RADIUS, } from '../../../helpers/constants/design-system'; import { TextField } from '../../component-library'; const [value, setValue] = useState('show clear'); const handleOnChange = (e) => { setValue(e.target.value); }; const handleOnClear = () => { setValue(''); }; <TextField placeholder="Enter text to show clear" value={value} onChange={handleOnChange} showClearButton clearButtonOnClick={handleOnClear} clearButtonProps={{ backgroundColor: COLORS.BACKGROUND_ALTERNATIVE, borderRadius: BORDER_RADIUS.XS, 'data-testid': 'clear-button', }} />; ```