@hyphen/hyphen-components 2.25.0 → 2.25.2
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/hyphen-components.cjs.development.js +15 -10
- 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 +15 -10
- package/dist/hyphen-components.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Sidebar/Sidebar.tsx +15 -11
package/package.json
CHANGED
|
@@ -61,12 +61,23 @@ const SidebarProvider = forwardRef<
|
|
|
61
61
|
ref
|
|
62
62
|
) => {
|
|
63
63
|
const isMobile = useIsMobile();
|
|
64
|
-
const [openMobile, setOpenMobile] = useState(
|
|
64
|
+
const [openMobile, setOpenMobile] = useState(() =>
|
|
65
|
+
isMobile ? false : openProp ?? defaultOpen
|
|
66
|
+
);
|
|
65
67
|
|
|
66
68
|
// Manages sidebar open state with a fallback to internal state when openProp is not provided
|
|
67
69
|
const [_open, _setOpen] = useState(openProp ?? defaultOpen);
|
|
68
70
|
const open = openProp ?? _open;
|
|
69
71
|
|
|
72
|
+
// Update open state when openProp or isMobile changes
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (isMobile) {
|
|
75
|
+
setOpenMobile(false); // Always start closed on mobile
|
|
76
|
+
} else {
|
|
77
|
+
_setOpen(openProp ?? defaultOpen); // Use desktop state
|
|
78
|
+
}
|
|
79
|
+
}, [isMobile, openProp, defaultOpen]);
|
|
80
|
+
|
|
70
81
|
const setOpen = useCallback(
|
|
71
82
|
(value: boolean | ((value: boolean) => boolean)) => {
|
|
72
83
|
const newOpenState = typeof value === 'function' ? value(open) : value;
|
|
@@ -106,13 +117,6 @@ const SidebarProvider = forwardRef<
|
|
|
106
117
|
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
107
118
|
}, [toggleSidebar]);
|
|
108
119
|
|
|
109
|
-
// Update open state when `isMobile` changes
|
|
110
|
-
useEffect(() => {
|
|
111
|
-
if (isMobile && open) {
|
|
112
|
-
setOpenMobile(open);
|
|
113
|
-
}
|
|
114
|
-
}, [isMobile, open]);
|
|
115
|
-
|
|
116
120
|
// Assign state for data attributes
|
|
117
121
|
const state = open ? 'expanded' : 'collapsed';
|
|
118
122
|
|
|
@@ -175,7 +179,7 @@ const Sidebar = React.forwardRef<
|
|
|
175
179
|
onDismiss={() => setOpenMobile(false)}
|
|
176
180
|
placement={side}
|
|
177
181
|
>
|
|
178
|
-
<Box data-sidebar="sidebar" data-mobile="true">
|
|
182
|
+
<Box data-sidebar="sidebar" data-mobile="true" height="100">
|
|
179
183
|
{children}
|
|
180
184
|
</Box>
|
|
181
185
|
</Drawer>
|
|
@@ -266,7 +270,7 @@ const SidebarTrigger = React.forwardRef<
|
|
|
266
270
|
variant="tertiary"
|
|
267
271
|
size="sm"
|
|
268
272
|
iconPrefix="dock-left"
|
|
269
|
-
className={className}
|
|
273
|
+
className={classNames('m-left-sm m-left-0-tablet', className)}
|
|
270
274
|
onClick={(event) => {
|
|
271
275
|
onClick?.(event);
|
|
272
276
|
toggleSidebar();
|
|
@@ -286,7 +290,7 @@ const SidebarInset = React.forwardRef<
|
|
|
286
290
|
<main
|
|
287
291
|
ref={ref}
|
|
288
292
|
className={classNames(
|
|
289
|
-
'display-flex flex-auto flex-direction-column g-lg align-items-flex-start p-lg background-color-secondary',
|
|
293
|
+
'display-flex flex-auto flex-direction-column g-lg align-items-flex-start p-h-0 p-top-lg p-bottom-0 p-lg-tablet background-color-secondary',
|
|
290
294
|
className
|
|
291
295
|
)}
|
|
292
296
|
{...props}
|