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
labelanddescriptiononTextField, instead of aTextnext to the control. The field links them to the input for assistive technology. - Use
Linkfor text that navigates. Inkstone keeps accent color for links and inline actions, andTexthas no accent tone. - Use
Badgefor a one-word status with a fill, andAlertfor a message that needs an icon and a surface.
Live demo
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
Tap a part to outline it in the demo.
- 01Text
textclasses.root
| Export | Renders | classes key | data-cui | Role |
|---|---|---|---|---|
Text | span, or the element in as | root | text | None |
The root also renders these attributes, which the stylesheet reads:
| Attribute | Values | Default |
|---|---|---|
data-size | badge, xs, caption, sm, md, lg, xl, 2xl | sm |
data-weight | normal, medium, semibold | normal |
data-tone | default, muted, hint, label, danger, success | default |
Variants
Size
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.
size | Token | Value | Inkstone step |
|---|---|---|---|
badge | --cui-font-size-badge | 11px | Micro |
xs | --cui-font-size-xs | 12px | Meta |
caption | --cui-font-size-caption | 13px | Base |
sm | --cui-font-size-sm | 14px | Label |
md | --cui-font-size-md | 16px | Title |
lg | --cui-font-size-lg | 18px | Display |
xl | --cui-font-size-xl | 20px | Display |
2xl | --cui-font-size-2xl | 24px | Display |
Inkstone uses Display sizes only for sheet titles and announcements. See Typography for the use of each step.
Weight
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
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.
tone | Token | Use |
|---|---|---|
default | --cui-text-default | Titles, values the user set, the selected item |
muted | --cui-text-muted | Descriptions, summaries and metadata |
hint | --cui-text-hint | Hints and timestamps |
label | --cui-text-label | Group labels over a set of controls |
danger | --cui-text-danger | Error messages |
success | --cui-action-success-active mixed with --cui-text-panel | Confirmation 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
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
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
| Variable | Use |
|---|---|
--cui-font-family-sans | Font family |
--cui-font-size-* | Size, one per size key |
--cui-font-weight-* | Weight, one per weight key |
--cui-font-line-height-normal | Line height, 1.5 for every size |
--cui-text-default, --cui-text-muted, --cui-text-hint, --cui-text-label, --cui-text-danger | Tone colors |
--cui-action-success-active, --cui-text-panel | The 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:
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.
Related
Stackplaces blocks of text.Textstyles them.Kbdshows a key inside running text.- Typography gives the Inkstone rules for each step of the scale.