@sereno-ds/ui 0.37.1 → 0.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
|
|
3
3
|
type TypographyVariant = 'display' | 'h1' | 'h2' | 'h3' | 'body' | 'bodySm' | 'label' | 'caption' | 'eyebrow';
|
|
4
|
-
type TypographyColor = 'primary' | 'secondary' | 'muted' | 'disabled' | 'inverse' | 'brand' | 'accent' | 'link' | 'error';
|
|
4
|
+
type TypographyColor = 'primary' | 'secondary' | 'muted' | 'disabled' | 'inverse' | 'brand' | 'accent' | 'link' | 'error' | 'success' | 'inherit';
|
|
5
5
|
interface TypographyProps extends React.HTMLAttributes<HTMLElement> {
|
|
6
6
|
variant?: TypographyVariant;
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* Overrides the variant's own default color token. `success` is the text green (a
|
|
9
|
+
* satisfied rule, a confirmed state). `inherit` is not a token: the text takes the color of
|
|
10
|
+
* its parent, for text on a colored strip or whose color is the parent's to set (so the
|
|
11
|
+
* contrast is then the parent's to keep).
|
|
12
|
+
*/
|
|
8
13
|
color?: TypographyColor;
|
|
9
14
|
/** Render as a different element than the variant's own default tag - e.g. an
|
|
10
15
|
* `h3`-styled label that should not enter the document's heading outline. */
|
package/dist/core/Typography.js
CHANGED
|
@@ -66,8 +66,12 @@ const COLOR_TOKEN = {
|
|
|
66
66
|
brand: "--text-brand",
|
|
67
67
|
accent: "--text-accent",
|
|
68
68
|
link: "--text-link",
|
|
69
|
-
error: "--interactive-error"
|
|
69
|
+
error: "--interactive-error",
|
|
70
|
+
success: "--status-success-fg"
|
|
70
71
|
};
|
|
72
|
+
function colorValue(color) {
|
|
73
|
+
return color === "inherit" ? "inherit" : "var(" + COLOR_TOKEN[color] + ")";
|
|
74
|
+
}
|
|
71
75
|
function Typography({ variant = "body", color, as, truncate, numeric, style, children, ...rest }) {
|
|
72
76
|
const v = VARIANTS[variant];
|
|
73
77
|
const Tag = as ?? v.as;
|
|
@@ -78,7 +82,7 @@ function Typography({ variant = "body", color, as, truncate, numeric, style, chi
|
|
|
78
82
|
style: sx({
|
|
79
83
|
margin: 0,
|
|
80
84
|
...v.style,
|
|
81
|
-
color:
|
|
85
|
+
color: colorValue(color ?? DEFAULT_COLOR[variant]),
|
|
82
86
|
// `overflow`/`textOverflow` are no-ops on a plain inline box (the
|
|
83
87
|
// default for the `span`-tagged variants) - `block` makes the
|
|
84
88
|
// element actually respect a constrained-width ancestor.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/Typography.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { sx } from '../_internal/style';\n\nexport type TypographyVariant = 'display' | 'h1' | 'h2' | 'h3' | 'body' | 'bodySm' | 'label' | 'caption' | 'eyebrow';\nexport type TypographyColor
|
|
1
|
+
{"version":3,"sources":["../../src/core/Typography.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { sx } from '../_internal/style';\n\nexport type TypographyVariant = 'display' | 'h1' | 'h2' | 'h3' | 'body' | 'bodySm' | 'label' | 'caption' | 'eyebrow';\nexport type TypographyColor =\n | 'primary'\n | 'secondary'\n | 'muted'\n | 'disabled'\n | 'inverse'\n | 'brand'\n | 'accent'\n | 'link'\n | 'error'\n | 'success'\n | 'inherit';\n\nexport interface TypographyProps extends React.HTMLAttributes<HTMLElement> {\n variant?: TypographyVariant;\n /**\n * Overrides the variant's own default color token. `success` is the text green (a\n * satisfied rule, a confirmed state). `inherit` is not a token: the text takes the color of\n * its parent, for text on a colored strip or whose color is the parent's to set (so the\n * contrast is then the parent's to keep).\n */\n color?: TypographyColor;\n /** Render as a different element than the variant's own default tag - e.g. an\n * `h3`-styled label that should not enter the document's heading outline. */\n as?: React.ElementType;\n /** Single-line ellipsis. Needs a width-constrained ancestor to actually clip. */\n truncate?: boolean;\n /** Tabular (fixed-width) figures - digits line up column-to-column instead of\n * each taking their own width. For a value that updates or stacks with others\n * at the same position: countdowns, ticket/queue numbers, times, prices. */\n numeric?: boolean;\n children?: React.ReactNode;\n}\n\nconst VARIANTS: Record<TypographyVariant, { as: React.ElementType; style: React.CSSProperties }> = {\n display: {\n as: 'h1',\n style: { fontFamily: 'var(--font-display)', fontSize: 'var(--text-5xl)', fontWeight: 'var(--weight-extrabold)', letterSpacing: 'var(--tracking-tight)', lineHeight: 'var(--leading-tight)' },\n },\n h1: {\n as: 'h1',\n style: { fontFamily: 'var(--font-display)', fontSize: 'var(--text-3xl)', fontWeight: 'var(--weight-bold)', letterSpacing: 'var(--tracking-tight)', lineHeight: 'var(--leading-tight)' },\n },\n h2: {\n as: 'h2',\n style: { fontFamily: 'var(--font-display)', fontSize: 'var(--text-xl)', fontWeight: 'var(--weight-bold)', letterSpacing: 'var(--tracking-snug)', lineHeight: 'var(--leading-tight)' },\n },\n h3: {\n as: 'h3',\n style: { fontFamily: 'var(--font-display)', fontSize: 'var(--text-md)', fontWeight: 'var(--weight-bold)', letterSpacing: 'var(--tracking-snug)', lineHeight: 'var(--leading-snug)' },\n },\n body: {\n as: 'p',\n style: { fontFamily: 'var(--font-body)', fontSize: 'var(--text-base)', fontWeight: 'var(--weight-regular)', lineHeight: 'var(--leading-normal)' },\n },\n bodySm: {\n as: 'p',\n style: { fontFamily: 'var(--font-body)', fontSize: 'var(--text-sm)', fontWeight: 'var(--weight-regular)', lineHeight: 'var(--leading-normal)' },\n },\n label: {\n as: 'span',\n style: { fontFamily: 'var(--font-body)', fontSize: 'var(--text-sm)', fontWeight: 'var(--weight-semibold)', letterSpacing: 'var(--tracking-snug)', lineHeight: 'var(--leading-snug)' },\n },\n caption: {\n as: 'span',\n style: { fontFamily: 'var(--font-body)', fontSize: 'var(--text-xs)', fontWeight: 'var(--weight-regular)', lineHeight: 'var(--leading-normal)' },\n },\n eyebrow: {\n as: 'span',\n style: {\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-2xs)',\n fontWeight: 'var(--weight-semibold)',\n letterSpacing: 'var(--tracking-caps)',\n textTransform: 'uppercase',\n lineHeight: 'var(--leading-normal)',\n },\n },\n};\n\n// Each variant's own sensible default - overridable via the `color` prop.\nconst DEFAULT_COLOR: Record<TypographyVariant, TypographyColor> = {\n display: 'primary',\n h1: 'primary',\n h2: 'primary',\n h3: 'primary',\n body: 'primary',\n bodySm: 'secondary',\n label: 'primary',\n caption: 'muted',\n eyebrow: 'muted',\n};\n\n// `inherit` is the one color that is not a token, so it is not in this map (see `colorValue`).\nconst COLOR_TOKEN: Record<Exclude<TypographyColor, 'inherit'>, string> = {\n primary: '--text-primary',\n secondary: '--text-secondary',\n muted: '--text-muted',\n disabled: '--text-disabled',\n inverse: '--text-inverse',\n brand: '--text-brand',\n accent: '--text-accent',\n link: '--text-link',\n error: '--interactive-error',\n success: '--status-success-fg',\n};\n\nfunction colorValue(color: TypographyColor): string {\n return color === 'inherit' ? 'inherit' : 'var(' + COLOR_TOKEN[color] + ')';\n}\n\n/**\n * Text primitive - one place for the type-scale/font-family/weight combos\n * every screen otherwise reconstructs by hand (see `/design-system/tokens`\n * for the raw scale this wraps). `variant` picks the look *and* the default\n * semantic tag; `as` overrides just the tag, `color` just the color, so a\n * heading-styled label that isn't really a document heading, or a caption in\n * the brand color, are one-prop changes, not a new style object.\n */\nexport function Typography({ variant = 'body', color, as, truncate, numeric, style, children, ...rest }: TypographyProps) {\n const v = VARIANTS[variant];\n const Tag = as ?? v.as;\n return (\n <Tag\n {...rest}\n style={sx({\n margin: 0,\n ...v.style,\n color: colorValue(color ?? DEFAULT_COLOR[variant]),\n // `overflow`/`textOverflow` are no-ops on a plain inline box (the\n // default for the `span`-tagged variants) - `block` makes the\n // element actually respect a constrained-width ancestor.\n ...(truncate ? { display: 'block', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } : null),\n ...(numeric ? { fontVariantNumeric: 'tabular-nums' } : null),\n ...style,\n })}\n >\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