mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-30 08:09:15 +01:00
de4cf0a7e5
* ButtonBase ellipsis update Update ui/components/multichain/account-picker/index.js Co-authored-by: Garrett Bear <gwhisten@gmail.com> Update ui/components/multichain/account-picker/index.js Co-authored-by: Garrett Bear <gwhisten@gmail.com> Update ui/components/multichain/account-picker/index.js Co-authored-by: Garrett Bear <gwhisten@gmail.com> Update ui/components/multichain/account-picker/index.js Co-authored-by: Garrett Bear <gwhisten@gmail.com> * buttonbase updates to fix ellipsis * multichain support * remove multichain * code cleanup * clean up * component clean up * span update * fix snapshots * fix snapshot * Updating ButtonBase to reduce html to a minimum but ensure all functionality still works (#18210) * fix color and disable * remove unused css * Update ui/components/component-library/button-base/README.mdx Co-authored-by: George Marshall <george.marshall@consensys.net> * fix e2e test from button update * update e2e test from button base update --------- Co-authored-by: David Walsh <davidwalsh83@gmail.com> Co-authored-by: George Marshall <george.marshall@consensys.net>
217 lines
5.1 KiB
Plaintext
217 lines
5.1 KiB
Plaintext
import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';
|
|
import { ButtonBase } from './button-base';
|
|
|
|
### This is a base component. It should not be used in your feature code directly but as a "base" for other UI components
|
|
|
|
# ButtonBase
|
|
|
|
The `ButtonBase` is the base component for buttons.
|
|
|
|
<Canvas>
|
|
<Story id="components-componentlibrary-buttonbase--default-story" />
|
|
</Canvas>
|
|
|
|
## Props
|
|
|
|
The `ButtonBase` accepts all props below as well as all [Box](/docs/components-ui-box--default-story#props) component props
|
|
|
|
<ArgsTable of={ButtonBase} />
|
|
|
|
### Size
|
|
|
|
Use the `size` prop and the `Size` object from `./ui/helpers/constants/design-system.js`
|
|
to change the size of `ButtonBase`. Defaults to `Size.MD`
|
|
|
|
Optional: `BUTTON_BASE_SIZES` from `./button-base` object can be used instead of `Size`.
|
|
|
|
Possible sizes include:
|
|
|
|
- `Size.SM` 32px
|
|
- `Size.MD` 40px
|
|
- `Size.LG` 48px
|
|
|
|
<Canvas>
|
|
<Story id="components-componentlibrary-buttonbase--size-story" />
|
|
</Canvas>
|
|
|
|
```jsx
|
|
import { Size } from '../../../helpers/constants/design-system';
|
|
import { ButtonBase } from '../../component-library';
|
|
|
|
<ButtonBase size={Size.SM} />
|
|
<ButtonBase size={Size.MD} />
|
|
<ButtonBase size={Size.LG} />
|
|
```
|
|
|
|
### Block
|
|
|
|
Use boolean `block` prop to quickly enable a full width block button
|
|
|
|
<Canvas>
|
|
<Story id="components-componentlibrary-buttonbase--block" />
|
|
</Canvas>
|
|
|
|
```jsx
|
|
import { DISPLAY } from '../../../helpers/constants/design-system';
|
|
import { ButtonBase } from '../../component-library';
|
|
|
|
<ButtonBase>Default Button</ButtonBase>
|
|
<ButtonBase block>Block Button</ButtonBase>
|
|
```
|
|
|
|
### As
|
|
|
|
Use the `as` box prop to change the element of `ButtonBase`. Defaults to `button`.
|
|
|
|
When an `href` prop is passed it will change the element to an anchor(`a`) tag.
|
|
|
|
Button `as` options:
|
|
|
|
- `button`
|
|
- `a`
|
|
|
|
<Canvas>
|
|
<Story id="components-componentlibrary-buttonbase--as" />
|
|
</Canvas>
|
|
|
|
```jsx
|
|
import { ButtonBase } from '../../component-library';
|
|
|
|
|
|
<ButtonBase as="button">Button Element</ButtonBase>
|
|
<ButtonBase as="a" href="#">
|
|
Anchor Element
|
|
</ButtonBase>
|
|
```
|
|
|
|
### Href
|
|
|
|
When an `href` prop is passed it will change the element to an anchor(`a`) tag.
|
|
|
|
<Canvas>
|
|
<Story id="components-componentlibrary-buttonbase--href" />
|
|
</Canvas>
|
|
|
|
```jsx
|
|
import { ButtonBase } from '../../component-library';
|
|
|
|
<ButtonBase href="/metamask">Anchor Element</ButtonBase>;
|
|
```
|
|
|
|
### External link
|
|
|
|
When an `externalLink` prop is passed it will change the element to an anchor(`a`) tag and add the `target="_blank"` and `rel="noopener noreferrer"` attributes.
|
|
|
|
<Canvas>
|
|
<Story id="components-componentlibrary-buttonbase--external-link" />
|
|
</Canvas>
|
|
|
|
```jsx
|
|
import { ButtonBase } from '../../component-library';
|
|
|
|
<ButtonBase href="https://metamask.io" externalLink>
|
|
Anchor element with external link
|
|
</ButtonBase>;
|
|
```
|
|
|
|
### Disabled
|
|
|
|
Use the boolean `disabled` prop to disable button
|
|
|
|
<Canvas>
|
|
<Story id="components-componentlibrary-buttonbase--disabled" />
|
|
</Canvas>
|
|
|
|
```jsx
|
|
import { ButtonBase } from '../../component-library';
|
|
|
|
<ButtonBase disabled>Disabled Button</ButtonBase>;
|
|
```
|
|
|
|
### Loading
|
|
|
|
Use the boolean `loading` prop to set loading spinner
|
|
|
|
<Canvas>
|
|
<Story id="components-componentlibrary-buttonbase--loading" />
|
|
</Canvas>
|
|
|
|
```jsx
|
|
import { ButtonBase } from '../../component-library';
|
|
|
|
<ButtonBase loading>Loading Button</ButtonBase>;
|
|
```
|
|
|
|
### Icon Name
|
|
|
|
Use the `startIconName` and/or `endIconName` prop with the `ICON_NAMES` object from `./ui/components/component-library` to select icon.
|
|
|
|
<Canvas>
|
|
<Story id="components-componentlibrary-buttonbase--start-icon-name" />
|
|
</Canvas>
|
|
|
|
```jsx
|
|
import { ButtonBase } from '../../component-library';
|
|
import { ICON_NAMES } from '../icon';
|
|
|
|
<ButtonBase startIconName={ICON_NAMES.ADD_SQUARE}>Button</ButtonBase>;
|
|
```
|
|
|
|
<Canvas>
|
|
<Story id="components-componentlibrary-buttonbase--end-icon-name" />
|
|
</Canvas>
|
|
|
|
```jsx
|
|
import { ButtonBase } from '../../component-library';
|
|
import { ICON_NAMES } from '../icon';
|
|
|
|
<ButtonBase endIconName={ICON_NAMES.ARROW_2_RIGHT}>Button</ButtonBase>;
|
|
```
|
|
|
|
### RTL
|
|
|
|
For RTL language support use the `textDirection` prop.
|
|
|
|
<Canvas>
|
|
<Story id="components-componentlibrary-buttonbase--rtl" />
|
|
</Canvas>
|
|
|
|
```jsx
|
|
import { ButtonBase, ICON_NAMES } from '../../component-library';
|
|
|
|
<>
|
|
<ButtonBase
|
|
startIconName={ICON_NAMES.ADD_SQUARE}
|
|
endIconName={ICON_NAMES.ARROW_2_RIGHT}
|
|
>
|
|
Button Demo
|
|
</ButtonBase>
|
|
<ButtonBase
|
|
startIconName={ICON_NAMES.ADD_SQUARE}
|
|
endIconName={ICON_NAMES.ARROW_2_RIGHT}
|
|
textDirection={TEXT_DIRECTIONS.RIGHT_TO_LEFT}
|
|
>
|
|
Button Demo
|
|
</ButtonBase>
|
|
</>;
|
|
```
|
|
|
|
### Ellipsis
|
|
|
|
Use the boolean `ellipsis` prop to change the if the `ButtonBase` component to have an ellipsis.
|
|
|
|
Note: this should only be used for dynamic/user generated content or addresses. Generally, button text should be succinct and only contain one or two words.
|
|
|
|
<Canvas>
|
|
<Story id="components-componentlibrary-buttonbase--ellipsis" />
|
|
</Canvas>
|
|
|
|
```jsx
|
|
import { ButtonBase } from '../../component-library';
|
|
|
|
<Box style={{ width: 180 }}>
|
|
<ButtonBase>This is long text example without ellipsis</ButtonBase>
|
|
<ButtonBase ellipsis>This is long text example with ellipsis</ButtonBase>
|
|
</Box>;
|
|
```
|