import { Collapsible } from "@replicas/ui";

const rowStyle = {
  display: "flex",
  alignItems: "center",
  height: 28,
  padding: "0 8px 0 20px",
  color: "var(--text-secondary)",
  fontSize: "var(--font-size-small)",
};

export default function CollapsibleDemo() {
  return (
    <Collapsible.Root defaultOpen style={{ display: "flex", flexDirection: "column", width: 220 }}>
      <Collapsible.Trigger style={{ alignSelf: "flex-start" }}>Your teams</Collapsible.Trigger>
      <Collapsible.Panel>
        <div style={rowStyle}>Engineering</div>
        <div style={rowStyle}>Design</div>
        <div style={rowStyle}>Product</div>
      </Collapsible.Panel>
    </Collapsible.Root>
  );
}

Prompt

Copy Prompt hands your agent everything it needs to build the Collapsible in the Clerk style: the measured tokens, the CSS and the structure.

Show Prompt
# Clerk Collapsible

A collapsible panel controlled by a button.

Build a Collapsible in this project that looks and behaves like Clerk's. Measured from the running Clerk app (clerk.com). Keep every value exact. Map the tokens onto the project's own theme variables instead of hard-coding them. Use the project's own component library for behaviour, or [Base UI](https://base-ui.com/react/components/collapsible) if it has none.

Fidelity: Partly measured from the Collapsible in Clerk's open source UI code. Not checked side by side.

## Tokens

| Token | Light | Dark |
| --- | --- | --- |
| `--clerk-primary` | `#2f3037` | `#ffffff` |
| `--clerk-primary-hover` | `color-mix(in srgb, #2f3037, white 20%)` | `color-mix(in srgb, #ffffff, white 20%)` |
| `--clerk-neutral-50` | `rgb(0 0 0 / 0.03)` | `rgb(255 255 255 / 0.03)` |
| `--clerk-neutral-400` | `rgb(0 0 0 / 0.41)` | `rgb(255 255 255 / 0.41)` |
| `--clerk-ring` | `0 0 0 4px var(--clerk-neutral-200)` | `0 0 0 4px var(--clerk-neutral-200)` |
| `--clerk-radius-md` | `6px` | `6px` |
| `--duration-controls` | `100ms` | `100ms` |
| `--duration-fast` | `120ms` | `120ms` |
| `--font-size-mini` | `0.75rem` | `0.75rem` |
| `--line-height-mini` | `calc(16 / 12)` | `calc(16 / 12)` |
| `--font-weight-medium` | `500` | `500` |

## CSS

Scoped under `[data-style="clerk"]`; dark rules sit under `[data-theme="dark"]`. The `ui-*` classes and data attributes match the structure below.

```css
[data-style="clerk"] {
  .ui-collapsible-trigger {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 24px;
    margin: 0;
    padding: 0 8px;
    border: 0;
    border-radius: var(--clerk-radius-md);
    background-color: transparent;
    color: var(--clerk-primary);
    font-family: inherit;
    font-size: var(--font-size-mini);
    font-weight: var(--font-weight-medium);
    line-height: var(--line-height-mini);
    user-select: none;
    cursor: pointer;
    outline: 0;
    transition-property: background-color, color, box-shadow;
    transition-duration: var(--duration-controls);

    &:focus-visible {
      box-shadow: var(--clerk-ring);
    }

    @media (hover: hover) {
      &:hover:not([data-disabled]) {
        background-color: var(--clerk-neutral-50);
        color: var(--clerk-primary-hover);
      }
    }

    &[data-disabled] {
      opacity: 0.5;
      cursor: not-allowed;
    }
  }

  .ui-collapsible-caret {
    width: 8px;
    height: 8px;
    flex-shrink: 0;
    color: var(--clerk-neutral-400);
    transform: rotate(-90deg);
    transition: transform var(--duration-fast);

    [data-panel-open] > & {
      transform: none;
    }
  }

  .ui-collapsible-panel {
    box-sizing: border-box;
    height: var(--collapsible-panel-height);
    overflow: hidden;
    transition:
      height var(--duration-fast) ease-out,
      opacity var(--duration-fast) ease-out;

    &[data-starting-style],
    &[data-ending-style] {
      height: 0;
      opacity: 0;
    }
  }
}
```

## Structure

How Replicas assembles it on Base UI.

```tsx
import { Collapsible as BaseCollapsible } from "@base-ui/react/collapsible";

const join = (base: string, extra?: string) => (extra ? `${base} ${extra}` : base);

function Trigger({
  className,
  children,
  ...props
}: Omit<BaseCollapsible.Trigger.Props, "className"> & { className?: string }) {
  return (
    <BaseCollapsible.Trigger className={join("ui-collapsible-trigger", className)} {...props}>
      {children}
      <svg className="ui-collapsible-caret" viewBox="0 0 8 8" fill="currentColor" aria-hidden>
        <path d="M1 2.5h6L4 6z" />
      </svg>
    </BaseCollapsible.Trigger>
  );
}

function Panel({ className, ...props }: Omit<BaseCollapsible.Panel.Props, "className"> & { className?: string }) {
  return <BaseCollapsible.Panel className={join("ui-collapsible-panel", className)} {...props} />;
}

export const Collapsible = {
  Root: BaseCollapsible.Root,
  Trigger,
  Panel,
};
```

## Example

```tsx
import { Collapsible } from "@replicas/ui";

const rowStyle = {
  display: "flex",
  alignItems: "center",
  height: 28,
  padding: "0 8px 0 20px",
  color: "var(--text-secondary)",
  fontSize: "var(--font-size-small)",
};

export default function CollapsibleDemo() {
  return (
    <Collapsible.Root defaultOpen style={{ display: "flex", flexDirection: "column", width: 220 }}>
      <Collapsible.Trigger style={{ alignSelf: "flex-start" }}>Your teams</Collapsible.Trigger>
      <Collapsible.Panel>
        <div style={rowStyle}>Engineering</div>
        <div style={rowStyle}>Design</div>
        <div style={rowStyle}>Product</div>
      </Collapsible.Panel>
    </Collapsible.Root>
  );
}
```

## Foundations

The rest of the Clerk style, as a skill: https://replicas.raphaelsalaja.com/skills/clerk/SKILL.md