# Split

Panes side by side that stack below a width of the layout itself: split screens, list and detail, media and text.

- Family: layout
- Import: `import { Split, SplitPane } from "@senvenli/react/layout";`
- Page: https://design.senvenli.com/docs/components/split
- JSON: https://design.senvenli.com/docs/components/split.json

## Example: A sign-in screen

A brand pane beside the form, left out when the layout is narrow. A real screen adds `fullHeight`.

```tsx
import { Button, Link } from "@senvenli/react/action";
import { Heading, Text } from "@senvenli/react/display";
import { Form, Input } from "@senvenli/react/form";
import { Split, SplitPane, Stack } from "@senvenli/react/layout";

export default function Example() {
  return (
    // A real sign-in page is the whole screen: `<Split fullHeight …>` and no frame.
    <div className="overflow-hidden rounded-ds-large border border-ds-border">
      <Split ratio="1.05fr 1fr" collapseBelow="48rem" hideOnNarrow="start">
        <SplitPane as="aside" background="surface-sunken" padding="space-600">
          <Stack space="space-600">
            <Text size="body-large" weight="medium">Acme</Text>
            <Stack space="space-100">
              <Heading level={2} size="heading-xlarge">Every project in one place</Heading>
              <Text tone="subtle">Plan the work, track it and bill it.</Text>
            </Stack>
          </Stack>
        </SplitPane>
        <SplitPane as="main" align="center" padding="space-600">
          <Stack space="space-300" as="div">
            <Stack space="space-075">
              <Heading level={1} size="heading-large">Sign in</Heading>
              <Text tone="subtle">Use your work email.</Text>
            </Stack>
            <Form onSubmit={(event) => event.preventDefault()}>
              <Input label="Email" name="email" type="email" autoComplete="email" isRequired />
              <Input type="password" label="Password" name="password" autoComplete="current-password" isRequired />
              <Button type="submit" variant="primary">Sign in</Button>
            </Form>
            <Link href="#reset" variant="subtle">Forgot your password?</Link>
          </Stack>
        </SplitPane>
      </Split>
    </div>
  );
}
```

## Examples

### List and detail

A fixed-width list beside the item it opens; stacked when narrow.

```tsx
import { GridList, type GridListStackProps } from "@senvenli/react/collection";
import { Heading, Text } from "@senvenli/react/display";
import { Split, SplitPane, Stack } from "@senvenli/react/layout";
import { useState } from "react";

const INVOICES = [
  { id: "inv-318", customer: "Northwind", total: "€1,240.00", due: "Due March 25" },
  { id: "inv-317", customer: "Globex", total: "€860.50", due: "Due March 27" },
  { id: "inv-316", customer: "Initech", total: "€2,015.00", due: "Due April 2" },
];

type Keys = NonNullable<GridListStackProps["selectedKeys"]>;

export default function Example() {
  const [selected, setSelected] = useState<Keys>(new Set(["inv-318"]));
  const id = selected === "all" ? INVOICES[0]!.id : ([...selected][0] ?? INVOICES[0]!.id);
  const invoice = INVOICES.find((item) => item.id === id)!;
  return (
    <Split ratio="16rem 1fr" space="space-300">
      <SplitPane>
        <GridList
          aria-label="Invoices"
          items={INVOICES}
          selectionMode="single"
          selectedKeys={selected}
          onSelectionChange={setSelected}
          renderItem={(item) => ({ id: item.id, title: item.customer, description: item.total })}
        />
      </SplitPane>
      <SplitPane background="surface-sunken" radius="large" padding="space-300">
        <Stack space="space-100">
          <Heading level={3} size="heading-small">{invoice.customer}</Heading>
          <Text size="body-large" weight="medium">{invoice.total}</Text>
          <Text tone="subtle">{invoice.due}</Text>
        </Stack>
      </SplitPane>
    </Split>
  );
}
```

## Guidelines

### When to use it

- A screen of two (or more) panes that sit side by side when there is room: a sign-in form beside a brand pane, a list beside its detail.
- The split must follow the space the layout gets (a dialog, a shell with a sidebar), not the window.

### Use something else when

- [grid](https://design.senvenli.com/docs/components/grid.md): Equal columns of cards or tiles that wrap.
- [sidebar](https://design.senvenli.com/docs/components/sidebar.md): The app's navigation beside the page.

### Do and avoid

- Hide a decorative pane on narrow layouts with hideOnNarrow; never hide the pane that holds the task.
- Put the page's one main landmark on the pane that holds the task (`as="main"`) when the Split is the whole page.

## Accessibility

Built in:

- A pane hidden on narrow layouts is display: none, so it leaves the accessibility tree too.
- Panes follow source order in every layout, so reading and tab order never jump.

You provide:

- The landmark of each pane (`as="main"`, `as="aside"`) and the headings in it.

## API reference

### Split

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| as | `LayoutElement` | `"div"` | no |  |
| ratio | `string` | `"1fr 1fr"` | no | The columns side by side, as a CSS grid template: `"1fr 1fr"` (default), `"1.05fr 1fr"`, `"20rem 1fr"`. |
| collapseBelow | `SplitCollapse` | `"48rem"` | no | Below this width of the layout itself the panes stack in one column. Default `"48rem"`. |
| hideOnNarrow | `"start" \| "end"` |  | no | The pane that is left out when stacked (a brand or picture pane that adds nothing on a phone). Default: none. |
| space | `Space` |  | no | The gap between the panes. Default none: panes meet edge to edge, each with its own ground. |
| fullHeight | `boolean` | `false` | no | At least as tall as the viewport: a screen of its own, like a sign-in page. |

Also takes 375 standard DOM and ARIA attributes (id, aria-label, event handlers…).

### SplitPane

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| padding | `Space` |  | no |  |
| paddingInline | `Space` |  | no |  |
| paddingBlock | `Space` |  | no |  |
| background | `Background` |  | no |  |
| radius | `Radius` |  | no |  |
| shadow | `Shadow` |  | no |  |
| border | `Border` |  | no |  |
| as | `LayoutElement` | `"div"` | no |  |
| align | `"center" \| "stretch"` | `"stretch"` | no | `stretch` (default): content fills the pane. `center`: content sits in the middle, both ways. |

Also takes 375 standard DOM and ARIA attributes (id, aria-label, event handlers…).

### Tokens it reads

`--ds-background-brand-subtle`, `--ds-background-danger`, `--ds-background-information`, `--ds-background-neutral`, `--ds-background-selected`, `--ds-background-success`, `--ds-background-warning`, `--ds-border`, `--ds-border-bold`, `--ds-radius-full`, `--ds-radius-large`, `--ds-radius-medium`, `--ds-radius-small`, `--ds-shadow-overflow`, `--ds-shadow-overlay`, `--ds-shadow-raised`, `--ds-space-0`, `--ds-space-025`, `--ds-space-050`, `--ds-space-075`, `--ds-space-100`, `--ds-space-1000`, `--ds-space-150`, `--ds-space-200`, `--ds-space-250`, `--ds-space-300`, `--ds-space-400`, `--ds-space-500`, `--ds-space-600`, `--ds-space-800`, `--ds-surface`, `--ds-surface-overlay`, `--ds-surface-raised`, `--ds-surface-sunken`

## Related

- [grid](https://design.senvenli.com/docs/components/grid.md)
- [form](https://design.senvenli.com/docs/components/form.md)
- [card](https://design.senvenli.com/docs/components/card.md)
