@carbonid1/design-system 5.3.0 → 5.4.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.
@@ -12,5 +12,5 @@ declare const textVariants: (props?: ({
12
12
  weight?: "bold" | "regular" | "medium" | "semibold" | null | undefined;
13
13
  align?: "end" | "center" | "start" | null | undefined;
14
14
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
15
- declare const Text: <E extends ElementType = "p">({ as, variant, color, font, weight, align, numeric, truncate, className, ...props }: TextProps<E>) => import("react/jsx-runtime").JSX.Element;
15
+ declare const Text: <E extends ElementType = "p">({ as, variant, color, font, weight, align, numeric, truncate, lines, className, style, title, children, ...props }: TextProps<E>) => import("react/jsx-runtime").JSX.Element;
16
16
  export { Text, textVariants };
package/dist/Text/Text.js CHANGED
@@ -53,9 +53,42 @@ const textVariants = cva('', {
53
53
  });
54
54
  /** Variants that read as secondary chrome and default to the muted token. */
55
55
  const MUTED_VARIANTS = new Set(['caption', 'overline']);
56
- const Text = ({ as, variant = 'body', color, font, weight, align, numeric, truncate, className, ...props }) => {
56
+ /**
57
+ * Literal clamp classes (not a template literal) so a consumer's `@source` scan
58
+ * over the published `dist` can see them. Line counts outside this range fall
59
+ * back to an inline `-webkit-line-clamp` style instead.
60
+ */
61
+ const LINE_CLAMP = {
62
+ 1: 'line-clamp-1',
63
+ 2: 'line-clamp-2',
64
+ 3: 'line-clamp-3',
65
+ 4: 'line-clamp-4',
66
+ 5: 'line-clamp-5',
67
+ 6: 'line-clamp-6',
68
+ };
69
+ const Text = ({ as, variant = 'body', color, font, weight, align, numeric, truncate, lines, className, style, title, children, ...props }) => {
57
70
  const Component = (as ?? 'p');
58
71
  const resolvedColor = color ?? (variant && MUTED_VARIANTS.has(variant) ? 'muted' : 'default');
59
- return (_jsx(Component, { className: cn(textVariants({ variant, color: resolvedColor, font, weight, align }), numeric && 'tabular-nums', truncate && 'truncate', className), ...props }));
72
+ // Only positive integers clamp; degenerate counts (0, negative, fractional,
73
+ // NaN) fall back to no clamp rather than emitting an invalid -webkit-line-clamp.
74
+ const clampLines = typeof lines === 'number' && Number.isInteger(lines) && lines > 0 ? lines : undefined;
75
+ // Multi-line clamp wins over single-line truncate. A count outside the mapped
76
+ // range is applied via inline style rather than a utility class.
77
+ const clampClass = clampLines != null ? LINE_CLAMP[clampLines] : truncate ? 'truncate' : undefined;
78
+ const clampStyle = clampLines != null && LINE_CLAMP[clampLines] === undefined
79
+ ? {
80
+ display: '-webkit-box',
81
+ WebkitBoxOrient: 'vertical',
82
+ WebkitLineClamp: clampLines,
83
+ overflow: 'hidden',
84
+ }
85
+ : undefined;
86
+ // When clipping a string/number child with no explicit title, surface the full
87
+ // text as a native tooltip so it stays readable on hover. Not overflow-aware
88
+ // yet (it shows even when the text fits) — a styled, measured reveal is a follow-up.
89
+ const isClipping = truncate || clampLines != null;
90
+ const childIsText = typeof children === 'string' || typeof children === 'number';
91
+ const resolvedTitle = title ?? (isClipping && childIsText ? String(children) : undefined);
92
+ return (_jsx(Component, { className: cn(textVariants({ variant, color: resolvedColor, font, weight, align }), numeric && 'tabular-nums', clampClass, className), title: resolvedTitle, style: clampStyle ? { ...clampStyle, ...style } : style, ...props, children: children }));
60
93
  };
61
94
  export { Text, textVariants };
@@ -6,8 +6,10 @@ type TextOwnProps<E extends ElementType = 'p'> = VariantProps<typeof textVariant
6
6
  as?: E;
7
7
  /** Tabular (fixed-width) digits for numeric columns, timers, and metrics. */
8
8
  numeric?: boolean;
9
- /** Clamp to a single line with an ellipsis (Tailwind's `truncate`). */
9
+ /** Clamp to a single line with an ellipsis (Tailwind's `truncate`). When the child is a string or number, the full text is exposed via the native `title` (mouse-only, and not yet overflow-aware — it shows even when the text fits). */
10
10
  truncate?: boolean;
11
+ /** Clamp to N lines with an ellipsis (uses `-webkit-box`, so prefer `truncate` for single-line inline text). Positive integers only; takes precedence over `truncate`. Like it, a string/number child is surfaced via the native `title`. Idiomatic range 1–6. */
12
+ lines?: number;
11
13
  className?: string;
12
14
  };
13
15
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carbonid1/design-system",
3
- "version": "5.3.0",
3
+ "version": "5.4.0",
4
4
  "description": "Shared React UI primitives + design tokens (themes, postcss config)",
5
5
  "repository": {
6
6
  "type": "git",