Skip to Content
CodeUI

Text

@codeui/solid v0.3.0

Text set in the kit type scale, with tones and polymorphic headings.

When to use

Use Text for any interface text that needs a size, weight or color from the kit tokens: a panel title, a row description, a hint under a field, an error line. It renders a span by default and any element through as, so one component covers headings, paragraphs and labels.

When to choose another component

  • Use the label and description built into a field, such as label and description on TextField, instead of a Text next to the control. The field links them to the input for assistive technology.
  • Use Link for text that navigates. Inkstone keeps accent color for links and inline actions, and Text has no accent tone.
  • Use Badge for a one-word status with a fill, and Alert for a message that needs an icon and a surface.

Live demo

Export settings

Choose the format and scale for hello-world.ts.Saved 2 minutes ago
text/basic.tsx
import { Stack, Text } from "@codeui/solid";

export default function TextBasic() {
	return (
		<Stack gap="1">
			<Text as="h3" size="md" weight="semibold">
				Export settings
			</Text>
			<Text tone="muted">Choose the format and scale for hello-world.ts.</Text>
			<Text size="xs" tone="hint">
				Saved 2 minutes ago
			</Text>
		</Stack>
	);
}

Anatomy

Choose the format and scale for hello-world.ts.

Tap a part to outline it in the demo.

  1. 01Texttextclasses.root
ExportRendersclasses keydata-cuiRole
Textspan, or the element in asroottextNone

The root also renders these attributes, which the stylesheet reads:

AttributeValuesDefault
data-sizebadge, xs, caption, sm, md, lg, xl, 2xlsm
data-weightnormal, medium, semiboldnormal
data-tonedefault, muted, hint, label, danger, successdefault

Variants

Size

badgeExport settings
xsExport settings
captionExport settings
smExport settings
mdExport settings
lgExport settings
xlExport settings
2xlExport settings
text/size.tsx
import { Stack, Text, type TextVariants } from "@codeui/solid";
import { For } from "solid-js";

const sizes: NonNullable<TextVariants["size"]>[] = ["badge", "xs", "caption", "sm", "md", "lg", "xl", "2xl"];

export default function TextSize() {
	return (
		<Stack gap="2">
			<For each={sizes}>
				{size => (
					<Stack direction="row" gap="4" align="baseline">
						<Text size="xs" tone="hint" style={{ width: "4rem" }}>
							{size}
						</Text>
						<Text size={size}>Export settings</Text>
					</Stack>
				)}
			</For>
		</Stack>
	);
}

size takes a key of the --cui-font-size-* scale. The default is sm.

sizeTokenValueInkstone step
badge--cui-font-size-badge11pxMicro
xs--cui-font-size-xs12pxMeta
caption--cui-font-size-caption13pxBase
sm--cui-font-size-sm14pxLabel
md--cui-font-size-md16pxTitle
lg--cui-font-size-lg18pxDisplay
xl--cui-font-size-xl20pxDisplay
2xl--cui-font-size-2xl24pxDisplay

Inkstone uses Display sizes only for sheet titles and announcements. See Typography for the use of each step.

Weight

normalExport settings
mediumExport settings
semiboldExport settings
text/weight.tsx
import { Stack, Text, type TextVariants } from "@codeui/solid";
import { For } from "solid-js";

const weights: NonNullable<TextVariants["weight"]>[] = ["normal", "medium", "semibold"];

export default function TextWeight() {
	return (
		<Stack gap="2">
			<For each={weights}>
				{weight => (
					<Stack direction="row" gap="4" align="baseline">
						<Text size="xs" tone="hint" style={{ width: "5rem" }}>
							{weight}
						</Text>
						<Text weight={weight}>Export settings</Text>
					</Stack>
				)}
			</For>
		</Stack>
	);
}

weight takes normal (400), medium (500) or semibold (600). The default is normal. Inkstone reads them as "400 reads, 500 acts, 600 heads".

Tone

defaulthello-world.ts
mutedTypeScript · 42 lines
hintSaved 2 minutes ago
labelBackground
dangerThe export failed. Try a smaller scale.
successCopied to the clipboard
text/tone.tsx
import { Stack, Text, type TextVariants } from "@codeui/solid";
import { For } from "solid-js";

const tones: { tone: NonNullable<TextVariants["tone"]>; sample: string }[] = [
	{ tone: "default", sample: "hello-world.ts" },
	{ tone: "muted", sample: "TypeScript · 42 lines" },
	{ tone: "hint", sample: "Saved 2 minutes ago" },
	{ tone: "label", sample: "Background" },
	{ tone: "danger", sample: "The export failed. Try a smaller scale." },
	{ tone: "success", sample: "Copied to the clipboard" },
];

export default function TextTone() {
	return (
		<Stack gap="2">
			<For each={tones}>
				{item => (
					<Stack direction="row" gap="4" align="baseline">
						<Text size="xs" tone="hint" style={{ width: "4rem" }}>
							{item.tone}
						</Text>
						<Text tone={item.tone}>{item.sample}</Text>
					</Stack>
				)}
			</For>
		</Stack>
	);
}

tone picks a text color role. The default is default.

toneTokenUse
default--cui-text-defaultTitles, values the user set, the selected item
muted--cui-text-mutedDescriptions, summaries and metadata
hint--cui-text-hintHints and timestamps
label--cui-text-labelGroup labels over a set of controls
danger--cui-text-dangerError messages
success--cui-action-success-active mixed with --cui-text-panelConfirmation messages

Most interface text in Inkstone is secondary, so muted is the common tone for anything under a title. Hierarchy comes from tone first, then weight, then size.

Polymorphic element

Snippet library

Every snippet you save in CodeImage appears here.

text/as.tsx
import { Stack, Text } from "@codeui/solid";

export default function TextAs() {
	return (
		<Stack gap="1">
			<Text as="h2" size="lg" weight="semibold">
				Snippet library
			</Text>
			<Text as="p" tone="muted">
				Every snippet you save in CodeImage appears here.
			</Text>
			<Text as="label" for="snippet-name" size="xs" weight="semibold" tone="label">
				Snippet name
			</Text>
		</Stack>
	);
}

as renders a different element. The default span has no meaning, so set as to h1 through h6 for a heading, p for a paragraph or label for a form label. The size does not follow the element. An h2 renders at sm until you set size. Every other prop, such as for on a label, goes to that element.

Truncation

Pathsrc/components/editor/frame/export-settings-panel.tsx
text/truncate.tsx
import { Stack, Text } from "@codeui/solid";

export default function TextTruncate() {
	return (
		<Stack direction="row" gap="4" align="baseline" style={{ "max-width": "18rem" }}>
			<Text weight="medium" style={{ "flex-shrink": "0" }}>
				Path
			</Text>
			<Text
				tone="muted"
				style={{ overflow: "hidden", "text-overflow": "ellipsis", "white-space": "nowrap", "min-width": "0" }}
			>
				src/components/editor/frame/export-settings-panel.tsx
			</Text>
		</Stack>
	);
}

Text has no truncation prop. To truncate a value to one line, set overflow: hidden, text-overflow: ellipsis and white-space: nowrap in your own class, and min-width: 0 when the text sits in a flex row. Inkstone truncates values, never labels, and keeps the full text reachable. The full string stays in the DOM, so screen readers read all of it. Add a Tooltip on a focusable parent when sighted users need it too.

Ready API

Text

Text renders a span, or the element in as, with the kit type class and the data attributes listed in Anatomy.

Prop

Type

Text takes every prop of the element in as, so there is no inherited Kobalte table. The exported types are TextProps, TextVariants, TextClasses and TextPart.

Styled parts API

Import the parts from @codeui/solid/text/parts.

Root

Root is the same component as Text. @codeui/solid exports it as Text, and @codeui/solid/text/parts exports it as Root, with RootProps equal to TextProps. It wraps no Kobalte primitive.

Styles export

textStyles

Call textStyles.root() for the base class and set data-size, data-weight, and data-tone on custom markup. The Solid component defaults to sm, normal, and default.

@codeui/solid and @codeui/solid/text/parts both export textStyles, TextStyles and textParts. Prefer <Text as="…">. Call textStyles only on markup you cannot render through the component.

Accessibility

Text renders a span with no role. Its semantics come from the element in as. Pick the heading level from the document outline, not from the size you want, and set the size separately.

Color alone does not carry meaning. A danger line should say what failed in words, and an error tied to a field belongs in the field's errorMessage, which links it to the input.

SSR notes

Text renders completely on the server: the element, the class and the data attributes. It has no effects, IDs or portals.

Theming hooks

VariableUse
--cui-font-family-sansFont family
--cui-font-size-*Size, one per size key
--cui-font-weight-*Weight, one per weight key
--cui-font-line-height-normalLine height, 1.5 for every size
--cui-text-default, --cui-text-muted, --cui-text-hint, --cui-text-label, --cui-text-dangerTone colors
--cui-action-success-active, --cui-text-panelThe success tone, mixed 85% to 15%

The defaults are in Tokens and Typography and spacing.

Composition examples

A settings row pairs a medium title with a muted description inside a Stack:

Show line numbersAdds a gutter to the exported image.
stack/settings-row.tsx
import { Stack, Switch, Text } from "@codeui/solid";

export default function StackSettingsRow() {
	return (
		<Stack direction="row" gap="4" align="center" justify="between">
			<Stack gap="0.5">
				<Text weight="medium">Show line numbers</Text>
				<Text size="xs" tone="muted">
					Adds a gutter to the exported image.
				</Text>
			</Stack>
			<Switch aria-label="Show line numbers" defaultChecked />
		</Stack>
	);
}

For a full panel, see Build settings.

  • Stack places blocks of text. Text styles them.
  • Kbd shows a key inside running text.
  • Typography gives the Inkstone rules for each step of the scale.

On this page