2024-11-26 11:59:11 +00:00
< script setup >
2024-12-04 15:06:34 +00:00
import Button from '~/components/ui/Button.vue'
2024-12-17 22:09:10 +00:00
import Layout from '~/components/ui/Layout.vue'
2024-12-18 15:58:27 +00:00
import { color } from '~/composables/colors.ts';
2024-12-04 15:06:34 +00:00
2024-11-26 11:59:11 +00:00
const click = () => new Promise(resolve => setTimeout(resolve, 1000))
< / script >
# Button
Buttons are UI elements that users can interact with to perform actions. Funkwhale uses buttons in many contexts.
2024-12-15 23:07:09 +00:00
| Prop | Data type | Required? | Default | Description |
| -------------- | --------- | --------- | ------- | ---------------------------------------------- |
| `shadow` | Boolean | No | `false` | Whether to render the button with a shadow |
| `round` | Boolean | No | `false` | Whether to render the button as a round button |
| `icon` | String | No | | The icon attached to the button |
| `aria-pressed` | Boolean | No | `false` | Whether the button is in an active state |
| `is-loading` | Boolean | No | `false` | Whether the button is in a loading state |
In addition, use [Colors] and [Variants]
2024-11-26 11:59:11 +00:00
## Button colors
Buttons come in different types depending on the type of action they represent.
2024-12-18 15:58:27 +00:00
Find [a complete overview of recommended styles on the color page ](../../using-color#links-and-buttons ).
### Default
< Layout flex >
```vue-html
< Button >
Default button
< / Button >
```
< Layout class = "preview" >
< Button >
Default button
< / Button >
< / Layout >
< / Layout >
2024-11-26 11:59:11 +00:00
### Primary
Primary buttons represent **positive** actions such as uploading, confirming, and accepting changes.
```vue-html
2024-12-15 23:07:09 +00:00
< Button primary >
2024-11-26 11:59:11 +00:00
Primary button
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
```
2024-12-15 23:07:09 +00:00
< Button primary >
2024-11-26 11:59:11 +00:00
Primary button
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
### Secondary
Secondary buttons represent **neutral** actions such as cancelling a change or dismissing a notification.
```vue-html
2024-12-15 23:07:09 +00:00
< Button secondary >
2024-11-26 11:59:11 +00:00
Secondary button
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
```
2024-12-15 23:07:09 +00:00
< Button secondary >
2024-11-26 11:59:11 +00:00
Secondary button
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
### Destructive
Desctrutive buttons represent **dangerous** actions including deleting items or purging domain information.
```vue-html
2024-12-15 23:07:09 +00:00
< Button destructive >
2024-11-26 11:59:11 +00:00
Destructive button
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
```
2024-12-15 23:07:09 +00:00
< Button destructive >
2024-11-26 11:59:11 +00:00
Destructive button
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
## Button variants
Buttons come in different styles that you can use depending on the location of the button.
### Solid
Solid buttons have a filled background. Use these to emphasize the action the button performs.
::: info
This is the default style. If you don't specify a style, a solid button is rendered.
:::
```vue-html
2024-12-04 15:06:34 +00:00
< Button >
2024-11-26 11:59:11 +00:00
Filled button
2024-12-04 15:06:34 +00:00
< / Button >
2024-12-15 23:07:09 +00:00
< Button solid >
Also filled button
< / Button >
2024-11-26 11:59:11 +00:00
```
2024-12-04 15:06:34 +00:00
< Button >
2024-11-26 11:59:11 +00:00
Filled button
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
2024-12-15 23:07:09 +00:00
< Button solid >
Also filled button
< / Button >
2024-11-26 11:59:11 +00:00
### Outline
Outline buttons have a transparent background. Use these to deemphasize the action the button performs.
```vue-html
2024-12-15 23:07:09 +00:00
< Button outline secondary >
2024-11-26 11:59:11 +00:00
Outline button
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
```
2024-12-15 23:07:09 +00:00
< Button outline secondary >
2024-11-26 11:59:11 +00:00
Outline button
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
### Ghost
Ghost buttons have a transparent background and border. Use these to deemphasize the action the button performs.
```vue-html
2024-12-15 23:07:09 +00:00
< Button ghost secondary >
2024-11-26 11:59:11 +00:00
Ghost button
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
```
2024-12-15 23:07:09 +00:00
< Button ghost secondary >
2024-11-26 11:59:11 +00:00
Ghost button
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
## Button styles
### Shadow
You can give a button a shadow to add depth.
```vue-html
2024-12-04 15:06:34 +00:00
< Button shadow >
2024-11-26 11:59:11 +00:00
Shadow button
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
```
2024-12-04 15:06:34 +00:00
< Button shadow >
2024-11-26 11:59:11 +00:00
Shadow button
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
## Button shapes
You can choose different shapes for buttons depending on their location and use.
### Normal
Normal buttons are slightly rounded rectangles.
::: info
This is the default shape. If you don't specify a type, a normal button is rendered.
:::
```vue-html
2024-12-04 15:06:34 +00:00
< Button >
2024-11-26 11:59:11 +00:00
Normal button
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
```
2024-12-04 15:06:34 +00:00
< Button >
2024-11-26 11:59:11 +00:00
Normal button
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
### Round
Round buttons have fully rounded edges.
```vue-html
2024-12-04 15:06:34 +00:00
< Button round >
2024-11-26 11:59:11 +00:00
Round button
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
```
2024-12-04 15:06:34 +00:00
< Button round >
2024-11-26 11:59:11 +00:00
Round button
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
## Button states
You can pass a state to indicate whether a user can interact with a button.
### Active
2024-12-15 23:07:09 +00:00
You can force an active state by passing an `aria-pressed` prop.
This can be useful for toggle buttons (if you don't want to use a [Toggle component ](toggle ))
2024-11-26 11:59:11 +00:00
```vue-html
2024-12-15 23:07:09 +00:00
< Button aria-pressed >
2024-11-26 11:59:11 +00:00
Active button
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
```
2024-12-15 23:07:09 +00:00
**Secondary (default):**
< Button >
Inactive button
< / Button >
< Button aria-pressed >
Active button
< / Button >
---
**Primary:**
< Button primary >
Inactive button
< / Button >
< Button primary aria-pressed >
2024-11-26 11:59:11 +00:00
Active button
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
### Disabled
Disabled buttons are non-interactive and inherit a less bold color than the one provided. You can apply a disabled state by passing a `disabled` prop.
```vue-html
2024-12-04 15:06:34 +00:00
< Button disabled >
2024-11-26 11:59:11 +00:00
Disabled button
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
```
2024-12-04 15:06:34 +00:00
< Button disabled >
2024-11-26 11:59:11 +00:00
Disabled button
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
### Loading
If a user can't interact with a button until something has finished loading, you can add a spinner by passing the `is-loading` prop.
```vue-html
2024-12-04 15:06:34 +00:00
< Button is-loading >
2024-11-26 11:59:11 +00:00
Loading button
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
```
2024-12-04 15:06:34 +00:00
< Button is-loading >
2024-11-26 11:59:11 +00:00
Loading button
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
### Promise handling in `@click`
When a function passed to `@click` returns a promise, the button automatically toggles a loading state on click. When the promise resolves or is rejected, the loading state turns off.
::: danger
2024-12-04 15:06:34 +00:00
There is no promise rejection mechanism implemented in the `<Button>` component. Make sure the `@click` handler never rejects.
2024-11-26 11:59:11 +00:00
:::
```vue
< script setup lang = "ts" >
const click = () => new Promise((resolve) => setTimeout(resolve, 1000));
< / script >
< template >
2024-12-04 15:06:34 +00:00
< Button @click =" click " > Click me </ Button >
2024-11-26 11:59:11 +00:00
< / template >
```
2024-12-04 15:06:34 +00:00
< Button @click =" click " >
2024-11-26 11:59:11 +00:00
Click me
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
You can override the promise state by passing a false `is-loading` prop.
```vue-html
2024-12-04 15:06:34 +00:00
< Button :is-loading = "false" >
2024-11-26 11:59:11 +00:00
Click me
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
```
2024-12-04 15:06:34 +00:00
< Button :is-loading = "false" >
2024-11-26 11:59:11 +00:00
Click me
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
## Icons
You can use [Bootstrap Icons ](https://icons.getbootstrap.com/ ) in your button component
::: info
2024-12-19 13:57:04 +00:00
Icon buttons shrink down to the icon size if you don't pass any content. If you want to keep the button at full width with just an icon, add `width=standard`
2024-11-26 11:59:11 +00:00
:::
```vue-html
2024-12-19 13:57:04 +00:00
< Button icon = "bi-three-dots-vertical" / >
< Button round icon = "bi-x" / >
< Button primary icon = "bi-save" width = "standard" / >
< Button destructive icon = "bi-trash" >
2024-11-26 11:59:11 +00:00
Delete
2024-12-04 15:06:34 +00:00
< / Button >
2024-11-26 11:59:11 +00:00
```
2024-12-15 23:07:09 +00:00
< Button icon = "bi-three-dots-vertical" / >
< Button round icon = "bi-x" / >
2024-12-17 22:09:10 +00:00
< Button primary icon = "bi-save" width = "standard" / >
2024-12-15 23:07:09 +00:00
< Button destructive icon = "bi-trash" >
2024-11-26 11:59:11 +00:00
Delete
2024-12-04 15:06:34 +00:00
< / Button >
2024-12-17 22:09:10 +00:00
## Width and alignment
< Layout flex >
```vue-html
< Button width = "auto" > ·< / Button >
< Button width = "standard" > ·< / Button >
< Button width = "full" > ·< / Button >
< hr / >
< Button alignSelf = "start" > ·< / Button >
< Button alignSelf = "center" > ·< / Button >
< Button alignSelf = "end" > ·< / Button >
< hr / >
< Button alignText = "left" > ·< / Button >
< Button alignText = "center" > ·< / Button >
< Button alignText = "right" > ·< / Button >
```
< Layout class = "preview solid secondary" stack no-gap >
< Button width = "auto" > ·< / Button >
< Button width = "standard" > ·< / Button >
< Button width = "full" > ·< / Button >
< hr / >
< Button alignSelf = "start" > ·< / Button >
< Button alignSelf = "center" > ·< / Button >
< Button alignSelf = "end" > ·< / Button >
< hr / >
< Button alignText = "left" > ·< / Button >
< Button alignText = "center" > ·< / Button >
< Button alignText = "right" > ·< / Button >
(Text to stretch the column)
< / Layout >
< / Layout >