IBM Carbon
JS behaviour
AI Label (Slug)
Carbon’s AI badge pinned to generated content — click it to pop open which model made this, plus actions; the signature of Carbon’s AI era.
Real scenarios
The component as it is used in a product — not a specimen grid.
Who wrote this? The badge knows
The gradient badge is pinned to AI-generated content: click it to see which model wrote the draft, with what confidence — then copy it, or revert in one click to the human version. Regenerate brings the AI back.
Ticket #2841 — draft reply
AI-generated content
- Model
- nabu-reply-3
- Confidence
- 92%
- Input tokens
- 1,940
- Reviewed by
- not yet
Sending an AI draft without review is logged on the ticket.
Back on the human draft — the badge is gone with it.
Inline, inside the heading
The inline kind rides along inside headings and copy — same popover, same actions, smaller footprint.
Conversation summary
AI-generated summary
- Model
- nabu-sum-2
- Messages read
- 64
The customer reported a delayed sales report; the agent confirmed the delay, attached the CSV export and fixed the reporting worker. One follow-up question about extra columns is still open.
AI-generated summary
- Model
- nabu-sum-2
- Messages read
- 64
The whole family
Three official sizes — xs to hug running text, md to mark an open surface.
xs · 20px
sm · 24px
md · 32px
Important props
| Prop | Type | Default | What it does |
|---|---|---|---|
| kind | string | 'default' | default or inline; the inline kind sits the same badge inside headings and copy. |
| size | string | 'xs · sm · md' | The three official badge sizes; small to hug text, large to mark open surfaces. |
| revert | action | optional | The badge popover can carry a revert button; one click rolls the generated content back to the human version. |
Snippet
<div class="cbai">
<button class="cbai-slug" aria-label="Generated with AI">AI</button>
<div class="cbai-pop" role="dialog" data-open="false">
<b>Suggested reply by the model</b>
<small>nabu-reply-3 · 92% confidence</small>
<footer><button>Revert</button></footer>
</div>
</div>
<style>
.cbai { position: relative; display: inline-flex; }
.cbai-slug { inline-size: 1.5rem; aspect-ratio: 1; border: none; border-radius: 999px;
background: linear-gradient(120deg, #8a3ffc, #d02670, #1192e8); color: #fff;
font: 600 .65rem/1 'IBM Plex Sans'; cursor: pointer; }
.cbai-pop { position: absolute; inset-block-start: calc(100% + 8px); inset-inline-end: 0;
inline-size: 16rem; padding: 1rem; background: #f4f4f4; }
.cbai-pop[data-open='false'] { display: none; }
</style>
// app/Pages/Ticket.jsx — Inertia page; renders the React snippet
// below unchanged, with Inertia's Link wired into the provider.
import { Link } from '@inertiajs/react';
import { NabuXUIProvider } from '@nabuxai/ui-react';
import AiDraftBadge from '@/components/AiDraftBadge';
export default function Ticket() {
return (
<NabuXUIProvider locale="en" linkComponent={Link}>
<main className="nx-page">
<AiDraftBadge />
</main>
</NabuXUIProvider>
);
}
// AiDraftBadge.jsx — Carbon AI label: the gradient badge proves who wrote this
import { useEffect, useRef, useState } from 'react';
import '@nabuxai/ui-core/css';
const DRAFTS = {
ai: 'Hello Lara, yes — the October sales report was ready by noon. The reporting worker briefly stopped responding, which we have fixed; the CSV export is attached. — Nabu support',
human: 'You are right — the report did land a little late and it is attached to this ticket now. Thanks for flagging it. — Nabu support',
};
export default function AiDraftBadge() {
const [pop, setPop] = useState(false);
const [mode, setMode] = useState('ai');
const boxRef = useRef(null);
useEffect(() => {
const onKey = (e) => e.key === 'Escape' && setPop(false);
const onTap = (e) => { if (!boxRef.current?.contains(e.target)) setPop(false); };
window.addEventListener('keydown', onKey);
window.addEventListener('pointerdown', onTap);
return () => {
window.removeEventListener('keydown', onKey);
window.removeEventListener('pointerdown', onTap);
};
}, []);
return (
<>
<style>{`
.cbai-draft { max-inline-size: 30rem; background: #f4f4f4;
font: 400 .875rem/1.6 'IBM Plex Sans', sans-serif; }
.cbai-draft-head { display: flex; align-items: center; gap: .625rem; padding: .75rem 1rem;
border-block-end: 1px solid #e0e0e0; }
.cbai-draft-head b { font-weight: 600; }
.cbai-draft-head small { margin-inline-start: auto; font-size: .75rem; color: #525252; }
.cbai-inline { position: relative; display: inline-flex; }
.cbai-slug { display: inline-grid; place-items: center; inline-size: 1.5rem; block-size: 1.5rem; border: none;
border-radius: 50%; color: #fff; cursor: pointer; font: 600 .625rem/1 'IBM Plex Sans', sans-serif;
background: linear-gradient(90deg, #8a3ffc, #d02670, #1192e8); }
.cbai-pop { position: absolute; inset-block-start: calc(100% + 8px); inset-inline-end: 0; z-index: 7;
inline-size: 16rem; padding: 1rem; background: #f4f4f4; box-shadow: 0 2px 6px rgba(0, 0, 0, .25); }
.cbai-pop[data-open='false'] { display: none; }
.cbai-pop b { font-weight: 600; }
.cbai-pop div { display: flex; justify-content: space-between; gap: 1rem; padding-block: .375rem;
border-block-end: 1px solid #e0e0e0; font-size: .75rem; }
.cbai-pop dt { color: #525252; }
.cbai-pop dd { margin: 0; font-weight: 600; font-family: 'IBM Plex Mono', Menlo, monospace; }
.cbai-pop-foot { display: flex; gap: .5rem; padding-block-start: .625rem; border-block-end: none; }
.cbai-act { block-size: 2rem; padding-inline: .875rem; border: none; background: transparent;
color: #0f62fe; font: 400 .8125rem/1 'IBM Plex Sans', sans-serif; cursor: pointer; }
.cbai-draft-body { padding: 1rem; }
.cbai-draft-body[data-ai='true'] { border-inline-start: 3px solid #d02670; }
.cbai-draft-foot { display: flex; padding: .625rem 1rem; border-block-start: 1px solid #e0e0e0; }
`}</style>
<div className="cbai-draft" ref={boxRef}>
<div className="cbai-draft-head">
<b>Ticket #2841 — draft reply</b>
<span className="cbai-inline">
<button type="button" className="cbai-slug" aria-label="Generated with AI — details"
aria-expanded={pop} onClick={() => setPop(!pop)}>AI</button>
<div className="cbai-pop" role="dialog" aria-label="AI details" data-open={pop}>
<b>AI-generated content</b>
<dl>
<div><dt>Model</dt><dd>nabu-reply-3</dd></div>
<div><dt>Confidence</dt><dd>92%</dd></div>
</dl>
<div className="cbai-pop-foot">
{/* One click rolls the draft back to the human version. */}
<button type="button" className="cbai-act"
onClick={() => { setPop(false); setMode('human'); }}>Revert to human draft</button>
</div>
</div>
</span>
<small>{mode === 'ai' ? 'suggested by nabu-reply-3' : 'human draft'}</small>
</div>
<p className="cbai-draft-body" data-ai={mode === 'ai'}>{DRAFTS[mode]}</p>
{mode === 'human' && (
<div className="cbai-draft-foot">
<button type="button" className="cbai-act" onClick={() => setMode('ai')}>Regenerate with AI</button>
</div>
)}
</div>
</>
);
}
<!-- AiDraftBadge.vue — Carbon AI label: the gradient badge proves who wrote this -->
<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref } from 'vue';
import '@nabuxai/ui-core/css';
const drafts = {
ai: 'Hello Lara, yes — the October sales report was ready by noon. The reporting worker briefly stopped responding, which we have fixed; the CSV export is attached. — Nabu support',
human: 'You are right — the report did land a little late and it is attached to this ticket now. Thanks for flagging it. — Nabu support',
};
const pop = ref(false);
const mode = ref<'ai' | 'human'>('ai');
const box = ref<HTMLElement | null>(null);
const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') pop.value = false; };
const onTap = (e: PointerEvent) => { if (!box.value?.contains(e.target as Node)) pop.value = false; };
onMounted(() => {
window.addEventListener('keydown', onKey);
window.addEventListener('pointerdown', onTap);
});
onBeforeUnmount(() => {
window.removeEventListener('keydown', onKey);
window.removeEventListener('pointerdown', onTap);
});
</script>
<template>
<div ref="box" class="cbai-draft">
<div class="cbai-draft-head">
<b>Ticket #2841 — draft reply</b>
<span class="cbai-inline">
<button type="button" class="cbai-slug" aria-label="Generated with AI — details"
:aria-expanded="pop" @click="pop = !pop">AI</button>
<div class="cbai-pop" role="dialog" aria-label="AI details" :data-open="pop">
<b>AI-generated content</b>
<dl>
<div><dt>Model</dt><dd>nabu-reply-3</dd></div>
<div><dt>Confidence</dt><dd>92%</dd></div>
</dl>
<div class="cbai-pop-foot">
<!-- One click rolls the draft back to the human version. -->
<button type="button" class="cbai-act" @click="pop = false; mode = 'human'">Revert to human draft</button>
</div>
</div>
</span>
<small>{{ mode === 'ai' ? 'suggested by nabu-reply-3' : 'human draft' }}</small>
</div>
<p class="cbai-draft-body" :data-ai="mode === 'ai'">{{ drafts[mode] }}</p>
<div v-if="mode === 'human'" class="cbai-draft-foot">
<button type="button" class="cbai-act" @click="mode = 'ai'">Regenerate with AI</button>
</div>
</div>
</template>
<style scoped>
.cbai-draft { max-inline-size: 30rem; background: #f4f4f4;
font: 400 .875rem/1.6 'IBM Plex Sans', sans-serif; }
.cbai-draft-head { display: flex; align-items: center; gap: .625rem; padding: .75rem 1rem;
border-block-end: 1px solid #e0e0e0; }
.cbai-draft-head b { font-weight: 600; }
.cbai-draft-head small { margin-inline-start: auto; font-size: .75rem; color: #525252; }
.cbai-inline { position: relative; display: inline-flex; }
.cbai-slug { display: inline-grid; place-items: center; inline-size: 1.5rem; block-size: 1.5rem; border: none;
border-radius: 50%; color: #fff; cursor: pointer; font: 600 .625rem/1 'IBM Plex Sans', sans-serif;
background: linear-gradient(90deg, #8a3ffc, #d02670, #1192e8); }
.cbai-pop { position: absolute; inset-block-start: calc(100% + 8px); inset-inline-end: 0; z-index: 7;
inline-size: 16rem; padding: 1rem; background: #f4f4f4; box-shadow: 0 2px 6px rgba(0, 0, 0, .25); }
.cbai-pop[data-open='false'] { display: none; }
.cbai-pop b { font-weight: 600; }
.cbai-pop div { display: flex; justify-content: space-between; gap: 1rem; padding-block: .375rem;
border-block-end: 1px solid #e0e0e0; font-size: .75rem; }
.cbai-pop dt { color: #525252; }
.cbai-pop dd { margin: 0; font-weight: 600; font-family: 'IBM Plex Mono', Menlo, monospace; }
.cbai-pop-foot { display: flex; gap: .5rem; padding-block-start: .625rem; border-block-end: none; }
.cbai-act { block-size: 2rem; padding-inline: .875rem; border: none; background: transparent;
color: #0f62fe; font: 400 .8125rem/1 'IBM Plex Sans', sans-serif; cursor: pointer; }
.cbai-draft-body { padding: 1rem; }
.cbai-draft-body[data-ai='true'] { border-inline-start: 3px solid #d02670; }
.cbai-draft-foot { display: flex; padding: .625rem 1rem; border-block-start: 1px solid #e0e0e0; }
</style>
<!-- AiDraftBadge.svelte — Carbon AI label: the gradient badge proves who wrote this -->
<script lang="ts">
import { onMount } from 'svelte';
import '@nabuxai/ui-core/css';
const drafts = {
ai: 'Hello Lara, yes — the October sales report was ready by noon. The reporting worker briefly stopped responding, which we have fixed; the CSV export is attached. — Nabu support',
human: 'You are right — the report did land a little late and it is attached to this ticket now. Thanks for flagging it. — Nabu support',
};
let pop = $state(false);
let mode = $state<'ai' | 'human'>('ai');
let box: HTMLElement;
onMount(() => {
const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') pop = false; };
const onTap = (e: PointerEvent) => { if (!box.contains(e.target as Node)) pop = false; };
window.addEventListener('keydown', onKey);
window.addEventListener('pointerdown', onTap);
return () => {
window.removeEventListener('keydown', onKey);
window.removeEventListener('pointerdown', onTap);
};
});
</script>
<div bind:this={box} class="cbai-draft">
<div class="cbai-draft-head">
<b>Ticket #2841 — draft reply</b>
<span class="cbai-inline">
<button type="button" class="cbai-slug" aria-label="Generated with AI — details"
aria-expanded={pop} onclick={() => (pop = !pop)}>AI</button>
<div class="cbai-pop" role="dialog" aria-label="AI details" data-open={pop}>
<b>AI-generated content</b>
<dl>
<div><dt>Model</dt><dd>nabu-reply-3</dd></div>
<div><dt>Confidence</dt><dd>92%</dd></div>
</dl>
<div class="cbai-pop-foot">
<!-- One click rolls the draft back to the human version. -->
<button type="button" class="cbai-act" onclick={() => { pop = false; mode = 'human'; }}>Revert to human draft</button>
</div>
</div>
</span>
<small>{mode === 'ai' ? 'suggested by nabu-reply-3' : 'human draft'}</small>
</div>
<p class="cbai-draft-body" data-ai={mode === 'ai'}>{drafts[mode]}</p>
{#if mode === 'human'}
<div class="cbai-draft-foot">
<button type="button" class="cbai-act" onclick={() => (mode = 'ai')}>Regenerate with AI</button>
</div>
{/if}
</div>
<style>
.cbai-draft { max-inline-size: 30rem; background: #f4f4f4;
font: 400 .875rem/1.6 'IBM Plex Sans', sans-serif; }
.cbai-draft-head { display: flex; align-items: center; gap: .625rem; padding: .75rem 1rem;
border-block-end: 1px solid #e0e0e0; }
.cbai-draft-head b { font-weight: 600; }
.cbai-draft-head small { margin-inline-start: auto; font-size: .75rem; color: #525252; }
.cbai-inline { position: relative; display: inline-flex; }
.cbai-slug { display: inline-grid; place-items: center; inline-size: 1.5rem; block-size: 1.5rem; border: none;
border-radius: 50%; color: #fff; cursor: pointer; font: 600 .625rem/1 'IBM Plex Sans', sans-serif;
background: linear-gradient(90deg, #8a3ffc, #d02670, #1192e8); }
.cbai-pop { position: absolute; inset-block-start: calc(100% + 8px); inset-inline-end: 0; z-index: 7;
inline-size: 16rem; padding: 1rem; background: #f4f4f4; box-shadow: 0 2px 6px rgba(0, 0, 0, .25); }
.cbai-pop[data-open='false'] { display: none; }
.cbai-pop b { font-weight: 600; }
.cbai-pop div { display: flex; justify-content: space-between; gap: 1rem; padding-block: .375rem;
border-block-end: 1px solid #e0e0e0; font-size: .75rem; }
.cbai-pop dt { color: #525252; }
.cbai-pop dd { margin: 0; font-weight: 600; font-family: 'IBM Plex Mono', Menlo, monospace; }
.cbai-pop-foot { display: flex; gap: .5rem; padding-block-start: .625rem; border-block-end: none; }
.cbai-act { block-size: 2rem; padding-inline: .875rem; border: none; background: transparent;
color: #0f62fe; font: 400 .8125rem/1 'IBM Plex Sans', sans-serif; cursor: pointer; }
.cbai-draft-body { padding: 1rem; }
.cbai-draft-body[data-ai='true'] { border-inline-start: 3px solid #d02670; }
.cbai-draft-foot { display: flex; padding: .625rem 1rem; border-block-start: 1px solid #e0e0e0; }
</style>