@sybilion/uilib 1.4.12 → 1.4.14
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/dist/esm/components/ui/Button/Button.styl.js +1 -1
- package/dist/esm/components/ui/Sidebar/Sidebar.js +21 -7
- package/dist/esm/components/ui/Sidebar/Sidebar.styl.js +2 -2
- package/dist/esm/components/ui/SmartTextTruncate/SmartTextTruncate.js +260 -67
- package/dist/esm/components/ui/SmartTextTruncate/SmartTextTruncate.styl.js +7 -0
- package/dist/esm/components/widgets/SidebarDatasetsItemsGrouped/SidebarDatasetsItemsGrouped.js +5 -5
- package/dist/esm/components/widgets/SidebarDatasetsItemsGrouped/SidebarDatasetsItemsGrouped.styl.js +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/types/src/components/ui/Chat/ChatSheet/ChatSheet.d.ts +1 -1
- package/dist/esm/types/src/components/ui/Sidebar/Sidebar.d.ts +9 -2
- package/dist/esm/types/src/components/ui/SmartTextTruncate/SmartTextTruncate.d.ts +5 -3
- package/dist/esm/types/src/components/ui/SmartTextTruncate/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/components/ui/Button/Button.styl +2 -2
- package/src/components/ui/Chat/ChatSheet/ChatSheet.tsx +1 -1
- package/src/components/ui/Sidebar/Sidebar.styl +63 -49
- package/src/components/ui/Sidebar/Sidebar.styl.d.ts +4 -0
- package/src/components/ui/Sidebar/Sidebar.tsx +78 -6
- package/src/components/ui/SmartTextTruncate/SmartTextTruncate.styl +34 -0
- package/src/components/ui/SmartTextTruncate/SmartTextTruncate.styl.d.ts +10 -0
- package/src/components/ui/SmartTextTruncate/SmartTextTruncate.tsx +335 -81
- package/src/components/ui/SmartTextTruncate/index.ts +5 -1
- package/src/components/widgets/SidebarDatasetsItemsGrouped/SidebarDatasetsItemsGrouped.styl +0 -24
- package/src/components/widgets/SidebarDatasetsItemsGrouped/SidebarDatasetsItemsGrouped.styl.d.ts +0 -2
- package/src/components/widgets/SidebarDatasetsItemsGrouped/SidebarDatasetsItemsGrouped.tsx +5 -11
- package/src/docs/components/DocsSidebar/DocsSidebar.tsx +17 -25
- package/src/docs/pages/SidebarDatasetsItemsGroupedPage.tsx +4 -1
- package/src/docs/pages/SmartTextTruncatePage.styl +13 -3
- package/src/docs/pages/SmartTextTruncatePage.styl.d.ts +2 -1
- package/src/docs/pages/SmartTextTruncatePage.tsx +16 -2
|
@@ -1,108 +1,371 @@
|
|
|
1
|
-
import
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
54
|
-
const
|
|
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
|
-
|
|
62
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
95
|
-
|
|
350
|
+
ensureResizeRootListeners();
|
|
351
|
+
const g = getGlobalState();
|
|
352
|
+
g.recalcCallbacks.add(recalc);
|
|
353
|
+
return () => {
|
|
354
|
+
g.recalcCallbacks.delete(recalc);
|
|
355
|
+
};
|
|
356
|
+
}, [recalc]);
|
|
96
357
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
358
|
+
useLayoutEffect(() => {
|
|
359
|
+
ensureResizeRootListeners();
|
|
360
|
+
const container = containerRef.current;
|
|
361
|
+
if (!container) {
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
101
364
|
|
|
102
|
-
|
|
365
|
+
observeWidthProbe(container);
|
|
103
366
|
|
|
104
367
|
return () => {
|
|
105
|
-
|
|
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
|
-
|
|
120
|
-
className={
|
|
121
|
-
{
|
|
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 {
|
|
391
|
+
export {
|
|
392
|
+
SmartTextTruncate,
|
|
393
|
+
notifyPanelWidthDragStart,
|
|
394
|
+
notifyPanelWidthDragEnd,
|
|
395
|
+
};
|
|
@@ -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)
|
|
@@ -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 {
|
|
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
|
-
|
|
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}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
-
import { Link, useLocation } from 'react-router-dom';
|
|
2
|
+
import { Link, useLocation, useNavigate } from 'react-router-dom';
|
|
3
3
|
|
|
4
4
|
import { Input } from '#uilib/components/ui/Input';
|
|
5
5
|
import {
|
|
@@ -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,25 +47,13 @@ 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();
|
|
66
53
|
const [sidebarSearch, setSidebarSearch] = useState('');
|
|
67
54
|
const q = sidebarSearch.trim().toLowerCase();
|
|
68
55
|
const isFiltering = q.length > 0;
|
|
69
|
-
|
|
56
|
+
const navigate = useNavigate();
|
|
70
57
|
const activeSection = useMemo(
|
|
71
58
|
() => sectionForPathname(location.pathname),
|
|
72
59
|
[location.pathname],
|
|
@@ -93,6 +80,14 @@ export function DocsSidebar() {
|
|
|
93
80
|
});
|
|
94
81
|
};
|
|
95
82
|
|
|
83
|
+
const handleSubItemClick = (
|
|
84
|
+
e: React.MouseEvent<HTMLAnchorElement>,
|
|
85
|
+
to: string,
|
|
86
|
+
) => {
|
|
87
|
+
e.preventDefault();
|
|
88
|
+
navigate(to);
|
|
89
|
+
};
|
|
90
|
+
|
|
96
91
|
return (
|
|
97
92
|
<Sidebar
|
|
98
93
|
variant="inset"
|
|
@@ -134,13 +129,12 @@ export function DocsSidebar() {
|
|
|
134
129
|
if (!isFiltering) toggleSection(section);
|
|
135
130
|
}}
|
|
136
131
|
isActive={sectionHasActive}
|
|
132
|
+
hasSubItems={filteredEntries.length > 0}
|
|
133
|
+
isExpanded={isExpanded}
|
|
137
134
|
>
|
|
138
|
-
|
|
139
|
-
<SmartTextTruncate>{section}</SmartTextTruncate>
|
|
140
|
-
</span>
|
|
141
|
-
{isFiltering ? null : renderSectionChevron(isExpanded)}
|
|
135
|
+
{section}
|
|
142
136
|
</SidebarMenuButton>
|
|
143
|
-
{isExpanded
|
|
137
|
+
{isExpanded && (
|
|
144
138
|
<SidebarMenuSub>
|
|
145
139
|
{filteredEntries.map(e => {
|
|
146
140
|
const to = `/docs/${e.slug}`;
|
|
@@ -148,19 +142,17 @@ export function DocsSidebar() {
|
|
|
148
142
|
return (
|
|
149
143
|
<SidebarMenuSubItem key={e.slug}>
|
|
150
144
|
<SidebarMenuSubButton
|
|
151
|
-
asChild
|
|
152
145
|
isActive={isActive}
|
|
153
146
|
size="md"
|
|
147
|
+
onClick={e => handleSubItemClick(e, to)}
|
|
154
148
|
>
|
|
155
|
-
|
|
156
|
-
<SmartTextTruncate>{e.title}</SmartTextTruncate>
|
|
157
|
-
</Link>
|
|
149
|
+
{e.title}
|
|
158
150
|
</SidebarMenuSubButton>
|
|
159
151
|
</SidebarMenuSubItem>
|
|
160
152
|
);
|
|
161
153
|
})}
|
|
162
154
|
</SidebarMenuSub>
|
|
163
|
-
)
|
|
155
|
+
)}
|
|
164
156
|
</SidebarMenuItem>
|
|
165
157
|
);
|
|
166
158
|
})}
|
|
@@ -67,7 +67,10 @@ const MOCK_DATASETS: SidebarDatasetsItemsGroupedDataset[] = [
|
|
|
67
67
|
sale_price: '0',
|
|
68
68
|
regions: [
|
|
69
69
|
{ id: 3, name: 'Europe' },
|
|
70
|
-
{
|
|
70
|
+
{
|
|
71
|
+
id: 4,
|
|
72
|
+
name: 'GermanyGermanyGermanyGermanyGermanyGermanyGermanyGermany',
|
|
73
|
+
},
|
|
71
74
|
],
|
|
72
75
|
unit: { id: 1, name: 'MT' },
|
|
73
76
|
},
|
|
@@ -1,13 +1,23 @@
|
|
|
1
|
-
.
|
|
1
|
+
.sectionLabel
|
|
2
|
+
margin 0 0 var(--p-2)
|
|
3
|
+
color var(--muted-foreground)
|
|
4
|
+
font-size 0.875rem
|
|
5
|
+
|
|
6
|
+
.resizableListDemo
|
|
2
7
|
resize horizontal
|
|
3
8
|
overflow auto
|
|
4
|
-
width
|
|
5
|
-
min-width
|
|
9
|
+
width 280px
|
|
10
|
+
min-width 120px
|
|
6
11
|
max-width 100%
|
|
12
|
+
max-height 300px
|
|
7
13
|
border 1px solid var(--border)
|
|
8
14
|
border-radius var(--p-2)
|
|
9
15
|
padding var(--p-2)
|
|
10
16
|
|
|
17
|
+
&:active
|
|
18
|
+
border 1px solid var(--brand-color)
|
|
19
|
+
|
|
11
20
|
.demoText
|
|
12
21
|
display block
|
|
13
22
|
width 100%
|
|
23
|
+
margin-bottom var(--p-1)
|