EXEPERTAI LAB

Research alpha

Time Machine
EXEPERTAI LAB
GALLERY / COLLECTION
← Browse Astryx gallery
Collapsible·hook·@astryxdesign/core

useCollapsible

Reusable hook that encapsulates the collapsible state machine. Supports three modes: group-controlled (inside CollapsibleGroup), controlled (isOpen + onOpenChange), and uncontrolled (self-managed with defaultIsOpen). Used internally by Card and Section.

Open in Playground @astryxdesign/core/Collapsible

Signature

Call shape
useCollapsible(options: UseCollapsibleOptions): UseCollapsibleReturn
Parameters
NameType and behavior
isCollapsibleboolean | CollapsibleConfig
Enable collapsible behavior. true = self-managed (starts open). Pass config object for controlled mode or custom defaults.
valuestring
Unique identifier within an CollapsibleGroup. When present and inside a group, state is managed by the group.
Returns
NameType and behavior
isEnabledboolean
Whether collapsible behavior is active.
isOpenboolean
Whether the content is currently expanded.
toggle() => void
Toggle open/closed state. Dispatches to group, controlled callback, or internal state.

Showcases and examples

2 documented examples

Collapsible

An accordion group with three collapsible sections in single mode: opening one closes the others.

Preview loads on approachPreview loads on approach
Exact source · collapsible-showcase
// Copyright (c) Meta Platforms, Inc. and affiliates.

'use client';

import {Collapsible, CollapsibleGroup} from '@astryxdesign/core/Collapsible';
import {Text} from '@astryxdesign/core/Text';
import {Card} from '@astryxdesign/core/Card';
import {Stack} from '@astryxdesign/core/Stack';

/**
 * Rows inside one card, coordinated so only one is open at a time.
 *
 * Triggers take body-semibold rather than the trigger's default `large`: three
 * rows sharing a single surface are peers, and at 17px semibold each would
 * read as its own section heading. Keep `large` for the case it is for — one
 * Collapsible per card or per Section, where the trigger really is the
 * heading of that surface (see the Multiple Mode and Controlled examples).
 */
export default function CollapsibleShowcase() {
  return (
    <Card width={420}>
      <CollapsibleGroup type="single" defaultValue="notifications">
        <Stack gap={4}>
          <Collapsible
            trigger={
              <Text type="body" weight="semibold">
                General
              </Text>
            }
            value="general">
            <Text type="body" color="secondary">
              Display name, language, and time zone. Time zone drives every date
              shown in the product, including scheduled reports.
            </Text>
          </Collapsible>

          <Collapsible
            trigger={
              <Text type="body" weight="semibold">
                Notifications
              </Text>
            }
            value="notifications">
            <Stack gap={2}>
              <Text type="body" color="secondary">
                Choose which email and push notifications you receive. Mentions
                and direct messages are always delivered — everything else can
                be turned off or batched into a daily digest.
              </Text>
              <Text type="body" color="secondary">
                Quiet hours pause push notifications overnight in your local
                time zone without affecting email.
              </Text>
            </Stack>
          </Collapsible>

          <Collapsible
            trigger={
              <Text type="body" weight="semibold">
                Privacy
              </Text>
            }
            value="privacy">
            <Text type="body" color="secondary">
              Control who can see your profile and activity, and whether your
              workspace appears in search for people outside your organization.
            </Text>
          </Collapsible>
        </Stack>
      </CollapsibleGroup>
    </Card>
  );
}

Usage

Reusable hook that encapsulates the collapsible state machine. Supports three modes: group-controlled (inside CollapsibleGroup), controlled (isOpen + onOpenChange), and uncontrolled (self-managed with defaultIsOpen). Used internally by Card and Section.

  • Use the hook directly when building custom collapsible components that need Astryx collapsible behavior without Collapsible wrapper.
  • For accordion behavior, wrap items in CollapsibleGroup and pass unique value props.
  • Implement your own open/close state when useCollapsible already provides it; the hook handles group coordination automatically.