@hyphen/hyphen-components 5.2.1 → 5.3.0
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/components/Sidebar/Sidebar.d.ts +1 -0
- package/dist/components/Sidebar/Sidebar.stories.d.ts +1 -0
- package/dist/css/index.css +3 -3
- package/dist/css/utilities.css +7 -1
- package/dist/css/variables.css +4 -2
- package/dist/hyphen-components.cjs.development.js +143 -115
- package/dist/hyphen-components.cjs.development.js.map +1 -1
- package/dist/hyphen-components.cjs.production.min.js +1 -1
- package/dist/hyphen-components.cjs.production.min.js.map +1 -1
- package/dist/hyphen-components.esm.js +142 -114
- package/dist/hyphen-components.esm.js.map +1 -1
- package/dist/lib/tokens.d.ts +1 -1
- package/package.json +9 -9
- package/src/components/Sidebar/Sidebar.module.scss +15 -0
- package/src/components/Sidebar/Sidebar.stories.tsx +347 -227
- package/src/components/Sidebar/Sidebar.tsx +102 -53
|
@@ -14,11 +14,17 @@ import { Box } from '../Box/Box';
|
|
|
14
14
|
import { IconName } from 'src/types';
|
|
15
15
|
import { Icon } from '../Icon/Icon';
|
|
16
16
|
import styles from './Sidebar.module.scss';
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
import {
|
|
18
|
+
Tooltip,
|
|
19
|
+
TooltipContent,
|
|
20
|
+
TooltipProvider,
|
|
21
|
+
TooltipTrigger,
|
|
22
|
+
} from '../Tooltip/Tooltip';
|
|
23
|
+
|
|
24
|
+
const SIDEBAR_COOKIE_NAME = 'sidebar_expanded';
|
|
19
25
|
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
|
|
20
26
|
const SIDEBAR_WIDTH = '16rem';
|
|
21
|
-
const SIDEBAR_WIDTH_ICON = '
|
|
27
|
+
const SIDEBAR_WIDTH_ICON = '44px';
|
|
22
28
|
const SIDEBAR_KEYBOARD_SHORTCUT = '[';
|
|
23
29
|
|
|
24
30
|
interface SidebarContextProps {
|
|
@@ -133,24 +139,26 @@ const SidebarProvider = forwardRef<
|
|
|
133
139
|
|
|
134
140
|
return (
|
|
135
141
|
<SidebarContext.Provider value={contextValue}>
|
|
136
|
-
<
|
|
137
|
-
|
|
138
|
-
{
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
142
|
+
<TooltipProvider delayDuration={0}>
|
|
143
|
+
<div
|
|
144
|
+
style={
|
|
145
|
+
{
|
|
146
|
+
'--sidebar-width': SIDEBAR_WIDTH,
|
|
147
|
+
'--sidebar-width-icon': SIDEBAR_WIDTH_ICON,
|
|
148
|
+
minBlockSize: '100svh',
|
|
149
|
+
...style,
|
|
150
|
+
} as React.CSSProperties
|
|
151
|
+
}
|
|
152
|
+
className={classNames(
|
|
153
|
+
'display-flex w-100 background-color-secondary',
|
|
154
|
+
className
|
|
155
|
+
)}
|
|
156
|
+
ref={ref}
|
|
157
|
+
{...props}
|
|
158
|
+
>
|
|
159
|
+
{children}
|
|
160
|
+
</div>
|
|
161
|
+
</TooltipProvider>
|
|
154
162
|
</SidebarContext.Provider>
|
|
155
163
|
);
|
|
156
164
|
}
|
|
@@ -188,7 +196,7 @@ const Sidebar = React.forwardRef<
|
|
|
188
196
|
return (
|
|
189
197
|
<div
|
|
190
198
|
className={classNames(
|
|
191
|
-
'display-flex h-100 font-size-xs flex-direction-column background-color-secondary font-color-base',
|
|
199
|
+
'group display-flex h-100 font-size-xs flex-direction-column background-color-secondary font-color-base',
|
|
192
200
|
className
|
|
193
201
|
)}
|
|
194
202
|
style={{
|
|
@@ -213,6 +221,7 @@ const Sidebar = React.forwardRef<
|
|
|
213
221
|
data-state={state}
|
|
214
222
|
data-collapsible={collapsible}
|
|
215
223
|
data-side={side}
|
|
224
|
+
className="group"
|
|
216
225
|
>
|
|
217
226
|
<div
|
|
218
227
|
style={{
|
|
@@ -222,7 +231,12 @@ const Sidebar = React.forwardRef<
|
|
|
222
231
|
transitionDuration: 'var(--sidebar-transition-duration, 200ms)',
|
|
223
232
|
animationDuration: 'var(--sidebar-transition-duration, 200ms)',
|
|
224
233
|
transitionProperty: 'width',
|
|
225
|
-
width:
|
|
234
|
+
width:
|
|
235
|
+
state === 'collapsed' && collapsible === 'icon'
|
|
236
|
+
? 'var(--sidebar-width-icon)'
|
|
237
|
+
: state === 'collapsed'
|
|
238
|
+
? '0'
|
|
239
|
+
: 'var(--sidebar-width)',
|
|
226
240
|
height: '100svh',
|
|
227
241
|
}}
|
|
228
242
|
className={classNames('position-relative', className)}
|
|
@@ -233,7 +247,10 @@ const Sidebar = React.forwardRef<
|
|
|
233
247
|
className
|
|
234
248
|
)}
|
|
235
249
|
style={{
|
|
236
|
-
left:
|
|
250
|
+
left:
|
|
251
|
+
state === 'expanded' || collapsible === 'icon'
|
|
252
|
+
? '0'
|
|
253
|
+
: 'calc(var(--sidebar-width)*-1)',
|
|
237
254
|
top: '0',
|
|
238
255
|
bottom: '0',
|
|
239
256
|
zIndex: 'var(--size-z-index-drawer)',
|
|
@@ -243,7 +260,10 @@ const Sidebar = React.forwardRef<
|
|
|
243
260
|
transitionDuration: 'var(--sidebar-transition-duration, 200ms)',
|
|
244
261
|
animationDuration: 'var(--sidebar-transition-duration, 200ms)',
|
|
245
262
|
transitionProperty: 'left, right, width',
|
|
246
|
-
width:
|
|
263
|
+
width:
|
|
264
|
+
state === 'collapsed' && collapsible === 'icon'
|
|
265
|
+
? 'var(--sidebar-width-icon)'
|
|
266
|
+
: 'var(--sidebar-width)',
|
|
247
267
|
height: '100svh',
|
|
248
268
|
}}
|
|
249
269
|
{...props}
|
|
@@ -312,7 +332,7 @@ const SidebarHeader = React.forwardRef<
|
|
|
312
332
|
ref={ref}
|
|
313
333
|
data-sidebar="header"
|
|
314
334
|
className={classNames(
|
|
315
|
-
'display-flex g-sm p-v-md p-h-md p-right-0-desktop',
|
|
335
|
+
'display-flex g-sm p-v-md p-h-md p-right-0-desktop overflow-hidden',
|
|
316
336
|
className
|
|
317
337
|
)}
|
|
318
338
|
{...props}
|
|
@@ -330,7 +350,7 @@ const SidebarFooter = React.forwardRef<
|
|
|
330
350
|
ref={ref}
|
|
331
351
|
data-sidebar="footer"
|
|
332
352
|
className={classNames(
|
|
333
|
-
'display-flex g-sm p-v-md p-h-md p-right-0-desktop',
|
|
353
|
+
'display-flex g-sm p-v-md p-h-md p-right-0-desktop overflow-hidden',
|
|
334
354
|
className
|
|
335
355
|
)}
|
|
336
356
|
{...props}
|
|
@@ -348,9 +368,10 @@ const SidebarContent = React.forwardRef<
|
|
|
348
368
|
ref={ref}
|
|
349
369
|
data-sidebar="content"
|
|
350
370
|
className={classNames(
|
|
351
|
-
'display-flex flex-direction-column g-xl minh-0 flex-auto
|
|
371
|
+
'display-flex flex-direction-column g-xl minh-0 flex-auto',
|
|
352
372
|
className
|
|
353
373
|
)}
|
|
374
|
+
style={{ overflowX: 'hidden', overflowY: 'auto' }}
|
|
354
375
|
{...props}
|
|
355
376
|
/>
|
|
356
377
|
);
|
|
@@ -384,6 +405,7 @@ const SidebarMenuItem = React.forwardRef<
|
|
|
384
405
|
ref={ref}
|
|
385
406
|
data-sidebar="menu-item"
|
|
386
407
|
className={classNames('font-size-sm position-relative', className)}
|
|
408
|
+
style={{ whiteSpace: 'nowrap' }}
|
|
387
409
|
{...props}
|
|
388
410
|
/>
|
|
389
411
|
));
|
|
@@ -395,31 +417,58 @@ const SidebarMenuButton = React.forwardRef<
|
|
|
395
417
|
asChild?: boolean;
|
|
396
418
|
isActive?: boolean;
|
|
397
419
|
icon?: IconName;
|
|
420
|
+
tooltip?: string | React.ComponentProps<typeof TooltipContent>;
|
|
398
421
|
}
|
|
399
|
-
>(
|
|
400
|
-
|
|
422
|
+
>(
|
|
423
|
+
(
|
|
424
|
+
{ asChild = false, isActive = false, icon, tooltip, className, ...props },
|
|
425
|
+
ref
|
|
426
|
+
) => {
|
|
427
|
+
const Comp = asChild ? Slot : 'button';
|
|
428
|
+
const { isMobile, state } = useSidebar();
|
|
401
429
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
430
|
+
const button = (
|
|
431
|
+
<Comp
|
|
432
|
+
ref={ref}
|
|
433
|
+
data-sidebar="menu-button"
|
|
434
|
+
data-active={isActive}
|
|
435
|
+
className={classNames(
|
|
436
|
+
'display-flex w-100 flex-auto p-sm br-sm g-lg flex-direction-row flex-auto align-items-center font-size-sm bw-0 font-weight-medium text-align-left td-none hover:background-color-tertiary font-color-base cursor-pointer',
|
|
437
|
+
{
|
|
438
|
+
'background-color-tertiary': isActive,
|
|
439
|
+
'background-color-transparent': !isActive,
|
|
440
|
+
},
|
|
441
|
+
className
|
|
442
|
+
)}
|
|
443
|
+
{...props}
|
|
444
|
+
>
|
|
445
|
+
{props.children}
|
|
446
|
+
</Comp>
|
|
447
|
+
);
|
|
420
448
|
|
|
421
|
-
|
|
422
|
-
|
|
449
|
+
if (!tooltip) {
|
|
450
|
+
return button;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
if (typeof tooltip === 'string') {
|
|
454
|
+
tooltip = {
|
|
455
|
+
children: tooltip,
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
return (
|
|
460
|
+
<Tooltip>
|
|
461
|
+
<TooltipTrigger asChild>{button}</TooltipTrigger>
|
|
462
|
+
<TooltipContent
|
|
463
|
+
side="right"
|
|
464
|
+
align="center"
|
|
465
|
+
hidden={state !== 'collapsed' || isMobile}
|
|
466
|
+
{...tooltip}
|
|
467
|
+
/>
|
|
468
|
+
</Tooltip>
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
);
|
|
423
472
|
SidebarMenuButton.displayName = 'SidebarMenuButton';
|
|
424
473
|
|
|
425
474
|
const SidebarGroup = React.forwardRef<
|
|
@@ -431,7 +480,7 @@ const SidebarGroup = React.forwardRef<
|
|
|
431
480
|
ref={ref}
|
|
432
481
|
data-sidebar="group"
|
|
433
482
|
className={classNames(
|
|
434
|
-
'position-relative p-h-md p-right-0-desktop display-flex w-100 minw-0 flex-direction-column',
|
|
483
|
+
'position-relative p-h-md p-right-0-desktop display-flex w-100 minw-0 flex-direction-column ',
|
|
435
484
|
className
|
|
436
485
|
)}
|
|
437
486
|
{...props}
|
|
@@ -449,7 +498,7 @@ const SidebarGroupLabel = React.forwardRef<
|
|
|
449
498
|
ref={ref}
|
|
450
499
|
data-sidebar="group-label"
|
|
451
500
|
className={classNames(
|
|
452
|
-
'display-flex h-3xl align-items-center br-sm p-h-sm font-color-secondary font-size-xs font-weight-medium outline-none',
|
|
501
|
+
'group-data-collapsible-icon-hidden display-flex h-3xl align-items-center br-sm p-h-sm font-color-secondary font-size-xs font-weight-medium outline-none',
|
|
453
502
|
className
|
|
454
503
|
)}
|
|
455
504
|
{...props}
|
|
@@ -606,7 +655,7 @@ const SidebarMenuBadge = React.forwardRef<
|
|
|
606
655
|
ref={ref}
|
|
607
656
|
data-sidebar="menu-badge"
|
|
608
657
|
className={classNames(
|
|
609
|
-
'position-absolute font-size-xs cursor-default lh-none p-xs font-color-base minw-0 align-items-center bw-0 br-sm outline-none background-color-transparent',
|
|
658
|
+
'group-data-collapsible-icon-hidden position-absolute font-size-xs cursor-default lh-none p-xs font-color-base minw-0 align-items-center bw-0 br-sm outline-none background-color-transparent',
|
|
610
659
|
className
|
|
611
660
|
)}
|
|
612
661
|
style={{
|