@spark-web/text 5.2.0 → 5.2.1

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @spark-web/text
2
2
 
3
+ ## 5.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#685](https://github.com/brighte-labs/spark-web/pull/685)
8
+ [`ffbfa06`](https://github.com/brighte-labs/spark-web/commit/ffbfa066a4b2f72a838e68b49dd2c63ac44621a1)
9
+ Thanks [@michtntbrighte](https://github.com/michtntbrighte)! - : add truncate
10
+ the text with an ellipsis by number of lines
11
+
3
12
  ## 5.2.0
4
13
 
5
14
  ### Minor Changes
@@ -2,10 +2,10 @@
2
2
  export declare const TextContext: import("react").Context<{
3
3
  size: import("@spark-web/theme/src/themes/_types/typography").TypographySizing;
4
4
  tone: string | number;
5
- weight: "bold" | "medium" | "light" | "thin" | "black" | "extralight" | "regular" | "semibold" | "extrabold" | undefined;
5
+ weight: "medium" | "light" | "thin" | "extralight" | "regular" | "semibold" | "bold" | "extrabold" | "black" | undefined;
6
6
  } | undefined>;
7
7
  export declare function useTextContext(): {
8
8
  size: import("@spark-web/theme/src/themes/_types/typography").TypographySizing;
9
9
  tone: string | number;
10
- weight: "bold" | "medium" | "light" | "thin" | "black" | "extralight" | "regular" | "semibold" | "extrabold" | undefined;
10
+ weight: "medium" | "light" | "thin" | "extralight" | "regular" | "semibold" | "bold" | "extrabold" | "black" | undefined;
11
11
  } | undefined;
@@ -11,6 +11,6 @@ export declare function DefaultTextPropsProvider({ children, size, tone, weight,
11
11
  export declare const useDefaultTextProps: ({ size: sizeProp, tone: toneProp, weight: weightProp, }: DefaultTextProps) => {
12
12
  size: import("@spark-web/theme/src/themes/_types/typography").TypographySizing;
13
13
  tone: string | number;
14
- weight: "bold" | "medium" | "light" | "thin" | "black" | "extralight" | "regular" | "semibold" | "extrabold" | undefined;
14
+ weight: "medium" | "light" | "thin" | "extralight" | "regular" | "semibold" | "bold" | "extrabold" | "black" | undefined;
15
15
  };
16
16
  export {};
@@ -3,6 +3,7 @@ export { DefaultTextPropsProvider, useDefaultTextProps, } from "./default-text-p
3
3
  export { Strong } from "./strong.js";
4
4
  export { Text } from "./text.js";
5
5
  export { useForegroundTone } from "./use-foreground-tone.js";
6
+ export { useNumberOfLines } from "./use-number-of-lines.js";
6
7
  export { useOverflowStrategy } from "./use-overflow-strategy.js";
7
8
  export { createTextStyles, useText } from "./use-text.js";
8
9
  export type { StrongProps } from "./strong.js";
@@ -31,9 +31,12 @@ export declare type TextProps = Partial<UseTextProps> & {
31
31
  tabularNumbers?: boolean;
32
32
  /** Transform the text casing. */
33
33
  transform?: CSSProperties['textTransform'];
34
+ /** Truncate the text with an ellipsis after computing the text layout, including line wrapping,
35
+ * such that the total number of lines does not exceed this number. */
36
+ numberOfLines?: number;
34
37
  } & (InlineProps | BlockProps);
35
38
  export declare const Text: <Comp extends import("react").ElementType<any, keyof import("react").JSX.IntrinsicElements> = "div">(props: {
36
39
  as?: Comp | undefined;
37
- ref?: import("react").Ref<Comp extends "symbol" | "svg" | "animate" | "animateMotion" | "animateTransform" | "circle" | "clipPath" | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "filter" | "foreignObject" | "g" | "image" | "line" | "linearGradient" | "marker" | "mask" | "metadata" | "mpath" | "path" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "set" | "stop" | "switch" | "text" | "textPath" | "tspan" | "use" | "view" | keyof HTMLElementTagNameMap ? (HTMLElementTagNameMap & Pick<SVGElementTagNameMap, "symbol" | "svg" | "animate" | "animateMotion" | "animateTransform" | "circle" | "clipPath" | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "filter" | "foreignObject" | "g" | "image" | "line" | "linearGradient" | "marker" | "mask" | "metadata" | "mpath" | "path" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "set" | "stop" | "switch" | "text" | "textPath" | "tspan" | "use" | "view">)[Comp] : Comp extends new (...args: any) => any ? InstanceType<Comp> : undefined> | undefined;
40
+ ref?: import("react").Ref<Comp extends "symbol" | "clipPath" | "filter" | "mask" | "marker" | "svg" | "animate" | "animateMotion" | "animateTransform" | "circle" | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "foreignObject" | "g" | "image" | "line" | "linearGradient" | "metadata" | "mpath" | "path" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "set" | "stop" | "switch" | "text" | "textPath" | "tspan" | "use" | "view" | keyof HTMLElementTagNameMap ? (HTMLElementTagNameMap & Pick<SVGElementTagNameMap, "symbol" | "clipPath" | "filter" | "mask" | "marker" | "svg" | "animate" | "animateMotion" | "animateTransform" | "circle" | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "foreignObject" | "g" | "image" | "line" | "linearGradient" | "metadata" | "mpath" | "path" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "set" | "stop" | "switch" | "text" | "textPath" | "tspan" | "use" | "view">)[Comp] : Comp extends new (...args: any) => any ? InstanceType<Comp> : undefined> | undefined;
38
41
  } & Omit<import("react").PropsWithoutRef<import("react").ComponentProps<Comp>>, "as"> & TextProps) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
39
42
  export {};
@@ -0,0 +1,2 @@
1
+ import type { CSSProperties } from 'react';
2
+ export declare const useNumberOfLines: (numberOfLines?: number) => CSSProperties;
@@ -66,6 +66,23 @@ var Strong = function Strong(_ref) {
66
66
  });
67
67
  };
68
68
 
69
+ var useNumberOfLines = function useNumberOfLines(numberOfLines) {
70
+ if (!numberOfLines) {
71
+ return {};
72
+ }
73
+ return {
74
+ overflow: 'hidden',
75
+ display: '-webkit-box',
76
+ WebkitLineClamp: numberOfLines,
77
+ lineClamp: numberOfLines,
78
+ WebkitBoxOrient: 'vertical',
79
+ textOverflow: 'ellipsis',
80
+ overflowWrap: 'break-word',
81
+ wordBreak: 'break-word',
82
+ wordWrap: 'break-word'
83
+ };
84
+ };
85
+
69
86
  var strategyMap = {
70
87
  truncate: {
71
88
  display: 'block',
@@ -171,7 +188,7 @@ function createTextStyles(_ref2) {
171
188
  }, leadingTrim);
172
189
  }
173
190
 
174
- var _excluded = ["as", "children", "data", "id", "align", "baseline", "css", "inline", "overflowStrategy", "size", "tabularNumbers", "tone", "transform", "weight"];
191
+ var _excluded = ["as", "children", "data", "id", "align", "baseline", "css", "inline", "overflowStrategy", "size", "tabularNumbers", "tone", "transform", "weight", "numberOfLines"];
175
192
  var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
176
193
  var as = _ref.as,
177
194
  children = _ref.children,
@@ -187,6 +204,7 @@ var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
187
204
  toneProp = _ref.tone,
188
205
  transform = _ref.transform,
189
206
  weightProp = _ref.weight,
207
+ numberOfLines = _ref.numberOfLines,
190
208
  consumerProps = _objectWithoutProperties(_ref, _excluded);
191
209
  var overflowStyles = useOverflowStrategy(overflowStrategy);
192
210
  var textContext = useTextContext();
@@ -205,6 +223,7 @@ var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
205
223
  tone: tone,
206
224
  weight: weight
207
225
  });
226
+ var numberOfLinesStyle = useNumberOfLines(numberOfLines);
208
227
  var styles = [textStyles, {
209
228
  display: inline ? 'inline' : 'block',
210
229
  fontVariantNumeric: tabularNumbers ? 'tabular-nums' : undefined,
@@ -225,12 +244,21 @@ var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
225
244
  }
226
245
 
227
246
  // prepare block variant
228
- var content = overflowStrategy ?
229
- // eslint-disable-next-line react/no-unknown-property
230
- jsxRuntime.jsx("span", {
231
- css: react$1.css(overflowStyles),
232
- children: children
233
- }) : children;
247
+ var content = function content() {
248
+ if (overflowStrategy) {
249
+ return jsxRuntime.jsx("span", {
250
+ css: react$1.css(overflowStyles),
251
+ children: children
252
+ });
253
+ }
254
+ if (numberOfLines) {
255
+ return jsxRuntime.jsx("span", {
256
+ style: numberOfLinesStyle,
257
+ children: children
258
+ });
259
+ }
260
+ return children;
261
+ };
234
262
  var textContextValue = react.useMemo(function () {
235
263
  return {
236
264
  size: size,
@@ -246,7 +274,7 @@ var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
246
274
  ref: forwardedRef,
247
275
  id: id,
248
276
  css: react$1.css(styles, cssProps),
249
- children: content
277
+ children: content()
250
278
  }))
251
279
  });
252
280
  });
@@ -257,6 +285,7 @@ exports.Text = Text;
257
285
  exports.createTextStyles = createTextStyles;
258
286
  exports.useDefaultTextProps = useDefaultTextProps;
259
287
  exports.useForegroundTone = useForegroundTone;
288
+ exports.useNumberOfLines = useNumberOfLines;
260
289
  exports.useOverflowStrategy = useOverflowStrategy;
261
290
  exports.useText = useText;
262
291
  exports.useTextContext = useTextContext;
@@ -66,6 +66,23 @@ var Strong = function Strong(_ref) {
66
66
  });
67
67
  };
68
68
 
69
+ var useNumberOfLines = function useNumberOfLines(numberOfLines) {
70
+ if (!numberOfLines) {
71
+ return {};
72
+ }
73
+ return {
74
+ overflow: 'hidden',
75
+ display: '-webkit-box',
76
+ WebkitLineClamp: numberOfLines,
77
+ lineClamp: numberOfLines,
78
+ WebkitBoxOrient: 'vertical',
79
+ textOverflow: 'ellipsis',
80
+ overflowWrap: 'break-word',
81
+ wordBreak: 'break-word',
82
+ wordWrap: 'break-word'
83
+ };
84
+ };
85
+
69
86
  var strategyMap = {
70
87
  truncate: {
71
88
  display: 'block',
@@ -171,7 +188,7 @@ function createTextStyles(_ref2) {
171
188
  }, leadingTrim);
172
189
  }
173
190
 
174
- var _excluded = ["as", "children", "data", "id", "align", "baseline", "css", "inline", "overflowStrategy", "size", "tabularNumbers", "tone", "transform", "weight"];
191
+ var _excluded = ["as", "children", "data", "id", "align", "baseline", "css", "inline", "overflowStrategy", "size", "tabularNumbers", "tone", "transform", "weight", "numberOfLines"];
175
192
  var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
176
193
  var as = _ref.as,
177
194
  children = _ref.children,
@@ -187,6 +204,7 @@ var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
187
204
  toneProp = _ref.tone,
188
205
  transform = _ref.transform,
189
206
  weightProp = _ref.weight,
207
+ numberOfLines = _ref.numberOfLines,
190
208
  consumerProps = _objectWithoutProperties(_ref, _excluded);
191
209
  var overflowStyles = useOverflowStrategy(overflowStrategy);
192
210
  var textContext = useTextContext();
@@ -205,6 +223,7 @@ var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
205
223
  tone: tone,
206
224
  weight: weight
207
225
  });
226
+ var numberOfLinesStyle = useNumberOfLines(numberOfLines);
208
227
  var styles = [textStyles, {
209
228
  display: inline ? 'inline' : 'block',
210
229
  fontVariantNumeric: tabularNumbers ? 'tabular-nums' : undefined,
@@ -225,12 +244,21 @@ var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
225
244
  }
226
245
 
227
246
  // prepare block variant
228
- var content = overflowStrategy ?
229
- // eslint-disable-next-line react/no-unknown-property
230
- jsxRuntime.jsx("span", {
231
- css: react$1.css(overflowStyles),
232
- children: children
233
- }) : children;
247
+ var content = function content() {
248
+ if (overflowStrategy) {
249
+ return jsxRuntime.jsx("span", {
250
+ css: react$1.css(overflowStyles),
251
+ children: children
252
+ });
253
+ }
254
+ if (numberOfLines) {
255
+ return jsxRuntime.jsx("span", {
256
+ style: numberOfLinesStyle,
257
+ children: children
258
+ });
259
+ }
260
+ return children;
261
+ };
234
262
  var textContextValue = react.useMemo(function () {
235
263
  return {
236
264
  size: size,
@@ -246,7 +274,7 @@ var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
246
274
  ref: forwardedRef,
247
275
  id: id,
248
276
  css: react$1.css(styles, cssProps),
249
- children: content
277
+ children: content()
250
278
  }))
251
279
  });
252
280
  });
@@ -257,6 +285,7 @@ exports.Text = Text;
257
285
  exports.createTextStyles = createTextStyles;
258
286
  exports.useDefaultTextProps = useDefaultTextProps;
259
287
  exports.useForegroundTone = useForegroundTone;
288
+ exports.useNumberOfLines = useNumberOfLines;
260
289
  exports.useOverflowStrategy = useOverflowStrategy;
261
290
  exports.useText = useText;
262
291
  exports.useTextContext = useTextContext;
@@ -62,6 +62,23 @@ var Strong = function Strong(_ref) {
62
62
  });
63
63
  };
64
64
 
65
+ var useNumberOfLines = function useNumberOfLines(numberOfLines) {
66
+ if (!numberOfLines) {
67
+ return {};
68
+ }
69
+ return {
70
+ overflow: 'hidden',
71
+ display: '-webkit-box',
72
+ WebkitLineClamp: numberOfLines,
73
+ lineClamp: numberOfLines,
74
+ WebkitBoxOrient: 'vertical',
75
+ textOverflow: 'ellipsis',
76
+ overflowWrap: 'break-word',
77
+ wordBreak: 'break-word',
78
+ wordWrap: 'break-word'
79
+ };
80
+ };
81
+
65
82
  var strategyMap = {
66
83
  truncate: {
67
84
  display: 'block',
@@ -167,7 +184,7 @@ function createTextStyles(_ref2) {
167
184
  }, leadingTrim);
168
185
  }
169
186
 
170
- var _excluded = ["as", "children", "data", "id", "align", "baseline", "css", "inline", "overflowStrategy", "size", "tabularNumbers", "tone", "transform", "weight"];
187
+ var _excluded = ["as", "children", "data", "id", "align", "baseline", "css", "inline", "overflowStrategy", "size", "tabularNumbers", "tone", "transform", "weight", "numberOfLines"];
171
188
  var Text = forwardRefWithAs(function (_ref, forwardedRef) {
172
189
  var as = _ref.as,
173
190
  children = _ref.children,
@@ -183,6 +200,7 @@ var Text = forwardRefWithAs(function (_ref, forwardedRef) {
183
200
  toneProp = _ref.tone,
184
201
  transform = _ref.transform,
185
202
  weightProp = _ref.weight,
203
+ numberOfLines = _ref.numberOfLines,
186
204
  consumerProps = _objectWithoutProperties(_ref, _excluded);
187
205
  var overflowStyles = useOverflowStrategy(overflowStrategy);
188
206
  var textContext = useTextContext();
@@ -201,6 +219,7 @@ var Text = forwardRefWithAs(function (_ref, forwardedRef) {
201
219
  tone: tone,
202
220
  weight: weight
203
221
  });
222
+ var numberOfLinesStyle = useNumberOfLines(numberOfLines);
204
223
  var styles = [textStyles, {
205
224
  display: inline ? 'inline' : 'block',
206
225
  fontVariantNumeric: tabularNumbers ? 'tabular-nums' : undefined,
@@ -221,12 +240,21 @@ var Text = forwardRefWithAs(function (_ref, forwardedRef) {
221
240
  }
222
241
 
223
242
  // prepare block variant
224
- var content = overflowStrategy ?
225
- // eslint-disable-next-line react/no-unknown-property
226
- jsx("span", {
227
- css: css(overflowStyles),
228
- children: children
229
- }) : children;
243
+ var content = function content() {
244
+ if (overflowStrategy) {
245
+ return jsx("span", {
246
+ css: css(overflowStyles),
247
+ children: children
248
+ });
249
+ }
250
+ if (numberOfLines) {
251
+ return jsx("span", {
252
+ style: numberOfLinesStyle,
253
+ children: children
254
+ });
255
+ }
256
+ return children;
257
+ };
230
258
  var textContextValue = useMemo(function () {
231
259
  return {
232
260
  size: size,
@@ -242,9 +270,9 @@ var Text = forwardRefWithAs(function (_ref, forwardedRef) {
242
270
  ref: forwardedRef,
243
271
  id: id,
244
272
  css: css(styles, cssProps),
245
- children: content
273
+ children: content()
246
274
  }))
247
275
  });
248
276
  });
249
277
 
250
- export { DefaultTextPropsProvider, Strong, Text, createTextStyles, useDefaultTextProps, useForegroundTone, useOverflowStrategy, useText, useTextContext };
278
+ export { DefaultTextPropsProvider, Strong, Text, createTextStyles, useDefaultTextProps, useForegroundTone, useNumberOfLines, useOverflowStrategy, useText, useTextContext };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spark-web/text",
3
- "version": "5.2.0",
3
+ "version": "5.2.1",
4
4
  "homepage": "https://github.com/brighte-labs/spark-web#readme",
5
5
  "repository": {
6
6
  "type": "git",