# Shopify Tag

A label for categorising items, with an optional colour and remove button.

Build a Tag 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 primitives if it has none.

Fidelity: Measured from Shopify admin Add product form, Tags chip. The left padding is ignored because the admin chip has a leading icon. The remove button follows the Polaris 13 Tag stylesheet.

## Tokens

| Token | Light | Dark |
| --- | --- | --- |
| `--p-border-radius-corner-shape` | `superellipse(1.333)` | `superellipse(1.333)` |
| `--p-border-radius-tag` | `.5rem` | `.5rem` |
| `--p-border-radius-tag-inner` | `.375rem` | `.375rem` |
| `--p-border-width-050` | `.125rem` | `.125rem` |
| `--p-color-bg-fill-transparent` | `#0000000d` | `#0000` |
| `--p-color-border-focus` | `rgba(80,131,240,1)` | `#97adff` |
| `--p-color-icon-hover` | `#0a0a0a` | `#eee` |
| `--p-color-icon-secondary` | `#606060` | `#aaa` |
| `--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-small` | `-.005em` | `-.005em` |
| `--p-font-line-height-body-small` | `1.125rem` | `1.125rem` |
| `--p-font-size-body-small` | `.75rem` | `.75rem` |
| `--p-font-weight-medium` | `500` | `500` |
| `--p-height-500` | `1.25rem` | `1.25rem` |
| `--p-space-025` | `.0625rem` | `.0625rem` |
| `--p-space-050` | `.125rem` | `.125rem` |
| `--p-space-100` | `.25rem` | `.25rem` |
| `--p-space-200` | `.5rem` | `.5rem` |

## 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-tag {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    gap: var(--p-space-050);
    max-width: 100%;
    height: var(--p-height-500);
    padding: var(--p-space-050) var(--p-space-200);
    border-radius: var(--p-border-radius-tag);
    corner-shape: var(--p-border-radius-corner-shape);
    background-color: var(--p-color-bg-fill-transparent);
    color: var(--p-color-text-secondary);
    font-family: var(--p-font-family-sans);
    font-size: var(--p-font-size-body-small);
    font-weight: var(--p-font-weight-medium);
    line-height: var(--p-font-line-height-body-small);
    letter-spacing: var(--p-font-letter-spacing-body-small);
    white-space: nowrap;
    user-select: none;

    &[data-removable] {
      padding-inline-end: var(--p-space-050);
    }

    &:has(.ui-tag-dot) {
      padding-inline-start: var(--p-space-100);
    }
  }

  .ui-tag-dot {
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    margin: 4px;
    border-radius: 50%;
    background-color: var(--tag-color);
  }

  .ui-tag-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .ui-tag-remove {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: var(--p-border-radius-tag-inner);
    corner-shape: var(--p-border-radius-corner-shape);
    background-color: transparent;
    color: var(--p-color-icon-secondary);
    cursor: pointer;

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

    &:is(:hover, :active) {
      color: var(--p-color-icon-hover);
    }

    &:focus-visible {
      color: var(--p-color-icon-hover);
      outline: var(--p-border-width-050) solid var(--p-color-border-focus);
      outline-offset: calc(var(--p-space-025) * -1);
    }
  }
}
```

## Structure

How Replicas assembles it on Base UI.

```tsx
import type { ComponentProps, CSSProperties } from "react";
import { join } from "./utils";

export type TagProps = ComponentProps<"span"> & {
  variant?: string;
  size?: string;
  color?: string;
  onRemove?: () => void;
  removeLabel?: string;
};

export function Tag({
  className,
  variant = "default",
  size = "medium",
  color,
  onRemove,
  removeLabel = "Remove",
  style,
  children,
  ...props
}: TagProps) {
  return (
    <span
      className={join("ui-tag", className)}
      data-variant={variant}
      data-size={size}
      data-removable={onRemove ? "" : undefined}
      style={color ? ({ "--tag-color": color, ...style } as CSSProperties) : style}
      {...props}
    >
      {color ? <span className="ui-tag-dot" aria-hidden /> : null}
      <span className="ui-tag-label">{children}</span>
      {onRemove ? (
        <button type="button" className="ui-tag-remove" aria-label={removeLabel} onClick={onRemove}>
          <svg viewBox="0 0 16 16" fill="none" aria-hidden>
            <path d="M5 5l6 6m0-6l-6 6" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
          </svg>
        </button>
      ) : null}
    </span>
  );
}
```

## Example

```tsx
import { Tag } from "@replicas/ui";
import { useState } from "react";

const initial = [
  { label: "Urgent", color: "#eb5757" },
  { label: "Marketing", color: "#4ea7fc" },
  { label: "Design", color: "#bb87fc" },
];

export default function TagDemo() {
  const [tags, setTags] = useState(initial);

  return (
    <>
      {tags.map((tag) => (
        <Tag
          key={tag.label}
          color={tag.color}
          onRemove={() => setTags((current) => current.filter((item) => item !== tag))}
          removeLabel={`Remove ${tag.label}`}
        >
          {tag.label}
        </Tag>
      ))}
      <Tag>Plain</Tag>
    </>
  );
}
```

## Foundations

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