SwapText
Text that changes with state in a place sized for its widest version, so nothing around it moves.
Activeproduction
function Basic() {
const [active, setActive] = useState(true);
return (
<div className="flex items-center gap-12 text-body">
<Switch size="sm" aria-label="Key active" checked={active} onCheckedChange={setActive} />
<span className="font-medium text-fg">
<SwapText reserve={["Active", "Paused"]} align="start">
{active ? "Active" : "Paused"}
</SwapText>
</span>
<span className="text-fg-secondary">production</span>
</div>
);
}import { SwapText } from "@logicplanes/kaeso-ui";Props
align"start" | "center" = centerAligns the shorter labels at the start or in the center of the reserved width.
childrenReactNodeWhat is shown now.
reserveReactNode[]Every text this place can show ("Copy page", "Copied"). The width fits the widest, so a state change never resizes the control.
wrapboolean = falseLets longer texts, such as a field's hint, wrap within their column; the height then fits the tallest, so nothing below moves.