Skip to content

nve-button

Selveste NVE-knappen. Bruk href for å gjøre den om til en link. Disse feltene skal ikke brukes:caret og pill Circle attributte skal brukes kun når man viser bare et ikon.

Arvet fra SlButton.

Denne komponenten bygger på en Shoelace-komponent. Sjekk også dokumentasjonen i Shoelace for å få full oversikt over hvordan komponenten funker.

Feil / oppgaver / PR

Ingen som vi vet om. Hvis du finner noe muffens, registrer en feil under Issues i Github og merk den med nve-button.

 

html
<nve-button>NVE-knappen</nve-button>

Eksempler

Varianter

Bruk variant for å velge farge. default er standard. success og warning skal ikke brukes. Vi bruker heller ikke outline-attributt, men neutral-variant

html
<nve-button variant="primary">primary</nve-button>
<nve-button>default</nve-button>
<nve-button variant="neutral">neutral</nve-button>
<nve-button variant="text">text</nve-button>
<nve-button variant="danger">danger</nve-button>

Størrelse

Bruk size for å endre størrelse. large er standard.

html
<nve-button size="small">small</nve-button>
<nve-button>medium</nve-button>
<nve-button size="large">large</nve-button>

Disabled

Bruk disabled for å deaktivere knappen.

html
<nve-button disabled>deaktivert</nve-button> <nve-button>ikke deaktivert</nve-button>

Prefix spor

Bruk prefix spor for å vise noe foran knapp teksten, f.eks et ikon.

html
<nve-button size="small"><nve-icon slot="prefix" name="warning"></nve-icon>Varsel</nve-button>
<nve-button><nve-icon slot="prefix" name="warning"></nve-icon>Varsel</nve-button>
<nve-button size="large"><nve-icon slot="prefix" name="warning"></nve-icon>Varsel</nve-button>

Suffix spor

Bruk suffix spor for å vise noe etter knapp teksten, f.eks et ikon.

html
<nve-button><nve-icon slot="suffix" name="thumb_up"></nve-icon>Bra</nve-button>

Loading

Bruk loading for å legge til ei snurre.

html
<nve-button loading>loading</nve-button>

Kun ikon

Knapper med kun ikon kan brukes ved å sette nve-icon i standardsporet.

html
<nve-button size="large" variant="primary"><nve-icon name="warning"></nve-icon></nve-button>
<nve-button><nve-icon name="warning"></nve-icon></nve-button>
<nve-button size="small" variant="neutral"><nve-icon name="warning"></nve-icon></nve-button>

Man kan fortsatt bruke loading attributtet for å vise kun spinner.

html
<nve-button loading size="medium" variant="primary"><nve-icon name="warning"></nve-icon></nve-button>

Knapper med bare ikon kan også bruke attributtet circle for å vise en rund knapp.

html
<nve-button circle variant="neutral" size="large"><nve-icon name="more_vert"></nve-button>
<nve-button circle><nve-icon name="more_vert"></nve-button>
<nve-button circle size="small" variant="text"><nve-icon name="more_vert"></nve-icon></nve-button>

Ikon farge

I noen tilfeller må man sette en annen farge på ikonet. Dette kan enkelt gjøres ved å sette --nve-icon-color CSS-egenskapen.

html
<nve-button size="medium" variant="neutral" style="--nve-icon-color: red"
  ><nve-icon name="warning"></nve-icon
></nve-button>

Spor

NavnBeskrivelse
(standard)The button's label.
prefixA presentational prefix icon or similar element.
suffixA presentational suffix icon or similar element.

Hendelser

NavnArvet fraBeskrivelse
sl-blurSlButtonEmitted when the button loses focus.
sl-focusSlButtonEmitted when the button gains focus.
sl-invalidSlButtonEmitted when the form control has been checked for validity and its constraints aren't satisfied.

Egenskaper

NavnTypeArvet fraBeskrivelseReflected
size'small' | 'medium' | 'large' = 'medium'
testIdstring | undefined = undefined
buttonHTMLButtonElement | HTMLLinkElement SlButton
invalidboolean = falseSlButton
titlestring = ''SlButton
variant'default' | 'primary' | 'success' | 'neutral' | 'warning' | 'danger' | 'text' = 'default'SlButtonThe button's theme variant.
caretboolean = falseSlButtonDraws the button with a caret. Used to indicate that the button triggers a dropdown menu or similar behavior.
disabledboolean = falseSlButtonDisables the button.
loadingboolean = falseSlButtonDraws the button in a loading state.
outlineboolean = falseSlButtonDraws an outlined button.
pillboolean = falseSlButtonDraws a pill-style button with rounded edges.
circleboolean = falseSlButtonDraws a circular icon button. When this attribute is present, the button expects a single `<sl-icon>` in the default slot.
type'button' | 'submit' | 'reset' = 'button'SlButtonThe type of button. Note that the default value is `button` instead of `submit`, which is opposite of how native `<button>` elements behave. When the type is `submit`, the button will submit the surrounding form.
namestring = ''SlButtonThe name of the button, submitted as a name/value pair with form data, but only when this button is the submitter. This attribute is ignored when `href` is present.
valuestring = ''SlButtonThe value of the button, submitted as a pair with the button's name as part of the form data, but only when this button is the submitter. This attribute is ignored when `href` is present.
hrefstring = ''SlButtonWhen set, the underlying button will be rendered as an `<a>` with this `href` instead of a `<button>`.
target'_blank' | '_parent' | '_self' | '_top' SlButtonTells the browser where to open the link. Only used when `href` is present.
relstring = 'noreferrer noopener'SlButtonWhen using `href`, this attribute will map to the underlying link's `rel` attribute. Unlike regular links, the default is `noreferrer noopener` to prevent security exploits. However, if you're using `target` to point to a specific tab/window, this will prevent that from working correctly. You can remove or change the default value by setting the attribute to an empty string or a value of your choice, respectively.
downloadstring | undefined SlButtonTells the browser to download the linked file as this filename. Only used when `href` is present.
formstring SlButtonThe "form owner" to associate the button with. If omitted, the closest containing form will be used instead. The value of this attribute must be an id of a form in the same document or shadow root as the button.
formActionstring SlButtonUsed to override the form owner's `action` attribute.
formEnctype'application/x-www-form-urlencoded' | 'multipart/form-data' | 'text/plain' SlButtonUsed to override the form owner's `enctype` attribute.
formMethod'post' | 'get' SlButtonUsed to override the form owner's `method` attribute.
formNoValidateboolean SlButtonUsed to override the form owner's `novalidate` attribute.
formTarget'_self' | '_blank' | '_parent' | '_top' | string SlButtonUsed to override the form owner's `target` attribute.
validity SlButtonGets the validity state object
validationMessage SlButtonGets the validation message

Metoder

NavnParametreReturtypeArvet fraBeskrivelse
handleDisabledChangeSlButton
clickSlButtonSimulates a click on the button.
focus
options: FocusOptions
SlButtonSets focus on the button.
blurSlButtonRemoves focus from the button.
checkValiditySlButtonChecks for validity but does not show a validation message. Returns `true` when valid and `false` when invalid.
getFormHTMLFormElement | nullSlButtonGets the associated form, if one exists.
reportValiditySlButtonChecks for validity and shows the browser's validation message if the control is invalid.
setCustomValidity
message: string
SlButtonSets a custom validation message. Pass an empty string to restore validity.

Deler

NavnBeskrivelse
baseThe component's base wrapper.
prefixThe container that wraps the prefix.
labelThe button's label.
suffixThe container that wraps the suffix.
caretThe button's caret icon, an `<sl-icon>` element.
spinnerThe spinner that shows when the button is in the loading state.