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

const roles = [
  { value: "viewer", label: "Viewer" },
  { value: "commenter", label: "Commenter" },
  { value: "editor", label: "Editor" },
  { value: "admin", label: "Admin" },
  { value: "owner", label: "Owner" },
];

export default function SelectDemo() {
  return (
    <Select.Root items={roles} defaultValue="viewer">
      <Select.Trigger aria-label="Role">
        <Select.Value />
      </Select.Trigger>
      <Select.Popup>
        {roles.map((role, index) => (
          <Select.Item key={role.value} value={role.value} shortcut={index}>
            {role.label}
          </Select.Item>
        ))}
      </Select.Popup>
    </Select.Root>
  );
}

Examples

Variants

<Select.Root items={fruits} defaultValue="apple">
  <Select.Trigger variant="chip">
    <Select.Value />
  </Select.Trigger>
  <Select.Popup>…</Select.Popup>
</Select.Root>
<Select.Root items={fruits} defaultValue="apple">
  <Select.Trigger variant="secondary">
    <Select.Value />
  </Select.Trigger>
  <Select.Popup>…</Select.Popup>
</Select.Root>

Sizes

<Select.Root items={fruits} defaultValue="apple">
  <Select.Trigger size="small">
    <Select.Value />
  </Select.Trigger>
  <Select.Popup>…</Select.Popup>
</Select.Root>
<Select.Root items={fruits} defaultValue="apple">
  <Select.Trigger size="normal">
    <Select.Value />
  </Select.Trigger>
  <Select.Popup>…</Select.Popup>
</Select.Root>

Prompt

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

Show Prompt
# Linear Select

A common form component for choosing a predefined value in a dropdown menu.

Build a Select in this project that looks and behaves like Linear's. Measured from the running Linear app (linear.app). 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/select) if it has none.

Fidelity: Partly measured from Linear's settings select and its dropdown, light and dark. The trigger has no chevron yet, and the chip variant has no reference.

## Variants

- `variant`: `chip`, `secondary`
- `size`: `small`, `normal`

## Tokens

| Token | Light | Dark |
| --- | --- | --- |
| `--text-secondary` | `lch(19.588% 1.25 282)` | `lch(90.451% 1.2 272)` |
| `--surface-bg` | `lch(100% 0 282)` | `lch(12.72% 0.85 272)` |
| `--surface-divider` | `lch(91.9% 0 282)` | `lch(20.28% 1.93 272)` |
| `--surface-text` | `lch(20% 1 282)` | `lch(91.178% 1.425 272)` |
| `--surface-text-strong` | `lch(10% 0 282)` | `lch(100% 0 272)` |
| `--surface-text-muted` | `lch(40% 1 282)` | `lch(64.714% 1.425 272)` |
| `--surface-highlight` | `lch(95% 0 282)` | `lch(20.82% 1.3 272)` |
| `--chip-bg` | `lch(100% 0 282)` | `lch(17.574% 1.589 272)` |
| `--chip-bg-hover` | `lch(95.886% 0 282)` | `lch(22.202% 1.975 272)` |
| `--chip-text` | `lch(40% 1 282)` | `lch(64.805% 1.65 272)` |
| `--chip-ring` | `lch(0% 0 0 / 0.088)` | `lch(100% 0 0 / 0.149)` |
| `--chip-ring-hover` | `lch(0% 0 0 / 0.147)` | `lch(100% 0 0 / 0.248)` |
| `--button-secondary-bg` | `lch(99.997% 0.5 282)` | `lch(10.149% 0.689 272)` |
| `--button-secondary-bg-hover` | `lch(95.883% 0.157 282)` | `lch(14.777% 1.075 272)` |
| `--button-ring` | `lch(0% 0 0 / 0.09)` | `lch(100% 0 0 / 0.137)` |
| `--button-ring-hover` | `lch(0% 0 0 / 0.15)` | `lch(100% 0 0 / 0.229)` |
| `--shadow-low` | `lch(0% 0 0 / 0.02) 0 3px 6px -2px, lch(0% 0 0 / 0.04) 0 1px 1px 0` | `lch(0% 0 0 / 0.3) 0 0.5px 1px 1px` |
| `--shadow-menu` | `lch(0% 0 0 / 0.02) 0 6px 18px 0, lch(0% 0 0 / 0.04) 0 3px 9px 0, lch(0% 0 0 / 0.04) 0 1px 1px 0` | `lch(0% 0 0 / 0.125) 0 3px 8px 0, lch(0% 0 0 / 0.125) 0 2px 5px 0, lch(0% 0 0 / 0.125) 0 1px 1px 0` |
| `--focus-ring` | `#5e69d1` | `#5e69d1` |
| `--font-regular` | `"Inter Variable", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif` | `"Inter Variable", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif` |
| `--font-size-micro` | `0.6875rem` | `0.6875rem` |
| `--font-size-mini` | `0.75rem` | `0.75rem` |
| `--font-size-small` | `0.8125rem` | `0.8125rem` |
| `--font-weight-normal` | `450` | `450` |
| `--font-weight-medium` | `500` | `500` |
| `--radius-control` | `8px` | `8px` |
| `--radius-menu` | `12px` | `12px` |
| `--radius-rounded` | `9999px` | `9999px` |
| `--speed-highlight-fade-out` | `0.15s` | `0.15s` |
| `--ease-spring-menu-open` | `linear(0, 0.0522, 0.1573, 0.2728, 0.3818, 0.4786, 0.562, 0.6329, 0.6927, 0.7429, 0.785, 0.8202, 0.8497, 0.8744, 0.895, 0.9122, 0.9266, 0.9386, 0.9487, 0.9571, 0.9642, 0.97, 0.9749, 0.9791, 0.9825, 0.9854, 0.9878, 0.9898, 0.9915, 0.9929, 0.994, 0.995, 0.9958, 0.9965, 0.9971, 0.9976, 0.998, 0.9983, 0.9986, 0.9988, 1)` | `linear(0, 0.0522, 0.1573, 0.2728, 0.3818, 0.4786, 0.562, 0.6329, 0.6927, 0.7429, 0.785, 0.8202, 0.8497, 0.8744, 0.895, 0.9122, 0.9266, 0.9386, 0.9487, 0.9571, 0.9642, 0.97, 0.9749, 0.9791, 0.9825, 0.9854, 0.9878, 0.9898, 0.9915, 0.9929, 0.994, 0.995, 0.9958, 0.9965, 0.9971, 0.9976, 0.998, 0.9983, 0.9986, 0.9988, 1)` |
| `--duration-spring-menu-open` | `390ms` | `390ms` |
| `--ease-spring-menu-open-opacity` | `linear(0, 0.0024, 0.0091, 0.0197, 0.0336, 0.0505, 0.0698, 0.0913, 0.1147, 0.1396, 0.1659, 0.1933, 0.2215, 0.2505, 0.2801, 0.3102, 0.3405, 0.371, 0.4017, 0.4324, 0.463, 0.4935, 0.5239, 0.554, 0.5838, 0.6134, 0.6426, 0.6714, 0.6999, 0.728, 0.7556, 0.7828, 0.8096, 0.8359, 0.8617, 0.8871, 0.912, 0.9364, 0.9604, 0.9839, 1)` | `linear(0, 0.0024, 0.0091, 0.0197, 0.0336, 0.0505, 0.0698, 0.0913, 0.1147, 0.1396, 0.1659, 0.1933, 0.2215, 0.2505, 0.2801, 0.3102, 0.3405, 0.371, 0.4017, 0.4324, 0.463, 0.4935, 0.5239, 0.554, 0.5838, 0.6134, 0.6426, 0.6714, 0.6999, 0.728, 0.7556, 0.7828, 0.8096, 0.8359, 0.8617, 0.8871, 0.912, 0.9364, 0.9604, 0.9839, 1)` |
| `--duration-spring-menu-open-opacity` | `52ms` | `52ms` |
| `--ease-spring-menu-close` | `linear(0, 0.0153, 0.0543, 0.1085, 0.1716, 0.239, 0.3074, 0.3745, 0.4388, 0.4993, 0.5555, 0.607, 0.6539, 0.6962, 0.7341, 0.7679, 0.7978, 0.8243, 0.8477, 0.8682, 0.8861, 0.9017, 0.9153, 0.9271, 0.9374, 0.9463, 0.9539, 0.9605, 0.9662, 0.9711, 0.9753, 0.9789, 0.982, 0.9847, 0.987, 0.9889, 0.9906, 0.992, 0.9932, 0.9942, 1)` | `linear(0, 0.0153, 0.0543, 0.1085, 0.1716, 0.239, 0.3074, 0.3745, 0.4388, 0.4993, 0.5555, 0.607, 0.6539, 0.6962, 0.7341, 0.7679, 0.7978, 0.8243, 0.8477, 0.8682, 0.8861, 0.9017, 0.9153, 0.9271, 0.9374, 0.9463, 0.9539, 0.9605, 0.9662, 0.9711, 0.9753, 0.9789, 0.982, 0.9847, 0.987, 0.9889, 0.9906, 0.992, 0.9932, 0.9942, 1)` |
| `--duration-spring-menu-close` | `149ms` | `149ms` |
| `--ease-spring-menu-close-opacity` | `linear(0, 0, 0.111, 0.2141, 0.3078, 0.3923, 0.4681, 0.5357, 0.5957, 0.6487, 0.6954, 0.7363, 0.7721, 0.8034, 0.8306, 0.8543, 0.8748, 0.8925, 0.9078, 0.9211, 0.9324, 0.9422, 0.9507, 0.9579, 0.9641, 0.9694, 0.9739, 0.9778, 0.9811, 0.984, 0.9864, 0.9884, 1)` | `linear(0, 0, 0.111, 0.2141, 0.3078, 0.3923, 0.4681, 0.5357, 0.5957, 0.6487, 0.6954, 0.7363, 0.7721, 0.8034, 0.8306, 0.8543, 0.8748, 0.8925, 0.9078, 0.9211, 0.9324, 0.9422, 0.9507, 0.9579, 0.9641, 0.9694, 0.9739, 0.9778, 0.9811, 0.984, 0.9864, 0.9884, 1)` |

## CSS

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

```css
[data-style="linear"] {
  .ui-select-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(--radius-rounded);
    background-color: var(--chip-bg);
    box-shadow:
      0 0 0 0.5px var(--chip-ring),
      var(--shadow-low);
    color: var(--chip-text);
    font-family: inherit;
    font-size: var(--font-size-mini);
    font-weight: var(--font-weight-normal);
    line-height: 1;
    white-space: nowrap;
    user-select: none;
    cursor: default;
    transition:
      background-color var(--speed-highlight-fade-out),
      box-shadow var(--speed-highlight-fade-out),
      color var(--speed-highlight-fade-out);

    @media (hover: hover) {
      &:hover:not([data-disabled]) {
        background-color: var(--chip-bg-hover);
        box-shadow:
          0 0 0 0.5px var(--chip-ring-hover),
          var(--shadow-low);
      }
    }

    &[data-popup-open] {
      background-color: var(--chip-bg-hover);
      box-shadow:
        0 0 0 0.5px var(--chip-ring-hover),
        var(--shadow-low);
    }

    &:focus-visible {
      outline: 1px solid var(--focus-ring);
    }

    &[data-disabled] {
      opacity: 0.6;
    }

    &[data-size="normal"] {
      height: 32px;
      padding: 0 12px;
      font-size: var(--font-size-small);
    }
  }

  .ui-select-trigger[data-variant="secondary"] {
    position: relative;
    height: 30px;
    padding: 1px 28px 1px 10px;
    border: 0.5px solid transparent;
    border-radius: var(--radius-control);
    background-color: var(--select-secondary-bg, var(--button-secondary-bg));
    box-shadow: none;
    color: var(--text-secondary);
    font-size: var(--font-size-small);
    line-height: normal;
    transition:
      background-color var(--speed-highlight-fade-out),
      border var(--speed-highlight-fade-out),
      color var(--speed-highlight-fade-out);

    &::after {
      content: "";
      position: absolute;
      inset: 0;
      border-radius: inherit;
      box-shadow:
        0 0 0 0.5px var(--button-ring),
        var(--shadow-low);
      pointer-events: none;
      transition: box-shadow var(--speed-highlight-fade-out);
    }

    @media (hover: hover) {
      &:hover:not([data-disabled]) {
        background-color: var(--button-secondary-bg-hover);
        box-shadow: none;

        &::after {
          box-shadow:
            0 0 0 0.5px var(--button-ring-hover),
            var(--shadow-low);
        }
      }
    }

    &[data-popup-open] {
      background-color: var(--button-secondary-bg-hover);
      box-shadow: none;
    }
  }

  &[data-theme="dark"] .ui-select-trigger {
    --select-secondary-bg: lch(13.773% 1.397 285.8);
  }

  .ui-select-positioner {
    outline: none;
  }

  .ui-select-popup {
    --select-popup-ring: lch(86.337% 0.019 352.3);
  }

  &[data-theme="dark"] .ui-select-popup {
    --select-popup-bg: lch(16.543% 1.483 266.5);
    --select-popup-ring: lch(38.134% 2.054 260.9);
  }

  .ui-select-popup {
    box-sizing: border-box;
    min-width: 224px;
    border: 0;
    border-radius: var(--radius-menu);
    background-color: var(--select-popup-bg, var(--surface-bg));
    box-shadow:
      0 0 0 0.5px var(--select-popup-ring),
      var(--shadow-menu);
    color: var(--surface-text);
    font-family: var(--font-regular);
    font-size: var(--font-size-small);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    outline: none;
    transform-origin: var(--transform-origin);
    transition:
      opacity var(--duration-spring-menu-open-opacity) var(--ease-spring-menu-open-opacity),
      scale var(--duration-spring-menu-open) var(--ease-spring-menu-open);

    &[data-starting-style],
    &[data-ending-style] {
      opacity: 0;
      scale: 0.98;
    }

    &[data-ending-style] {
      transition:
        opacity var(--duration-spring-menu-close) var(--ease-spring-menu-close-opacity),
        scale var(--duration-spring-menu-close) var(--ease-spring-menu-close);
    }
  }

  .ui-select-list {
    box-sizing: border-box;
    max-height: var(--available-height);
    padding: 6px 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scroll-padding-block: 6px;
    outline: none;
  }

  .ui-select-item {
    position: relative;
    isolation: isolate;
    display: flex;
    align-items: center;
    height: 32px;
    padding: 0 35px 0 12px;
    color: var(--surface-text);
    cursor: default;
    user-select: none;
    outline: none;

    &::before {
      content: "";
      position: absolute;
      inset: 0 4px;
      z-index: -1;
      border-radius: var(--radius-control);
    }

    &[data-highlighted] {
      color: var(--surface-text-strong);

      &::before {
        background-color: var(--surface-highlight);
      }
    }

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

  .ui-select-label {
    flex: 1;
    font-weight: var(--font-weight-normal);
    line-height: normal;
  }

  .ui-select-indicator {
    display: flex;
    margin-left: 12px;
    color: var(--surface-text);

    & svg {
      width: 14px;
      height: 14px;
    }
  }

  .ui-select-shortcut {
    margin-left: 16px;
    font-size: var(--font-size-micro);
    font-weight: var(--font-weight-medium);
    line-height: 1.1;
    color: var(--surface-text-muted);
  }

  .ui-select-separator {
    height: 0;
    padding: 6px 0;

    &::before {
      content: "";
      display: block;
      border-bottom: 0.5px solid var(--surface-divider);
    }
  }
}
```

## Structure

How Replicas assembles it on Base UI.

```tsx
import { Select as BaseSelect } from "@base-ui/react/select";
import type { ReactNode } from "react";
import { usePortalContainer } from "./portal";

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

function Trigger({
  className,
  variant,
  size,
  ...props
}: Omit<BaseSelect.Trigger.Props, "className"> & { className?: string; variant?: string; size?: string }) {
  return (
    <BaseSelect.Trigger
      className={join("ui-select-trigger", className)}
      data-variant={variant}
      data-size={size}
      {...props}
    />
  );
}

type PopupProps = Omit<BaseSelect.Popup.Props, "className"> & {
  className?: string;
  side?: BaseSelect.Positioner.Props["side"];
  align?: BaseSelect.Positioner.Props["align"];
  sideOffset?: number;
  alignItemWithTrigger?: boolean;
};

function Popup({
  className,
  side = "bottom",
  align = "start",
  sideOffset = 4,
  alignItemWithTrigger = false,
  children,
  ...props
}: PopupProps) {
  return (
    <BaseSelect.Portal container={usePortalContainer()}>
      <BaseSelect.Positioner
        className="ui-select-positioner"
        side={side}
        align={align}
        sideOffset={sideOffset}
        alignItemWithTrigger={alignItemWithTrigger}
      >
        <BaseSelect.Popup className={join("ui-select-popup", className)} {...props}>
          <BaseSelect.List className="ui-select-list">{children}</BaseSelect.List>
        </BaseSelect.Popup>
      </BaseSelect.Positioner>
    </BaseSelect.Portal>
  );
}

type ItemProps = Omit<BaseSelect.Item.Props, "className"> & {
  className?: string;
  shortcut?: ReactNode;
};

function Item({ className, shortcut, children, ...props }: ItemProps) {
  return (
    <BaseSelect.Item className={join("ui-select-item", className)} {...props}>
      <BaseSelect.ItemText className="ui-select-label">{children}</BaseSelect.ItemText>
      <BaseSelect.ItemIndicator className="ui-select-indicator">
        <svg viewBox="0 0 16 16" fill="none" aria-hidden>
          <path d="M3.5 8.5l3 3 6-7" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
        </svg>
      </BaseSelect.ItemIndicator>
      {shortcut !== undefined ? <span className="ui-select-shortcut">{shortcut}</span> : null}
    </BaseSelect.Item>
  );
}

function Separator({ className, ...props }: Omit<BaseSelect.Separator.Props, "className"> & { className?: string }) {
  return <BaseSelect.Separator className={join("ui-select-separator", className)} {...props} />;
}

export const Select = {
  Root: BaseSelect.Root,
  Trigger,
  Value: BaseSelect.Value,
  Popup,
  Item,
  Separator,
};
```

## Example

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

const roles = [
  { value: "viewer", label: "Viewer" },
  { value: "commenter", label: "Commenter" },
  { value: "editor", label: "Editor" },
  { value: "admin", label: "Admin" },
  { value: "owner", label: "Owner" },
];

export default function SelectDemo() {
  return (
    <Select.Root items={roles} defaultValue="viewer">
      <Select.Trigger aria-label="Role">
        <Select.Value />
      </Select.Trigger>
      <Select.Popup>
        {roles.map((role, index) => (
          <Select.Item key={role.value} value={role.value} shortcut={index}>
            {role.label}
          </Select.Item>
        ))}
      </Select.Popup>
    </Select.Root>
  );
}
```

## Foundations

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