# Family Accordion

A set of collapsible panels with headings.

Build a Accordion in this project that looks and behaves like Family's. Measured from the running Family app (app.family.co). 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/accordion) if it has none.

Fidelity: Derived from Family's list rows, dividers and chevron icon tokens. The app has no accordion. Panel padding and the chevron turn are guesses.

## Tokens

| Token | Light | Dark |
| --- | --- | --- |
| `--body-color` | `#222` | `#fff` |
| `--body-color-muted` | `#17171780` | `#ffffff80` |
| `--icon-color-tertiary` | `#adadad` | `#adadad` |
| `--body-bg-secondary` | `#f9fafb` | `#272727` |
| `--hr-color` | `#f0f0f0` | `#ffffff0d` |
| `--focus-color` | `#007aff80` | `#007aff80` |
| `--font-size-small` | `0.875rem` | `0.875rem` |
| `--font-size-regular` | `1rem` | `1rem` |
| `--font-weight-normal` | `400` | `400` |
| `--font-weight-medium` | `500` | `500` |
| `--letter-spacing-small` | `-0.00563rem` | `-0.00563rem` |
| `--letter-spacing-input` | `-0.01125rem` | `-0.01125rem` |
| `--radius-item` | `0.5rem` | `0.5rem` |
| `--radius-tab` | `0.625rem` | `0.625rem` |
| `--ease-snappy-out` | `cubic-bezier(0.19, 1, 0.22, 1)` | `cubic-bezier(0.19, 1, 0.22, 1)` |
| `--duration-control` | `0.1s` | `0.1s` |
| `--duration-height` | `0.4s` | `0.4s` |

## CSS

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

```css
[data-style="family"] {
  .ui-accordion {
    display: flex;
    flex-direction: column;
    width: 100%;
  }

  .ui-accordion > * {
    position: relative;
    padding: 0.25rem;

    &:not(:last-child)::after {
      content: "";
      position: absolute;
      right: 0;
      bottom: 0;
      left: 0;
      height: 1px;
      background: var(--hr-color);
    }
  }

  .ui-accordion-header {
    margin: 0;
    font: inherit;
  }

  .ui-accordion-trigger {
    position: relative;
    isolation: isolate;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    margin: 0;
    padding: 0.75rem;
    border: 0;
    border-radius: var(--radius-item);
    outline: none;
    background: none;
    color: var(--body-color);
    font-family: inherit;
    font-size: var(--font-size-regular);
    font-weight: var(--font-weight-medium);
    line-height: 1.125rem;
    letter-spacing: var(--letter-spacing-input);
    text-align: left;
    user-select: none;
    cursor: pointer;

    &::before {
      content: "";
      position: absolute;
      inset: 0;
      z-index: -1;
      border-radius: var(--radius-tab);
      background: var(--body-bg-secondary);
      opacity: 0;
      transform: scale(0.75);
      transition: all var(--duration-control);
    }

    @media (hover: hover) {
      &:hover:not([data-disabled])::before {
        opacity: 1;
        transform: none;
      }
    }

    &:focus-visible {
      outline: 0.125rem solid var(--focus-color);
      outline-offset: -0.25rem;
    }

    &[data-disabled] {
      opacity: 0.4;
      pointer-events: none;
    }
  }

  .ui-accordion-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .ui-accordion-chevron {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
    color: var(--icon-color-tertiary);
    transition: transform var(--duration-control);

    [data-panel-open] > & {
      transform: rotate(90deg);
    }
  }

  .ui-accordion-panel {
    box-sizing: border-box;
    height: var(--accordion-panel-height);
    overflow: hidden;
    transition: height var(--duration-height) var(--ease-snappy-out);

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

  .ui-accordion-content {
    padding: 0 0.75rem 0.75rem;
    color: var(--body-color-muted);
    font-size: var(--font-size-small);
    font-weight: var(--font-weight-normal);
    line-height: 1.4175rem;
    letter-spacing: var(--letter-spacing-small);
  }

  @media (prefers-reduced-motion: reduce) {
    .ui-accordion-panel,
    .ui-accordion-chevron {
      transition: none;
    }
  }
}
```

## Structure

How Replicas assembles it on Base UI.

```tsx
import { Accordion as BaseAccordion } from "@base-ui/react/accordion";

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

function Root({ className, ...props }: Omit<BaseAccordion.Root.Props, "className"> & { className?: string }) {
  return <BaseAccordion.Root className={join("ui-accordion", className)} {...props} />;
}

function Header({ className, ...props }: Omit<BaseAccordion.Header.Props, "className"> & { className?: string }) {
  return <BaseAccordion.Header className={join("ui-accordion-header", className)} {...props} />;
}

function Trigger({
  className,
  children,
  ...props
}: Omit<BaseAccordion.Trigger.Props, "className"> & { className?: string }) {
  return (
    <BaseAccordion.Trigger className={join("ui-accordion-trigger", className)} {...props}>
      <span className="ui-accordion-label">{children}</span>
      <svg className="ui-accordion-chevron" viewBox="0 0 16 16" fill="none" aria-hidden>
        <path d="M6 4l4 4-4 4" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
      </svg>
    </BaseAccordion.Trigger>
  );
}

function Panel({
  className,
  children,
  ...props
}: Omit<BaseAccordion.Panel.Props, "className"> & { className?: string }) {
  return (
    <BaseAccordion.Panel className={join("ui-accordion-panel", className)} {...props}>
      <div className="ui-accordion-content">{children}</div>
    </BaseAccordion.Panel>
  );
}

export const Accordion = {
  Root,
  Item: BaseAccordion.Item,
  Header,
  Trigger,
  Panel,
};
```

## Example

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

const items = [
  {
    value: "plans",
    title: "Can I change plans later?",
    body: "Yes. Upgrades apply right away and downgrades take effect at the end of the billing period.",
  },
  {
    value: "refunds",
    title: "Do you offer refunds?",
    body: "Annual plans can be refunded in full within 30 days of purchase.",
  },
  {
    value: "export",
    title: "Can I export my data?",
    body: "Export everything as CSV or JSON from Settings at any time.",
  },
];

export default function AccordionDemo() {
  return (
    <Accordion.Root defaultValue={["plans"]} style={{ width: 320 }}>
      {items.map((item) => (
        <Accordion.Item key={item.value} value={item.value}>
          <Accordion.Header>
            <Accordion.Trigger>{item.title}</Accordion.Trigger>
          </Accordion.Header>
          <Accordion.Panel>{item.body}</Accordion.Panel>
        </Accordion.Item>
      ))}
    </Accordion.Root>
  );
}
```

## Foundations

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