@spark-web/text 0.0.0-snapshot-release-20260409001813
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 +754 -0
- package/CLAUDE.md +91 -0
- package/README.md +145 -0
- package/dist/declarations/src/context.d.ts +10 -0
- package/dist/declarations/src/default-text-props.d.ts +16 -0
- package/dist/declarations/src/index.d.ts +12 -0
- package/dist/declarations/src/strong.d.ts +5 -0
- package/dist/declarations/src/text.d.ts +41 -0
- package/dist/declarations/src/use-foreground-tone.d.ts +3 -0
- package/dist/declarations/src/use-number-of-lines.d.ts +2 -0
- package/dist/declarations/src/use-overflow-strategy.d.ts +27 -0
- package/dist/declarations/src/use-text.d.ts +31 -0
- package/dist/spark-web-text.cjs.d.ts +2 -0
- package/dist/spark-web-text.cjs.dev.js +291 -0
- package/dist/spark-web-text.cjs.js +7 -0
- package/dist/spark-web-text.cjs.prod.js +291 -0
- package/dist/spark-web-text.esm.js +278 -0
- package/package.json +35 -0
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
7
|
+
var react$1 = require('@emotion/react');
|
|
8
|
+
var theme = require('@spark-web/theme');
|
|
9
|
+
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
10
|
+
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
11
|
+
var box = require('@spark-web/box');
|
|
12
|
+
var ts = require('@spark-web/utils/ts');
|
|
13
|
+
|
|
14
|
+
var TextContext = /*#__PURE__*/react.createContext(undefined);
|
|
15
|
+
function useTextContext() {
|
|
16
|
+
return react.useContext(TextContext);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
var DefaultTextPropsContext = /*#__PURE__*/react.createContext({
|
|
20
|
+
size: undefined,
|
|
21
|
+
tone: undefined,
|
|
22
|
+
weight: undefined
|
|
23
|
+
});
|
|
24
|
+
function DefaultTextPropsProvider(_ref) {
|
|
25
|
+
var children = _ref.children,
|
|
26
|
+
size = _ref.size,
|
|
27
|
+
tone = _ref.tone,
|
|
28
|
+
weight = _ref.weight;
|
|
29
|
+
var defaultTextProps = react.useMemo(function () {
|
|
30
|
+
return {
|
|
31
|
+
size: size,
|
|
32
|
+
tone: tone,
|
|
33
|
+
weight: weight
|
|
34
|
+
};
|
|
35
|
+
}, [size, tone, weight]);
|
|
36
|
+
return jsxRuntime.jsx(DefaultTextPropsContext.Provider, {
|
|
37
|
+
value: defaultTextProps,
|
|
38
|
+
children: children
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
var useDefaultTextProps = function useDefaultTextProps(_ref2) {
|
|
42
|
+
var _ref3, _ref4;
|
|
43
|
+
var sizeProp = _ref2.size,
|
|
44
|
+
toneProp = _ref2.tone,
|
|
45
|
+
weightProp = _ref2.weight;
|
|
46
|
+
var _useContext = react.useContext(DefaultTextPropsContext),
|
|
47
|
+
size = _useContext.size,
|
|
48
|
+
tone = _useContext.tone,
|
|
49
|
+
weight = _useContext.weight;
|
|
50
|
+
return {
|
|
51
|
+
size: (_ref3 = sizeProp !== null && sizeProp !== void 0 ? sizeProp : size) !== null && _ref3 !== void 0 ? _ref3 : 'standard',
|
|
52
|
+
tone: (_ref4 = toneProp !== null && toneProp !== void 0 ? toneProp : tone) !== null && _ref4 !== void 0 ? _ref4 : 'neutral',
|
|
53
|
+
weight: weightProp !== null && weightProp !== void 0 ? weightProp : weight
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
var Strong = function Strong(_ref) {
|
|
58
|
+
var children = _ref.children;
|
|
59
|
+
var theme$1 = theme.useTheme();
|
|
60
|
+
var styles = {
|
|
61
|
+
fontWeight: theme$1.typography.fontWeight.semibold
|
|
62
|
+
};
|
|
63
|
+
return jsxRuntime.jsx("strong", {
|
|
64
|
+
css: react$1.css(styles),
|
|
65
|
+
children: children
|
|
66
|
+
});
|
|
67
|
+
};
|
|
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
|
+
|
|
86
|
+
var strategyMap = {
|
|
87
|
+
truncate: {
|
|
88
|
+
display: 'block',
|
|
89
|
+
overflow: 'hidden',
|
|
90
|
+
textOverflow: 'ellipsis',
|
|
91
|
+
whiteSpace: 'nowrap'
|
|
92
|
+
},
|
|
93
|
+
nowrap: {
|
|
94
|
+
whiteSpace: 'nowrap'
|
|
95
|
+
},
|
|
96
|
+
// https://css-tricks.com/better-line-breaks-for-long-urls/
|
|
97
|
+
breakword: {
|
|
98
|
+
display: 'block',
|
|
99
|
+
overflowWrap: 'break-word',
|
|
100
|
+
wordBreak: 'break-word',
|
|
101
|
+
wordWrap: 'break-word'
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
function useOverflowStrategy(strategy) {
|
|
105
|
+
if (!strategy) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
return strategyMap[strategy];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
var invertableTones = {
|
|
112
|
+
neutral: {
|
|
113
|
+
dark: 'neutralInverted',
|
|
114
|
+
light: 'neutral'
|
|
115
|
+
},
|
|
116
|
+
muted: {
|
|
117
|
+
dark: 'mutedInverted',
|
|
118
|
+
light: 'muted'
|
|
119
|
+
},
|
|
120
|
+
link: {
|
|
121
|
+
dark: 'neutralInverted',
|
|
122
|
+
light: 'link'
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
function useForegroundTone(tone) {
|
|
126
|
+
var theme$1 = theme.useTheme();
|
|
127
|
+
var backgroundLightness = box.useBackgroundLightness();
|
|
128
|
+
if (tone in invertableTones) {
|
|
129
|
+
return theme$1.color.foreground[invertableTones[tone][backgroundLightness]];
|
|
130
|
+
}
|
|
131
|
+
return theme$1.color.foreground[tone];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function useText(_ref) {
|
|
135
|
+
var _ref$baseline = _ref.baseline,
|
|
136
|
+
baseline = _ref$baseline === void 0 ? true : _ref$baseline,
|
|
137
|
+
size = _ref.size,
|
|
138
|
+
tone = _ref.tone,
|
|
139
|
+
weight = _ref.weight;
|
|
140
|
+
var theme$1 = theme.useTheme();
|
|
141
|
+
var color = useForegroundTone(tone);
|
|
142
|
+
var _theme$typography$tex = theme$1.typography.text[size],
|
|
143
|
+
mobile = _theme$typography$tex.mobile,
|
|
144
|
+
tablet = _theme$typography$tex.tablet;
|
|
145
|
+
var responsiveStyles = theme$1.utils.responsiveStyles({
|
|
146
|
+
mobile: createTextStyles(mobile, {
|
|
147
|
+
includeTrims: baseline,
|
|
148
|
+
includeWeight: !weight
|
|
149
|
+
}),
|
|
150
|
+
tablet: createTextStyles(tablet, {
|
|
151
|
+
includeTrims: baseline,
|
|
152
|
+
includeWeight: !weight
|
|
153
|
+
})
|
|
154
|
+
});
|
|
155
|
+
var styles = [responsiveStyles, {
|
|
156
|
+
color: color,
|
|
157
|
+
fontFamily: theme$1.typography.fontFamily.sans.name,
|
|
158
|
+
fontWeight: weight ? theme$1.typography.fontWeight[weight] : undefined
|
|
159
|
+
}];
|
|
160
|
+
return styles;
|
|
161
|
+
}
|
|
162
|
+
function createTextStyles(_ref2) {
|
|
163
|
+
var fontSize = _ref2.fontSize,
|
|
164
|
+
fontWeight = _ref2.fontWeight,
|
|
165
|
+
lineHeight = _ref2.lineHeight,
|
|
166
|
+
trims = _ref2.trims;
|
|
167
|
+
var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
168
|
+
_ref3$includeTrims = _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;
|
|
172
|
+
var pseudo = {
|
|
173
|
+
content: '" "',
|
|
174
|
+
display: 'table'
|
|
175
|
+
};
|
|
176
|
+
var leadingTrim = includeTrims ? {
|
|
177
|
+
'::before': _objectSpread(_objectSpread({}, pseudo), {}, {
|
|
178
|
+
marginBottom: trims.capHeightTrim
|
|
179
|
+
}),
|
|
180
|
+
'::after': _objectSpread(_objectSpread({}, pseudo), {}, {
|
|
181
|
+
marginTop: trims.baselineTrim
|
|
182
|
+
})
|
|
183
|
+
} : null;
|
|
184
|
+
return _objectSpread({
|
|
185
|
+
fontSize: fontSize,
|
|
186
|
+
fontWeight: includeWeight ? fontWeight : undefined,
|
|
187
|
+
lineHeight: lineHeight
|
|
188
|
+
}, leadingTrim);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
var _excluded = ["as", "children", "data", "id", "align", "baseline", "css", "inline", "overflowStrategy", "size", "tabularNumbers", "tone", "transform", "weight", "numberOfLines"];
|
|
192
|
+
var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
|
|
193
|
+
var as = _ref.as,
|
|
194
|
+
children = _ref.children,
|
|
195
|
+
data = _ref.data,
|
|
196
|
+
id = _ref.id,
|
|
197
|
+
align = _ref.align,
|
|
198
|
+
baselineProp = _ref.baseline,
|
|
199
|
+
cssProps = _ref.css,
|
|
200
|
+
inline = _ref.inline,
|
|
201
|
+
overflowStrategy = _ref.overflowStrategy,
|
|
202
|
+
sizeProp = _ref.size,
|
|
203
|
+
tabularNumbers = _ref.tabularNumbers,
|
|
204
|
+
toneProp = _ref.tone,
|
|
205
|
+
transform = _ref.transform,
|
|
206
|
+
weightProp = _ref.weight,
|
|
207
|
+
numberOfLines = _ref.numberOfLines,
|
|
208
|
+
consumerProps = _objectWithoutProperties(_ref, _excluded);
|
|
209
|
+
var overflowStyles = useOverflowStrategy(overflowStrategy);
|
|
210
|
+
var textContext = useTextContext();
|
|
211
|
+
var _useDefaultTextProps = useDefaultTextProps({
|
|
212
|
+
size: sizeProp !== null && sizeProp !== void 0 ? sizeProp : textContext === null || textContext === void 0 ? void 0 : textContext.size,
|
|
213
|
+
tone: toneProp !== null && toneProp !== void 0 ? toneProp : textContext === null || textContext === void 0 ? void 0 : textContext.tone,
|
|
214
|
+
weight: weightProp !== null && weightProp !== void 0 ? weightProp : textContext === null || textContext === void 0 ? void 0 : textContext.weight
|
|
215
|
+
}),
|
|
216
|
+
size = _useDefaultTextProps.size,
|
|
217
|
+
tone = _useDefaultTextProps.tone,
|
|
218
|
+
weight = _useDefaultTextProps.weight;
|
|
219
|
+
var baseline = !inline && baselineProp;
|
|
220
|
+
var textStyles = useText({
|
|
221
|
+
baseline: baseline,
|
|
222
|
+
size: size,
|
|
223
|
+
tone: tone,
|
|
224
|
+
weight: weight
|
|
225
|
+
});
|
|
226
|
+
var numberOfLinesStyle = useNumberOfLines(numberOfLines);
|
|
227
|
+
var styles = [textStyles, {
|
|
228
|
+
display: inline ? 'inline' : 'block',
|
|
229
|
+
fontVariantNumeric: tabularNumbers ? 'tabular-nums' : undefined,
|
|
230
|
+
textAlign: align,
|
|
231
|
+
textTransform: transform
|
|
232
|
+
}];
|
|
233
|
+
|
|
234
|
+
// early exit for inline variant
|
|
235
|
+
if (inline) {
|
|
236
|
+
return jsxRuntime.jsx(box.Box, _objectSpread(_objectSpread({}, consumerProps), {}, {
|
|
237
|
+
as: as !== null && as !== void 0 ? as : 'span',
|
|
238
|
+
data: data,
|
|
239
|
+
ref: forwardedRef,
|
|
240
|
+
id: id,
|
|
241
|
+
css: react$1.css(styles, cssProps),
|
|
242
|
+
children: children
|
|
243
|
+
}));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// prepare block variant
|
|
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
|
+
};
|
|
262
|
+
var textContextValue = react.useMemo(function () {
|
|
263
|
+
return {
|
|
264
|
+
size: size,
|
|
265
|
+
tone: tone,
|
|
266
|
+
weight: weight
|
|
267
|
+
};
|
|
268
|
+
}, [size, tone, weight]);
|
|
269
|
+
return jsxRuntime.jsx(TextContext.Provider, {
|
|
270
|
+
value: textContextValue,
|
|
271
|
+
children: jsxRuntime.jsx(box.Box, _objectSpread(_objectSpread({}, consumerProps), {}, {
|
|
272
|
+
as: as,
|
|
273
|
+
data: data,
|
|
274
|
+
ref: forwardedRef,
|
|
275
|
+
id: id,
|
|
276
|
+
css: react$1.css(styles, cssProps),
|
|
277
|
+
children: content()
|
|
278
|
+
}))
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
exports.DefaultTextPropsProvider = DefaultTextPropsProvider;
|
|
283
|
+
exports.Strong = Strong;
|
|
284
|
+
exports.Text = Text;
|
|
285
|
+
exports.createTextStyles = createTextStyles;
|
|
286
|
+
exports.useDefaultTextProps = useDefaultTextProps;
|
|
287
|
+
exports.useForegroundTone = useForegroundTone;
|
|
288
|
+
exports.useNumberOfLines = useNumberOfLines;
|
|
289
|
+
exports.useOverflowStrategy = useOverflowStrategy;
|
|
290
|
+
exports.useText = useText;
|
|
291
|
+
exports.useTextContext = useTextContext;
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
7
|
+
var react$1 = require('@emotion/react');
|
|
8
|
+
var theme = require('@spark-web/theme');
|
|
9
|
+
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
10
|
+
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
11
|
+
var box = require('@spark-web/box');
|
|
12
|
+
var ts = require('@spark-web/utils/ts');
|
|
13
|
+
|
|
14
|
+
var TextContext = /*#__PURE__*/react.createContext(undefined);
|
|
15
|
+
function useTextContext() {
|
|
16
|
+
return react.useContext(TextContext);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
var DefaultTextPropsContext = /*#__PURE__*/react.createContext({
|
|
20
|
+
size: undefined,
|
|
21
|
+
tone: undefined,
|
|
22
|
+
weight: undefined
|
|
23
|
+
});
|
|
24
|
+
function DefaultTextPropsProvider(_ref) {
|
|
25
|
+
var children = _ref.children,
|
|
26
|
+
size = _ref.size,
|
|
27
|
+
tone = _ref.tone,
|
|
28
|
+
weight = _ref.weight;
|
|
29
|
+
var defaultTextProps = react.useMemo(function () {
|
|
30
|
+
return {
|
|
31
|
+
size: size,
|
|
32
|
+
tone: tone,
|
|
33
|
+
weight: weight
|
|
34
|
+
};
|
|
35
|
+
}, [size, tone, weight]);
|
|
36
|
+
return jsxRuntime.jsx(DefaultTextPropsContext.Provider, {
|
|
37
|
+
value: defaultTextProps,
|
|
38
|
+
children: children
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
var useDefaultTextProps = function useDefaultTextProps(_ref2) {
|
|
42
|
+
var _ref3, _ref4;
|
|
43
|
+
var sizeProp = _ref2.size,
|
|
44
|
+
toneProp = _ref2.tone,
|
|
45
|
+
weightProp = _ref2.weight;
|
|
46
|
+
var _useContext = react.useContext(DefaultTextPropsContext),
|
|
47
|
+
size = _useContext.size,
|
|
48
|
+
tone = _useContext.tone,
|
|
49
|
+
weight = _useContext.weight;
|
|
50
|
+
return {
|
|
51
|
+
size: (_ref3 = sizeProp !== null && sizeProp !== void 0 ? sizeProp : size) !== null && _ref3 !== void 0 ? _ref3 : 'standard',
|
|
52
|
+
tone: (_ref4 = toneProp !== null && toneProp !== void 0 ? toneProp : tone) !== null && _ref4 !== void 0 ? _ref4 : 'neutral',
|
|
53
|
+
weight: weightProp !== null && weightProp !== void 0 ? weightProp : weight
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
var Strong = function Strong(_ref) {
|
|
58
|
+
var children = _ref.children;
|
|
59
|
+
var theme$1 = theme.useTheme();
|
|
60
|
+
var styles = {
|
|
61
|
+
fontWeight: theme$1.typography.fontWeight.semibold
|
|
62
|
+
};
|
|
63
|
+
return jsxRuntime.jsx("strong", {
|
|
64
|
+
css: react$1.css(styles),
|
|
65
|
+
children: children
|
|
66
|
+
});
|
|
67
|
+
};
|
|
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
|
+
|
|
86
|
+
var strategyMap = {
|
|
87
|
+
truncate: {
|
|
88
|
+
display: 'block',
|
|
89
|
+
overflow: 'hidden',
|
|
90
|
+
textOverflow: 'ellipsis',
|
|
91
|
+
whiteSpace: 'nowrap'
|
|
92
|
+
},
|
|
93
|
+
nowrap: {
|
|
94
|
+
whiteSpace: 'nowrap'
|
|
95
|
+
},
|
|
96
|
+
// https://css-tricks.com/better-line-breaks-for-long-urls/
|
|
97
|
+
breakword: {
|
|
98
|
+
display: 'block',
|
|
99
|
+
overflowWrap: 'break-word',
|
|
100
|
+
wordBreak: 'break-word',
|
|
101
|
+
wordWrap: 'break-word'
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
function useOverflowStrategy(strategy) {
|
|
105
|
+
if (!strategy) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
return strategyMap[strategy];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
var invertableTones = {
|
|
112
|
+
neutral: {
|
|
113
|
+
dark: 'neutralInverted',
|
|
114
|
+
light: 'neutral'
|
|
115
|
+
},
|
|
116
|
+
muted: {
|
|
117
|
+
dark: 'mutedInverted',
|
|
118
|
+
light: 'muted'
|
|
119
|
+
},
|
|
120
|
+
link: {
|
|
121
|
+
dark: 'neutralInverted',
|
|
122
|
+
light: 'link'
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
function useForegroundTone(tone) {
|
|
126
|
+
var theme$1 = theme.useTheme();
|
|
127
|
+
var backgroundLightness = box.useBackgroundLightness();
|
|
128
|
+
if (tone in invertableTones) {
|
|
129
|
+
return theme$1.color.foreground[invertableTones[tone][backgroundLightness]];
|
|
130
|
+
}
|
|
131
|
+
return theme$1.color.foreground[tone];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function useText(_ref) {
|
|
135
|
+
var _ref$baseline = _ref.baseline,
|
|
136
|
+
baseline = _ref$baseline === void 0 ? true : _ref$baseline,
|
|
137
|
+
size = _ref.size,
|
|
138
|
+
tone = _ref.tone,
|
|
139
|
+
weight = _ref.weight;
|
|
140
|
+
var theme$1 = theme.useTheme();
|
|
141
|
+
var color = useForegroundTone(tone);
|
|
142
|
+
var _theme$typography$tex = theme$1.typography.text[size],
|
|
143
|
+
mobile = _theme$typography$tex.mobile,
|
|
144
|
+
tablet = _theme$typography$tex.tablet;
|
|
145
|
+
var responsiveStyles = theme$1.utils.responsiveStyles({
|
|
146
|
+
mobile: createTextStyles(mobile, {
|
|
147
|
+
includeTrims: baseline,
|
|
148
|
+
includeWeight: !weight
|
|
149
|
+
}),
|
|
150
|
+
tablet: createTextStyles(tablet, {
|
|
151
|
+
includeTrims: baseline,
|
|
152
|
+
includeWeight: !weight
|
|
153
|
+
})
|
|
154
|
+
});
|
|
155
|
+
var styles = [responsiveStyles, {
|
|
156
|
+
color: color,
|
|
157
|
+
fontFamily: theme$1.typography.fontFamily.sans.name,
|
|
158
|
+
fontWeight: weight ? theme$1.typography.fontWeight[weight] : undefined
|
|
159
|
+
}];
|
|
160
|
+
return styles;
|
|
161
|
+
}
|
|
162
|
+
function createTextStyles(_ref2) {
|
|
163
|
+
var fontSize = _ref2.fontSize,
|
|
164
|
+
fontWeight = _ref2.fontWeight,
|
|
165
|
+
lineHeight = _ref2.lineHeight,
|
|
166
|
+
trims = _ref2.trims;
|
|
167
|
+
var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
168
|
+
_ref3$includeTrims = _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;
|
|
172
|
+
var pseudo = {
|
|
173
|
+
content: '" "',
|
|
174
|
+
display: 'table'
|
|
175
|
+
};
|
|
176
|
+
var leadingTrim = includeTrims ? {
|
|
177
|
+
'::before': _objectSpread(_objectSpread({}, pseudo), {}, {
|
|
178
|
+
marginBottom: trims.capHeightTrim
|
|
179
|
+
}),
|
|
180
|
+
'::after': _objectSpread(_objectSpread({}, pseudo), {}, {
|
|
181
|
+
marginTop: trims.baselineTrim
|
|
182
|
+
})
|
|
183
|
+
} : null;
|
|
184
|
+
return _objectSpread({
|
|
185
|
+
fontSize: fontSize,
|
|
186
|
+
fontWeight: includeWeight ? fontWeight : undefined,
|
|
187
|
+
lineHeight: lineHeight
|
|
188
|
+
}, leadingTrim);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
var _excluded = ["as", "children", "data", "id", "align", "baseline", "css", "inline", "overflowStrategy", "size", "tabularNumbers", "tone", "transform", "weight", "numberOfLines"];
|
|
192
|
+
var Text = ts.forwardRefWithAs(function (_ref, forwardedRef) {
|
|
193
|
+
var as = _ref.as,
|
|
194
|
+
children = _ref.children,
|
|
195
|
+
data = _ref.data,
|
|
196
|
+
id = _ref.id,
|
|
197
|
+
align = _ref.align,
|
|
198
|
+
baselineProp = _ref.baseline,
|
|
199
|
+
cssProps = _ref.css,
|
|
200
|
+
inline = _ref.inline,
|
|
201
|
+
overflowStrategy = _ref.overflowStrategy,
|
|
202
|
+
sizeProp = _ref.size,
|
|
203
|
+
tabularNumbers = _ref.tabularNumbers,
|
|
204
|
+
toneProp = _ref.tone,
|
|
205
|
+
transform = _ref.transform,
|
|
206
|
+
weightProp = _ref.weight,
|
|
207
|
+
numberOfLines = _ref.numberOfLines,
|
|
208
|
+
consumerProps = _objectWithoutProperties(_ref, _excluded);
|
|
209
|
+
var overflowStyles = useOverflowStrategy(overflowStrategy);
|
|
210
|
+
var textContext = useTextContext();
|
|
211
|
+
var _useDefaultTextProps = useDefaultTextProps({
|
|
212
|
+
size: sizeProp !== null && sizeProp !== void 0 ? sizeProp : textContext === null || textContext === void 0 ? void 0 : textContext.size,
|
|
213
|
+
tone: toneProp !== null && toneProp !== void 0 ? toneProp : textContext === null || textContext === void 0 ? void 0 : textContext.tone,
|
|
214
|
+
weight: weightProp !== null && weightProp !== void 0 ? weightProp : textContext === null || textContext === void 0 ? void 0 : textContext.weight
|
|
215
|
+
}),
|
|
216
|
+
size = _useDefaultTextProps.size,
|
|
217
|
+
tone = _useDefaultTextProps.tone,
|
|
218
|
+
weight = _useDefaultTextProps.weight;
|
|
219
|
+
var baseline = !inline && baselineProp;
|
|
220
|
+
var textStyles = useText({
|
|
221
|
+
baseline: baseline,
|
|
222
|
+
size: size,
|
|
223
|
+
tone: tone,
|
|
224
|
+
weight: weight
|
|
225
|
+
});
|
|
226
|
+
var numberOfLinesStyle = useNumberOfLines(numberOfLines);
|
|
227
|
+
var styles = [textStyles, {
|
|
228
|
+
display: inline ? 'inline' : 'block',
|
|
229
|
+
fontVariantNumeric: tabularNumbers ? 'tabular-nums' : undefined,
|
|
230
|
+
textAlign: align,
|
|
231
|
+
textTransform: transform
|
|
232
|
+
}];
|
|
233
|
+
|
|
234
|
+
// early exit for inline variant
|
|
235
|
+
if (inline) {
|
|
236
|
+
return jsxRuntime.jsx(box.Box, _objectSpread(_objectSpread({}, consumerProps), {}, {
|
|
237
|
+
as: as !== null && as !== void 0 ? as : 'span',
|
|
238
|
+
data: data,
|
|
239
|
+
ref: forwardedRef,
|
|
240
|
+
id: id,
|
|
241
|
+
css: react$1.css(styles, cssProps),
|
|
242
|
+
children: children
|
|
243
|
+
}));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// prepare block variant
|
|
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
|
+
};
|
|
262
|
+
var textContextValue = react.useMemo(function () {
|
|
263
|
+
return {
|
|
264
|
+
size: size,
|
|
265
|
+
tone: tone,
|
|
266
|
+
weight: weight
|
|
267
|
+
};
|
|
268
|
+
}, [size, tone, weight]);
|
|
269
|
+
return jsxRuntime.jsx(TextContext.Provider, {
|
|
270
|
+
value: textContextValue,
|
|
271
|
+
children: jsxRuntime.jsx(box.Box, _objectSpread(_objectSpread({}, consumerProps), {}, {
|
|
272
|
+
as: as,
|
|
273
|
+
data: data,
|
|
274
|
+
ref: forwardedRef,
|
|
275
|
+
id: id,
|
|
276
|
+
css: react$1.css(styles, cssProps),
|
|
277
|
+
children: content()
|
|
278
|
+
}))
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
exports.DefaultTextPropsProvider = DefaultTextPropsProvider;
|
|
283
|
+
exports.Strong = Strong;
|
|
284
|
+
exports.Text = Text;
|
|
285
|
+
exports.createTextStyles = createTextStyles;
|
|
286
|
+
exports.useDefaultTextProps = useDefaultTextProps;
|
|
287
|
+
exports.useForegroundTone = useForegroundTone;
|
|
288
|
+
exports.useNumberOfLines = useNumberOfLines;
|
|
289
|
+
exports.useOverflowStrategy = useOverflowStrategy;
|
|
290
|
+
exports.useText = useText;
|
|
291
|
+
exports.useTextContext = useTextContext;
|