Button
Komponent som används för att låta användaren utföra en handling t.ex. spara ifylld information eller öppna ett formulär.
Installation
- npm
- Yarn
- pnpm
npm install @midas-ds/components
yarn add @midas-ds/components
pnpm add @midas-ds/components
import { Button } from '@midas-ds/components'
Varianter
Primär
En primär knapp används för den primära eller positiva handlingen i ett flöde (OK, Skicka, Nästa). Det bör endast finnas en primärknapp per sida, sektion eller tydligt avgränsad yta.
Sekundär
En sekundär knapp används för underordnade handlingar i ett flöde (Avbryt, Tillbaka). Används alltid tillsammans med en primär knapp.
Tertiär
Den tertiära knappen kan användas tillsammans med primär- och sekundär knapp där det finns behov av ett ytterligare val
Om den tertiära knappen används fristående från andra knappar ska den ha en ikon. Ikonen läggs till via icon
.
Du kan välja vilken sida av texten ikonen ska vara på med iconPlacement
.
Grupp av knappar
För att få korrekt layout på flertalet knappar kan komponenten ButtonGroup
användas.
Riktlinjer
Val av komponent
Se mönstret Knappar och länkar
Generella riktlinjer
- Undvik inaktiva knappar. Alla knappar i externa system ska gå att interagera med. Om användaren inte uppfyllt kraven, t.ex för att gå till nästa sida i en e-tjänst, ska ett felmeddelande visas som påtalar vad som krävs för att kunna gå vidare.
- Undvik att ha för många knappar på samma sida.
Placering och ordning
Knappar placeras i regel i nedre vänstra hörnet. Vi sätter alltid den primära knappen till vänster.
API
Button
Namn | Typ | Standard | Beskrivning |
---|---|---|---|
variant | "icon" | "primary" | "secondary" | "tertiary" | "danger" | primary | Primary button is used as a positive action in a flow. Always use one primary button and never a seconday button on it's own. When using just an icon you must pass an aria-label |
fullwidth | boolean | false | Adds width: 100%; for the button to span entire width of parent |
size | "small" | - | Choose between different button sizes |
icon | LucideIcon | - | Add an icon from lucide-react @see {@link https://lucide.dev/icons/} |
iconSize | number | - | Adjust icon size |
iconPlacement | "left" | "right" | - | Display your icon on the left och right side of the button text |
children | (ReactNode | ((values: ButtonRenderProps & { defaultChildren: ReactNode; }) => ReactNode)) & (ReactNode | ((values: ButtonRenderProps & { ...; }) => ReactNode)) | - | The children of the component. A function may be provided to alter the children based on component state. |
form | string | - | The `<form>` element to associate the button with. The value of this attribute must be the id of a `<form>` in the same document. |
formAction | string | - | The URL that processes the information submitted by the button. Overrides the action attribute of the button's form owner. |
formEncType | string | - | Indicates how to encode the form data that is submitted. |
formMethod | string | - | Indicates the HTTP method used to submit the form. |
formNoValidate | boolean | - | Indicates that the form is not to be validated when it is submitted. |
formTarget | string | - | Overrides the target attribute of the button's form owner. |
name | string | - | Submitted as a pair with the button's value as part of the form data. |
value | string | - | The value associated with the button's name when it's submitted with the form data. |
isPending | boolean | - | Whether the button is in a pending state. This disables press and hover events while retaining focusability, and announces the pending state to screen readers. |
type | "button" | "submit" | "reset" | 'button' | The behavior of the button when used in an HTML form. |
isDisabled | boolean | - | Whether the button is disabled. |
id | string | - | The element's unique identifier. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id). |
autoFocus | boolean | - | Whether the element should receive focus on render. |
preventFocusOnPress | boolean | - | Whether to prevent focus from moving to the button when pressing it. Caution, this can make the button inaccessible and should only be used when alternative keyboard interaction is provided, such as ComboBox's MenuTrigger or a NumberField's increment/decrement control. |
excludeFromTabOrder | boolean | - | Whether to exclude the element from the sequential tab order. If true, the element will not be focusable via the keyboard by tabbing. This should be avoided except in rare scenarios where an alternative means of accessing the element or its functionality via the keyboard is available. |
slot | string | - | A slot name for the component. Slots allow the component to receive props from a parent component. An explicit `null` value indicates that the local props completely override all props received from a parent. |
className | string | ((values: ButtonRenderProps & { defaultClassName: string; }) => string) | - | The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state. |
style | CSSProperties | ((values: ButtonRenderProps & { defaultStyle: CSSProperties; }) => CSSProperties) | - | The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the element. A function may be provided to compute the style based on component state. |