Button
A button lets the user perform an action with a tap or a click, like starting a new flow or confirming something. It can be also used as an anchor tag to navigate to a different page by setting to or href props.
Showcase
<LnxButton @click="..." <-- Emitted when the button is clicked > Click me! </LnxButton>
ButtonModeDisplay mode. Recommended for changing the importance Default value: BUTTON_MODES.SOLIDstring | objectConverts the button in a router-link with the given route. If `href` is set, this is ignored. Default value: undefinedbooleanIndicates if the button should take the full width of its parent Default value: falseWhen to use
- For actions: submitting a form, saving changes, opening a Modal.
- For navigation, set
hrefortoso it is a real link that can be opened in a new tab. - Keep one solid button per view for the main action, and use
outlineorclearfor the rest so they don't compete. - For a list of related actions, open them in a Dropdown from a single button.
Examples
Importance
The mode tells how important an action is: solid (the default) for the main one, outline or clear for the others.
<LnxButton>Save</LnxButton>
<LnxButton mode="outline">Preview</LnxButton>
<LnxButton mode="clear">Cancel</LnxButton>2
3
Meaning
The variant tells what the action does: danger when it destroys data, success to approve, grayscale for neutral actions.
<LnxButton variant="danger">Delete</LnxButton>
<LnxButton variant="success">Approve</LnxButton>
<LnxButton variant="grayscale">Archive</LnxButton>2
3
With an icon
Use the prefix or suffix slots. A button with only an icon needs an aria-label, so screen readers can tell what it does.
<LnxButton>
<template #prefix>
<LnxIcon icon="mdi:plus" />
</template>
New project
</LnxButton>
<LnxButton shape="icon" aria-label="Settings">
<LnxIcon icon="mdi:cog" />
</LnxButton>2
3
4
5
6
7
8
9
Loading
While the action runs, is-loading disables the button and makes it pulse, keeping its size. The loading slot, if given, replaces the content meanwhile.
<LnxButton is-loading>Saving</LnxButton>Size
lnx-size-small and lnx-size-large resize a button, or every button and field inside a container. See Sizing for other sizes.
<LnxButton class="lnx-size-small">Small</LnxButton>
<LnxButton>Default</LnxButton>
<LnxButton class="lnx-size-large">Large</LnxButton>2
3
In a form
A button is type="button" by default, so it never submits a form by accident. Set type="submit" on the one that should.
<form @submit.prevent>
<LnxButton type="submit">Send</LnxButton>
<LnxButton mode="clear">Clear</LnxButton>
</form>2
3
4
As a link
With href it renders an <a>, and with to a router-link.
<LnxButton href="https://github.com/dmoyadev/lnx" target="_blank" mode="link">
View on GitHub
</LnxButton>2
3
API
Props
| Prop | Type | Description |
|---|---|---|
variant | ButtonVariant | Applies different palette of colors Default: BUTTON_VARIANTS.PRIMARY |
mode | ButtonMode | Display mode. Recommended for changing the importance Default: BUTTON_MODES.SOLID |
shape | ButtonShape | Reimagines how it's built Default: BUTTON_SHAPES.NORMAL |
href | string | Converts the button in an anchor tag with the given URL |
to | string | object | Converts the button in a router-link with the given route. If href is set, this is ignored. |
is-loading | boolean | When loading, it is disabled and shows a different content Default: false |
is-block | boolean | Indicates if the button should take the full width of its parent Default: false |
Native attributes
| Attribute | Type | Description |
|---|---|---|
disabled | boolean | Native HTML attribute to disable the button Default: false |
target | string | Only works if href prop is set. Native HTML attribute to define where the link should open |
Events
| Event | Payload | Description |
|---|---|---|
click | PointerEvent | Emitted when the button is clicked. Native HTML event |
Slots
| Slot | Scope | Description |
|---|---|---|
default | — | Actual content of the button |
loading | — | Displayed content when the button is loading |
prefix | — | Icon that should be prefixed before to the content |
suffix | — | Icon that should be suffixed after to the content |
CSS variables
| Variable | Description |
|---|---|
--lnx-button-content-gap | Separation between elements inside the button |
--lnx-button-border | — |
--lnx-button-border-color | — |
--lnx-button-border-radius | — |
--lnx-button-box-shadow | — |
--lnx-button-background | — |
--lnx-button-color | Text color |
--lnx-button-padding | — |
--lnx-button-size | — |
Types
ButtonVariant
export const BUTTON_VARIANTS = {
PRIMARY: 'primary',
GRAYSCALE: 'grayscale',
DANGER: 'danger',
SUCCESS: 'success',
INFO: 'info',
WARNING: 'warning',
} as const;
export type ButtonVariant = ValueOf<typeof BUTTON_VARIANTS>;2
3
4
5
6
7
8
9
ButtonMode
export const BUTTON_MODES = {
SOLID: 'solid',
OUTLINE: 'outline',
CLEAR: 'clear',
LINK: 'link',
} as const;
export type ButtonMode = ValueOf<typeof BUTTON_MODES>;2
3
4
5
6
7
ButtonShape
export const BUTTON_SHAPES = {
NORMAL: 'normal',
ICON: 'icon',
CIRCLE: 'circle',
} as const;
export type ButtonShape = ValueOf<typeof BUTTON_SHAPES>;2
3
4
5
6