Button
Usage
Use the default slot to set the label of the Button.
<template>
<PButton>Button</PButton>
</template>
Label
Use the label prop to set the label of the Button.
<template>
<PButton label="Button" />
</template>
Color
Use the color prop to change the color of the Button.
<template>
<PButton color="neutral">Button</PButton>
</template>
Variant
Use the variant prop to change the variant of the Button.
<template>
<PButton color="neutral" variant="outline">Button</PButton>
</template>
Size
Use the size prop to change the size of the Button.
<template>
<PButton size="xl">Button</PButton>
</template>
Icon
Use the icon prop to show an Icon inside the Button.
<template>
<PButton icon="i-lucide:rocket" size="md" color="primary" variant="solid">Button</PButton>
</template>
Use the leading and trailing props to set the icon position or the leading-icon and trailing-icon props to set a different icon for each position.
<template>
<PButton trailing-icon="i-lucide:arrow-right" size="md">Button</PButton>
</template>
The label as prop or slot is optional so you can use the Button as an icon-only button.
<template>
<PButton icon="i-lucide:search" size="md" color="primary" variant="solid" />
</template>
Avatar
Use the avatar prop to show an Avatar inside the Button.
<template>
<PButton
:avatar="{
src: 'https://github.com/nuxt.png'
}"
size="md"
color="neutral"
variant="outline"
>
Button
</PButton>
</template>
The label as prop or slot is optional so you can use the Button as an avatar-only button.
<template>
<PButton
:avatar="{
src: 'https://github.com/nuxt.png'
}"
size="md"
color="neutral"
variant="outline"
/>
</template>
Link
You can pass any property from the Link component such as to, target, etc.
<template>
<PButton to="https://github.com/nuxt/ui" target="_blank">Button</PButton>
</template>
When the Button is a link or when using the active prop, you can use the active-color and active-variant props to customize the active state.
<template>
<PButton active color="neutral" variant="outline" active-color="primary" active-variant="solid">
Button
</PButton>
</template>
You can also use the active-class and inactive-class props to customize the active state.
<template>
<PButton active active-class="font-bold" inactive-class="font-light">Button</PButton>
</template>
app.config.ts file under the pohon.button.variants.active key.export default defineAppConfig({
pohon: {
button: {
variants: {
active: {
true: {
base: 'font-bold'
}
}
}
}
}
})
Loading
Use the loading prop to show a loading icon and disable the Button.
<template>
<PButton loading>Button</PButton>
</template>
Use the loading-auto prop to show the loading icon automatically while the @click promise is pending.
<script setup lang="ts">
async function onClick() {
return new Promise<void>((res) => setTimeout(res, 1000));
}
</script>
<template>
<PButton
loading-auto
@click="onClick"
>
Button
</PButton>
</template>
This also works with the Form component.
<script setup lang="ts">
import { reactive } from 'vue';
const state = reactive({ fullName: '' });
async function onSubmit() {
return new Promise<void>((res) => setTimeout(res, 1000));
}
async function validate(data: Partial<typeof state>) {
if (!data.fullName?.length) {
return [{ name: 'fullName', message: 'Required' }];
}
return [];
}
</script>
<template>
<PForm
:state="state"
:validate="validate"
@submit="onSubmit"
>
<PFormField
name="fullName"
label="Full name"
>
<PInput v-model="state.fullName" />
</PFormField>
<PButton
type="submit"
class="mt-2"
loading-auto
>
Submit
</PButton>
</PForm>
</template>
Loading Icon
Use the loading-icon prop to customize the loading icon. Defaults to i-lucide:loader-circle.
<template>
<PButton loading loading-icon="i-lucide:loader">Button</PButton>
</template>
Disabled
Use the disabled prop to disable the Button.
<template>
<PButton disabled>Button</PButton>
</template>
Examples
class prop
Use the class prop to override the base styles of the Button.
<template>
<PButton class="akar:font-bold akar:rounded-full">Button</PButton>
</template>
pohon prop
Use the pohon prop to override the slots styles of the Button.
<template>
<PButton
icon="i-lucide:rocket"
color="neutral"
variant="outline"
:pohon="{
leadingIcon: 'color-primary'
}"
>
Button
</PButton>
</template>
API
Props
| Prop | Default | Type |
|---|---|---|
as | 'button' | anyThe element or component this component should render as when not a link. |
to | string | kt | TtRoute Location the link should navigate to when clicked on.
| |
autofocus | false | true | "true" | "false" | |
name | string | |
type | 'button' | "submit" | "reset" | "button"The type of the button when not a link. |
download | any | |
hreflang | string | |
media | string | |
ping | string | |
target | string & {} | "_blank" | "_parent" | "_self" | "_top"Where to display the linked URL, as the name for a browsing context.
| |
referrerpolicy | "" | "no-referrer" | "no-referrer-when-downgrade" | "origin" | "origin-when-cross-origin" | "same-origin" | "strict-origin" | "strict-origin-when-cross-origin" | "unsafe-url" | |
trailingSlash | "append" | "remove"An option to either add or remove trailing slashes in the | |
label | string | |
color | 'primary' | "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral" |
activeColor | "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral" | |
variant | 'solid' | "link" | "solid" | "outline" | "soft" | "subtle" | "ghost" |
activeVariant | "link" | "solid" | "outline" | "soft" | "subtle" | "ghost" | |
size | 'md' | "md" | "xs" | "sm" | "lg" | "xl" |
icon | string | objectDisplay an icon based on the | |
avatar | PAvatarPropsDisplay an avatar on the left side.
| |
leadingIcon | string | objectDisplay an icon on the left side. | |
trailingIcon | string | objectDisplay an icon on the right side. | |
loadingIcon | appConfig.pohon.icons.loading | string | objectThe icon when the |
disabled | boolean | |
active | booleanForce the link to be active independent of the current route. | |
square | booleanRender the button with equal padding on all sides. | |
block | booleanRender the button full width. | |
loadingAuto | booleanSet loading state automatically based on the | |
leading | booleanWhen | |
trailing | booleanWhen | |
loading | booleanWhen | |
pohon | { base?: ClassValue; label?: ClassValue; leadingIcon?: ClassValue; leadingAvatar?: ClassValue; leadingAvatarSize?: ClassValue; trailingIcon?: ClassValue; } |
Slots
| Slot | Type |
|---|---|
leading | { pohon: object; } |
default | { pohon: object; } |
trailing | { pohon: object; } |
Theme
Below is the theme configuration skeleton for the PButton. Since the component is provided unstyled by default, you will need to fill in these values to apply your own custom look and feel. If you prefer to use our pre-built, opinionated styling, you can instead use our UnoCSS preset, this docs is using it as well.
export default defineAppConfig({
pohon: {
button: {
slots: {
base: '',
label: '',
leadingIcon: '',
leadingAvatar: '',
leadingAvatarSize: '',
trailingIcon: ''
},
variants: {
fieldGroup: {
horizontal: '',
vertical: ''
},
color: {
primary: '',
secondary: '',
success: '',
info: '',
warning: '',
error: '',
neutral: ''
},
variant: {
solid: '',
outline: '',
soft: '',
subtle: '',
ghost: '',
link: ''
},
size: {
xs: {
base: '',
leadingIcon: '',
leadingAvatarSize: '',
trailingIcon: ''
},
sm: {
base: '',
leadingIcon: '',
leadingAvatarSize: '',
trailingIcon: ''
},
md: {
base: '',
leadingIcon: '',
leadingAvatarSize: '',
trailingIcon: ''
},
lg: {
base: '',
leadingIcon: '',
leadingAvatarSize: '',
trailingIcon: ''
},
xl: {
base: '',
leadingIcon: '',
leadingAvatarSize: '',
trailingIcon: ''
}
},
block: {
true: {
base: '',
trailingIcon: ''
}
},
square: {
true: ''
},
leading: {
true: ''
},
trailing: {
true: ''
},
loading: {
true: ''
},
active: {
true: {
base: ''
},
false: {
base: ''
}
}
},
compoundVariants: [],
defaultVariants: {
color: 'primary',
variant: 'solid',
size: 'md'
}
}
}
};
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import pohon from 'pohon-ui/vite'
export default defineAppConfig({
pohon: {
button: {
slots: {
base: '',
label: '',
leadingIcon: '',
leadingAvatar: '',
leadingAvatarSize: '',
trailingIcon: ''
},
variants: {
fieldGroup: {
horizontal: '',
vertical: ''
},
color: {
primary: '',
secondary: '',
success: '',
info: '',
warning: '',
error: '',
neutral: ''
},
variant: {
solid: '',
outline: '',
soft: '',
subtle: '',
ghost: '',
link: ''
},
size: {
xs: {
base: '',
leadingIcon: '',
leadingAvatarSize: '',
trailingIcon: ''
},
sm: {
base: '',
leadingIcon: '',
leadingAvatarSize: '',
trailingIcon: ''
},
md: {
base: '',
leadingIcon: '',
leadingAvatarSize: '',
trailingIcon: ''
},
lg: {
base: '',
leadingIcon: '',
leadingAvatarSize: '',
trailingIcon: ''
},
xl: {
base: '',
leadingIcon: '',
leadingAvatarSize: '',
trailingIcon: ''
}
},
block: {
true: {
base: '',
trailingIcon: ''
}
},
square: {
true: ''
},
leading: {
true: ''
},
trailing: {
true: ''
},
loading: {
true: ''
},
active: {
true: {
base: ''
},
false: {
base: ''
}
}
},
compoundVariants: [],
defaultVariants: {
color: 'primary',
variant: 'solid',
size: 'md'
}
}
}
};