# Geodesic badges (/docs/geodesic)





The context badges from the Figma frame "Badges — 4 statuses, 4 levels" (42 UI Kit V3). Each kind of thing a learner works on has its own solid, and each status has its own colour, so a badge says what it is and where it stands at a glance.

```tsx
import { GiftToken, ModuleBadge, ProjectBadge } from "@42-central/ui-react/geodesic";
import "@42-central/ui-react/geodesic/styles.css";

<ModuleBadge status="in-progress" progress={50} label="Graphics, in progress" />
<ProjectBadge status="done" size={48} />
<GiftToken hue="orange" icon={<Coffee />} />
```

The badges need their own stylesheet, `@42-central/ui-react/geodesic/styles.css`: it carries the status transitions and the progress fill.

## Playground [#playground]

<story.Playground />

## The grammar [#the-grammar]

* **One shape per level.** The geodesic sphere is a module (`ModuleBadge`), the cube a project (`ProjectBadge`), the square slab on its square tile an exam (`ExamBadge`), the octahedron an activity (`ActivityBadge`), the 7-sided crystal a skill (`SkillBadge`). A gift is a box in a pentagon (`GiftBoxBadge`), social is three small spheres in an octagon (`SocialBadge`).
* **One colour per status.** `locked` is neutral, `available` purple, `in-progress` pink. `done` takes the shape's own colour: module green, project purple, exam blue, activity blue (you take part in an activity, you don't validate it), skill `brand`, gift orange, social cyan. `failed` is red on every shape: the solid stays unlit, but the tile closes and glows, since the attempt is over.
* **One progression everywhere.** A wireframe, then half lit, then full with a closed tile and a glow. Locked shows a padlock over a dotted silhouette. The module and the exam keep their wireframe instead.

<Preview align="center" code="&#x22;<ModuleBadge status=\&#x22;locked\&#x22; label=\&#x22;Graphics, locked\&#x22; />\n<ModuleBadge status=\&#x22;available\&#x22; label=\&#x22;Graphics, available\&#x22; />\n<ModuleBadge status=\&#x22;in-progress\&#x22; progress={50} label=\&#x22;Graphics, in progress\&#x22; />\n<ModuleBadge status=\&#x22;done\&#x22; label=\&#x22;Graphics, validated\&#x22; />\n<ModuleBadge status=\&#x22;failed\&#x22; label=\&#x22;Graphics, failed\&#x22; />\n{/* …and the same five for ProjectBadge, ExamBadge, ActivityBadge,\n    SkillBadge, GiftBoxBadge and SocialBadge */}&#x22;">
  <GeodesicMatrix />
</Preview>

## Progress [#progress]

Every statused badge takes `progress` (0 to 100) while `in-progress`. The solid fills like a liquid, from the bottom up: each face fills from its own base through a long, soft gradient, so every percent moves the fill. The exam fills its own way: its sides light up and a square grows on its top from the front corner, its side tracking progress. The 0 to 100 range is drawn as 15 to 100% of the fill, so started work never reads as merely available. Changes animate, and a badge fills up when it mounts.

<Preview align="center" code="`<ExamBadge status=&#x22;in-progress&#x22; progress={progress} />`">
  <GeodesicProgress />
</Preview>

## Gift token [#gift-token]

`GiftToken` is a received gift: a lit hexagon in its orbit, with the gift's glyph inside. It has no status, it takes a `hue`. Pass `remaining` (0 to 1) and the orbit drains clockwise from the top, the satellite riding its end.

<Preview align="center" code="&#x22;<GiftToken hue=\&#x22;orange\&#x22; icon={<Coffee />} />\n<GiftToken hue=\&#x22;pink\&#x22; icon={<Flower2 />} remaining={0.6} />\n<GiftToken hue=\&#x22;yellow\&#x22; icon={<Sparkles />} remaining={0.25} />\n<GiftToken hue=\&#x22;red\&#x22; icon={<Rocket />} />&#x22;">
  <div className="flex flex-wrap items-center gap-4">
    <GiftToken hue="orange" icon="<Coffee />" />

    <GiftToken hue="pink" icon="<Flower2 />" remaining="0.6" />

    <GiftToken hue="yellow" icon="<Sparkles />" remaining="0.25" />

    <GiftToken hue="red" icon="<Rocket />" />
  </div>
</Preview>

For a glyph in a tinted square instead, use [`ThemeIcon`](/docs/theme-icon).

## Planet [#planet]

`Planet` is a learner's level: a finer geodesic sphere, lit like an in-progress badge (same bottom-up order, floor and pink tones), but swept smoothly, the lit edge gliding through whole faces. It is 240px by default and takes any CSS length as `size`. `planetLevelOffset(progress)` gives the lit edge's height as a fraction of that size, to line a readout's leader up with it.

<Preview align="center" code="`<Planet progress={62} size={200} />`">
  <GeodesicPlanet />
</Preview>

## Sizes [#sizes]

Badges are 64px by default; `size` takes any number of pixels. The solids are drawn in a 64-unit box, so their lines scale with the badge, while a slotted glyph keeps a 1.5px stroke.

<Preview align="center" code="&#x22;<ProjectBadge status=\&#x22;done\&#x22; size={24} />\n<ProjectBadge status=\&#x22;done\&#x22; size={32} />\n<ProjectBadge status=\&#x22;done\&#x22; size={48} />\n<ProjectBadge status=\&#x22;done\&#x22; size={64} />\n<ProjectBadge status=\&#x22;done\&#x22; size={96} />&#x22;">
  <div className="flex flex-wrap items-center gap-4">
    <ProjectBadge status="done" size="24" />

    <ProjectBadge status="done" size="32" />

    <ProjectBadge status="done" size="48" />

    <ProjectBadge status="done" size="64" />

    <ProjectBadge status="done" size="96" />
  </div>
</Preview>

## API [#api]

Every statused badge (`ModuleBadge`, `ProjectBadge`, `ExamBadge`, `ActivityBadge`, `SkillBadge`, `GiftBoxBadge`, `SocialBadge`) takes the same props, `BadgeBaseProps`:

<TypeTable
  type="{
  status: {
    type: &#x22;'locked' | 'available' | 'in-progress' | 'done' | 'failed'&#x22;,
    required: true,
    description: 'Where the learner stands. Picks the colour and how lit the solid is.',
  },
  progress: {
    type: 'number',
    default: '50',
    description: 'Completion while `in-progress`, 0 to 100. Ignored in other statuses.',
  },
  size: { type: 'number', default: '64', description: 'Rendered width and height, in px.' },
  label: {
    type: 'string',
    description: 'Accessible name. Without one the badge is decorative and hidden from assistive tech.',
  },
  className: { type: 'string' },
  style: { type: 'CSSProperties' },
  testId: { type: 'string', description: 'Renders as `data-testid` on the root. See [Testing](/docs/testing).' },
}"
/>

`GiftToken`:

<TypeTable
  type="{
  hue: {
    type: &#x22;'neutral' | 'brand' | 'blue' | 'cyan' | 'teal' | 'green' | 'yellow' | 'orange' | 'red' | 'pink' | 'purple'&#x22;,
    required: true,
    description: &#x22;The gift's own colour.&#x22;,
  },
  icon: { type: 'ReactNode', required: true, description: &#x22;The gift's glyph, drawn at a 1.5px stroke.&#x22; },
  remaining: {
    type: 'number',
    description: &#x22;How much of the gift's time is left, 0 to 1. Without it the orbit is whole.&#x22;,
  },
  size: { type: 'number', default: '64' },
  label: { type: 'string', description: 'Accessible name. Without one the token is decorative.' },
  testId: { type: 'string' },
}"
/>

`Planet`:

<TypeTable
  type="{
  progress: { type: 'number', required: true, description: 'How far along, 0 to 100.' },
  size: { type: 'number | string', default: '240', description: 'px, or any CSS length (`100%`, `clamp(…)`).' },
  label: { type: 'string', description: 'Accessible name. Without one the planet is decorative.' },
  testId: { type: 'string' },
}"
/>

## Accessibility [#accessibility]

A badge with a `label` is one image (`role="img"` with that name); without one it is decoration and stays out of the accessibility tree. Name a badge whenever it carries information the text around it does not, for instance "Graphics, in progress".

Reduced motion turns the status transitions and the fill animation off. The badges follow the system setting, and also `data-motion="reduced"` on `<html>`, for apps that let people choose in-app.

## How the shapes are made [#how-the-shapes-are-made]

The Figma frame is flattened, so the solids are rebuilt from math. `packages/react/scripts/generate-geometry.ts` builds each mesh, poses it, projects it, and writes the result to `geometry.ts`: the facets turned to the viewer, a light bucket and a bottom-up rank per facet, edge paths, and the silhouette. The camera never moves, so none of this runs in the browser. After changing a solid, run `pnpm --filter @42/ui-react generate:geodesic`; a test fails if the committed data drifts from the script.
