Disclosure group

A row that reveals details, its chevron turning as it opens.

content

Apple: Disclosure controls

· Base UI: Collapsible

Advanced options

"use client"

import {
  DisclosureGroup,
  DisclosureGroupPanel,
  DisclosureGroupTrigger,
} from "@applecn/ui/components/disclosure-group"
import { Label } from "@applecn/ui/components/label"
import { Switch } from "@applecn/ui/components/switch"

export default function DisclosureGroupBasic() {
  return (
    <DisclosureGroup className="max-w-sm rounded-4xl bg-card px-4">
      <DisclosureGroupTrigger>Advanced Options</DisclosureGroupTrigger>
      <DisclosureGroupPanel>
        <div className="flex flex-col gap-3 pb-3">
          <Label className="justify-between">
            Include audio <Switch aria-label="Include audio" defaultChecked />
          </Label>
          <Label className="justify-between">
            Export as PDF <Switch aria-label="Export as PDF" />
          </Label>
        </div>
      </DisclosureGroupPanel>
    </DisclosureGroup>
  )
}

Install

From the registry this site publishes, with dependencies resolved by the CLI.

npx shadcn@latest add https://applecn.vercel.app/r/disclosure-group.json

Source

packages/ui/src/components/disclosure-group.tsx

"use client"

import { Collapsible as CollapsiblePrimitive } from "@base-ui/react/collapsible"
import { ArrowRight01Icon } from "@hugeicons/core-free-icons"
import { cn } from "cn"

import { Icon } from "./icon"

/**
 * Disclosure controls (HIG › Disclosure controls): a row whose chevron points along the
 * leading edge when collapsed and down when expanded, hiding details until they are relevant.
 */
function DisclosureGroup({
  className,
  ...props
}: CollapsiblePrimitive.Root.Props) {
  return (
    <CollapsiblePrimitive.Root
      data-slot="disclosure-group"
      className={cn("group/disclosure flex flex-col", className)}
      {...props}
    />
  )
}

function DisclosureGroupTrigger({
  className,
  children,
  ...props
}: CollapsiblePrimitive.Trigger.Props) {
  return (
    <CollapsiblePrimitive.Trigger
      data-slot="disclosure-group-trigger"
      className={cn(
        "flex w-full items-center justify-between gap-2 py-2 text-start type-body text-label outline-none select-none focus-visible:ring-4 focus-visible:ring-ring/60 disabled:opacity-40",
        className
      )}
      {...props}
    >
      {children}
      <Icon
        icon={ArrowRight01Icon}
        weight="semibold"
        data-slot="disclosure-group-chevron"
        className="text-label-3 transition-transform duration-(--duration-press) ease-(--ease-standard) group-data-open/disclosure:rotate-90 motion-reduce:transition-none"
      />
    </CollapsiblePrimitive.Trigger>
  )
}

function DisclosureGroupPanel({
  className,
  ...props
}: CollapsiblePrimitive.Panel.Props) {
  return (
    <CollapsiblePrimitive.Panel
      data-slot="disclosure-group-panel"
      className={cn(
        "h-(--collapsible-panel-height) overflow-hidden type-body text-label transition-[height] duration-(--duration-overlay) ease-(--ease-standard) data-ending-style:h-0 data-starting-style:h-0 motion-reduce:transition-none",
        className
      )}
      {...props}
    />
  )
}

export { DisclosureGroup, DisclosureGroupPanel, DisclosureGroupTrigger }