Accordion
shadcn-lit-registry/accordionFreeComponent
A vertically stacked set of interactive headings that each reveal a section of content. Supports single and multiple open items with smooth animations and full keyboard navigation.
Install it
npx shadcn@latest add https://lit-registry.lloydrichards.dev/r/accordion.jsonSource
1import { html, LitElement, nothing, type PropertyValues } from "lit";2import { customElement, property, state } from "lit/decorators.js";3import { unsafeSVG } from "lit/directives/unsafe-svg.js";4import { ChevronDown } from "lucide-static";5import { TW } from "@/registry/lib/tailwindMixin";6import { cn } from "@/registry/lib/utils";78const TwLitElement = TW(LitElement);910/**11 * Accordion component properties and events12 */13export interface AccordionProperties {14 type?: "single" | "multiple";15 value?: string;16 defaultValue?: string;17 collapsible?: boolean;18 disabled?: boolean;19}2021export interface AccordionItemProperties {22 value: string;23 disabled?: boolean;24}2526export interface AccordionTriggerProperties {27 disabled?: boolean;28}2930export interface AccordionContentProperties {31 forceMount?: boolean;32}3334export interface AccordionValueChangeEvent extends CustomEvent {35 detail: { value: string | string[] };36}3738/**39 * Root accordion container managing state40 */41@customElement("ui-accordion")42export class Accordion extends TwLitElement implements AccordionProperties {43 @property({ type: String }) type: "single" | "multiple" = "single";44 @property({ type: String }) value = "";45 @property({ type: String, attribute: "default-value" }) defaultValue = "";46 @property({ type: Boolean }) collapsible = false;47 @property({ type: Boolean }) disabled = false;4849 @state() _openValues: Set<string> = new Set();5051 override connectedCallback() {52 super.connectedCallback();5354 // Initialize from defaultValue55 if (!this.value && this.defaultValue) {56 this.value = this.defaultValue;57 }5859 this.addEventListener(60 "accordion-trigger-click",61 this.handleTriggerClick as EventListener,62 );63 }6465 override disconnectedCallback() {66 super.disconnectedCallback();67 this.removeEventListener(68 "accordion-trigger-click",69 this.handleTriggerClick as EventListener,70 );71 }7273 override updated(changedProperties: PropertyValues) {74 super.updated(changedProperties);7576 if (77 changedProperties.has("value") ||78 changedProperties.has("_openValues")79 ) {80 this.updateItems();81 this.dispatchValueChangeEvent();82 }83 }8485 private handleTriggerClick = (e: CustomEvent) => {86 if (this.disabled) return;8788 const clickedValue = e.detail.value;8990 if (this.type === "single") {91 // Single mode: toggle or switch active item92 if (this.collapsible && this.value === clickedValue) {93 this.value = "";94// … truncated
What it pulls in
npm packages
Files it writes
More from shadcn-lit-registry
All 26 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Avataravatar | shadcn-lit-registry | Components | Free | no deps · 2 files | |
| Badgebadge | shadcn-lit-registry | Components | Free | no deps · 2 files | |
| Buttonbutton | shadcn-lit-registry | Components | Free | 1 dep · 2 files | |
| Cardcard | shadcn-lit-registry | Components | Free | no deps · 2 files | |
| Checkboxcheckbox | shadcn-lit-registry | Components | Free | 1 dep · 2 files | |
| Collapsiblecollapsible | shadcn-lit-registry | Components | Free | 1 dep · 2 files | |
| Commandcommand | shadcn-lit-registry | Components | Free | 1 dep · 2 files | |
| Context Menucontext-menu | shadcn-lit-registry | Components | Free | 2 deps · 2 files |
