package examples import (package examples import ( "github.com/axadrn/shadcn-templ/v2/components/icon" "github.com/axadrn/shadcn-templ/v2/components/toggle") templ ToggleDemo() { @toggle.Toggle(toggle.Props{ Variant: toggle.VariantOutline, Size: toggle.SizeSm, Attributes: templ.Attributes{"aria-label": "Toggle bookmark"}, }) { @icon.Bookmark(icon.Props{Class: "group-aria-pressed/toggle:fill-foreground"}) Bookmark }}Installation
Usage
Outline
Use Variant: toggle.VariantOutline for an outline style.
package examples import (package examples import ( "github.com/axadrn/shadcn-templ/v2/components/icon" "github.com/axadrn/shadcn-templ/v2/components/toggle") templ ToggleOutline() { <div class="flex flex-wrap items-center gap-2"> @toggle.Toggle(toggle.Props{ Variant: toggle.VariantOutline, Attributes: templ.Attributes{"aria-label": "Toggle italic"}, }) { @icon.Italic() Italic } @toggle.Toggle(toggle.Props{ Variant: toggle.VariantOutline, Attributes: templ.Attributes{"aria-label": "Toggle bold"}, }) { @icon.Bold() Bold } </div>}With Text
package examples import (package examples import ( "github.com/axadrn/shadcn-templ/v2/components/icon" "github.com/axadrn/shadcn-templ/v2/components/toggle") templ ToggleText() { @toggle.Toggle(toggle.Props{ Attributes: templ.Attributes{"aria-label": "Toggle italic"}, }) { @icon.Italic() Italic }}Size
Use the Size prop to change the size of the toggle.
package examples import "github.com/axadrn/shadcn-templ/v2/components/toggle"package examples import "github.com/axadrn/shadcn-templ/v2/components/toggle" templ ToggleSizes() { <div class="flex flex-wrap items-center gap-2"> @toggle.Toggle(toggle.Props{ Variant: toggle.VariantOutline, Size: toggle.SizeSm, Attributes: templ.Attributes{"aria-label": "Toggle small"}, }) { Small } @toggle.Toggle(toggle.Props{ Variant: toggle.VariantOutline, Size: toggle.SizeDefault, Attributes: templ.Attributes{"aria-label": "Toggle default"}, }) { Default } @toggle.Toggle(toggle.Props{ Variant: toggle.VariantOutline, Size: toggle.SizeLg, Attributes: templ.Attributes{"aria-label": "Toggle large"}, }) { Large } </div>}Disabled
package examples import "github.com/axadrn/shadcn-templ/v2/components/toggle"package examples import "github.com/axadrn/shadcn-templ/v2/components/toggle" templ ToggleDisabled() { <div class="flex flex-wrap items-center gap-2"> @toggle.Toggle(toggle.Props{ Disabled: true, Attributes: templ.Attributes{"aria-label": "Toggle disabled"}, }) { Disabled } @toggle.Toggle(toggle.Props{ Variant: toggle.VariantOutline, Disabled: true, Attributes: templ.Attributes{"aria-label": "Toggle disabled outline"}, }) { Disabled } </div>}API Reference
Toggle
The Toggle component renders a pressable two-state button.