import * as stylex from "@stylexjs/stylex";
import { createComponent } from "#lib/ui-sdk/create-component.tsx";
import { defineRecipe } from "#lib/recipe-props.ts";
import { colorPalette } from "@stylexblocks/ui/color-palette.stylex.ts";
import { semanticColors } from "@stylexblocks/ui/semantic-tokens/colors.stylex.ts";
import { fontSizes } from "@stylexblocks/ui/tokens/font-sizes.stylex.ts";
import { fontWeights } from "@stylexblocks/ui/tokens/font-weights.stylex.ts";
import { fonts } from "@stylexblocks/ui/tokens/fonts.stylex.ts";
import { letterSpacings } from "@stylexblocks/ui/tokens/letter-spacings.stylex.ts";
import { lineHeights } from "@stylexblocks/ui/tokens/line-heights.stylex.ts";
const textStyles = stylex.create({
base: {
fontFamily: fonts.body,
marginTop: 0,
marginBottom: 0,
},
});
const textVariants = stylex.create({
body: {
color: semanticColors.fg,
},
muted: {
color: semanticColors.fgMuted,
},
subtle: {
color: semanticColors.fgSubtle,
},
caption: {
color: semanticColors.fgMuted,
fontSize: fontSizes.xs,
lineHeight: lineHeights.xs,
},
label: {
color: semanticColors.fg,
fontWeight: fontWeights.medium,
},
overline: {
color: semanticColors.fgMuted,
fontSize: fontSizes.xs,
lineHeight: lineHeights.xs,
fontWeight: fontWeights.semibold,
letterSpacing: letterSpacings.wider,
textTransform: "uppercase",
},
mono: {
fontFamily: fonts.mono,
color: semanticColors.fg,
},
});
const textSizes = stylex.create({
"2xs": { fontSize: fontSizes._2xs, lineHeight: lineHeights._2xs },
xs: { fontSize: fontSizes.xs, lineHeight: lineHeights.xs },
sm: { fontSize: fontSizes.sm, lineHeight: lineHeights.sm },
md: { fontSize: fontSizes.md, lineHeight: lineHeights.md },
lg: { fontSize: fontSizes.lg, lineHeight: lineHeights.lg },
xl: { fontSize: fontSizes.xl, lineHeight: lineHeights.xl },
"2xl": { fontSize: fontSizes._2xl, lineHeight: lineHeights._2xl },
});
const textTones = stylex.create({
inherit: {},
default: { color: semanticColors.fg },
muted: { color: semanticColors.fgMuted },
subtle: { color: semanticColors.fgSubtle },
accent: { color: colorPalette.fg },
success: { color: semanticColors.fgSuccess },
warning: { color: semanticColors.fgWarning },
error: { color: semanticColors.fgError },
info: { color: semanticColors.fgInfo },
});
const textWeights = stylex.create({
inherit: {},
normal: { fontWeight: fontWeights.normal },
medium: { fontWeight: fontWeights.medium },
semibold: { fontWeight: fontWeights.semibold },
bold: { fontWeight: fontWeights.bold },
});
const textAligns = stylex.create({
start: { textAlign: "start" },
center: { textAlign: "center" },
end: { textAlign: "end" },
});
const textTruncate = stylex.create({
false: {},
true: {
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
},
});
const textTabular = stylex.create({
false: {},
true: {
fontVariantNumeric: "tabular-nums",
},
});
const textRecipe = defineRecipe({
styles: textStyles,
axes: {
size: textSizes,
variant: textVariants,
tone: textTones,
weight: textWeights,
align: textAligns,
truncate: textTruncate,
tabular: textTabular,
},
defaultVariants: {
size: "sm",
variant: "body",
tone: "inherit",
weight: "inherit",
align: "start",
truncate: "false",
tabular: "false",
},
});
/**
* Text — typographic primitive for body copy, muted descriptions, labels,
* captions, overlines, tabular numbers, and truncated single-line text.
* Composition via `render`.
*/
export const Text = createComponent("p", textRecipe, "Text");
export type TextProps = React.ComponentProps<typeof Text>;