SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

TagCloud

Tags in a wrapping row, each set larger the more posts carry it, in steps between the least and most used, built from parts.

View code
tsx
import { TagCloud } from "@sdxc/ui/blog";

let tags = [
	{ label: "accessibility", count: 3 },
	{ label: "backups", count: 2 },
	{ label: "caching", count: 14 },
	{ label: "css", count: 9 },
	{ label: "databases", count: 6 },
	{ label: "deploys", count: 4 },
	{ label: "logging", count: 7 },
	{ label: "queues", count: 5 },
	{ label: "security", count: 1 },
	{ label: "testing", count: 11 },
];

<TagCloud range={{ least: 1, most: 14 }}>
	{tags.map((tag) => (
		<TagCloud.Tag href={`/tags/${tag.label}`} count={tag.count}>
			{tag.label}
			<TagCloud.Count />
			<TagCloud.CountLabel> ({tag.count === 1 ? "1 post" : `${tag.count} posts`})</TagCloud.CountLabel>
		</TagCloud.Tag>
	))}
</TagCloud>

Installation

An ordinary dependency: install it, import the theme once, and import the component where it is used.

Terminal
npm add @sdxc/ui remix
typescript
import "@sdxc/ui/theme.css";

Usage

typescript
import { TagCloud } from "@sdxc/ui/blog";

Renders the cloud as a wrapping <ul> of its tags, sharing range, steps and scale so each TagCloud.Tag sizes itself. Recolour or turn the tags into chips through TagCloud.CustomProperties.

Composition

The parts the component publishes, each a static property of the host.

  • TagCloud
  • TagCloud.TagOne tag as a list item and link, carrying its weight step (1 to steps) in data-weight and a font size to match, semibold in the top steps; on the middle step when the cloud has no range or every count is equal.
  • TagCloud.CountThe tag's count as a small number beside its name, hidden from screen readers, which hear the words in TagCloud.CountLabel instead.
  • TagCloud.CountLabelThe count in words for screen readers only, such as "(12 posts)", so the size difference is never the only way to tell tags apart.

Props

Read from the component's own types, so every prop, every default and every allowed value is listed.

PropTypeDefaultRequiredDescription
rangeRange—NoThe least and most used tags' counts; without it every tag sits on the middle step.
stepsnumber—NoHow many sizes lie between the least- and most-used tag; a larger number approaches a continuous scale.
scalenumber—NoMultiplies every size, for a page where the cloud is the content.

Also accepts everything in ElementProps<"ul">.

TagCloud.Tag

TagCloud.Count

Also accepts everything in Omit<ElementProps<"span">, "children">.

TagCloud.CountLabel

Also accepts everything in ElementProps<"span">.

@sdxc/ui

Can’t find it? Contact us