-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding TextFieldBase
component
#16043
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
963c5bb
Adding TextInputBase component
georgewrmarshall ea87976
Removing keyup and keydown props, tests and docs
georgewrmarshall 9770c08
removing showClear from stories
georgewrmarshall 3c1c32b
removing unneeded css
georgewrmarshall df4635a
simplifying uncontrolled vs controlled to work
georgewrmarshall 4277417
Fortifying maxLength test
georgewrmarshall 61a10d3
Lint fix for test
georgewrmarshall dc06a8d
Doc, style and prop updates
georgewrmarshall eeb8b96
Updating constant names with 'base'
georgewrmarshall 21fd101
Adding a background color
georgewrmarshall ee76b6c
Adding a background color to input
georgewrmarshall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
298 changes: 298 additions & 0 deletions
298
ui/components/component-library/text-field-base/README.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,298 @@ | ||
import { Story, Canvas, ArgsTable } from '@storybook/addon-docs'; | ||
|
||
import { TextFieldBase } from './text-field-base'; | ||
|
||
### This is a base component. It should not be used in your feature code directly but as a "base" for other UI components | ||
|
||
# TextFieldBase | ||
|
||
The `TextFieldBase` is the base component for all text fields. It should not be used directly. It functions as both a uncontrolled and controlled input. | ||
|
||
<Canvas> | ||
<Story id="ui-components-component-library-text-field-base-text-field-base-stories-js--default-story" /> | ||
</Canvas> | ||
|
||
## Props | ||
|
||
The `TextFieldBase` accepts all props below as well as all [Box](/docs/ui-components-ui-box-box-stories-js--default-story#props) component props | ||
|
||
<ArgsTable of={TextFieldBase} /> | ||
|
||
### Size | ||
|
||
Use the `size` prop to set the height of the `TextFieldBase`. | ||
|
||
Possible sizes include: | ||
|
||
- `sm` 32px | ||
- `md` 40px | ||
- `lg` 48px | ||
|
||
Defaults to `md` | ||
|
||
<Canvas> | ||
<Story id="ui-components-component-library-text-field-base-text-field-base-stories-js--size" /> | ||
</Canvas> | ||
|
||
```jsx | ||
import { TextFieldBase } from '../../ui/component-library/text-field-base'; | ||
import { SIZES } from '../../../helpers/constants/design-system'; | ||
|
||
<TextFieldBase size={SIZES.SM} /> | ||
<TextFieldBase size={SIZES.MD} /> | ||
<TextFieldBase size={SIZES.LG} /> | ||
``` | ||
|
||
### Type | ||
|
||
Use the `type` prop to change the type of input. | ||
|
||
Possible types include: | ||
|
||
- `text` | ||
- `number` | ||
- `password` | ||
|
||
Defaults to `text`. | ||
|
||
<Canvas> | ||
<Story id="ui-components-component-library-text-field-base-text-field-base-stories-js--type" /> | ||
</Canvas> | ||
|
||
```jsx | ||
import { TextFieldBase } from '../../ui/component-library/text-field-base'; | ||
|
||
<TextFieldBase type="text" /> // (Default) | ||
<TextFieldBase type="number" /> | ||
<TextFieldBase type="password" /> | ||
``` | ||
|
||
### Truncate | ||
|
||
Use the `truncate` prop to truncate the text of the the `TextFieldBase` | ||
|
||
<Canvas> | ||
<Story id="ui-components-component-library-text-field-base-text-field-base-stories-js--truncate" /> | ||
</Canvas> | ||
|
||
```jsx | ||
import { TextFieldBase } from '../../ui/component-library/text-field-base'; | ||
|
||
<TextFieldBase truncate />; | ||
``` | ||
|
||
### Left Accessory Right Accessory | ||
|
||
Use the `leftAccessory` and `rightAccessory` props to add components such as icons or buttons to either side of the `TextFieldBase`. | ||
|
||
<Canvas> | ||
<Story id="ui-components-component-library-text-field-base-text-field-base-stories-js--left-accessory-right-accessory" /> | ||
</Canvas> | ||
|
||
```jsx | ||
import { COLORS, SIZES } from '../../../helpers/constants/design-system'; | ||
import { Icon, ICON_NAMES } from '../../ui/component-library/icons'; | ||
|
||
import { TextFieldBase } from '../../ui/component-library/text-field-base'; | ||
|
||
<TextFieldBase | ||
placeholder="Search" | ||
leftAccessory={ | ||
<Icon | ||
color={COLORS.ICON_ALTERNATIVE} | ||
name={ICON_NAMES.SEARCH_FILLED} | ||
/> | ||
} | ||
/> | ||
|
||
<TextFieldBase | ||
placeholder="MetaMask" | ||
rightAccessory={ | ||
// TODO: replace with ButtonIcon | ||
<button> | ||
<Icon name={ICON_NAMES.CLOSE_OUTLINE} size={SIZES.SM} /> | ||
</button> | ||
} | ||
/> | ||
|
||
<TextFieldBase | ||
truncate | ||
leftAccessory={<AvatarToken tokenName="ast" size={SIZES.SM} />} | ||
rightAccessory={ | ||
// TODO: replace with ButtonIcon | ||
<button> | ||
<Icon name={ICON_NAMES.CLOSE_OUTLINE} size={SIZES.SM} /> | ||
</button> | ||
} | ||
/> | ||
|
||
<TextFieldBase | ||
placeholder="Enter amount" | ||
type="number" | ||
leftAccessory={ | ||
<AvatarToken | ||
tokenName="ast" | ||
tokenImageUrl="./AST.png" | ||
size={SIZES.SM} | ||
/> | ||
} | ||
rightAccessory={ | ||
// TODO: replace with ButtonLink | ||
<button>Max</button> | ||
} | ||
/> | ||
``` | ||
|
||
### Input Ref | ||
|
||
Use the `inputRef` prop to access the ref of the `<input />` html element of `TextFieldBase`. This is useful for focusing the input from a button or other component. | ||
|
||
<Canvas> | ||
<Story id="ui-components-component-library-text-field-base-text-field-base-stories-js--input-ref" /> | ||
</Canvas> | ||
|
||
```jsx | ||
import { TextFieldBase } from '../../ui/component-library/text-field-base'; | ||
|
||
const inputRef = useRef(null); | ||
const [value, setValue] = useState(''); | ||
const handleOnClick = () => { | ||
inputRef.current.focus(); | ||
}; | ||
const handleOnChange = (e) => { | ||
setValue(e.target.value); | ||
}; | ||
|
||
<TextFieldBase | ||
inputRef={inputRef} | ||
value={value} | ||
onChange={handleOnChange} | ||
/> | ||
// TODO: replace with Button component | ||
<Box | ||
as="button" | ||
backgroundColor={COLORS.BACKGROUND_ALTERNATIVE} | ||
color={COLORS.TEXT_DEFAULT} | ||
borderColor={COLORS.BORDER_DEFAULT} | ||
borderRadius={SIZES.XL} | ||
marginLeft={1} | ||
paddingLeft={2} | ||
paddingRight={2} | ||
onClick={handleOnClick} | ||
> | ||
Edit | ||
</Box> | ||
``` | ||
|
||
### Auto Complete | ||
|
||
Use the `autoComplete` prop to set the autocomplete html attribute. It allows the browser to predict the value based on earlier typed values. | ||
|
||
<Canvas> | ||
<Story id="ui-components-component-library-text-field-base-text-field-base-stories-js--auto-complete" /> | ||
</Canvas> | ||
|
||
```jsx | ||
import { TextFieldBase } from '../../ui/component-library/text-field-base'; | ||
|
||
<TextFieldBase type="password" autoComplete />; | ||
``` | ||
|
||
### Auto Focus | ||
|
||
Use the `autoFocus` prop to focus the `TextFieldBase` during the first mount | ||
|
||
<Canvas> | ||
<Story id="ui-components-component-library-text-field-base-text-field-base-stories-js--auto-focus" /> | ||
</Canvas> | ||
|
||
```jsx | ||
import { TextFieldBase } from '../../ui/component-library/text-field-base'; | ||
|
||
<TextFieldBase autoFocus />; | ||
``` | ||
|
||
### Default Value | ||
|
||
Use the `defaultValue` prop to set the default value of the `TextFieldBase` | ||
|
||
<Canvas> | ||
<Story id="ui-components-component-library-text-field-base-text-field-base-stories-js--default-value" /> | ||
</Canvas> | ||
|
||
```jsx | ||
import { TextFieldBase } from '../../ui/component-library/text-field-base'; | ||
|
||
<TextFieldBase defaultValue="default value" />; | ||
``` | ||
|
||
### Disabled | ||
|
||
Use the `disabled` prop to set the disabled state of the `TextFieldBase` | ||
|
||
<Canvas> | ||
<Story id="ui-components-component-library-text-field-base-text-field-base-stories-js--disabled" /> | ||
</Canvas> | ||
|
||
```jsx | ||
import { TextFieldBase } from '../../ui/component-library/text-field-base'; | ||
|
||
<TextFieldBase disabled />; | ||
``` | ||
|
||
### Error | ||
|
||
Use the `error` prop to set the error state of the `TextFieldBase` | ||
|
||
<Canvas> | ||
<Story id="ui-components-component-library-text-field-base-text-field-base-stories-js--error-story" /> | ||
</Canvas> | ||
|
||
```jsx | ||
import { TextFieldBase } from '../../ui/component-library/text-field-base'; | ||
|
||
<TextFieldBase error />; | ||
``` | ||
|
||
### Max Length | ||
|
||
Use the `maxLength` prop to set the maximum allowed input characters for the `TextFieldBase` | ||
|
||
<Canvas> | ||
<Story id="ui-components-component-library-text-field-base-text-field-base-stories-js--max-length" /> | ||
</Canvas> | ||
|
||
```jsx | ||
import { TextFieldBase } from '../../ui/component-library/text-field-base'; | ||
|
||
<TextFieldBase maxLength={10} />; | ||
``` | ||
|
||
### Read Only | ||
|
||
Use the `readOnly` prop to set the `TextFieldBase` to read only | ||
|
||
<Canvas> | ||
<Story id="ui-components-component-library-text-field-base-text-field-base-stories-js--read-only" /> | ||
</Canvas> | ||
|
||
```jsx | ||
import { TextFieldBase } from '../../ui/component-library/text-field-base'; | ||
|
||
<TextFieldBase readOnly />; | ||
``` | ||
|
||
### Required | ||
|
||
Use the `required` prop to set the `TextFieldBase` to required. Currently there is no visual difference to the `TextFieldBase` when required. | ||
|
||
<Canvas> | ||
<Story id="ui-components-component-library-text-field-base-text-field-base-stories-js--required" /> | ||
</Canvas> | ||
|
||
```jsx | ||
import { TextFieldBase } from '../../ui/component-library/text-field-base'; | ||
|
||
// Currently no visual difference | ||
<TextFieldBase required />; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export { TextFieldBase } from './text-field-base'; | ||
export { | ||
TEXT_FIELD_BASE_SIZES, | ||
TEXT_FIELD_BASE_TYPES, | ||
} from './text-field-base.constants'; |
12 changes: 12 additions & 0 deletions
12
ui/components/component-library/text-field-base/text-field-base.constants.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { SIZES } from '../../../helpers/constants/design-system'; | ||
|
||
export const TEXT_FIELD_BASE_SIZES = { | ||
SM: SIZES.SM, | ||
MD: SIZES.MD, | ||
LG: SIZES.LG, | ||
}; | ||
export const TEXT_FIELD_BASE_TYPES = { | ||
TEXT: 'text', | ||
NUMBER: 'number', | ||
PASSWORD: 'password', | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍