Skip to content

Toggle ​

A two-state button that can be either on or off.

## Installation
bash
npx @galaxy-stack/nebula-cli@latest add toggle
bash
pnpm dlx @galaxy-stack/nebula-cli@latest add toggle
bash
yarn dlx @galaxy-stack/nebula-cli@latest add toggle
bash
bunx @galaxy-stack/nebula-cli@latest add toggle
bash
# If you have installed galaxy-design globally
galaxy-design add toggle

Usage ​

vue
<script setup lang="ts">
import { Toggle } from '@/components/ui/toggle'
import { Bold } from 'lucide-vue-next'
</script>

<template>
  <Toggle aria-label="Toggle bold">
    <Bold class="h-4 w-4" />
  </Toggle>
</template>
tsx
import { Toggle } from "@/components/ui/toggle"
import { Bold } from "lucide-react"

export default function App() {
  return (
    <Toggle aria-label="Toggle bold">
      <Bold className="h-4 w-4" />
    </Toggle>
  )
}
typescript
import { Component } from '@angular/core';
import { ToggleComponent } from '@/components/ui/toggle';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [ToggleComponent],
  template: `
    <ui-toggle aria-label="Toggle bold">
      <lucide-icon name="bold" class="h-4 w-4"></lucide-icon>
    </ui-toggle>
  `
})
export class AppComponent {}

Examples ​

Default ​

vue
<Toggle>
  <Bold class="h-4 w-4" />
</Toggle>
tsx
<Toggle>
  <Bold className="h-4 w-4" />
</Toggle>
html
<ui-toggle>
  <lucide-icon name="bold" class="h-4 w-4"></lucide-icon>
</ui-toggle>

Outline ​

vue
<Toggle variant="outline">
  <Italic class="h-4 w-4" />
</Toggle>
tsx
<Toggle variant="outline">
  <Italic className="h-4 w-4" />
</Toggle>
html
<ui-toggle variant="outline">
  <lucide-icon name="italic" class="h-4 w-4"></lucide-icon>
</ui-toggle>

With Text ​

vue
<Toggle>
  <Italic class="mr-2 h-4 w-4" />
  Italic
</Toggle>
tsx
<Toggle>
  <Italic className="mr-2 h-4 w-4" />
  Italic
</Toggle>
html
<ui-toggle>
  <lucide-icon name="italic" class="mr-2 h-4 w-4"></lucide-icon>
  Italic
</ui-toggle>

Small ​

vue
<Toggle size="sm">
  <Italic class="h-4 w-4" />
</Toggle>
tsx
<Toggle size="sm">
  <Italic className="h-4 w-4" />
</Toggle>
html
<ui-toggle size="sm">
  <lucide-icon name="italic" class="h-4 w-4"></lucide-icon>
</ui-toggle>

Large ​

vue
<Toggle size="lg">
  <Italic class="h-4 w-4" />
</Toggle>
tsx
<Toggle size="lg">
  <Italic className="h-4 w-4" />
</Toggle>
html
<ui-toggle size="lg">
  <lucide-icon name="italic" class="h-4 w-4"></lucide-icon>
</ui-toggle>

Disabled ​

vue
<Toggle disabled>
  <Underline class="h-4 w-4" />
</Toggle>
tsx
<Toggle disabled>
  <Underline className="h-4 w-4" />
</Toggle>
html
<ui-toggle [disabled]="true">
  <lucide-icon name="underline" class="h-4 w-4"></lucide-icon>
</ui-toggle>

API Reference ​

Props ​

PropTypeDefaultDescriptionFrameworks
pressedboolean-Controlled pressed stateAll
defaultPressedbooleanfalseInitial pressed state for uncontrolled usageAll
onPressedChange(pressed: boolean) => void-Called when pressed state changesAll
disabledbooleanfalseDisables the toggleAll
variant'default' | 'outline''default'Visual style variantAll
size'default' | 'sm' | 'lg''default'Size variantAll
asChildbooleanfalseRender as child elementReact, Vue, Angular
classNamestring''Additional CSS classesAll

Accessibility ​

Keyboard Interactions ​

KeyDescription
SpaceToggles the component on and off
EnterToggles the component on and off

Author ​

Bùi Trọng Hiếu (kevinbui)

License ​

MIT © 2025 Bùi Trọng Hiếu (kevinbui)

Released under the MIT License.