# Shopify Slider

An easily stylable range input.

Build a Slider in this project that looks and behaves like Shopify's. Measured from the running Shopify app (admin.shopify.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/slider) if it has none.

Fidelity: Derived from Polaris 13 RangeSlider. The track and thumb follow the Polaris 13 stylesheet mapped onto the admin tokens.

## Tokens

| Token | Light | Dark |
| --- | --- | --- |
| `--p-border-radius-full` | `624.9375rem` | `624.9375rem` |
| `--p-border-width-025` | `.0625rem` | `.0625rem` |
| `--p-border-width-050` | `.125rem` | `.125rem` |
| `--p-color-bg-fill-brand` | `#f7f7f7` | `#414141` |
| `--p-color-bg-fill-tertiary` | `#ddd` | `#414141` |
| `--p-color-border-focus` | `rgba(80,131,240,1)` | `#97adff` |
| `--p-color-text` | `#101010` | `#eee` |
| `--p-color-text-secondary` | `rgba(74,74,74,1)` | `#aaa` |
| `--p-font-family-sans` | `"ShopifyInter", "Noto Sans Arabic", "Noto Sans Hebrew", ui-sans-serif, system-ui, sans-serif` | `"ShopifyInter", "Noto Sans Arabic", "Noto Sans Hebrew", ui-sans-serif, system-ui, sans-serif` |
| `--p-font-letter-spacing-body-medium` | `-.01em` | `-.01em` |
| `--p-font-line-height-body-medium` | `1.25rem` | `1.25rem` |
| `--p-font-size-body-medium` | `.8125rem` | `.8125rem` |
| `--p-font-weight-medium` | `500` | `500` |
| `--p-motion-duration-200` | `200ms` | `200ms` |
| `--p-motion-ease` | `cubic-bezier(.25, .1, .25, 1)` | `cubic-bezier(.25, .1, .25, 1)` |
| `--p-space-025` | `.0625rem` | `.0625rem` |
| `--p-space-100` | `.25rem` | `.25rem` |
| `--p-space-300` | `.75rem` | `.75rem` |
| `--p-space-400` | `1rem` | `1rem` |

## CSS

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

```css
[data-style="shopify"] {
  .ui-slider {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: baseline;
    row-gap: var(--p-space-100);
    width: 240px;
    max-width: 100%;
    color: var(--p-color-text);
    font-family: var(--p-font-family-sans);
    font-size: var(--p-font-size-body-medium);
    line-height: var(--p-font-line-height-body-medium);
    letter-spacing: var(--p-font-letter-spacing-body-medium);

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

  .ui-slider-label {
    color: var(--p-color-text);
    font-weight: var(--p-font-weight-medium);
  }

  .ui-slider-value {
    color: var(--p-color-text-secondary);
    font-variant-numeric: tabular-nums;
  }

  .ui-slider-control {
    box-sizing: border-box;
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    padding-block: var(--p-space-300);
    touch-action: none;
    user-select: none;
    cursor: pointer;
  }

  .ui-slider-track {
    width: 100%;
    height: var(--p-space-100);
    border-radius: var(--p-space-100);
    background-color: var(--p-color-bg-fill-tertiary);
  }

  .ui-slider-indicator {
    border-radius: inherit;
    background-color: var(--p-color-bg-fill-brand);
  }

  .ui-slider-thumb {
    box-sizing: border-box;
    width: var(--p-space-400);
    height: var(--p-space-400);
    border: var(--p-border-width-025) solid transparent;
    border-radius: var(--p-border-radius-full);
    background-color: var(--p-color-bg-fill-brand);
    cursor: grab;
    transition:
      border-color var(--p-motion-duration-200) var(--p-motion-ease),
      transform var(--p-motion-duration-200) var(--p-motion-ease);

    &:has(:focus-visible) {
      outline: var(--p-border-width-050) solid var(--p-color-border-focus);
      outline-offset: var(--p-space-025);
    }

    &:active,
    &[data-dragging] {
      cursor: grabbing;
    }
  }

  .ui-slider[data-disabled] .ui-slider-control,
  .ui-slider[data-disabled] .ui-slider-thumb {
    cursor: not-allowed;
  }
}
```

## Structure

How Replicas assembles it on Base UI.

```tsx
import { Slider as BaseSlider } from "@base-ui/react/slider";

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

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

function Label({ className, ...props }: Omit<BaseSlider.Label.Props, "className"> & { className?: string }) {
  return <BaseSlider.Label className={join("ui-slider-label", className)} {...props} />;
}

function Value({ className, ...props }: Omit<BaseSlider.Value.Props, "className"> & { className?: string }) {
  return <BaseSlider.Value className={join("ui-slider-value", className)} {...props} />;
}

function Thumb({ className, ...props }: Omit<BaseSlider.Thumb.Props, "className"> & { className?: string }) {
  return <BaseSlider.Thumb className={join("ui-slider-thumb", className)} {...props} />;
}

function Control({ className, children, ...props }: Omit<BaseSlider.Control.Props, "className"> & { className?: string }) {
  return (
    <BaseSlider.Control className={join("ui-slider-control", className)} {...props}>
      <BaseSlider.Track className="ui-slider-track">
        <BaseSlider.Indicator className="ui-slider-indicator" />
        {children ?? <Thumb />}
      </BaseSlider.Track>
    </BaseSlider.Control>
  );
}

export const Slider = {
  Root,
  Label,
  Value,
  Control,
  Thumb,
};
```

## Example

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

export default function SliderDemo() {
  return (
    <Slider.Root defaultValue={60} min={0} max={100}>
      <Slider.Label>Volume</Slider.Label>
      <Slider.Value>{(_, values) => `${values[0]}%`}</Slider.Value>
      <Slider.Control />
    </Slider.Root>
  );
}
```

## Foundations

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