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 pohon.icons property:

app.config.ts
export default defineAppConfig({
  pohon: {
    icons: {
      light: 'i-ph:sun',
      dark: 'i-ph:moon'
    }
  }
})

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

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

export default defineConfig({
  plugins: [
    vue(),
    pohon({
      pohon: {
        icons: {
          light: 'i-ph:sun',
          dark: 'i-ph:moon'
        }
      }
    })
  ]
})

With fallback slot

As the button is wrapped in a ClientOnly component, you can pass a fallback slot to display a placeholder while the component is loading.

<template>
  <PColorModeButton>
    <template #fallback>
      <PButton loading variant="ghost" color="neutral" />
    </template>
  </PColorModeButton>
</template>

API

Props

Prop Default Type
as'button'any

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

color'neutral' "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral"
variant'ghost' "link" | "ghost" | "solid" | "outline" | "soft" | "subtle"
trailingIcon string | object

Display an icon on the right side.

name string
trailingboolean

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

loadingboolean

When true, the loading icon will be displayed.

icon string | object

Display an icon based on the leading and trailing props.

size'md' "md" | "xs" | "sm" | "lg" | "xl"
avatar PAvatarProps

Display an avatar on the left side.

autofocus false | true | "true" | "false"
disabledboolean
type'button' "reset" | "submit" | "button"

The type of the button when not a link.

label string
activeColor "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral"
activeVariant "link" | "ghost" | "solid" | "outline" | "soft" | "subtle"
squareboolean

Render the button with equal padding on all sides.

blockboolean

Render the button full width.

loadingAutoboolean

Set loading state automatically based on the @click promise state

leadingboolean

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

leadingIcon string | object

Display an icon on the left side.

loadingIconappConfig.pohon.icons.loading string | object

The icon when the loading prop is true.

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

Slots

Slot Type
fallbackobject

Changelog

No recent changes