-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update IconButton & TextButton
- Loading branch information
1 parent
c67995d
commit e3129b9
Showing
19 changed files
with
551 additions
and
544 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@strapi/design-system': patch | ||
--- | ||
|
||
fix(IconButton): sizing was wrong compared to other buttons |
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
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,58 @@ | ||
import { Meta, Canvas } from '@storybook/blocks'; | ||
import { IconButton } from '@strapi/design-system'; | ||
|
||
import * as IconButtonStories from './IconButton.stories'; | ||
|
||
<Meta of={IconButtonStories} /> | ||
|
||
# IconButton | ||
|
||
- [Overview](#overview) | ||
- [Usage](#usage) | ||
- [Props](#props) | ||
- [Variants](#variants) | ||
- [Button Groups](#button-groups) | ||
|
||
## Overview | ||
|
||
A type of button that does not have a visible label but instead an icon to denote it's action. The component does | ||
require a label for accessibility & by default, will show a tooltip with that label. | ||
|
||
<ViewSource path="components/IconButton" /> | ||
|
||
## Usage | ||
|
||
```js | ||
import { IconButton, IconButtonGroup } from '@strapi/design-system'; | ||
``` | ||
|
||
<Canvas of={IconButtonStories.Base} /> | ||
|
||
## Props | ||
|
||
<TypeTable of={IconButton} /> | ||
|
||
## Variants | ||
|
||
### Variant styles | ||
|
||
Similar to the [`Button`](../?path=/docs/components-button--docs) component, the `IconButton` component has the same | ||
variants available. However, `tertiary` is considered the default. | ||
|
||
<Canvas of={IconButtonStories.AllVariants} /> | ||
|
||
### Disabled | ||
|
||
<Canvas of={IconButtonStories.Disabled} /> | ||
|
||
### Small Size | ||
|
||
<Canvas of={IconButtonStories.SizeSmall} /> | ||
|
||
### Large Size | ||
|
||
<Canvas of={IconButtonStories.SizeLarge} /> | ||
|
||
## Button Groups | ||
|
||
<Canvas of={IconButtonStories.Group} /> |
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,166 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { fn } from '@storybook/test'; | ||
import { Flex, IconButton, IconButtonGroup, IconButtonProps } from '@strapi/design-system'; | ||
import * as Icons from '@strapi/icons'; | ||
import { outdent } from 'outdent'; | ||
|
||
interface IconButtonArgs extends IconButtonProps { | ||
children: keyof typeof Icons; | ||
} | ||
|
||
const BUTTON_VARIANTS = [ | ||
'default', | ||
'secondary', | ||
'tertiary', | ||
'success', | ||
'success-light', | ||
'danger', | ||
'danger-light', | ||
'ghost', | ||
] as const; | ||
|
||
const meta: Meta<IconButtonArgs> = { | ||
title: 'Components/IconButton', | ||
component: IconButton, | ||
args: { | ||
children: 'More', | ||
disabled: false, | ||
label: 'More actions', | ||
onClick: fn(), | ||
size: 'M', | ||
variant: 'tertiary', | ||
}, | ||
argTypes: { | ||
children: { | ||
control: 'select', | ||
options: Object.keys(Icons), | ||
}, | ||
size: { | ||
control: 'select', | ||
options: ['S', 'M', 'L'], | ||
}, | ||
variant: { | ||
control: 'select', | ||
options: BUTTON_VARIANTS, | ||
}, | ||
}, | ||
parameters: { | ||
chromatic: { disableSnapshot: false }, | ||
docs: { | ||
source: { | ||
code: outdent` | ||
<IconButton label="More actions"> | ||
<More /> | ||
</IconButton> | ||
`, | ||
}, | ||
}, | ||
}, | ||
render: ({ children, ...args }) => { | ||
// eslint-disable-next-line import/namespace | ||
const Icon = Icons[children]; | ||
|
||
return ( | ||
<IconButton {...args}> | ||
<Icon /> | ||
</IconButton> | ||
); | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<IconButtonArgs>; | ||
|
||
export const Base = { | ||
name: 'base', | ||
} satisfies Story; | ||
|
||
export const Disabled = { | ||
args: { | ||
disabled: true, | ||
}, | ||
parameters: { | ||
docs: { | ||
source: { | ||
code: outdent` | ||
<IconButton disabled label="More actions"> | ||
<More /> | ||
</IconButton> | ||
`, | ||
}, | ||
}, | ||
}, | ||
name: 'disabled', | ||
} satisfies Story; | ||
|
||
export const SizeSmall = { | ||
args: { | ||
size: 'S', | ||
}, | ||
parameters: { | ||
docs: { | ||
source: { | ||
code: outdent` | ||
<IconButton size="S" label="More actions"> | ||
<More /> | ||
</IconButton> | ||
`, | ||
}, | ||
}, | ||
}, | ||
name: 'size small', | ||
} satisfies Story; | ||
|
||
export const SizeLarge = { | ||
args: { | ||
size: 'L', | ||
}, | ||
parameters: { | ||
docs: { | ||
source: { | ||
code: outdent` | ||
<IconButton size="L" label="More actions"> | ||
<More /> | ||
</IconButton> | ||
`, | ||
}, | ||
}, | ||
}, | ||
name: 'size large', | ||
} satisfies Story; | ||
|
||
export const AllVariants = { | ||
render: ({ children, ...args }) => { | ||
// eslint-disable-next-line import/namespace | ||
const Icon = Icons[children]; | ||
|
||
return ( | ||
<Flex gap={2}> | ||
{BUTTON_VARIANTS.map((variant) => ( | ||
<IconButton key={variant} {...args} variant={variant}> | ||
<Icon /> | ||
</IconButton> | ||
))} | ||
</Flex> | ||
); | ||
}, | ||
name: 'all variants', | ||
} satisfies Story; | ||
|
||
export const Group = { | ||
render: () => ( | ||
<IconButtonGroup> | ||
<IconButton label="Edit"> | ||
<Icons.Pencil /> | ||
</IconButton> | ||
<IconButton label="Clone"> | ||
<Icons.Duplicate /> | ||
</IconButton> | ||
<IconButton label="Delete" variant="danger"> | ||
<Icons.Trash /> | ||
</IconButton> | ||
</IconButtonGroup> | ||
), | ||
name: 'group', | ||
}; |
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 |
---|---|---|
|
@@ -32,7 +32,6 @@ const meta: Meta<ProgressArgs> = { | |
}, | ||
}, | ||
args: { | ||
children: 'loading', | ||
size: 'M', | ||
value: 50, | ||
}, | ||
|
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,81 @@ | ||
import { Meta, Canvas } from '@storybook/blocks'; | ||
import { TextButton } from '@strapi/design-system'; | ||
|
||
import * as TextButtonStories from './TextButton.stories'; | ||
|
||
<Meta of={TextButtonStories} /> | ||
|
||
# TextButton | ||
|
||
- [Overview](#overview) | ||
- [Usage](#usage) | ||
- [Props](#props) | ||
- [Variants](#variants) | ||
- [Usage with other routing libraries](#usage-with-other-routing-libraries) | ||
|
||
## Overview | ||
|
||
Typically used for internal navigation within a Strapi application. These buttons are not supposed to have "actions" | ||
e.g. clone a document. | ||
|
||
<ViewSource path="components/TextButton" /> | ||
|
||
## Usage | ||
|
||
```ts | ||
import { TextButton } from '@strapi/design-system'; | ||
``` | ||
|
||
<Canvas of={TextButtonStories.Base} /> | ||
|
||
## Props | ||
|
||
<TypeTable of={TextButton} /> | ||
|
||
## Variants | ||
|
||
### Disabled | ||
|
||
<Canvas of={TextButtonStories.Disabled} /> | ||
|
||
### Loading | ||
|
||
<Canvas of={TextButtonStories.Loading} /> | ||
|
||
### With start icon | ||
|
||
<Canvas of={TextButtonStories.StartIcon} /> | ||
|
||
### With end icon | ||
|
||
<Canvas of={TextButtonStories.EndIcon} /> | ||
|
||
## Usage with other routing libraries | ||
|
||
### React Router | ||
|
||
To use the LinkButton component with a routing library (e.g. react-router-dom), you'll need to pass the `NavLink` | ||
component to the `tag` prop in order to replace the default HTML anchor `<a />`. You'll now be able to pass all | ||
`NavLink` props. | ||
|
||
```jsx | ||
import { TextButton } from '@strapi/design-system'; | ||
import { NavLink } from 'react-router-dom'; | ||
|
||
<TextButton tag={NavLink} to="/home"> | ||
Home | ||
</TextButton>; | ||
``` | ||
|
||
### NextJS | ||
|
||
For NextJS, you'll need to wrap the `LinkButton` with the `NextLink` component | ||
|
||
```jsx | ||
import { TextButton } from '@strapi/design-system'; | ||
import NextLink from 'next/link'; | ||
|
||
<NextLink href="/home" passHref> | ||
<TextButton>Home</TextButton> | ||
</NextLink>; | ||
``` |
Oops, something went wrong.