ColorModeButton

ButtonGitHub
A Button to switch between light and dark mode.

Usage

The ColorModeButton component extends the Button component, so you can pass any property such as color, variant, size, etc.

<template>
  <PColorModeButton />
</template>
The button defaults to color="neutral" and variant="ghost".

Examples

With custom icons

Use the app.config.ts to customize the icon with the ui.icons property:

app/app.config.ts
export default defineAppConfig({
  ui: {
    icons: {
      light: 'i-lucide-sun-medium',
      dark: 'i-lucide-moon-star'
    }
  }
});

Use the vite.config.ts to customize the icon with the ui.icons property:

vite.config.ts
import vue from '@vitejs/plugin-vue';
import ui from 'pohon-ui/vite';
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [
    vue(),
    ui({
      ui: {
        icons: {
          light: 'i-lucide-sun-medium',
          dark: 'i-lucide-moon-star'
        }
      }
    })
  ]
});

API

Props

Prop Default Type
as
'button'
any

The element or component this component should render as when not a link.

class
any
icon
any

Display an icon based on the leading and trailing props.

leadingIcon
any

Display an icon on the left side.

trailingIcon
any

Display an icon on the right side.

loadingIcon
appConfig.ui.icons.loading
any

The icon when the loading prop is true.

color
'neutral'
"primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral"
variant
'ghost'
"solid" | "outline" | "soft" | "subtle" | "ghost" | "link"
autofocus
false | true | "true" | "false"
disabled
boolean
name
string
type
'button'
"button" | "submit" | "reset"

The type of the button when not a link.

label
string
activeColor
"primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral"
activeVariant
"solid" | "outline" | "soft" | "subtle" | "ghost" | "link"
size
'md'
"xs" | "sm" | "md" | "lg" | "xl"
square
boolean

Render the button with equal padding on all sides.

block
boolean

Render the button full width.

loadingAuto
boolean

Set loading state automatically based on the @click promise state

avatar
AvatarProps

Display an avatar on the left side.

leading
boolean

When true, the icon will be displayed on the left side.

trailing
boolean

When true, the icon will be displayed on the right side.

loading
boolean

When true, the loading icon will be displayed.

ui
{ base?: SlotClass; label?: SlotClass; leadingIcon?: SlotClass; leadingAvatar?: SlotClass; leadingAvatarSize?: SlotClass; trailingIcon?: SlotClass; }
This component also supports all native <button> HTML attributes.

Changelog

No recent changes