To create a button, use the Button component:

<script>
  import { Button } from "@makigas/genshi-svelte";
</script>

<Button>Click me</Button>

Use the Link component instead. It accepts a prop called href with an URL. The button will be rendered as an hyperlink. It is important to always understand the semantic distinction between a link and a button. Only pass an href prop if you want the browser to point at a different address. You shouldn’t use regular buttons with JavaScript events to change the browser URL if you can avoid it. Also, you shouldn’t use a link to trigger some interactivity.

<script>
  import { Link } from "@makigas/genshi-svelte";
</script>

<Link href="https://github.com/makigas/genshi">Star repo on GitHub</Link>
Star repo on GitHub

Buttons with icons

The button component is compatible with symbolic icons. You can provide two snippets called iconBefore and iconAfter. These snippets must emit SVG.

You can also omit the text altogether, but remember to use an aria-label in that case in the Button component.

Button sizes

Buttons come in a variety of sizes. If you don’t want to use the default medium size, change it via the size parameter, which accepts one of the possible values in: xs sm md lg xl.

<Button size="xs">Extra small</Button>
<Button size="sm">Small</Button>
<Button size="md">Medium (default)</Button>
<Button size="lg">Large</Button>
<Button size="xl">Extra large</Button>

Button appearance

Depending on the intentions, a different visual indication of the button may help convey additional meaning.

  • Use the accent button to boldly indicate the suggested action. Do not abuse of this button, though, because if every action is important, then there is no important action.
  • Use the destructive button to indicate that triggering an action may have consequences where data is removed or affect the system.
  • Use the link button to disguise a button as a link, or to treat it as a ghost button.
<Button>Outline</Button>
<Button appearance="accent">Accent</Button>
<Button appearance="destructive">Destructive</Button>
<Button appearance="link">Link</Button>

Disabled buttons

To mark a button as disabled and non clickable, add the disabled prop.

<Button disabled>Can't touch this</Button>