Button
A button allows users to trigger an action or event, such as submitting a form, triggering a process or navigate users within an application.
Usage
<script> import { Button } from 'deskblocks'; </script> <Button>Label</Button>
Variants
<Button variant="primary">Label</Button> <Button variant="secondary">Label</Button> <Button variant="tertiary">Label</Button> <!-- Destructive --> <Button variant="danger">Label</Button> <Button variant="danger-secondary">Label</Button> <!-- Ghost --> <Button variant="ghost">Label</Button>
Link button
A button can be turned into a link by using the href
property, making it function like an anchor tag.
Security Considerations:
When the
href
property is used, it is important to ensure that the link is secure, especially if it leads to an external website. Therefore, therel
attribute is set tonoopener
andnoreferrer
by default when thehref
attribute is used.Read more on this: https://developer.chrome.com/docs/lighthouse/best-practices/external-anchors-use-rel-noopener/
<Button href="https://zoho.com/desk">Open Link</Button>
Disabled state
<Button disabled variant="primary">Label</Button> <Button disabled variant="secondary">Label</Button> <Button disabled variant="tertiary">Label</Button> <Button disabled variant="danger">Label</Button> <Button disabled variant="danger-secondary">Label</Button> <Button disabled variant="ghost">Label</Button>
Buton with icon
The slots labeled “left-icon” and “right-icon” should be used for placing icons on the left and right sides, respectively. The icon’s color is automatically selected by the component based on the context.
Note:
<script> import { Button, Icon } from 'deskblocks'; import { IconIdea } from 'deskblocks/icons'; </script> <Button> <Icon slot="left-icon" icon={IconIdea} /> Get Started </Button> <Button> <Icon slot="right-icon" icon="→" /> Get Started </Button>
Icon button
To render an icon on its own, the IconButton
component can be used. The icon’s color is automatically determined by the component based on the context.
<script> import { IconButton, Icon } from 'deskblocks'; import { IconUndo } from 'deskblocks/icons'; </script> <IconButton><Icon icon={IconUndo} /></IconButton> <IconButton variant="secondary"><Icon icon={IconUndo} /></IconButton> <IconButton variant="tertiary"><Icon icon={IconUndo} /></IconButton> <IconButton variant="danger"><Icon icon={IconUndo} /></IconButton> <IconButton variant="danger-secondary"><Icon icon={IconUndo} /></IconButton> <IconButton variant="ghost"><Icon icon={IconUndo} /></IconButton>
Loading state
The loading state for the button can be displayed by placing the Spinner component in the left-icon
slot.
<script> import { Button, Spinner } from 'deskblocks'; </script> <Button> <Spinner slot="left-icon" onbrand /> Loading </Button>
Props
variant | ‘primary’ | ‘secondary’ | ‘tertiary’ | ‘ghost’ | ‘danger’ | ‘danger-secondary’ | ‘primary’ | Determines the visual style of the button. |
disabled | boolean | false | Disables the button, preventing user interaction. |
href | string | undefined | Specifies the URL to navigate to when the button is clicked, making the button function as a link. |
popovertarget | string | undefined | Specifies the ID of an associated popover element that will be triggered by the button. |
tabindex | number | 0 | Sets the order in which the button is focused during keyboard navigation. |
class | string | undefined | Custom CSS class name for additional styling. |
Slots
default
left-icon
right-icon
Events
on:click
on:focus
on:blur
on:mouseover
on:mouseenter
on:mouseleave