@instructure/ui-truncate-text 11.7.8 → 11.7.9-pr-snapshot-1792147648392
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 +13 -0
- package/es/TruncateText/v1/index.js +195 -245
- package/es/TruncateText/v1/props.js +12 -26
- package/es/TruncateText/v1/styles.js +23 -57
- package/es/TruncateText/v1/theme.js +10 -41
- package/es/TruncateText/v1/utils/cleanData.js +98 -151
- package/es/TruncateText/v1/utils/cleanString.js +14 -51
- package/es/TruncateText/v1/utils/measureText.js +35 -69
- package/es/TruncateText/v1/utils/truncate.js +237 -322
- package/es/TruncateText/v2/index.js +191 -244
- package/es/TruncateText/v2/props.js +12 -26
- package/es/TruncateText/v2/styles.js +22 -56
- package/es/TruncateText/v2/utils/cleanData.js +98 -151
- package/es/TruncateText/v2/utils/cleanString.js +14 -51
- package/es/TruncateText/v2/utils/measureText.js +35 -69
- package/es/TruncateText/v2/utils/truncate.js +236 -321
- package/es/exports/a.js +1 -24
- package/es/exports/b.js +1 -24
- package/package.json +15 -21
- package/tsconfig.build.json +0 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/lib/TruncateText/v1/index.js +0 -278
- package/lib/TruncateText/v1/props.js +0 -31
- package/lib/TruncateText/v1/styles.js +0 -64
- package/lib/TruncateText/v1/theme.js +0 -48
- package/lib/TruncateText/v1/utils/cleanData.js +0 -166
- package/lib/TruncateText/v1/utils/cleanString.js +0 -59
- package/lib/TruncateText/v1/utils/measureText.js +0 -79
- package/lib/TruncateText/v1/utils/truncate.js +0 -353
- package/lib/TruncateText/v2/index.js +0 -275
- package/lib/TruncateText/v2/props.js +0 -31
- package/lib/TruncateText/v2/styles.js +0 -63
- package/lib/TruncateText/v2/utils/cleanData.js +0 -166
- package/lib/TruncateText/v2/utils/cleanString.js +0 -59
- package/lib/TruncateText/v2/utils/measureText.js +0 -79
- package/lib/TruncateText/v2/utils/truncate.js +0 -353
- package/lib/exports/a.js +0 -12
- package/lib/exports/b.js +0 -12
- package/lib/package.json +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,19 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [11.7.9-pr-snapshot-1792147648392](https://github.com/instructure/instructure-ui/compare/v11.7.8...v11.7.9-pr-snapshot-1792147648392) (2026-10-16)
|
|
7
|
+
|
|
8
|
+
### Build System
|
|
9
|
+
|
|
10
|
+
* **many:** replace babel with swc ([7e36c54](https://github.com/instructure/instructure-ui/commit/7e36c54d240b4fa483801c03ab18e7f860f561e2))
|
|
11
|
+
|
|
12
|
+
### BREAKING CHANGES
|
|
13
|
+
|
|
14
|
+
* **many:** `@instructure/ui-babel-preset` and
|
|
15
|
+
`@instructure/browserslist-config-instui` are removed and will no longer be
|
|
16
|
+
published. Packages depend on `@swc/helpers` instead of `@babel/runtime`.
|
|
17
|
+
|
|
18
|
+
|
|
6
19
|
## [11.7.8](https://github.com/instructure/instructure-ui/compare/v11.7.7...v11.7.8) (2026-10-02)
|
|
7
20
|
|
|
8
21
|
**Note:** Version bump only for package @instructure/ui-truncate-text
|
|
@@ -1,28 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* The MIT License (MIT)
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
-
*
|
|
7
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
-
* in the Software without restriction, including without limitation the rights
|
|
10
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
-
* furnished to do so, subject to the following conditions:
|
|
13
|
-
*
|
|
14
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
-
* copies or substantial portions of the Software.
|
|
16
|
-
*
|
|
17
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
-
* SOFTWARE.
|
|
24
|
-
*/
|
|
25
|
-
|
|
1
|
+
import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
26
3
|
import { Children, Component } from 'react';
|
|
27
4
|
import { debounce } from '@instructure/debounce';
|
|
28
5
|
import { canUseDOM, getBoundingClientRect } from '@instructure/ui-dom-utils';
|
|
@@ -33,239 +10,212 @@ import generateStyle from './styles.js';
|
|
|
33
10
|
import generateComponentTheme from './theme.js';
|
|
34
11
|
import truncate from './utils/truncate.js';
|
|
35
12
|
import { allowedProps } from './props.js';
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
get _ref() {
|
|
66
|
-
return this.ref;
|
|
67
|
-
}
|
|
68
|
-
get initialState() {
|
|
69
|
-
return {
|
|
70
|
-
isTruncated: false,
|
|
71
|
-
needsSecondRender: true,
|
|
72
|
-
truncatedElement: undefined,
|
|
73
|
-
truncatedText: undefined
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
componentDidMount() {
|
|
77
|
-
const {
|
|
78
|
-
children,
|
|
79
|
-
makeStyles
|
|
80
|
-
} = this.props;
|
|
81
|
-
makeStyles?.();
|
|
82
|
-
if (children) {
|
|
83
|
-
this.checkChildren();
|
|
84
|
-
const txt = ensureSingleChild(children);
|
|
85
|
-
this._text = txt ? txt : undefined;
|
|
86
|
-
this.truncate();
|
|
87
|
-
this._debounced = debounce(this.update, this.props.debounce, {
|
|
88
|
-
leading: true,
|
|
89
|
-
trailing: true
|
|
90
|
-
});
|
|
91
|
-
this._prevWidth = getBoundingClientRect(this.ref)?.width;
|
|
92
|
-
this._resizeListener = new ResizeObserver(entries => {
|
|
93
|
-
// requestAnimationFrame call is needed becuase some truncatetext test cases
|
|
94
|
-
// failed due to ResizeObserver was not able to deliver all observations within a single animation frame
|
|
95
|
-
// see: https://stackoverflow.com/questions/49384120/resizeobserver-loop-limit-exceeded
|
|
96
|
-
requestAnimationFrame(() => {
|
|
97
|
-
for (const entry of entries) {
|
|
98
|
-
const {
|
|
99
|
-
width
|
|
100
|
-
} = entry.contentRect;
|
|
101
|
-
if (this._prevWidth !== width) {
|
|
102
|
-
this._prevWidth = width;
|
|
103
|
-
this.props.debounce === 0 ? this.update() : this._debounced();
|
|
13
|
+
class TruncateText extends Component {
|
|
14
|
+
static{
|
|
15
|
+
this.displayName = 'TruncateText';
|
|
16
|
+
}
|
|
17
|
+
static{
|
|
18
|
+
this.componentId = 'TruncateText';
|
|
19
|
+
}
|
|
20
|
+
static{
|
|
21
|
+
this.allowedProps = allowedProps;
|
|
22
|
+
}
|
|
23
|
+
static{
|
|
24
|
+
this.defaultProps = {
|
|
25
|
+
maxLines: 1,
|
|
26
|
+
ellipsis: '\u2026',
|
|
27
|
+
truncate: 'character',
|
|
28
|
+
position: 'end',
|
|
29
|
+
ignore: [
|
|
30
|
+
' ',
|
|
31
|
+
'.',
|
|
32
|
+
','
|
|
33
|
+
],
|
|
34
|
+
debounce: 0
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
constructor(props){
|
|
38
|
+
super(props), this.ref = null, this._stage = null, this._prevWidth = null, this.update = ()=>{
|
|
39
|
+
if (this.ref) {
|
|
40
|
+
this.setState(this.initialState);
|
|
104
41
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
});
|
|
108
|
-
this._resizeListener.observe(this.ref);
|
|
42
|
+
};
|
|
43
|
+
this.state = this.initialState;
|
|
109
44
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
this._resizeListener.disconnect();
|
|
45
|
+
get _ref() {
|
|
46
|
+
void 0;
|
|
47
|
+
return this.ref;
|
|
114
48
|
}
|
|
115
|
-
|
|
116
|
-
|
|
49
|
+
get initialState() {
|
|
50
|
+
return {
|
|
51
|
+
isTruncated: false,
|
|
52
|
+
needsSecondRender: true,
|
|
53
|
+
truncatedElement: undefined,
|
|
54
|
+
truncatedText: undefined
|
|
55
|
+
};
|
|
117
56
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
57
|
+
componentDidMount() {
|
|
58
|
+
const { children, makeStyles } = this.props;
|
|
59
|
+
makeStyles?.();
|
|
60
|
+
if (children) {
|
|
61
|
+
this.checkChildren();
|
|
62
|
+
const txt = ensureSingleChild(children);
|
|
63
|
+
this._text = txt ? txt : undefined;
|
|
64
|
+
this.truncate();
|
|
65
|
+
this._debounced = debounce(this.update, this.props.debounce, {
|
|
66
|
+
leading: true,
|
|
67
|
+
trailing: true
|
|
68
|
+
});
|
|
69
|
+
this._prevWidth = getBoundingClientRect(this.ref)?.width;
|
|
70
|
+
this._resizeListener = new ResizeObserver((entries)=>{
|
|
71
|
+
requestAnimationFrame(()=>{
|
|
72
|
+
for (const entry of entries){
|
|
73
|
+
const { width } = entry.contentRect;
|
|
74
|
+
if (this._prevWidth !== width) {
|
|
75
|
+
this._prevWidth = width;
|
|
76
|
+
this.props.debounce === 0 ? this.update() : this._debounced();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
this._resizeListener.observe(this.ref);
|
|
82
|
+
}
|
|
124
83
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
84
|
+
componentWillUnmount() {
|
|
85
|
+
if (this._resizeListener) {
|
|
86
|
+
this._resizeListener.disconnect();
|
|
87
|
+
}
|
|
88
|
+
if (this._debounced) {
|
|
89
|
+
this._debounced.cancel();
|
|
90
|
+
}
|
|
129
91
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
isTruncated,
|
|
141
|
-
needsSecondRender,
|
|
142
|
-
truncatedText
|
|
143
|
-
} = this.state;
|
|
144
|
-
if (children) {
|
|
145
|
-
// for some reason in React 19 prevPros and this.props are a different
|
|
146
|
-
// object even if their contents are the same, so we cannot use !==
|
|
147
|
-
if (!this.shallowCompare(prevProps, this.props)) {
|
|
148
|
-
if (prevProps.children !== this.props.children) {
|
|
149
|
-
// reset internal text variable if children change
|
|
150
|
-
this.checkChildren();
|
|
151
|
-
const txt = ensureSingleChild(children);
|
|
152
|
-
this._text = txt ? txt : undefined;
|
|
92
|
+
shallowCompare(obj1, obj2) {
|
|
93
|
+
const keys1 = Object.keys(obj1);
|
|
94
|
+
const keys2 = Object.keys(obj2);
|
|
95
|
+
if (keys1.length !== keys2.length) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
for (const key of keys1){
|
|
99
|
+
if (obj1[key] !== obj2[key]) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
153
102
|
}
|
|
154
|
-
|
|
155
|
-
this.setState(this.initialState);
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
if (!needsSecondRender && (isTruncated || this._wasTruncated)) {
|
|
159
|
-
onUpdate?.(isTruncated, truncatedText);
|
|
160
|
-
this._wasTruncated = isTruncated;
|
|
161
|
-
} else {
|
|
162
|
-
this.truncate();
|
|
163
|
-
}
|
|
103
|
+
return true;
|
|
164
104
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
105
|
+
componentDidUpdate(prevProps) {
|
|
106
|
+
const { children, onUpdate, makeStyles } = this.props;
|
|
107
|
+
makeStyles?.();
|
|
108
|
+
const { isTruncated, needsSecondRender, truncatedText } = this.state;
|
|
109
|
+
if (children) {
|
|
110
|
+
if (!this.shallowCompare(prevProps, this.props)) {
|
|
111
|
+
if (prevProps.children !== this.props.children) {
|
|
112
|
+
this.checkChildren();
|
|
113
|
+
const txt = ensureSingleChild(children);
|
|
114
|
+
this._text = txt ? txt : undefined;
|
|
115
|
+
}
|
|
116
|
+
this.setState(this.initialState);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (!needsSecondRender && (isTruncated || this._wasTruncated)) {
|
|
120
|
+
onUpdate?.(isTruncated, truncatedText);
|
|
121
|
+
this._wasTruncated = isTruncated;
|
|
122
|
+
} else {
|
|
123
|
+
this.truncate();
|
|
177
124
|
}
|
|
178
|
-
});
|
|
179
125
|
}
|
|
180
|
-
});
|
|
181
|
-
return isTooDeep;
|
|
182
|
-
})(), `[TruncateText] Some children are too deep in the node tree and will not render.`);
|
|
183
|
-
}
|
|
184
|
-
update = () => {
|
|
185
|
-
if (this.ref) {
|
|
186
|
-
this.setState(this.initialState);
|
|
187
126
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
127
|
+
checkChildren() {
|
|
128
|
+
error(!(()=>{
|
|
129
|
+
let isTooDeep = false;
|
|
130
|
+
const text = ensureSingleChild(this.props.children);
|
|
131
|
+
Children.forEach(text.props.children, (child)=>{
|
|
132
|
+
if (child.props) {
|
|
133
|
+
Children.forEach(child.props.children, (grandChild)=>{
|
|
134
|
+
if (grandChild.props) {
|
|
135
|
+
isTooDeep = true;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
return isTooDeep;
|
|
141
|
+
})(), `[TruncateText] Some children are too deep in the node tree and will not render.`);
|
|
192
142
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
143
|
+
truncate() {
|
|
144
|
+
if (!this.state.needsSecondRender) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (canUseDOM) {
|
|
148
|
+
const result = truncate(this._stage, {
|
|
149
|
+
...this.props,
|
|
150
|
+
parent: this.ref ? this.ref : undefined,
|
|
151
|
+
lineHeight: this.props.styles?.lineHeight
|
|
152
|
+
});
|
|
153
|
+
if (result) {
|
|
154
|
+
const element = this.renderChildren(result.isTruncated, result.data, result.constraints.width);
|
|
155
|
+
this.setState({
|
|
156
|
+
needsSecondRender: false,
|
|
157
|
+
isTruncated: result.isTruncated,
|
|
158
|
+
truncatedElement: element,
|
|
159
|
+
truncatedText: result.text
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
} else {
|
|
163
|
+
const textContent = this.ref?.textContent ? this.ref?.textContent : undefined;
|
|
164
|
+
this.setState({
|
|
165
|
+
needsSecondRender: false,
|
|
166
|
+
isTruncated: false,
|
|
167
|
+
truncatedElement: this._text,
|
|
168
|
+
truncatedText: textContent
|
|
169
|
+
});
|
|
170
|
+
}
|
|
217
171
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
172
|
+
renderChildren(truncated, data, width) {
|
|
173
|
+
if (!truncated) {
|
|
174
|
+
return this._text;
|
|
175
|
+
}
|
|
176
|
+
const childElements = [];
|
|
177
|
+
for(let i = 0; i < data.length; i++){
|
|
178
|
+
const item = data[i];
|
|
179
|
+
const element = this._text.props.children[i];
|
|
180
|
+
const nodeText = item.join('');
|
|
181
|
+
if (element && element.props) {
|
|
182
|
+
childElements.push(safeCloneElement(element, element.props, nodeText));
|
|
183
|
+
} else {
|
|
184
|
+
childElements.push(nodeText);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
childElements.push(/*#__PURE__*/ _jsx("span", {
|
|
188
|
+
css: this.props.styles?.spacer,
|
|
189
|
+
style: {
|
|
190
|
+
width: width || undefined
|
|
191
|
+
}
|
|
192
|
+
}, "spacer"));
|
|
193
|
+
const children = Children.map(childElements, (child)=>child);
|
|
194
|
+
return this._text.props ? safeCloneElement(this._text, this._text.props, children) : children;
|
|
222
195
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
196
|
+
render() {
|
|
197
|
+
const { truncatedElement } = this.state;
|
|
198
|
+
const { children } = this.props;
|
|
199
|
+
return /*#__PURE__*/ _jsxs("span", {
|
|
200
|
+
"data-cid": "TruncateText",
|
|
201
|
+
css: this.props.styles?.truncateText,
|
|
202
|
+
ref: (el)=>{
|
|
203
|
+
this.ref = el;
|
|
204
|
+
},
|
|
205
|
+
children: [
|
|
206
|
+
children && (truncatedElement ? null : /*#__PURE__*/ _jsx("span", {
|
|
207
|
+
ref: (el)=>{
|
|
208
|
+
this._stage = el;
|
|
209
|
+
},
|
|
210
|
+
children: ensureSingleChild(children)
|
|
211
|
+
})),
|
|
212
|
+
truncatedElement
|
|
213
|
+
]
|
|
214
|
+
});
|
|
235
215
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
css: this.props.styles?.spacer,
|
|
241
|
-
style: {
|
|
242
|
-
width: width || undefined
|
|
243
|
-
}
|
|
244
|
-
}, "spacer"));
|
|
245
|
-
const children = Children.map(childElements, child => child);
|
|
246
|
-
return this._text.props ? safeCloneElement(this._text, this._text.props, children) : children;
|
|
247
|
-
}
|
|
248
|
-
render() {
|
|
249
|
-
const {
|
|
250
|
-
truncatedElement
|
|
251
|
-
} = this.state;
|
|
252
|
-
const {
|
|
253
|
-
children
|
|
254
|
-
} = this.props;
|
|
255
|
-
return _jsxs("span", {
|
|
256
|
-
"data-cid": "TruncateText",
|
|
257
|
-
css: this.props.styles?.truncateText,
|
|
258
|
-
ref: el => {
|
|
259
|
-
this.ref = el;
|
|
260
|
-
},
|
|
261
|
-
children: [children && (truncatedElement ? null : _jsx("span", {
|
|
262
|
-
ref: el => {
|
|
263
|
-
this._stage = el;
|
|
264
|
-
},
|
|
265
|
-
children: ensureSingleChild(children)
|
|
266
|
-
})), truncatedElement]
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
}) || _class);
|
|
216
|
+
}
|
|
217
|
+
TruncateText = _ts_decorate([
|
|
218
|
+
withStyle(generateStyle, generateComponentTheme)
|
|
219
|
+
], TruncateText);
|
|
270
220
|
export default TruncateText;
|
|
271
|
-
export { TruncateText };
|
|
221
|
+
export { TruncateText };
|
|
@@ -1,26 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
const allowedProps = ['children', 'maxLines', 'position', 'truncate', 'ellipsis', 'ignore', 'debounce', 'onUpdate', 'shouldTruncateWhenInvisible'];
|
|
26
|
-
export { allowedProps };
|
|
1
|
+
const allowedProps = [
|
|
2
|
+
'children',
|
|
3
|
+
'maxLines',
|
|
4
|
+
'position',
|
|
5
|
+
'truncate',
|
|
6
|
+
'ellipsis',
|
|
7
|
+
'ignore',
|
|
8
|
+
'debounce',
|
|
9
|
+
'onUpdate',
|
|
10
|
+
'shouldTruncateWhenInvisible'
|
|
11
|
+
];
|
|
12
|
+
export { allowedProps };
|
|
@@ -1,58 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* ---
|
|
27
|
-
* private: true
|
|
28
|
-
* ---
|
|
29
|
-
* Generates the style object from the theme and provided additional information
|
|
30
|
-
* @param {Object} componentTheme The theme variable object.
|
|
31
|
-
* @param {Object} props the props of the component, the style is applied to
|
|
32
|
-
* @param {Object} state the state of the component, the style is applied to
|
|
33
|
-
* @return {Object} The final style object, which will be used in the component
|
|
34
|
-
*/
|
|
35
|
-
const generateStyle = componentTheme => {
|
|
36
|
-
return {
|
|
37
|
-
truncateText: {
|
|
38
|
-
label: 'truncateText',
|
|
39
|
-
display: 'block',
|
|
40
|
-
overflow: 'hidden',
|
|
41
|
-
wordWrap: 'break-word',
|
|
42
|
-
whiteSpace: 'normal',
|
|
43
|
-
fontFamily: componentTheme.fontFamily
|
|
44
|
-
},
|
|
45
|
-
auto: {
|
|
46
|
-
label: 'truncateText__auto',
|
|
47
|
-
height: '100%'
|
|
48
|
-
},
|
|
49
|
-
spacer: {
|
|
50
|
-
label: 'truncateText__spacer',
|
|
51
|
-
visibility: 'hidden',
|
|
52
|
-
maxHeight: '0',
|
|
53
|
-
display: 'block'
|
|
54
|
-
},
|
|
55
|
-
lineHeight: componentTheme.lineHeight
|
|
56
|
-
};
|
|
1
|
+
const generateStyle = (componentTheme)=>{
|
|
2
|
+
return {
|
|
3
|
+
truncateText: {
|
|
4
|
+
label: 'truncateText',
|
|
5
|
+
display: 'block',
|
|
6
|
+
overflow: 'hidden',
|
|
7
|
+
wordWrap: 'break-word',
|
|
8
|
+
whiteSpace: 'normal',
|
|
9
|
+
fontFamily: componentTheme.fontFamily
|
|
10
|
+
},
|
|
11
|
+
auto: {
|
|
12
|
+
label: 'truncateText__auto',
|
|
13
|
+
height: '100%'
|
|
14
|
+
},
|
|
15
|
+
spacer: {
|
|
16
|
+
label: 'truncateText__spacer',
|
|
17
|
+
visibility: 'hidden',
|
|
18
|
+
maxHeight: '0',
|
|
19
|
+
display: 'block'
|
|
20
|
+
},
|
|
21
|
+
lineHeight: componentTheme.lineHeight
|
|
22
|
+
};
|
|
57
23
|
};
|
|
58
|
-
export default generateStyle;
|
|
24
|
+
export default generateStyle;
|
|
@@ -1,42 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Generates the theme object for the component from the theme and provided additional information
|
|
27
|
-
* @param {Object} theme The actual theme object.
|
|
28
|
-
* @return {Object} The final theme object with the overrides and component variables
|
|
29
|
-
*/
|
|
30
|
-
const generateComponentTheme = theme => {
|
|
31
|
-
const {
|
|
32
|
-
typography
|
|
33
|
-
} = theme;
|
|
34
|
-
const componentVariables = {
|
|
35
|
-
fontFamily: typography?.fontFamily,
|
|
36
|
-
lineHeight: typography?.lineHeight
|
|
37
|
-
};
|
|
38
|
-
return {
|
|
39
|
-
...componentVariables
|
|
40
|
-
};
|
|
1
|
+
const generateComponentTheme = (theme)=>{
|
|
2
|
+
const { typography } = theme;
|
|
3
|
+
const componentVariables = {
|
|
4
|
+
fontFamily: typography?.fontFamily,
|
|
5
|
+
lineHeight: typography?.lineHeight
|
|
6
|
+
};
|
|
7
|
+
return {
|
|
8
|
+
...componentVariables
|
|
9
|
+
};
|
|
41
10
|
};
|
|
42
|
-
export default generateComponentTheme;
|
|
11
|
+
export default generateComponentTheme;
|