# Grok Stock

A quote with its change, a chart, ranges and key figures.

Build a Stock in this project that looks and behaves like Grok's. Measured from the running Grok app (grok.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: Concept, not a real feature. Designed from Grok's card values. Concept, not a real feature. Designed from Grok's 24px card, muted greys and its green and red. The chart line and area take the direction colour.

## Tokens

| Token | Light | Dark |
| --- | --- | --- |
| `--grok-text-danger-primary` | `lab(55.9999% 77.47 46.6542)` | `lab(55.9999% 77.47 46.6542)` |
| `--grok-card-bg` | `rgb(255 255 255)` | `rgb(35 33 31)` |
| `--grok-card-shadow` | `0 0 0 var(--grok-border-width-hairline) var(--grok-card-ring), 0 2px 8px rgb(0 0 0 / 0.04)` | `0 0 0 var(--grok-border-width-hairline) var(--grok-card-ring), 0 2px 8px rgb(0 0 0 / 0.04)` |
| `--grok-card-text` | `rgb(5 5 5)` | `rgb(252 252 252)` |
| `--grok-card-text-muted` | `rgb(99 99 99)` | `rgb(158 158 158)` |
| `--grok-card-text-hint` | `rgb(133 133 133)` | `rgb(133 133 133)` |
| `--grok-card-text-dim` | `rgb(158 158 158)` | `rgb(99 99 99)` |
| `--grok-card-divider` | `rgb(5 5 5 / 0.06)` | `rgb(252 252 252 / 0.06)` |
| `--grok-card-success` | `rgb(0 148 39)` | `rgb(140 227 143)` |
| `--grok-card-radius` | `24px` | `24px` |
| `--grok-font-weight-card-title` | `550` | `550` |
| `--grok-font-weight-card-label` | `500` | `500` |
| `--grok-font-sans` | `"X-VF", system-ui, -apple-system, "Segoe UI", sans-serif` | `"X-VF", system-ui, -apple-system, "Segoe UI", sans-serif` |
| `--grok-font-size-hint` | `12px` | `12px` |
| `--grok-font-size-section-headline` | `13px` | `13px` |
| `--grok-font-size-chrome` | `14px` | `14px` |
| `--grok-font-size-body` | `15px` | `15px` |
| `--grok-font-size-display` | `28px` | `28px` |
| `--grok-font-weight-regular` | `425` | `425` |
| `--grok-line-height-hint` | `16px` | `16px` |
| `--grok-line-height-compact` | `20px` | `20px` |
| `--grok-line-height-title-small` | `22px` | `22px` |
| `--grok-letter-spacing-body` | `0.0027em` | `0.0027em` |
| `--grok-space-0-5` | `2px` | `2px` |
| `--grok-space-1` | `4px` | `4px` |
| `--grok-space-1-5` | `6px` | `6px` |
| `--grok-space-2` | `8px` | `8px` |
| `--grok-space-3` | `12px` | `12px` |
| `--grok-space-3-5` | `14px` | `14px` |
| `--grok-space-4` | `16px` | `16px` |

## CSS

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

```css
[data-style="grok"] {
  .ui-stock {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: var(--grok-space-3-5) var(--grok-space-4) var(--grok-space-4);
    border-radius: var(--grok-card-radius);
    background-color: var(--grok-card-bg);
    box-shadow: var(--grok-card-shadow);
    color: var(--grok-card-text);
    font-family: var(--grok-font-sans);
    font-size: var(--grok-font-size-chrome);
    font-weight: var(--grok-font-weight-regular);
    line-height: var(--grok-line-height-compact);
    letter-spacing: var(--grok-letter-spacing-body);
  }

  .ui-stock-header {
    display: flex;
    align-items: baseline;
    gap: var(--grok-space-1-5);
    min-width: 0;
  }

  .ui-stock-symbol {
    font-size: var(--grok-font-size-body);
    font-weight: var(--grok-font-weight-card-title);
    line-height: var(--grok-line-height-title-small);
  }

  .ui-stock-name {
    min-width: 0;
    overflow: hidden;
    color: var(--grok-card-text-hint);
    font-size: var(--grok-font-size-section-headline);
    line-height: 18px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .ui-stock-quote {
    display: flex;
    align-items: baseline;
    gap: var(--grok-space-2);
    margin-top: var(--grok-space-1);
  }

  .ui-stock-price {
    font-size: var(--grok-font-size-display);
    font-weight: var(--grok-font-weight-card-title);
    line-height: 34px;
    letter-spacing: -0.4px;
    font-variant-numeric: tabular-nums;
  }

  .ui-stock-change {
    color: var(--grok-card-success);
    font-weight: var(--grok-font-weight-card-label);
    font-variant-numeric: tabular-nums;
  }

  .ui-stock-chart {
    display: block;
    width: 100%;
    height: 96px;
    margin-top: var(--grok-space-3);
    overflow: visible;
  }

  .ui-stock-area {
    fill: color-mix(in srgb, var(--grok-card-success) 10%, transparent);
    stroke: none;
  }

  .ui-stock-baseline {
    stroke: var(--grok-card-text-dim);
    stroke-width: 1;
    stroke-dasharray: 2 3;
    vector-effect: non-scaling-stroke;
  }

  .ui-stock-line {
    stroke: var(--grok-card-success);
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .ui-stock[data-direction="down"] {
    & .ui-stock-change {
      color: var(--grok-text-danger-primary);
    }

    & .ui-stock-area {
      fill: color-mix(in srgb, var(--grok-text-danger-primary) 10%, transparent);
    }

    & .ui-stock-line {
      stroke: var(--grok-text-danger-primary);
    }
  }

  .ui-stock[data-direction="flat"] {
    & .ui-stock-change {
      color: var(--grok-card-text-muted);
    }

    & .ui-stock-area {
      fill: color-mix(in srgb, var(--grok-card-text-muted) 10%, transparent);
    }

    & .ui-stock-line {
      stroke: var(--grok-card-text-muted);
    }
  }

  .ui-stock-ranges {
    display: flex;
    margin-top: var(--grok-space-2);
  }

  .ui-stock-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--grok-space-2);
    margin: var(--grok-space-3) 0 0;
    padding-top: var(--grok-space-3);
    border-top: 1px solid var(--grok-card-divider);
  }

  .ui-stock-stat {
    display: flex;
    flex-direction: column;
    gap: var(--grok-space-0-5);
    min-width: 0;

    & dt {
      color: var(--grok-card-text-hint);
      font-size: var(--grok-font-size-hint);
      line-height: var(--grok-line-height-hint);
    }

    & dd {
      margin: 0;
      font-weight: var(--grok-font-weight-card-label);
      font-variant-numeric: tabular-nums;
    }
  }
}
```

## Structure

How Replicas assembles it on Base UI.

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

type Direction = "up" | "down" | "flat";

type RootProps = ComponentProps<"div"> & { direction?: Direction };

function Root({ className, direction = "up", ...props }: RootProps) {
  return <div className={join("ui-stock", className)} data-direction={direction} {...props} />;
}

const part = (name: string) =>
  function Part({ className, ...props }: ComponentProps<"div">) {
    return <div className={join(`ui-stock-${name}`, className)} {...props} />;
  };

const text = (name: string) =>
  function Text({ className, ...props }: ComponentProps<"span">) {
    return <span className={join(`ui-stock-${name}`, className)} {...props} />;
  };

type ChartProps = Omit<ComponentProps<"svg">, "children" | "points"> & { points: number[]; baseline?: number };

function Chart({ className, points, baseline, ...props }: ChartProps) {
  const width = 300;
  const height = 96;
  const min = Math.min(...points, baseline ?? Number.POSITIVE_INFINITY);
  const max = Math.max(...points, baseline ?? Number.NEGATIVE_INFINITY);
  const range = max - min || 1;
  const x = (index: number) => (index / Math.max(points.length - 1, 1)) * width;
  const y = (value: number) => height - 4 - ((value - min) / range) * (height - 8);
  const line = points.map((value, index) => `${index ? "L" : "M"}${x(index).toFixed(1)} ${y(value).toFixed(1)}`).join(" ");
  return (
    <svg className={join("ui-stock-chart", className)} viewBox={`0 0 ${width} ${height}`} preserveAspectRatio="none" aria-hidden {...props}>
      <path className="ui-stock-area" d={`${line} L${width} ${height} L0 ${height} Z`} />
      {baseline === undefined ? null : <line className="ui-stock-baseline" x1="0" x2={width} y1={y(baseline)} y2={y(baseline)} />}
      <path className="ui-stock-line" d={line} fill="none" vectorEffect="non-scaling-stroke" />
    </svg>
  );
}

function Stats({ className, ...props }: ComponentProps<"dl">) {
  return <dl className={join("ui-stock-stats", className)} {...props} />;
}

type StatProps = Omit<ComponentProps<"div">, "children"> & { label: ReactNode; value: ReactNode };

function Stat({ className, label, value, ...props }: StatProps) {
  return (
    <div className={join("ui-stock-stat", className)} {...props}>
      <dt>{label}</dt>
      <dd>{value}</dd>
    </div>
  );
}

export const Stock = {
  Root,
  Header: part("header"),
  Symbol: text("symbol"),
  Name: text("name"),
  Quote: part("quote"),
  Price: text("price"),
  Change: text("change"),
  Chart,
  Ranges: part("ranges"),
  Stats,
  Stat,
};
```

## Example

```tsx
import { Stock, Toggle, ToggleGroup } from "@replicas/ui";
import { useState } from "react";

const series: Record<string, number[]> = {
  "1D": [180.05, 180.4, 179.8, 180.9, 181.3, 180.7, 181.6, 182.1, 181.8, 182.6, 182.2, 182.4],
  "5D": [176.2, 177.8, 177.1, 178.9, 178.4, 179.6, 180.05, 181.2, 182.4],
  "1M": [171.4, 169.8, 172.6, 174.1, 173.2, 175.9, 177.3, 176.1, 178.8, 180.05, 182.4],
  "1Y": [142.3, 149.8, 147.1, 155.6, 161.2, 158.4, 166.9, 171.3, 168.7, 176.5, 182.4],
};

export default function StockDemo() {
  const [range, setRange] = useState("1D");
  return (
    <Stock.Root direction="up" style={{ width: "100%", maxWidth: 420 }}>
      <Stock.Header>
        <Stock.Symbol>ACME</Stock.Symbol>
        <Stock.Name>Acme Corp · NASDAQ</Stock.Name>
      </Stock.Header>
      <Stock.Quote>
        <Stock.Price>$182.40</Stock.Price>
        <Stock.Change>+2.35 (1.31%)</Stock.Change>
      </Stock.Quote>
      <Stock.Chart points={series[range]} baseline={range === "1D" ? 180.05 : undefined} />
      <Stock.Ranges>
        <ToggleGroup size="small" value={[range]} onValueChange={(value) => value[0] && setRange(value[0] as string)}>
          {Object.keys(series).map((key) => (
            <Toggle key={key} value={key} size="small">
              {key}
            </Toggle>
          ))}
        </ToggleGroup>
      </Stock.Ranges>
      <Stock.Stats>
        <Stock.Stat label="Open" value="180.12" />
        <Stock.Stat label="High" value="183.05" />
        <Stock.Stat label="Low" value="179.64" />
        <Stock.Stat label="Mkt cap" value="2.84T" />
      </Stock.Stats>
    </Stock.Root>
  );
}
```

## Foundations

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