CwBadge

Wrap any content and anchor a badge at top-left, top-right, bottom-left, or bottom-right.

Top right 7
Top left 12
Bottom right 3
Bottom left (dot)
CwBadge example Copy code
<CwBadge value={7} position="top_right">
	<button type="button" class="demo-target">Refresh</button>
</CwBadge>

<CwBadge dot tone="success" position="bottom_left">
	<button type="button" class="demo-target">Live</button>
</CwBadge>
Documentation Upgrade

Start here

CwBadge decorates existing content. The wrapped content is still the thing users interact with; the badge only adds count, dot, or custom status UI around it.

How to think about it

  1. Wrap the real target Place the button, icon, or avatar you already have inside `CwBadge` so the badge stays anchored to it.
  2. Pick one display mode Use `value` for counts, `dot` for a simple indicator, or the `badge` snippet when you need custom markup.
  3. Clamp noisy counts Set `max` so large numbers stay compact, for example showing `99+` instead of overflowing.

Props and callbacks

APITypeDetails
position

Default: top_right

'top_left' | 'top_right' | 'bottom_left' | 'bottom_right'Corner where the badge is anchored.
tone

Default: danger

CwToneColor theme applied to the badge.
size

Default: md

'sm' | 'md' | 'lg'Badge size preset.
value
string | numberText or numeric count displayed inside the badge.
max

Default: 99

numberUpper cap before a numeric value is rendered as `max+`.
dot

Default: false

booleanRenders a dot-only badge with no text.
hidden

Default: false

booleanKeeps the wrapped content visible while hiding the badge.
children Required
SnippetThe wrapped content the badge is attached to.
badge
SnippetOptional custom badge content. Overrides normal text rendering.

Copy-paste examples

These snippets intentionally show the full public API surface the live demo relies on.

Count badge with cap

Good for notifications, queue depth, or unread counts.

Count badge with cap Copy code
<CwBadge value={147} max={99} tone="danger" position="top_right">
	<button type="button">Alerts</button>
</CwBadge>
Dot and custom badge content

Use the `badge` snippet when you need something richer than a number.

Dot and custom badge content Copy code
<script lang="ts">
	let online = $state(true);
</script>

<CwBadge dot tone="success" hidden={!online}>
	<button type="button">Gateway</button>
</CwBadge>

<CwBadge position="bottom_left" tone="info">
	{#snippet badge()}
		<span style="padding-inline:0.25rem">NEW</span>
	{/snippet}
	<button type="button">Firmware</button>
</CwBadge>