@bensdev/react-sidebar 0.2.0 → 0.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/index.d.ts CHANGED
@@ -46,7 +46,12 @@ interface SidebarActionItem extends SidebarItemBase {
46
46
  interface SidebarGroupItem extends SidebarItemBase {
47
47
  type: 'group';
48
48
  items: SidebarItem[];
49
- /** `false` renders a static section: label as heading, children always visible. */
49
+ /**
50
+ * `false` renders a static section: label as heading, children always visible — including on
51
+ * the collapsed icon rail, where it overrides `collapsedGroupBehavior` entirely (no flyout, no
52
+ * hiding). Give the group an `icon` to also get a row for it on the rail; without one, only its
53
+ * (icon-bearing) children render there.
54
+ */
50
55
  collapsible?: boolean;
51
56
  defaultOpen?: boolean;
52
57
  open?: boolean;
@@ -176,6 +181,12 @@ interface SidebarProps {
176
181
  onOpenGroupsChange?: (ids: string[]) => void;
177
182
  accordion?: boolean;
178
183
  autoOpenActiveGroup?: boolean;
184
+ /**
185
+ * How a *collapsible* group presents once the sidebar collapses to its icon rail: a
186
+ * hover/focus flyout (default), inline-and-indented (`"expand"`), or trigger-only with
187
+ * children unreachable (`"ignore"`). Has no effect on `collapsible: false` groups — those
188
+ * always stay fully expanded, on the rail or off.
189
+ */
179
190
  collapsedGroupBehavior?: 'flyout' | 'expand' | 'ignore';
180
191
  mobileOpen?: boolean;
181
192
  onMobileClose?: () => void;
package/dist/index.js CHANGED
@@ -500,10 +500,17 @@ function SidebarGroupRow({ item, depth }) {
500
500
  children: /* @__PURE__ */ jsx(ChevronDownIcon, { size: 14 })
501
501
  }
502
502
  ),
503
- showTooltip && behavior !== "flyout" && /* @__PURE__ */ jsx(Tooltip, { id: tooltipId, className: ctx.classNames.tooltip, children: item.tooltip ?? item.label })
503
+ showTooltip && (!collapsible || behavior !== "flyout") && /* @__PURE__ */ jsx(Tooltip, { id: tooltipId, className: ctx.classNames.tooltip, children: item.tooltip ?? item.label })
504
504
  ]
505
505
  }
506
506
  );
507
+ if (!collapsible) {
508
+ const showTrigger = item.icon != null || !isRail;
509
+ return /* @__PURE__ */ jsxs("li", { className: cx("bsb-list-item", "bsb-group"), children: [
510
+ showTrigger && trigger,
511
+ /* @__PURE__ */ jsx("ul", { id: panelId, className: cx("bsb-group__panel", ctx.classNames.groupPanel), children: /* @__PURE__ */ jsx(SidebarNodeList, { items: item.items, depth: depth + 1 }) })
512
+ ] });
513
+ }
507
514
  if (isRail && behavior === "flyout") {
508
515
  return /* @__PURE__ */ jsxs("li", { className: cx("bsb-list-item", "bsb-group", "bsb-group--flyout"), children: [
509
516
  trigger,
@@ -526,7 +533,7 @@ function SidebarGroupRow({ item, depth }) {
526
533
  }
527
534
  return /* @__PURE__ */ jsxs("li", { className: cx("bsb-list-item", "bsb-group"), children: [
528
535
  trigger,
529
- (isOpen || !collapsible) && /* @__PURE__ */ jsx("ul", { id: panelId, className: cx("bsb-group__panel", ctx.classNames.groupPanel), children: /* @__PURE__ */ jsx(SidebarNodeList, { items: item.items, depth: depth + 1 }) })
536
+ isOpen && /* @__PURE__ */ jsx("ul", { id: panelId, className: cx("bsb-group__panel", ctx.classNames.groupPanel), children: /* @__PURE__ */ jsx(SidebarNodeList, { items: item.items, depth: depth + 1 }) })
530
537
  ] });
531
538
  }
532
539
  function SidebarNode({ item, depth }) {
@@ -830,7 +837,10 @@ function MobileDrawer({
830
837
  closeLabel,
831
838
  classNames,
832
839
  durationMs = 400,
833
- children
840
+ children,
841
+ rootClassName,
842
+ rootStyle,
843
+ rootDataAttrs
834
844
  }) {
835
845
  const { mounted, state, onPanelTransitionEnd } = useMountTransition(open, durationMs);
836
846
  const panelRef = React21.useRef(null);
@@ -842,7 +852,7 @@ function MobileDrawer({
842
852
  useBodyScrollLock(lockScroll && open);
843
853
  if (!mounted) return null;
844
854
  const widthValue = typeof width === "number" ? `${width}px` : width;
845
- return /* @__PURE__ */ jsxs(Portal, { target: portalTarget, disabled: disablePortal, children: [
855
+ return /* @__PURE__ */ jsx(Portal, { target: portalTarget, disabled: disablePortal, children: /* @__PURE__ */ jsxs("div", { className: cx(rootClassName, "bsb-root--drawer-host"), style: rootStyle, ...rootDataAttrs, children: [
846
856
  /* @__PURE__ */ jsx(
847
857
  "div",
848
858
  {
@@ -881,7 +891,7 @@ function MobileDrawer({
881
891
  ]
882
892
  }
883
893
  )
884
- ] });
894
+ ] }) });
885
895
  }
886
896
  function widthToCss(value) {
887
897
  if (value == null) return void 0;
@@ -1125,35 +1135,32 @@ var Sidebar = React21.forwardRef(function Sidebar2(props, ref) {
1125
1135
  )
1126
1136
  }
1127
1137
  ),
1128
- isMobile && /* @__PURE__ */ jsx(
1129
- "div",
1130
- {
1131
- ref: rootRef,
1132
- className: rootClassName,
1133
- style: mergedStyle,
1134
- ...rootDataAttrs,
1135
- children: /* @__PURE__ */ jsx(
1136
- MobileDrawer,
1137
- {
1138
- open: mobileOpen,
1139
- onClose: closeMobile,
1140
- ariaLabel,
1141
- width: drawerWidth,
1142
- position,
1143
- closeOnEscape,
1144
- closeOnBackdropClick,
1145
- trapFocus,
1146
- lockScroll,
1147
- restoreFocus,
1148
- portalTarget,
1149
- disablePortal,
1150
- closeLabel: "Close navigation",
1151
- classNames,
1152
- children: /* @__PURE__ */ jsx(SidebarShell, { ...shellProps, collapsed: false, showToggle: false, onToggle: toggleCollapsed, togglePosition: position, toggleStrategy, toggleLabels: { expand: "Expand sidebar", collapse: "Collapse sidebar" } })
1153
- }
1154
- )
1155
- }
1156
- )
1138
+ isMobile && /* @__PURE__ */ jsxs(Fragment, { children: [
1139
+ /* @__PURE__ */ jsx("span", { ref: rootRef, "aria-hidden": "true", style: { display: "none" } }),
1140
+ /* @__PURE__ */ jsx(
1141
+ MobileDrawer,
1142
+ {
1143
+ open: mobileOpen,
1144
+ onClose: closeMobile,
1145
+ ariaLabel,
1146
+ width: drawerWidth,
1147
+ position,
1148
+ closeOnEscape,
1149
+ closeOnBackdropClick,
1150
+ trapFocus,
1151
+ lockScroll,
1152
+ restoreFocus,
1153
+ portalTarget,
1154
+ disablePortal,
1155
+ closeLabel: "Close navigation",
1156
+ classNames,
1157
+ rootClassName,
1158
+ rootStyle: mergedStyle,
1159
+ rootDataAttrs,
1160
+ children: /* @__PURE__ */ jsx(SidebarShell, { ...shellProps, collapsed: false, showToggle: false, onToggle: toggleCollapsed, togglePosition: position, toggleStrategy, toggleLabels: { expand: "Expand sidebar", collapse: "Collapse sidebar" } })
1161
+ }
1162
+ )
1163
+ ] })
1157
1164
  ] });
1158
1165
  });
1159
1166
  Sidebar.displayName = "Sidebar";