mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +00:00
docs(button): improve docs
This commit is contained in:
parent
a3a494f29f
commit
b5b102aff5
1 changed files with 44 additions and 12 deletions
|
@ -4,57 +4,73 @@
|
||||||
import TrashCan from "carbon-icons-svelte/lib/TrashCan.svelte";
|
import TrashCan from "carbon-icons-svelte/lib/TrashCan.svelte";
|
||||||
import Login from "carbon-icons-svelte/lib/Login.svelte";
|
import Login from "carbon-icons-svelte/lib/Login.svelte";
|
||||||
import Preview from "../../components/Preview.svelte";
|
import Preview from "../../components/Preview.svelte";
|
||||||
|
|
||||||
let index = 1;
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
Buttons trigger actions in the interface. Use them to submit forms, navigate between pages, or perform specific tasks. Choose from different styles and sizes to match the importance and context of each action.
|
||||||
|
|
||||||
## Primary button
|
## Primary button
|
||||||
|
|
||||||
|
The default button style is primary. This should be used for primary actions.
|
||||||
|
|
||||||
<Button>Primary button</Button>
|
<Button>Primary button</Button>
|
||||||
|
|
||||||
## Secondary button
|
## Secondary button
|
||||||
|
|
||||||
|
Set `kind="secondary"` for secondary actions.
|
||||||
|
|
||||||
<Button kind="secondary">Secondary button</Button>
|
<Button kind="secondary">Secondary button</Button>
|
||||||
|
|
||||||
## Tertiary button
|
## Tertiary button
|
||||||
|
|
||||||
|
Set `kind="tertiary"` for tertiary actions.
|
||||||
|
|
||||||
<Button kind="tertiary">Tertiary button</Button>
|
<Button kind="tertiary">Tertiary button</Button>
|
||||||
|
|
||||||
## Ghost button
|
## Ghost button
|
||||||
|
|
||||||
|
Set `kind="ghost"` for ghost-style buttons.
|
||||||
|
|
||||||
<Button kind="ghost">Ghost button</Button>
|
<Button kind="ghost">Ghost button</Button>
|
||||||
|
|
||||||
## Danger button
|
## Danger button
|
||||||
|
|
||||||
|
Set `kind="danger"` for destructive actions.
|
||||||
|
|
||||||
<Button kind="danger">Danger button</Button>
|
<Button kind="danger">Danger button</Button>
|
||||||
|
|
||||||
## Danger tertiary button
|
## Danger tertiary button
|
||||||
|
|
||||||
|
Set `kind="danger-tertiary"` for less prominent destructive actions.
|
||||||
|
|
||||||
<Button kind="danger-tertiary">Danger tertiary button</Button>
|
<Button kind="danger-tertiary">Danger tertiary button</Button>
|
||||||
|
|
||||||
## Danger tertiary, icon-only button
|
## Danger tertiary, icon-only button
|
||||||
|
|
||||||
<InlineNotification svx-ignore lowContrast title="Note:" kind="info" hideCloseButton>
|
<InlineNotification svx-ignore lowContrast title="Note:" kind="info" hideCloseButton>
|
||||||
<div class="body-short-01">
|
<div class="body-short-01">
|
||||||
You must provide an <strong>iconDescription</strong> for the button tooltip.
|
Provide an <strong>iconDescription</strong> for accessibility. This text will be used as the button's tooltip and screen reader label.
|
||||||
</div>
|
</div>
|
||||||
</InlineNotification>
|
</InlineNotification>
|
||||||
|
|
||||||
<Button kind="danger-tertiary"iconDescription="Delete" icon={TrashCan} />
|
<Button kind="danger-tertiary" iconDescription="Delete" icon={TrashCan} />
|
||||||
|
|
||||||
## Danger ghost button
|
## Danger ghost button
|
||||||
|
|
||||||
|
Set `kind="danger-ghost"` for ghost-style destructive actions.
|
||||||
|
|
||||||
<Button kind="danger-ghost">Danger ghost button</Button>
|
<Button kind="danger-ghost">Danger ghost button</Button>
|
||||||
|
|
||||||
## Button with icon
|
## Button with icon
|
||||||
|
|
||||||
|
Add an icon to the button using the `icon` prop.
|
||||||
|
|
||||||
<Button icon={Add}>With icon</Button>
|
<Button icon={Add}>With icon</Button>
|
||||||
|
|
||||||
## Icon-only button
|
## Icon-only button
|
||||||
|
|
||||||
<InlineNotification svx-ignore lowContrast title="Note:" kind="info" hideCloseButton>
|
<InlineNotification svx-ignore lowContrast title="Note:" kind="info" hideCloseButton>
|
||||||
<div class="body-short-01">
|
<div class="body-short-01">
|
||||||
You must provide an <strong>iconDescription</strong> for the button tooltip.
|
Provide an <strong>iconDescription</strong> for accessibility. This text will be used as the button's tooltip and screen reader label.
|
||||||
</div>
|
</div>
|
||||||
</InlineNotification>
|
</InlineNotification>
|
||||||
|
|
||||||
|
@ -62,11 +78,13 @@
|
||||||
|
|
||||||
## Icon-only, link button
|
## Icon-only, link button
|
||||||
|
|
||||||
|
Set `href` to create an icon-only link button.
|
||||||
|
|
||||||
<Button iconDescription="Login" icon={Login} href="#" />
|
<Button iconDescription="Login" icon={Login} href="#" />
|
||||||
|
|
||||||
## Icon-only button (custom tooltip position)
|
## Icon-only button (custom tooltip position)
|
||||||
|
|
||||||
The tooltip position and alignment can be controlled by `tooltipPosition` and `tooltipAlignment`.
|
Control the tooltip position and alignment with `tooltipPosition` and `tooltipAlignment`.
|
||||||
|
|
||||||
<Button tooltipPosition="right" tooltipAlignment="end" iconDescription="Tooltip text" icon={Add} />
|
<Button tooltipPosition="right" tooltipAlignment="end" iconDescription="Tooltip text" icon={Add} />
|
||||||
|
|
||||||
|
@ -78,19 +96,21 @@ Set `isSelected` to `true` to enable the selected state for an icon-only, ghost
|
||||||
|
|
||||||
## Link button
|
## Link button
|
||||||
|
|
||||||
If an `href` value is specified, the component will render an [anchor element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a) instead of a `button` element.
|
Set `href` to render an [anchor element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a) instead of a `button` element.
|
||||||
|
|
||||||
<Button href="#">Link button</Button>
|
<Button href="#">Link button</Button>
|
||||||
|
|
||||||
## Link button with icon
|
## Link button with icon
|
||||||
|
|
||||||
|
Similarly, link buttons can have icons.
|
||||||
|
|
||||||
<Button href="#" icon={Add}>Link button with icon</Button>
|
<Button href="#" icon={Add}>Link button with icon</Button>
|
||||||
|
|
||||||
## Custom element
|
## Custom element
|
||||||
|
|
||||||
By default, the `Button` will render either a `button` or `a` element.
|
By default, the `Button` will render either a `button` or `a` element.
|
||||||
|
|
||||||
If you need to render a different element, set `as` to `true` and spread `let:props` to the element.
|
To render a different element, set `as` to `true` and spread `let:props` to the element.
|
||||||
|
|
||||||
<Button as let:props>
|
<Button as let:props>
|
||||||
<p {...props}>Custom element</p>
|
<p {...props}>Custom element</p>
|
||||||
|
@ -98,6 +118,10 @@ If you need to render a different element, set `as` to `true` and spread `let:pr
|
||||||
|
|
||||||
## Field size
|
## Field size
|
||||||
|
|
||||||
|
The default size is "default".
|
||||||
|
|
||||||
|
Set `size="field"` for field-sized buttons.
|
||||||
|
|
||||||
<Button size="field">Primary</Button>
|
<Button size="field">Primary</Button>
|
||||||
<Button size="field" kind="secondary">Secondary</Button>
|
<Button size="field" kind="secondary">Secondary</Button>
|
||||||
<Button size="field" kind="tertiary">Tertiary</Button>
|
<Button size="field" kind="tertiary">Tertiary</Button>
|
||||||
|
@ -106,6 +130,8 @@ If you need to render a different element, set `as` to `true` and spread `let:pr
|
||||||
|
|
||||||
## Small size
|
## Small size
|
||||||
|
|
||||||
|
Set `size="small"` for small buttons.
|
||||||
|
|
||||||
<Button size="small">Primary</Button>
|
<Button size="small">Primary</Button>
|
||||||
<Button size="small" kind="secondary">Secondary</Button>
|
<Button size="small" kind="secondary">Secondary</Button>
|
||||||
<Button size="small" kind="tertiary">Tertiary</Button>
|
<Button size="small" kind="tertiary">Tertiary</Button>
|
||||||
|
@ -114,6 +140,8 @@ If you need to render a different element, set `as` to `true` and spread `let:pr
|
||||||
|
|
||||||
## Large size
|
## Large size
|
||||||
|
|
||||||
|
Set `size="lg"` for large buttons.
|
||||||
|
|
||||||
<Button size="lg">Primary</Button>
|
<Button size="lg">Primary</Button>
|
||||||
<Button size="lg" kind="secondary">Secondary</Button>
|
<Button size="lg" kind="secondary">Secondary</Button>
|
||||||
<Button size="lg" kind="tertiary">Tertiary</Button>
|
<Button size="lg" kind="tertiary">Tertiary</Button>
|
||||||
|
@ -122,6 +150,8 @@ If you need to render a different element, set `as` to `true` and spread `let:pr
|
||||||
|
|
||||||
## Extra-large size
|
## Extra-large size
|
||||||
|
|
||||||
|
Set `size="xl"` for extra-large buttons.
|
||||||
|
|
||||||
<Button size="xl">Primary</Button>
|
<Button size="xl">Primary</Button>
|
||||||
<Button size="xl" kind="secondary">Secondary</Button>
|
<Button size="xl" kind="secondary">Secondary</Button>
|
||||||
<Button size="xl" kind="tertiary">Tertiary</Button>
|
<Button size="xl" kind="tertiary">Tertiary</Button>
|
||||||
|
@ -130,6 +160,8 @@ If you need to render a different element, set `as` to `true` and spread `let:pr
|
||||||
|
|
||||||
## Disabled state
|
## Disabled state
|
||||||
|
|
||||||
|
Set `disabled` to disable the button.
|
||||||
|
|
||||||
<Button disabled>Disabled button</Button>
|
<Button disabled>Disabled button</Button>
|
||||||
<Button disabled iconDescription="Tooltip text" icon={Add} />
|
<Button disabled iconDescription="Tooltip text" icon={Add} />
|
||||||
|
|
||||||
|
@ -139,7 +171,7 @@ Set `expressive` to `true` to use Carbon's expressive typesetting.
|
||||||
|
|
||||||
<InlineNotification svx-ignore lowContrast title="Note:" kind="info" hideCloseButton>
|
<InlineNotification svx-ignore lowContrast title="Note:" kind="info" hideCloseButton>
|
||||||
<div class="body-short-01">
|
<div class="body-short-01">
|
||||||
Expressive styles only work with the default, "lg", and "xl" button sizes.
|
Use expressive styles with default, "lg", or "xl" button sizes.
|
||||||
</div>
|
</div>
|
||||||
</InlineNotification>
|
</InlineNotification>
|
||||||
|
|
||||||
|
@ -163,6 +195,8 @@ Set `expressive` to `true` to use Carbon's expressive typesetting.
|
||||||
|
|
||||||
## Skeleton
|
## Skeleton
|
||||||
|
|
||||||
|
Set `skeleton` to show a loading state.
|
||||||
|
|
||||||
<Button size="xl" skeleton />
|
<Button size="xl" skeleton />
|
||||||
<Button size="lg" skeleton />
|
<Button size="lg" skeleton />
|
||||||
<Button skeleton />
|
<Button skeleton />
|
||||||
|
@ -171,8 +205,6 @@ Set `expressive` to `true` to use Carbon's expressive typesetting.
|
||||||
|
|
||||||
## Programmatic focus
|
## Programmatic focus
|
||||||
|
|
||||||
Bind to the `ref` prop to access a reference to the underlying button element.
|
Bind to the `ref` prop to access the button element for programmatic focus.
|
||||||
|
|
||||||
You can use this reference to programmatically focus the button.
|
|
||||||
|
|
||||||
<FileSource src="/framed/Button/ProgrammaticFocus" />
|
<FileSource src="/framed/Button/ProgrammaticFocus" />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue