@sybilion/uilib 1.4.12 → 1.4.13

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.
Files changed (30) hide show
  1. package/dist/esm/components/ui/Button/Button.styl.js +1 -1
  2. package/dist/esm/components/ui/Sidebar/Sidebar.js +20 -7
  3. package/dist/esm/components/ui/Sidebar/Sidebar.styl.js +2 -2
  4. package/dist/esm/components/ui/SmartTextTruncate/SmartTextTruncate.js +260 -67
  5. package/dist/esm/components/ui/SmartTextTruncate/SmartTextTruncate.styl.js +7 -0
  6. package/dist/esm/components/widgets/SidebarDatasetsItemsGrouped/SidebarDatasetsItemsGrouped.js +5 -5
  7. package/dist/esm/components/widgets/SidebarDatasetsItemsGrouped/SidebarDatasetsItemsGrouped.styl.js +2 -2
  8. package/dist/esm/index.js +1 -1
  9. package/dist/esm/types/src/components/ui/Chat/ChatSheet/ChatSheet.d.ts +1 -1
  10. package/dist/esm/types/src/components/ui/Sidebar/Sidebar.d.ts +7 -2
  11. package/dist/esm/types/src/components/ui/SmartTextTruncate/SmartTextTruncate.d.ts +5 -3
  12. package/dist/esm/types/src/components/ui/SmartTextTruncate/index.d.ts +1 -1
  13. package/package.json +1 -1
  14. package/src/components/ui/Button/Button.styl +2 -2
  15. package/src/components/ui/Chat/ChatSheet/ChatSheet.tsx +1 -1
  16. package/src/components/ui/Sidebar/Sidebar.styl +60 -50
  17. package/src/components/ui/Sidebar/Sidebar.styl.d.ts +4 -0
  18. package/src/components/ui/Sidebar/Sidebar.tsx +66 -6
  19. package/src/components/ui/SmartTextTruncate/SmartTextTruncate.styl +34 -0
  20. package/src/components/ui/SmartTextTruncate/SmartTextTruncate.styl.d.ts +10 -0
  21. package/src/components/ui/SmartTextTruncate/SmartTextTruncate.tsx +335 -81
  22. package/src/components/ui/SmartTextTruncate/index.ts +5 -1
  23. package/src/components/widgets/SidebarDatasetsItemsGrouped/SidebarDatasetsItemsGrouped.styl +0 -24
  24. package/src/components/widgets/SidebarDatasetsItemsGrouped/SidebarDatasetsItemsGrouped.styl.d.ts +0 -2
  25. package/src/components/widgets/SidebarDatasetsItemsGrouped/SidebarDatasetsItemsGrouped.tsx +5 -11
  26. package/src/docs/components/DocsSidebar/DocsSidebar.tsx +3 -17
  27. package/src/docs/pages/SidebarDatasetsItemsGroupedPage.tsx +4 -1
  28. package/src/docs/pages/SmartTextTruncatePage.styl +22 -0
  29. package/src/docs/pages/SmartTextTruncatePage.styl.d.ts +2 -0
  30. package/src/docs/pages/SmartTextTruncatePage.tsx +21 -1
@@ -1,108 +1,371 @@
1
- import { useLayoutEffect, useRef, useState } from 'react';
1
+ import cn from 'classnames';
2
+ import { memo, useCallback, useLayoutEffect, useRef, useState } from 'react';
2
3
 
4
+ import S from './SmartTextTruncate.styl';
3
5
  import type { SmartTextTruncateProps } from './SmartTextTruncate.types';
4
6
 
5
7
  const ELLIPSIS = ' ... ';
6
8
  const END_CHARS_COUNT = 10;
9
+ const RESIZE_SETTLE_MS = 120;
10
+ const GLOBAL_KEY = '__sybilionSmartTextTruncate';
11
+ const RESIZE_ROOT_SELECTOR = '[data-smart-text-truncate-resize-root]';
12
+ const DRAG_THRESHOLD_PX = 3;
7
13
 
8
- function SmartTextTruncate({
14
+ type InteractionStore = {
15
+ isPanelDragging: boolean;
16
+ isResizeRootDragging: boolean;
17
+ };
18
+
19
+ type GlobalState = {
20
+ store: InteractionStore;
21
+ settleTimer: ReturnType<typeof setTimeout> | null;
22
+ resizeRafId: number;
23
+ recalcCallbacks: Set<() => void>;
24
+ resizeRootListenersInit: boolean;
25
+ panelDragActive: boolean;
26
+ };
27
+
28
+ type PendingResizeRootDrag = {
29
+ pointerId: number;
30
+ startX: number;
31
+ startY: number;
32
+ };
33
+
34
+ function getGlobalState(): GlobalState {
35
+ const w = window as Window & { [GLOBAL_KEY]?: GlobalState };
36
+ if (!w[GLOBAL_KEY]) {
37
+ w[GLOBAL_KEY] = {
38
+ store: {
39
+ isPanelDragging: false,
40
+ isResizeRootDragging: false,
41
+ },
42
+ settleTimer: null,
43
+ resizeRafId: 0,
44
+ recalcCallbacks: new Set(),
45
+ resizeRootListenersInit: false,
46
+ panelDragActive: false,
47
+ };
48
+ }
49
+ return w[GLOBAL_KEY];
50
+ }
51
+
52
+ let pendingResizeRootDrag: PendingResizeRootDrag | null = null;
53
+
54
+ function getIsFastMode(store: InteractionStore) {
55
+ return store.isPanelDragging || store.isResizeRootDragging;
56
+ }
57
+
58
+ function syncFastModeDom(store: InteractionStore) {
59
+ if (typeof document === 'undefined') {
60
+ return;
61
+ }
62
+ if (getIsFastMode(store)) {
63
+ document.documentElement.dataset.smartTextTruncateFast = '';
64
+ } else {
65
+ delete document.documentElement.dataset.smartTextTruncateFast;
66
+ }
67
+ }
68
+
69
+ function clearSettleTimer() {
70
+ const g = getGlobalState();
71
+ if (g.settleTimer) {
72
+ clearTimeout(g.settleTimer);
73
+ g.settleTimer = null;
74
+ }
75
+ }
76
+
77
+ function runSettleRecalc() {
78
+ getGlobalState().recalcCallbacks.forEach(recalc => recalc());
79
+ }
80
+
81
+ function scheduleSettle() {
82
+ const g = getGlobalState();
83
+ clearSettleTimer();
84
+
85
+ g.settleTimer = setTimeout(() => {
86
+ g.settleTimer = null;
87
+ runSettleRecalc();
88
+ }, RESIZE_SETTLE_MS);
89
+ }
90
+
91
+ function notifyContainerResize() {
92
+ const g = getGlobalState();
93
+ if (getIsFastMode(g.store)) {
94
+ return;
95
+ }
96
+ scheduleSettle();
97
+ }
98
+
99
+ function beginResizeRootDrag() {
100
+ const g = getGlobalState();
101
+ if (g.store.isResizeRootDragging) {
102
+ return;
103
+ }
104
+
105
+ clearSettleTimer();
106
+ g.store = { ...g.store, isResizeRootDragging: true };
107
+ syncFastModeDom(g.store);
108
+ }
109
+
110
+ function endResizeRootDrag() {
111
+ const g = getGlobalState();
112
+ pendingResizeRootDrag = null;
113
+
114
+ if (!g.store.isResizeRootDragging) {
115
+ return;
116
+ }
117
+
118
+ g.store = { ...g.store, isResizeRootDragging: false };
119
+ syncFastModeDom(g.store);
120
+ scheduleSettle();
121
+ }
122
+
123
+ function onResizeRootPointerDown(e: PointerEvent) {
124
+ if (e.button !== 0) {
125
+ return;
126
+ }
127
+
128
+ const root = (e.target as Element | null)?.closest(RESIZE_ROOT_SELECTOR);
129
+ if (!root) {
130
+ return;
131
+ }
132
+
133
+ clearSettleTimer();
134
+ pendingResizeRootDrag = {
135
+ pointerId: e.pointerId,
136
+ startX: e.clientX,
137
+ startY: e.clientY,
138
+ };
139
+ }
140
+
141
+ function onResizeRootPointerMove(e: PointerEvent) {
142
+ const pending = pendingResizeRootDrag;
143
+ if (!pending || e.pointerId !== pending.pointerId) {
144
+ return;
145
+ }
146
+
147
+ const dx = e.clientX - pending.startX;
148
+ const dy = e.clientY - pending.startY;
149
+ if (Math.hypot(dx, dy) < DRAG_THRESHOLD_PX) {
150
+ return;
151
+ }
152
+
153
+ beginResizeRootDrag();
154
+ }
155
+
156
+ function onResizeRootPointerUp(e: PointerEvent) {
157
+ const pending = pendingResizeRootDrag;
158
+ if (!pending || e.pointerId !== pending.pointerId) {
159
+ return;
160
+ }
161
+
162
+ endResizeRootDrag();
163
+ }
164
+
165
+ function ensureResizeRootListeners() {
166
+ const g = getGlobalState();
167
+ if (g.resizeRootListenersInit) {
168
+ return;
169
+ }
170
+ g.resizeRootListenersInit = true;
171
+ window.addEventListener('pointerdown', onResizeRootPointerDown);
172
+ window.addEventListener('pointermove', onResizeRootPointerMove);
173
+ window.addEventListener('pointerup', onResizeRootPointerUp);
174
+ window.addEventListener('pointercancel', onResizeRootPointerUp);
175
+ }
176
+
177
+ function scheduleContainerResize() {
178
+ const g = getGlobalState();
179
+ if (g.resizeRafId !== 0) {
180
+ return;
181
+ }
182
+ g.resizeRafId = requestAnimationFrame(() => {
183
+ g.resizeRafId = 0;
184
+ notifyContainerResize();
185
+ });
186
+ }
187
+
188
+ let sharedResizeObserver: ResizeObserver | null = null;
189
+ let widthProbe: Element | null = null;
190
+
191
+ function observeWidthProbe(container: Element) {
192
+ if (widthProbe) {
193
+ return;
194
+ }
195
+
196
+ if (!sharedResizeObserver) {
197
+ sharedResizeObserver = new ResizeObserver(() => {
198
+ const g = getGlobalState();
199
+ if (getIsFastMode(g.store)) {
200
+ return;
201
+ }
202
+ scheduleContainerResize();
203
+ });
204
+ }
205
+
206
+ widthProbe = container;
207
+ sharedResizeObserver.observe(container);
208
+ }
209
+
210
+ function unobserveWidthProbe(container: Element) {
211
+ if (widthProbe !== container) {
212
+ return;
213
+ }
214
+
215
+ sharedResizeObserver?.unobserve(container);
216
+ widthProbe = null;
217
+ }
218
+
219
+ /** Panel resize handle — call on first pointer move after press, not on pointer down. */
220
+ function notifyPanelWidthDragStart() {
221
+ const g = getGlobalState();
222
+ if (g.panelDragActive) {
223
+ return;
224
+ }
225
+
226
+ clearSettleTimer();
227
+ g.panelDragActive = true;
228
+ g.store = { ...g.store, isPanelDragging: true };
229
+ syncFastModeDom(g.store);
230
+ }
231
+
232
+ function notifyPanelWidthDragEnd() {
233
+ const g = getGlobalState();
234
+ if (!g.panelDragActive) {
235
+ return;
236
+ }
237
+
238
+ g.panelDragActive = false;
239
+ g.store = { ...g.store, isPanelDragging: false };
240
+ syncFastModeDom(g.store);
241
+ scheduleSettle();
242
+ }
243
+
244
+ function computeTruncatedText(
245
+ fullTextEl: HTMLSpanElement,
246
+ text: string,
247
+ containerWidth: number,
248
+ ): string {
249
+ if (text.length <= END_CHARS_COUNT) {
250
+ return text;
251
+ }
252
+
253
+ fullTextEl.textContent = text;
254
+ if (fullTextEl.scrollWidth <= containerWidth) {
255
+ return text;
256
+ }
257
+
258
+ const endPart = text.slice(-END_CHARS_COUNT);
259
+ let left = 0;
260
+ let right = text.length - END_CHARS_COUNT;
261
+ let bestStart = 0;
262
+
263
+ while (left <= right) {
264
+ const mid = Math.floor((left + right) / 2);
265
+ const startPart = text.slice(0, mid);
266
+ const truncated = startPart + ELLIPSIS + endPart;
267
+
268
+ fullTextEl.textContent = truncated;
269
+ if (fullTextEl.scrollWidth <= containerWidth) {
270
+ bestStart = mid;
271
+ left = mid + 1;
272
+ } else {
273
+ right = mid - 1;
274
+ }
275
+ }
276
+
277
+ if (bestStart === 0) {
278
+ fullTextEl.textContent = ELLIPSIS + endPart;
279
+ if (fullTextEl.scrollWidth <= containerWidth) {
280
+ return ELLIPSIS + endPart;
281
+ }
282
+ return endPart;
283
+ }
284
+
285
+ return text.slice(0, bestStart) + ELLIPSIS + endPart;
286
+ }
287
+
288
+ const SmartTextTruncate = memo(function SmartTextTruncate({
9
289
  children,
10
290
  className,
11
291
  ...props
12
292
  }: SmartTextTruncateProps) {
13
293
  const containerRef = useRef<HTMLSpanElement>(null);
14
294
  const fullTextRef = useRef<HTMLSpanElement>(null);
295
+ const lastMeasuredWidthRef = useRef(0);
296
+ const childrenRef = useRef(children);
297
+ childrenRef.current = children;
15
298
  const [displayText, setDisplayText] = useState<string>(
16
299
  typeof children === 'string' ? children : '',
17
300
  );
18
- const [resizeTrigger, setResizeTrigger] = useState(0);
301
+ const displayTextRef = useRef(displayText);
302
+ displayTextRef.current = displayText;
303
+
304
+ const recalc = useCallback(() => {
305
+ if (getIsFastMode(getGlobalState().store)) {
306
+ return;
307
+ }
19
308
 
20
- useLayoutEffect(() => {
21
309
  const container = containerRef.current;
22
310
  const fullText = fullTextRef.current;
311
+ const text = childrenRef.current;
23
312
 
24
- if (!container || !fullText || typeof children !== 'string') {
313
+ if (!container || !fullText || typeof text !== 'string') {
25
314
  return;
26
315
  }
27
316
 
28
- const text = children;
29
-
30
- // If text is shorter than END_CHARS_COUNT, no truncation needed
31
317
  if (text.length <= END_CHARS_COUNT) {
32
- setDisplayText(text);
318
+ if (displayTextRef.current !== text) {
319
+ setDisplayText(text);
320
+ }
33
321
  return;
34
322
  }
35
323
 
36
- // Measure container width
37
324
  const containerWidth = container.clientWidth;
38
325
  if (containerWidth === 0) {
39
- // Container not yet rendered, keep current text
40
326
  return;
41
327
  }
42
328
 
43
- // Measure full text width
44
- fullText.textContent = text;
45
- const fullTextWidth = fullText.scrollWidth;
46
-
47
- // If text fits, show full text
48
- if (fullTextWidth <= containerWidth) {
49
- setDisplayText(text);
329
+ if (
330
+ containerWidth === lastMeasuredWidthRef.current &&
331
+ lastMeasuredWidthRef.current !== 0
332
+ ) {
50
333
  return;
51
334
  }
52
335
 
53
- // Calculate truncated text: <start>...<last 10 chars>
54
- const endPart = text.slice(-END_CHARS_COUNT);
55
-
56
- // Binary search for optimal start length
57
- let left = 0;
58
- let right = text.length - END_CHARS_COUNT;
59
- let bestStart = 0;
336
+ lastMeasuredWidthRef.current = containerWidth;
337
+ const nextText = computeTruncatedText(fullText, text, containerWidth);
60
338
 
61
- while (left <= right) {
62
- const mid = Math.floor((left + right) / 2);
63
- const startPart = text.slice(0, mid);
64
- const truncated = startPart + ELLIPSIS + endPart;
65
-
66
- fullText.textContent = truncated;
67
- const truncatedWidth = fullText.scrollWidth;
68
-
69
- if (truncatedWidth <= containerWidth) {
70
- bestStart = mid;
71
- left = mid + 1;
72
- } else {
73
- right = mid - 1;
74
- }
339
+ if (nextText !== displayTextRef.current) {
340
+ setDisplayText(nextText);
75
341
  }
342
+ }, []);
76
343
 
77
- // Ensure we have at least some start text
78
- if (bestStart === 0) {
79
- // If even just ellipsis + end doesn't fit, show only end part
80
- fullText.textContent = ELLIPSIS + endPart;
81
- if (fullText.scrollWidth <= containerWidth) {
82
- setDisplayText(ELLIPSIS + endPart);
83
- } else {
84
- // Last resort: show only end part without ellipsis
85
- setDisplayText(endPart);
86
- }
87
- } else {
88
- setDisplayText(text.slice(0, bestStart) + ELLIPSIS + endPart);
89
- }
90
- }, [children, resizeTrigger]);
344
+ useLayoutEffect(() => {
345
+ lastMeasuredWidthRef.current = 0;
346
+ recalc();
347
+ }, [children, recalc]);
91
348
 
92
- // Handle ResizeObserver for container resizing
93
349
  useLayoutEffect(() => {
94
- const container = containerRef.current;
95
- if (!container) return;
350
+ ensureResizeRootListeners();
351
+ const g = getGlobalState();
352
+ g.recalcCallbacks.add(recalc);
353
+ return () => {
354
+ g.recalcCallbacks.delete(recalc);
355
+ };
356
+ }, [recalc]);
96
357
 
97
- const resizeObserver = new ResizeObserver(() => {
98
- // Trigger recalculation by updating resizeTrigger
99
- setResizeTrigger(prev => prev + 1);
100
- });
358
+ useLayoutEffect(() => {
359
+ ensureResizeRootListeners();
360
+ const container = containerRef.current;
361
+ if (!container) {
362
+ return;
363
+ }
101
364
 
102
- resizeObserver.observe(container);
365
+ observeWidthProbe(container);
103
366
 
104
367
  return () => {
105
- resizeObserver.disconnect();
368
+ unobserveWidthProbe(container);
106
369
  };
107
370
  }, []);
108
371
 
@@ -115,27 +378,18 @@ function SmartTextTruncate({
115
378
  }
116
379
 
117
380
  return (
118
- <span
119
- ref={containerRef}
120
- className={className}
121
- {...props}
122
- style={{ position: 'relative', ...props.style }}
123
- >
124
- {displayText}
125
- <span
126
- ref={fullTextRef}
127
- style={{
128
- position: 'absolute',
129
- visibility: 'hidden',
130
- whiteSpace: 'nowrap',
131
- top: '-9999px',
132
- }}
133
- aria-hidden="true"
134
- >
381
+ <span ref={containerRef} className={cn(S.root, className)} {...props}>
382
+ <span className={S.measuredLabel}>{displayText || children}</span>
383
+ <span className={S.liveLabel}>{children}</span>
384
+ <span ref={fullTextRef} className={S.fullText} aria-hidden="true">
135
385
  {children}
136
386
  </span>
137
387
  </span>
138
388
  );
139
- }
389
+ });
140
390
 
141
- export { SmartTextTruncate };
391
+ export {
392
+ SmartTextTruncate,
393
+ notifyPanelWidthDragStart,
394
+ notifyPanelWidthDragEnd,
395
+ };
@@ -1,2 +1,6 @@
1
- export { SmartTextTruncate } from './SmartTextTruncate';
1
+ export {
2
+ SmartTextTruncate,
3
+ notifyPanelWidthDragStart,
4
+ notifyPanelWidthDragEnd,
5
+ } from './SmartTextTruncate';
2
6
  export type { SmartTextTruncateProps } from './SmartTextTruncate.types';
@@ -1,29 +1,5 @@
1
- .chevronContainer
2
- margin-left auto
3
-
4
1
  .subMenuContainer
5
2
  position relative
6
3
 
7
- .subMenuBorder
8
- position absolute
9
- left var(--p-5)
10
- top 0
11
- bottom 26px
12
- width 1px
13
- background var(--sidebar-border)
14
-
15
4
  .subMenuItem
16
5
  position relative
17
- margin-left var(--p-6)
18
-
19
- &::before
20
- content ''
21
- position absolute
22
- left calc(var(--p-1) * -1)
23
- top var(--p-2)
24
- bottom 0
25
- width var(--p-3)
26
- height var(--p-3)
27
- border-left 1px solid var(--sidebar-border)
28
- border-bottom 1px solid var(--sidebar-border)
29
- border-bottom-left-radius var(--p-2)
@@ -1,8 +1,6 @@
1
1
  // This file is automatically generated.
2
2
  // Please do not change this file!
3
3
  interface CssExports {
4
- 'chevronContainer': string;
5
- 'subMenuBorder': string;
6
4
  'subMenuContainer': string;
7
5
  'subMenuItem': string;
8
6
  }
@@ -10,7 +10,7 @@ import {
10
10
  SidebarMenuSubItem,
11
11
  } from '#uilib/components/ui/Sidebar/Sidebar';
12
12
  import { SmartTextTruncate } from '#uilib/components/ui/SmartTextTruncate';
13
- import { ChevronDown, ChevronRight, PackageOpen } from 'lucide-react';
13
+ import { PackageOpen } from 'lucide-react';
14
14
 
15
15
  import S from './SidebarDatasetsItemsGrouped.styl';
16
16
  import {
@@ -102,22 +102,16 @@ export function SidebarDatasetsItemsGrouped({
102
102
  <SidebarMenuButton
103
103
  type="button"
104
104
  isActive={parentActive}
105
+ hasSubItems
106
+ isExpanded={isExpanded}
105
107
  onClick={() => toggleGroup(groupName)}
108
+ icon={<PackageOpen strokeWidth={1.5} size={16} />}
106
109
  >
107
- <PackageOpen strokeWidth={1.5} size={16} />
108
- <SmartTextTruncate>{groupName}</SmartTextTruncate>
109
- <div className={S.chevronContainer}>
110
- {isExpanded ? (
111
- <ChevronDown size={12} />
112
- ) : (
113
- <ChevronRight size={12} />
114
- )}
115
- </div>
110
+ {groupName}
116
111
  </SidebarMenuButton>
117
112
 
118
113
  {isExpanded && (
119
114
  <SidebarMenuSub className={S.subMenuContainer}>
120
- <div className={S.subMenuBorder} />
121
115
  {groupDatasets.map(dataset => (
122
116
  <SidebarMenuSubItem
123
117
  key={dataset.id}
@@ -14,7 +14,6 @@ import {
14
14
  SidebarMenuSubItem,
15
15
  } from '#uilib/components/ui/Sidebar/Sidebar';
16
16
  import { SmartTextTruncate } from '#uilib/components/ui/SmartTextTruncate';
17
- import { ChevronDown, ChevronRight } from 'lucide-react';
18
17
 
19
18
  import { DOC_REGISTRY, DOC_SECTION_ORDER } from '../../registry';
20
19
  import S from './DocsSidebar.styl';
@@ -48,18 +47,6 @@ function entryMatchesQuery(
48
47
  );
49
48
  }
50
49
 
51
- function renderSectionChevron(isExpanded: boolean) {
52
- return (
53
- <div>
54
- {isExpanded ? (
55
- <ChevronDown size={12} strokeWidth={1.5} />
56
- ) : (
57
- <ChevronRight size={12} strokeWidth={1.5} />
58
- )}
59
- </div>
60
- );
61
- }
62
-
63
50
  export function DocsSidebar() {
64
51
  const location = useLocation();
65
52
  const bySection = entriesBySection();
@@ -134,11 +121,10 @@ export function DocsSidebar() {
134
121
  if (!isFiltering) toggleSection(section);
135
122
  }}
136
123
  isActive={sectionHasActive}
124
+ hasSubItems={filteredEntries.length > 0}
125
+ isExpanded={isExpanded}
137
126
  >
138
- <span>
139
- <SmartTextTruncate>{section}</SmartTextTruncate>
140
- </span>
141
- {isFiltering ? null : renderSectionChevron(isExpanded)}
127
+ {section}
142
128
  </SidebarMenuButton>
143
129
  {isExpanded ? (
144
130
  <SidebarMenuSub>
@@ -67,7 +67,10 @@ const MOCK_DATASETS: SidebarDatasetsItemsGroupedDataset[] = [
67
67
  sale_price: '0',
68
68
  regions: [
69
69
  { id: 3, name: 'Europe' },
70
- { id: 4, name: 'Germany' },
70
+ {
71
+ id: 4,
72
+ name: 'GermanyGermanyGermanyGermanyGermanyGermanyGermanyGermany',
73
+ },
71
74
  ],
72
75
  unit: { id: 1, name: 'MT' },
73
76
  },
@@ -1,3 +1,8 @@
1
+ .sectionLabel
2
+ margin 0 0 var(--p-2)
3
+ color var(--muted-foreground)
4
+ font-size 0.875rem
5
+
1
6
  .resizableDemo
2
7
  resize horizontal
3
8
  overflow auto
@@ -7,6 +12,23 @@
7
12
  border 1px solid var(--border)
8
13
  border-radius var(--p-2)
9
14
  padding var(--p-2)
15
+ margin-bottom var(--p-6)
16
+
17
+ .resizableListDemo
18
+ resize horizontal
19
+ overflow auto
20
+ width 280px
21
+ min-width 120px
22
+ max-width 100%
23
+ border 1px solid var(--border)
24
+ border-radius var(--p-2)
25
+ padding var(--p-2)
26
+ display flex
27
+ flex-direction column
28
+ gap var(--p-1)
29
+
30
+ &:active
31
+ border 1px solid var(--brand-color)
10
32
 
11
33
  .demoText
12
34
  display block
@@ -3,6 +3,8 @@
3
3
  interface CssExports {
4
4
  'demoText': string;
5
5
  'resizableDemo': string;
6
+ 'resizableListDemo': string;
7
+ 'sectionLabel': string;
6
8
  }
7
9
  export const cssExports: CssExports;
8
10
  export default cssExports;
@@ -10,6 +10,13 @@ import S from './SmartTextTruncatePage.styl';
10
10
  const LONG =
11
11
  'Very-long-identifier-that-might-not-fit-in-a-narrow-container-without-smart-truncation';
12
12
 
13
+ const LIST_ITEMS = Array.from({ length: 50 }, (_, index) => {
14
+ const suffix = ['Constraints', 'Ontraction', 'Market Risk', 'City Protests'][
15
+ index % 4
16
+ ];
17
+ return `Impact — Impact Report: Professional Beauty Segment Analysis ${index + 1} ${suffix} Index`;
18
+ });
19
+
13
20
  export default function SmartTextTruncatePage() {
14
21
  return (
15
22
  <>
@@ -21,9 +28,22 @@ export default function SmartTextTruncatePage() {
21
28
  />
22
29
  <DocsGuidance source={smartTextTruncateGuidance} />
23
30
  <PageContentSection>
24
- <div className={S.resizableDemo}>
31
+ <p className={S.sectionLabel}>Single item</p>
32
+ <div className={S.resizableDemo} data-smart-text-truncate-resize-root>
25
33
  <SmartTextTruncate className={S.demoText}>{LONG}</SmartTextTruncate>
26
34
  </div>
35
+
36
+ <p className={S.sectionLabel}>List stress test (50 items)</p>
37
+ <div
38
+ className={S.resizableListDemo}
39
+ data-smart-text-truncate-resize-root
40
+ >
41
+ {LIST_ITEMS.map(label => (
42
+ <SmartTextTruncate key={label} className={S.demoText}>
43
+ {label}
44
+ </SmartTextTruncate>
45
+ ))}
46
+ </div>
27
47
  </PageContentSection>
28
48
  </>
29
49
  );