@spark-web/text 5.1.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 +20 -0
- package/dist/declarations/src/context.d.ts +2 -2
- package/dist/declarations/src/default-text-props.d.ts +1 -1
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/declarations/src/text.d.ts +8 -1
- package/dist/declarations/src/use-number-of-lines.d.ts +2 -0
- package/dist/declarations/src/use-text.d.ts +4 -3
- package/dist/spark-web-text.cjs.dev.js +53 -19
- package/dist/spark-web-text.cjs.prod.js +53 -19
- package/dist/spark-web-text.esm.js +53 -20
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
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
|
+
|
|
12
|
+
## 5.2.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- [#554](https://github.com/brighte-labs/spark-web/pull/554)
|
|
17
|
+
[`8e67e65`](https://github.com/brighte-labs/spark-web/commit/8e67e658cff29a4819417142c989f3c3de1e46c1)
|
|
18
|
+
Thanks [@ralcoriza-brighte](https://github.com/ralcoriza-brighte)! - Add
|
|
19
|
+
support for `css` prop in <Text />
|
|
20
|
+
|
|
21
|
+
Fixed issues with the `weight` prop in text
|
|
22
|
+
|
|
3
23
|
## 5.1.0
|
|
4
24
|
|
|
5
25
|
### 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: "
|
|
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: "
|
|
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: "
|
|
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";
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** @jsxImportSource @emotion/react */
|
|
2
|
+
import type { CSSObject } from '@emotion/react';
|
|
1
3
|
import type { BoxProps } from '@spark-web/box';
|
|
2
4
|
import type { DataAttributeMap } from '@spark-web/utils/internal';
|
|
3
5
|
import type { CSSProperties, ReactNode } from 'react';
|
|
@@ -19,6 +21,8 @@ declare type BlockProps = {
|
|
|
19
21
|
export declare type TextProps = Partial<UseTextProps> & {
|
|
20
22
|
/** The text content. */
|
|
21
23
|
children?: ReactNode;
|
|
24
|
+
/** Customizes the component element. */
|
|
25
|
+
css?: CSSObject;
|
|
22
26
|
/** Sets data attributes on the component. */
|
|
23
27
|
data?: DataAttributeMap;
|
|
24
28
|
/** An identifier which must be unique in the whole document. */
|
|
@@ -27,9 +31,12 @@ export declare type TextProps = Partial<UseTextProps> & {
|
|
|
27
31
|
tabularNumbers?: boolean;
|
|
28
32
|
/** Transform the text casing. */
|
|
29
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;
|
|
30
37
|
} & (InlineProps | BlockProps);
|
|
31
38
|
export declare const Text: <Comp extends import("react").ElementType<any, keyof import("react").JSX.IntrinsicElements> = "div">(props: {
|
|
32
39
|
as?: Comp | undefined;
|
|
33
|
-
ref?: import("react").Ref<Comp extends "symbol" | "svg" | "animate" | "animateMotion" | "animateTransform" | "circle" | "
|
|
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;
|
|
34
41
|
} & Omit<import("react").PropsWithoutRef<import("react").ComponentProps<Comp>>, "as"> & TextProps) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
|
35
42
|
export {};
|
|
@@ -8,11 +8,12 @@ export declare type UseTextProps = {
|
|
|
8
8
|
/** The tone of the text. */
|
|
9
9
|
tone: ForegroundTone;
|
|
10
10
|
/** The weight of the text. */
|
|
11
|
-
weight
|
|
11
|
+
weight?: keyof SparkTheme['typography']['fontWeight'];
|
|
12
12
|
};
|
|
13
13
|
export declare function useText({ baseline, size, tone, weight }: UseTextProps): (import("@emotion/serialize").CSSObject | undefined)[];
|
|
14
|
-
export declare function createTextStyles({ fontSize, fontWeight, lineHeight, trims }: SparkTextDefinition, { includeTrims }?: {
|
|
14
|
+
export declare function createTextStyles({ fontSize, fontWeight, lineHeight, trims }: SparkTextDefinition, { includeTrims, includeWeight }?: {
|
|
15
15
|
includeTrims?: boolean | undefined;
|
|
16
|
+
includeWeight?: boolean | undefined;
|
|
16
17
|
}): {
|
|
17
18
|
'::before'?: {
|
|
18
19
|
marginBottom: string;
|
|
@@ -25,6 +26,6 @@ export declare function createTextStyles({ fontSize, fontWeight, lineHeight, tri
|
|
|
25
26
|
display: string;
|
|
26
27
|
} | undefined;
|
|
27
28
|
fontSize: string;
|
|
28
|
-
fontWeight: number;
|
|
29
|
+
fontWeight: number | undefined;
|
|
29
30
|
lineHeight: string;
|
|
30
31
|
};
|
|
@@ -39,7 +39,7 @@ function DefaultTextPropsProvider(_ref) {
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
var useDefaultTextProps = function useDefaultTextProps(_ref2) {
|
|
42
|
-
var _ref3, _ref4
|
|
42
|
+
var _ref3, _ref4;
|
|
43
43
|
var sizeProp = _ref2.size,
|
|
44
44
|
toneProp = _ref2.tone,
|
|
45
45
|
weightProp = _ref2.weight;
|
|
@@ -50,7 +50,7 @@ var useDefaultTextProps = function useDefaultTextProps(_ref2) {
|
|
|
50
50
|
return {
|
|
51
51
|
size: (_ref3 = sizeProp !== null && sizeProp !== void 0 ? sizeProp : size) !== null && _ref3 !== void 0 ? _ref3 : 'standard',
|
|
52
52
|
tone: (_ref4 = toneProp !== null && toneProp !== void 0 ? toneProp : tone) !== null && _ref4 !== void 0 ? _ref4 : 'neutral',
|
|
53
|
-
weight:
|
|
53
|
+
weight: weightProp !== null && weightProp !== void 0 ? weightProp : weight
|
|
54
54
|
};
|
|
55
55
|
};
|
|
56
56
|
|
|
@@ -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',
|
|
@@ -127,17 +144,19 @@ function useText(_ref) {
|
|
|
127
144
|
tablet = _theme$typography$tex.tablet;
|
|
128
145
|
var responsiveStyles = theme$1.utils.responsiveStyles({
|
|
129
146
|
mobile: createTextStyles(mobile, {
|
|
130
|
-
includeTrims: baseline
|
|
147
|
+
includeTrims: baseline,
|
|
148
|
+
includeWeight: !weight
|
|
131
149
|
}),
|
|
132
150
|
tablet: createTextStyles(tablet, {
|
|
133
|
-
includeTrims: baseline
|
|
151
|
+
includeTrims: baseline,
|
|
152
|
+
includeWeight: !weight
|
|
134
153
|
})
|
|
135
154
|
});
|
|
136
|
-
var styles = [{
|
|
155
|
+
var styles = [responsiveStyles, {
|
|
137
156
|
color: color,
|
|
138
157
|
fontFamily: theme$1.typography.fontFamily.sans.name,
|
|
139
|
-
fontWeight: theme$1.typography.fontWeight[weight]
|
|
140
|
-
}
|
|
158
|
+
fontWeight: weight ? theme$1.typography.fontWeight[weight] : undefined
|
|
159
|
+
}];
|
|
141
160
|
return styles;
|
|
142
161
|
}
|
|
143
162
|
function createTextStyles(_ref2) {
|
|
@@ -147,7 +166,9 @@ function createTextStyles(_ref2) {
|
|
|
147
166
|
trims = _ref2.trims;
|
|
148
167
|
var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
149
168
|
_ref3$includeTrims = _ref3.includeTrims,
|
|
150
|
-
includeTrims = _ref3$includeTrims === void 0 ? true : _ref3$includeTrims
|
|
169
|
+
includeTrims = _ref3$includeTrims === void 0 ? true : _ref3$includeTrims,
|
|
170
|
+
_ref3$includeWeight = _ref3.includeWeight,
|
|
171
|
+
includeWeight = _ref3$includeWeight === void 0 ? true : _ref3$includeWeight;
|
|
151
172
|
var pseudo = {
|
|
152
173
|
content: '" "',
|
|
153
174
|
display: 'table'
|
|
@@ -162,12 +183,12 @@ function createTextStyles(_ref2) {
|
|
|
162
183
|
} : null;
|
|
163
184
|
return _objectSpread({
|
|
164
185
|
fontSize: fontSize,
|
|
165
|
-
fontWeight: fontWeight,
|
|
186
|
+
fontWeight: includeWeight ? fontWeight : undefined,
|
|
166
187
|
lineHeight: lineHeight
|
|
167
188
|
}, leadingTrim);
|
|
168
189
|
}
|
|
169
190
|
|
|
170
|
-
var _excluded = ["as", "children", "data", "id", "align", "baseline", "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"];
|
|
171
192
|
var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
|
|
172
193
|
var as = _ref.as,
|
|
173
194
|
children = _ref.children,
|
|
@@ -175,6 +196,7 @@ var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
|
|
|
175
196
|
id = _ref.id,
|
|
176
197
|
align = _ref.align,
|
|
177
198
|
baselineProp = _ref.baseline,
|
|
199
|
+
cssProps = _ref.css,
|
|
178
200
|
inline = _ref.inline,
|
|
179
201
|
overflowStrategy = _ref.overflowStrategy,
|
|
180
202
|
sizeProp = _ref.size,
|
|
@@ -182,6 +204,7 @@ var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
|
|
|
182
204
|
toneProp = _ref.tone,
|
|
183
205
|
transform = _ref.transform,
|
|
184
206
|
weightProp = _ref.weight,
|
|
207
|
+
numberOfLines = _ref.numberOfLines,
|
|
185
208
|
consumerProps = _objectWithoutProperties(_ref, _excluded);
|
|
186
209
|
var overflowStyles = useOverflowStrategy(overflowStrategy);
|
|
187
210
|
var textContext = useTextContext();
|
|
@@ -200,6 +223,7 @@ var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
|
|
|
200
223
|
tone: tone,
|
|
201
224
|
weight: weight
|
|
202
225
|
});
|
|
226
|
+
var numberOfLinesStyle = useNumberOfLines(numberOfLines);
|
|
203
227
|
var styles = [textStyles, {
|
|
204
228
|
display: inline ? 'inline' : 'block',
|
|
205
229
|
fontVariantNumeric: tabularNumbers ? 'tabular-nums' : undefined,
|
|
@@ -214,18 +238,27 @@ var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
|
|
|
214
238
|
data: data,
|
|
215
239
|
ref: forwardedRef,
|
|
216
240
|
id: id,
|
|
217
|
-
css: react$1.css(styles),
|
|
241
|
+
css: react$1.css(styles, cssProps),
|
|
218
242
|
children: children
|
|
219
243
|
}));
|
|
220
244
|
}
|
|
221
245
|
|
|
222
246
|
// prepare block variant
|
|
223
|
-
var content =
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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
|
+
};
|
|
229
262
|
var textContextValue = react.useMemo(function () {
|
|
230
263
|
return {
|
|
231
264
|
size: size,
|
|
@@ -240,8 +273,8 @@ var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
|
|
|
240
273
|
data: data,
|
|
241
274
|
ref: forwardedRef,
|
|
242
275
|
id: id,
|
|
243
|
-
css: react$1.css(styles),
|
|
244
|
-
children: content
|
|
276
|
+
css: react$1.css(styles, cssProps),
|
|
277
|
+
children: content()
|
|
245
278
|
}))
|
|
246
279
|
});
|
|
247
280
|
});
|
|
@@ -252,6 +285,7 @@ exports.Text = Text;
|
|
|
252
285
|
exports.createTextStyles = createTextStyles;
|
|
253
286
|
exports.useDefaultTextProps = useDefaultTextProps;
|
|
254
287
|
exports.useForegroundTone = useForegroundTone;
|
|
288
|
+
exports.useNumberOfLines = useNumberOfLines;
|
|
255
289
|
exports.useOverflowStrategy = useOverflowStrategy;
|
|
256
290
|
exports.useText = useText;
|
|
257
291
|
exports.useTextContext = useTextContext;
|
|
@@ -39,7 +39,7 @@ function DefaultTextPropsProvider(_ref) {
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
var useDefaultTextProps = function useDefaultTextProps(_ref2) {
|
|
42
|
-
var _ref3, _ref4
|
|
42
|
+
var _ref3, _ref4;
|
|
43
43
|
var sizeProp = _ref2.size,
|
|
44
44
|
toneProp = _ref2.tone,
|
|
45
45
|
weightProp = _ref2.weight;
|
|
@@ -50,7 +50,7 @@ var useDefaultTextProps = function useDefaultTextProps(_ref2) {
|
|
|
50
50
|
return {
|
|
51
51
|
size: (_ref3 = sizeProp !== null && sizeProp !== void 0 ? sizeProp : size) !== null && _ref3 !== void 0 ? _ref3 : 'standard',
|
|
52
52
|
tone: (_ref4 = toneProp !== null && toneProp !== void 0 ? toneProp : tone) !== null && _ref4 !== void 0 ? _ref4 : 'neutral',
|
|
53
|
-
weight:
|
|
53
|
+
weight: weightProp !== null && weightProp !== void 0 ? weightProp : weight
|
|
54
54
|
};
|
|
55
55
|
};
|
|
56
56
|
|
|
@@ -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',
|
|
@@ -127,17 +144,19 @@ function useText(_ref) {
|
|
|
127
144
|
tablet = _theme$typography$tex.tablet;
|
|
128
145
|
var responsiveStyles = theme$1.utils.responsiveStyles({
|
|
129
146
|
mobile: createTextStyles(mobile, {
|
|
130
|
-
includeTrims: baseline
|
|
147
|
+
includeTrims: baseline,
|
|
148
|
+
includeWeight: !weight
|
|
131
149
|
}),
|
|
132
150
|
tablet: createTextStyles(tablet, {
|
|
133
|
-
includeTrims: baseline
|
|
151
|
+
includeTrims: baseline,
|
|
152
|
+
includeWeight: !weight
|
|
134
153
|
})
|
|
135
154
|
});
|
|
136
|
-
var styles = [{
|
|
155
|
+
var styles = [responsiveStyles, {
|
|
137
156
|
color: color,
|
|
138
157
|
fontFamily: theme$1.typography.fontFamily.sans.name,
|
|
139
|
-
fontWeight: theme$1.typography.fontWeight[weight]
|
|
140
|
-
}
|
|
158
|
+
fontWeight: weight ? theme$1.typography.fontWeight[weight] : undefined
|
|
159
|
+
}];
|
|
141
160
|
return styles;
|
|
142
161
|
}
|
|
143
162
|
function createTextStyles(_ref2) {
|
|
@@ -147,7 +166,9 @@ function createTextStyles(_ref2) {
|
|
|
147
166
|
trims = _ref2.trims;
|
|
148
167
|
var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
149
168
|
_ref3$includeTrims = _ref3.includeTrims,
|
|
150
|
-
includeTrims = _ref3$includeTrims === void 0 ? true : _ref3$includeTrims
|
|
169
|
+
includeTrims = _ref3$includeTrims === void 0 ? true : _ref3$includeTrims,
|
|
170
|
+
_ref3$includeWeight = _ref3.includeWeight,
|
|
171
|
+
includeWeight = _ref3$includeWeight === void 0 ? true : _ref3$includeWeight;
|
|
151
172
|
var pseudo = {
|
|
152
173
|
content: '" "',
|
|
153
174
|
display: 'table'
|
|
@@ -162,12 +183,12 @@ function createTextStyles(_ref2) {
|
|
|
162
183
|
} : null;
|
|
163
184
|
return _objectSpread({
|
|
164
185
|
fontSize: fontSize,
|
|
165
|
-
fontWeight: fontWeight,
|
|
186
|
+
fontWeight: includeWeight ? fontWeight : undefined,
|
|
166
187
|
lineHeight: lineHeight
|
|
167
188
|
}, leadingTrim);
|
|
168
189
|
}
|
|
169
190
|
|
|
170
|
-
var _excluded = ["as", "children", "data", "id", "align", "baseline", "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"];
|
|
171
192
|
var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
|
|
172
193
|
var as = _ref.as,
|
|
173
194
|
children = _ref.children,
|
|
@@ -175,6 +196,7 @@ var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
|
|
|
175
196
|
id = _ref.id,
|
|
176
197
|
align = _ref.align,
|
|
177
198
|
baselineProp = _ref.baseline,
|
|
199
|
+
cssProps = _ref.css,
|
|
178
200
|
inline = _ref.inline,
|
|
179
201
|
overflowStrategy = _ref.overflowStrategy,
|
|
180
202
|
sizeProp = _ref.size,
|
|
@@ -182,6 +204,7 @@ var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
|
|
|
182
204
|
toneProp = _ref.tone,
|
|
183
205
|
transform = _ref.transform,
|
|
184
206
|
weightProp = _ref.weight,
|
|
207
|
+
numberOfLines = _ref.numberOfLines,
|
|
185
208
|
consumerProps = _objectWithoutProperties(_ref, _excluded);
|
|
186
209
|
var overflowStyles = useOverflowStrategy(overflowStrategy);
|
|
187
210
|
var textContext = useTextContext();
|
|
@@ -200,6 +223,7 @@ var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
|
|
|
200
223
|
tone: tone,
|
|
201
224
|
weight: weight
|
|
202
225
|
});
|
|
226
|
+
var numberOfLinesStyle = useNumberOfLines(numberOfLines);
|
|
203
227
|
var styles = [textStyles, {
|
|
204
228
|
display: inline ? 'inline' : 'block',
|
|
205
229
|
fontVariantNumeric: tabularNumbers ? 'tabular-nums' : undefined,
|
|
@@ -214,18 +238,27 @@ var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
|
|
|
214
238
|
data: data,
|
|
215
239
|
ref: forwardedRef,
|
|
216
240
|
id: id,
|
|
217
|
-
css: react$1.css(styles),
|
|
241
|
+
css: react$1.css(styles, cssProps),
|
|
218
242
|
children: children
|
|
219
243
|
}));
|
|
220
244
|
}
|
|
221
245
|
|
|
222
246
|
// prepare block variant
|
|
223
|
-
var content =
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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
|
+
};
|
|
229
262
|
var textContextValue = react.useMemo(function () {
|
|
230
263
|
return {
|
|
231
264
|
size: size,
|
|
@@ -240,8 +273,8 @@ var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
|
|
|
240
273
|
data: data,
|
|
241
274
|
ref: forwardedRef,
|
|
242
275
|
id: id,
|
|
243
|
-
css: react$1.css(styles),
|
|
244
|
-
children: content
|
|
276
|
+
css: react$1.css(styles, cssProps),
|
|
277
|
+
children: content()
|
|
245
278
|
}))
|
|
246
279
|
});
|
|
247
280
|
});
|
|
@@ -252,6 +285,7 @@ exports.Text = Text;
|
|
|
252
285
|
exports.createTextStyles = createTextStyles;
|
|
253
286
|
exports.useDefaultTextProps = useDefaultTextProps;
|
|
254
287
|
exports.useForegroundTone = useForegroundTone;
|
|
288
|
+
exports.useNumberOfLines = useNumberOfLines;
|
|
255
289
|
exports.useOverflowStrategy = useOverflowStrategy;
|
|
256
290
|
exports.useText = useText;
|
|
257
291
|
exports.useTextContext = useTextContext;
|
|
@@ -35,7 +35,7 @@ function DefaultTextPropsProvider(_ref) {
|
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
var useDefaultTextProps = function useDefaultTextProps(_ref2) {
|
|
38
|
-
var _ref3, _ref4
|
|
38
|
+
var _ref3, _ref4;
|
|
39
39
|
var sizeProp = _ref2.size,
|
|
40
40
|
toneProp = _ref2.tone,
|
|
41
41
|
weightProp = _ref2.weight;
|
|
@@ -46,7 +46,7 @@ var useDefaultTextProps = function useDefaultTextProps(_ref2) {
|
|
|
46
46
|
return {
|
|
47
47
|
size: (_ref3 = sizeProp !== null && sizeProp !== void 0 ? sizeProp : size) !== null && _ref3 !== void 0 ? _ref3 : 'standard',
|
|
48
48
|
tone: (_ref4 = toneProp !== null && toneProp !== void 0 ? toneProp : tone) !== null && _ref4 !== void 0 ? _ref4 : 'neutral',
|
|
49
|
-
weight:
|
|
49
|
+
weight: weightProp !== null && weightProp !== void 0 ? weightProp : weight
|
|
50
50
|
};
|
|
51
51
|
};
|
|
52
52
|
|
|
@@ -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',
|
|
@@ -123,17 +140,19 @@ function useText(_ref) {
|
|
|
123
140
|
tablet = _theme$typography$tex.tablet;
|
|
124
141
|
var responsiveStyles = theme.utils.responsiveStyles({
|
|
125
142
|
mobile: createTextStyles(mobile, {
|
|
126
|
-
includeTrims: baseline
|
|
143
|
+
includeTrims: baseline,
|
|
144
|
+
includeWeight: !weight
|
|
127
145
|
}),
|
|
128
146
|
tablet: createTextStyles(tablet, {
|
|
129
|
-
includeTrims: baseline
|
|
147
|
+
includeTrims: baseline,
|
|
148
|
+
includeWeight: !weight
|
|
130
149
|
})
|
|
131
150
|
});
|
|
132
|
-
var styles = [{
|
|
151
|
+
var styles = [responsiveStyles, {
|
|
133
152
|
color: color,
|
|
134
153
|
fontFamily: theme.typography.fontFamily.sans.name,
|
|
135
|
-
fontWeight: theme.typography.fontWeight[weight]
|
|
136
|
-
}
|
|
154
|
+
fontWeight: weight ? theme.typography.fontWeight[weight] : undefined
|
|
155
|
+
}];
|
|
137
156
|
return styles;
|
|
138
157
|
}
|
|
139
158
|
function createTextStyles(_ref2) {
|
|
@@ -143,7 +162,9 @@ function createTextStyles(_ref2) {
|
|
|
143
162
|
trims = _ref2.trims;
|
|
144
163
|
var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
145
164
|
_ref3$includeTrims = _ref3.includeTrims,
|
|
146
|
-
includeTrims = _ref3$includeTrims === void 0 ? true : _ref3$includeTrims
|
|
165
|
+
includeTrims = _ref3$includeTrims === void 0 ? true : _ref3$includeTrims,
|
|
166
|
+
_ref3$includeWeight = _ref3.includeWeight,
|
|
167
|
+
includeWeight = _ref3$includeWeight === void 0 ? true : _ref3$includeWeight;
|
|
147
168
|
var pseudo = {
|
|
148
169
|
content: '" "',
|
|
149
170
|
display: 'table'
|
|
@@ -158,12 +179,12 @@ function createTextStyles(_ref2) {
|
|
|
158
179
|
} : null;
|
|
159
180
|
return _objectSpread({
|
|
160
181
|
fontSize: fontSize,
|
|
161
|
-
fontWeight: fontWeight,
|
|
182
|
+
fontWeight: includeWeight ? fontWeight : undefined,
|
|
162
183
|
lineHeight: lineHeight
|
|
163
184
|
}, leadingTrim);
|
|
164
185
|
}
|
|
165
186
|
|
|
166
|
-
var _excluded = ["as", "children", "data", "id", "align", "baseline", "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"];
|
|
167
188
|
var Text = forwardRefWithAs(function (_ref, forwardedRef) {
|
|
168
189
|
var as = _ref.as,
|
|
169
190
|
children = _ref.children,
|
|
@@ -171,6 +192,7 @@ var Text = forwardRefWithAs(function (_ref, forwardedRef) {
|
|
|
171
192
|
id = _ref.id,
|
|
172
193
|
align = _ref.align,
|
|
173
194
|
baselineProp = _ref.baseline,
|
|
195
|
+
cssProps = _ref.css,
|
|
174
196
|
inline = _ref.inline,
|
|
175
197
|
overflowStrategy = _ref.overflowStrategy,
|
|
176
198
|
sizeProp = _ref.size,
|
|
@@ -178,6 +200,7 @@ var Text = forwardRefWithAs(function (_ref, forwardedRef) {
|
|
|
178
200
|
toneProp = _ref.tone,
|
|
179
201
|
transform = _ref.transform,
|
|
180
202
|
weightProp = _ref.weight,
|
|
203
|
+
numberOfLines = _ref.numberOfLines,
|
|
181
204
|
consumerProps = _objectWithoutProperties(_ref, _excluded);
|
|
182
205
|
var overflowStyles = useOverflowStrategy(overflowStrategy);
|
|
183
206
|
var textContext = useTextContext();
|
|
@@ -196,6 +219,7 @@ var Text = forwardRefWithAs(function (_ref, forwardedRef) {
|
|
|
196
219
|
tone: tone,
|
|
197
220
|
weight: weight
|
|
198
221
|
});
|
|
222
|
+
var numberOfLinesStyle = useNumberOfLines(numberOfLines);
|
|
199
223
|
var styles = [textStyles, {
|
|
200
224
|
display: inline ? 'inline' : 'block',
|
|
201
225
|
fontVariantNumeric: tabularNumbers ? 'tabular-nums' : undefined,
|
|
@@ -210,18 +234,27 @@ var Text = forwardRefWithAs(function (_ref, forwardedRef) {
|
|
|
210
234
|
data: data,
|
|
211
235
|
ref: forwardedRef,
|
|
212
236
|
id: id,
|
|
213
|
-
css: css(styles),
|
|
237
|
+
css: css(styles, cssProps),
|
|
214
238
|
children: children
|
|
215
239
|
}));
|
|
216
240
|
}
|
|
217
241
|
|
|
218
242
|
// prepare block variant
|
|
219
|
-
var content =
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
+
};
|
|
225
258
|
var textContextValue = useMemo(function () {
|
|
226
259
|
return {
|
|
227
260
|
size: size,
|
|
@@ -236,10 +269,10 @@ var Text = forwardRefWithAs(function (_ref, forwardedRef) {
|
|
|
236
269
|
data: data,
|
|
237
270
|
ref: forwardedRef,
|
|
238
271
|
id: id,
|
|
239
|
-
css: css(styles),
|
|
240
|
-
children: content
|
|
272
|
+
css: css(styles, cssProps),
|
|
273
|
+
children: content()
|
|
241
274
|
}))
|
|
242
275
|
});
|
|
243
276
|
});
|
|
244
277
|
|
|
245
|
-
export { DefaultTextPropsProvider, Strong, Text, createTextStyles, useDefaultTextProps, useForegroundTone, useOverflowStrategy, useText, useTextContext };
|
|
278
|
+
export { DefaultTextPropsProvider, Strong, Text, createTextStyles, useDefaultTextProps, useForegroundTone, useNumberOfLines, useOverflowStrategy, useText, useTextContext };
|