Button

A button is a widget that enables users to trigger an action or event, such as submitting a form, opening a dialog, canceling an action, or performing a delete operation.

Installation

Installation

Import the component in the script section of your Svelte file:


import Button from 'svve11/Button.svelte'
            
Usage

Usage

Creating a Button

To supply the button with its contents, an options object is passed as a prop to the button. This object can be created in the script section of the .svelte file or imported in from another location. The options object has 5 properties.

    Required Props

  • label (string): Sets the aria-label attribute of the button component.
  • content (string): Sets the text that is displayed inside the button component.
  • handleClick (function): Defines the action or event to be triggered when the button is clicked.
  • Optional Props

  • id (string): Sets the id attribute of the button component.
  • style (string): Sets the styles of the button component.

Example Options Object:


const buttonOptions = {
  id: 'demo-button-1',
  content: 'Click me!',
  label: 'accessible-button-1',
  handleClick: () => alert('You clicked a button!'),
  style: 'height: 50px; width: 300px;'
};
              

Instantiating a button


<Button options={buttonOptions}/>
              

Example Button:

Styling

Styling

The button is made of 1 component that can have styles applied to it using the pre-assigned class and a globally scoped CSS stylesheet. The class is:

  • sv-button: This applies styling to the button
Component API

Component API

This table describes the props that should be passed to the button in the options object
PropTypeRequiredDefault Value
label string true N/A
content string true N/A
handleClick function false N/A
id string false N/A
style string false N/A