GitHub Primer
JS behaviour
State Label
Open, Closed, Merged, Draft pills with circular octicons in Primer's success green, done purple and danger red. The smallest atom that screams GitHub.
Real scenarios
The component as it is used in a product — not a specimen grid.
One pill, a whole lifecycle
Drive the pull request through its life — the StateLabel swaps its octicon and its Primer colour the moment the verdict changes.
nabux / dashboardPull request
feat: PDF export for monthly reports
Open Merged Closed DraftGreen = open work · purple = merged with done · red = closed without merging · gray = still a draft.
The full palette of verdicts
Issues and PRs share the anatomy but not the verdicts — closed issues go purple when completed, PRs only when merged.
Openissue · open
Closedissue · completed
Not plannedissue · not planned
OpenPR · open
MergedPR · merged
ClosedPR · closed
DraftPR · draft
Mergedlarge size
Important props
| Prop | Type | Default | What it does |
|---|---|---|---|
| status | state | 'issueOpen' | issueOpen · issueClosed · prOpen · prMerged · prClosed · draft; the octicon and the colour switch together. |
| icon | octicon · 16px | 'filled circle' | A filled white circle glyph on the tinted field — the StateLabel signature. |
| radius | length | '2em' | The fully rounded pill; 12px text at weight 500. |
| size | height | '24 · 32' | The two official sizes: small inside rows, large on the issue/PR header. |
Snippet
<span class="prs-label" data-status="open">
<svg viewBox="0 0 16 16">…</svg> Open
</span>
<span class="prs-label" data-status="merged">
<svg viewBox="0 0 16 16">…</svg> Merged
</span>
<style>
.prs-label { display: inline-flex; align-items: center; gap: 4px; block-size: 24px;
padding-inline: 10px; border-radius: 2em; font: 500 12px system-ui; }
.prs-label[data-status='open'] { background: #1A7F37; color: #fff; }
.prs-label[data-status='merged'] { background: #8250DF; color: #fff; }
</style>
// resources/js/Pages/Pulls/Show.tsx — the PR header mounts the
// React snippet; the state lifecycle lives entirely client-side.
import { Head } from '@inertiajs/react';
import StateLabel from '@/components/primer/StateLabel';
export default function PullShow() {
return (
<>
<Head title="Pull request #412" />
<StateLabel initial="open" />
</>
);
}
import { useState } from 'react';
import '@nabuxai/ui-core/css';
type Status = 'open' | 'merged' | 'closed' | 'draft';
const PILL: Record<Status, string> = { open: 'Open', merged: 'Merged', closed: 'Closed', draft: 'Draft' };
export default function StateLabel({ initial = 'open' }: { initial?: Status }) {
const [st, setSt] = useState<Status>(initial);
return (
<div style={{ display: 'grid', gap: 12, justifyItems: 'start' }}>
<span className="prs-label" data-status={st}>● {PILL[st]}</span>
<div role="group" aria-label="Change state" style={{ display: 'flex', gap: 8 }}>
{(Object.keys(PILL) as Status[]).map((s) => (
<button key={s} aria-pressed={st === s} onClick={() => setSt(s)}>{PILL[s]}</button>
))}
</div>
<style>{`
.prs-label { display: inline-flex; align-items: center; gap: 4px; block-size: 24px;
padding-inline: 10px; border-radius: 2em; font: 500 12px system-ui; }
.prs-label[data-status='open'] { background: #1A7F37; color: #fff; }
.prs-label[data-status='merged'] { background: #8250DF; color: #fff; }
.prs-label[data-status='closed'] { background: #CF222E; color: #fff; }
.prs-label[data-status='draft'] { background: #59636E; color: #fff; }
`}</style>
</div>
);
}
<!-- StateLabel.vue -->
<script setup lang="ts">
import { ref } from 'vue';
import '@nabuxai/ui-core/css';
type Status = 'open' | 'merged' | 'closed' | 'draft';
const PILL: Record<Status, string> = { open: 'Open', merged: 'Merged', closed: 'Closed', draft: 'Draft' };
const st = ref<Status>('open');
</script>
<template>
<div style="display: grid; gap: 12px; justify-items: start">
<span class="prs-label" :data-status="st">● {{ PILL[st] }}</span>
<div role="group" aria-label="Change state" style="display: flex; gap: 8px">
<button v-for="(label, s) in PILL" :key="s" :aria-pressed="st === s" @click="st = s">{{ label }}</button>
</div>
</div>
</template>
<style scoped>
.prs-label { display: inline-flex; align-items: center; gap: 4px; block-size: 24px;
padding-inline: 10px; border-radius: 2em; font: 500 12px system-ui; }
.prs-label[data-status='open'] { background: #1a7f37; color: #fff; }
.prs-label[data-status='merged'] { background: #8250df; color: #fff; }
.prs-label[data-status='closed'] { background: #cf222e; color: #fff; }
.prs-label[data-status='draft'] { background: #59636e; color: #fff; }
</style>
<!-- StateLabel.svelte -->
<script lang="ts">
import '@nabuxai/ui-core/css';
type Status = 'open' | 'merged' | 'closed' | 'draft';
const PILL: Record<Status, string> = { open: 'Open', merged: 'Merged', closed: 'Closed', draft: 'Draft' };
let { initial = 'open' }: { initial?: Status } = $props();
let st = $state<Status>(initial);
</script>
<div style="display: grid; gap: 12px; justify-items: start">
<span class="prs-label" data-status={st}>● {PILL[st]}</span>
<div role="group" aria-label="Change state" style="display: flex; gap: 8px">
{#each Object.keys(PILL) as s (s)}
<button aria-pressed={st === s} onclick={() => (st = s as Status)}>{PILL[s as Status]}</button>
{/each}
</div>
</div>
<style>
.prs-label { display: inline-flex; align-items: center; gap: 4px; block-size: 24px;
padding-inline: 10px; border-radius: 2em; font: 500 12px system-ui; }
.prs-label[data-status='open'] { background: #1a7f37; color: #fff; }
.prs-label[data-status='merged'] { background: #8250df; color: #fff; }
.prs-label[data-status='closed'] { background: #cf222e; color: #fff; }
.prs-label[data-status='draft'] { background: #59636e; color: #fff; }
</style>