xladmin 0.9.0 → 0.9.1

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.
@@ -1,7 +1,9 @@
1
1
  import type { ReactNode } from 'react';
2
2
  type ShellContextValue = {
3
- isMobile: boolean;
4
- openMobileSidebar: () => void;
3
+ hasSidebar: boolean;
4
+ sidebarId: string;
5
+ isSidebarOpen: boolean;
6
+ toggleSidebar: () => void;
5
7
  pendingPath: string | null;
6
8
  pendingView: 'overview' | 'model' | 'generic' | null;
7
9
  startPendingNavigation: (path: string, view?: 'overview' | 'model' | 'generic') => void;
package/dist/index.js CHANGED
@@ -1716,8 +1716,10 @@ function useAdminData() {
1716
1716
  import { createContext as createContext5, useContext as useContext5 } from "react";
1717
1717
  import { jsx as jsx7 } from "react/jsx-runtime";
1718
1718
  var defaultShellContextValue = {
1719
- isMobile: false,
1720
- openMobileSidebar: () => {
1719
+ hasSidebar: false,
1720
+ sidebarId: "",
1721
+ isSidebarOpen: false,
1722
+ toggleSidebar: () => {
1721
1723
  },
1722
1724
  pendingPath: null,
1723
1725
  pendingView: null,
@@ -2156,7 +2158,6 @@ var MAIN_HEADER_TITLE_HEIGHT = 34;
2156
2158
  var MAIN_HEADER_SUBTITLE_HEIGHT = 16;
2157
2159
  function MainHeader({ title, subtitle, details, error, beforeTitle, beforeSubtitle, actions }) {
2158
2160
  const t = useAdminTranslation();
2159
- const { isMobile, openMobileSidebar } = useShellContext();
2160
2161
  const [isDetailsOpen, setIsDetailsOpen] = useState6(false);
2161
2162
  return /* @__PURE__ */ jsxs7(
2162
2163
  Paper3,
@@ -2175,16 +2176,7 @@ function MainHeader({ title, subtitle, details, error, beforeTitle, beforeSubtit
2175
2176
  /* @__PURE__ */ jsxs7(Stack5, { spacing: 0.5, children: [
2176
2177
  /* @__PURE__ */ jsxs7(Stack5, { direction: "row", spacing: 1.5, sx: { minWidth: 0, alignItems: "center", justifyContent: "space-between" }, children: [
2177
2178
  /* @__PURE__ */ jsxs7(Stack5, { direction: "row", spacing: 1, sx: { minWidth: 0, flex: 1, alignItems: "center" }, children: [
2178
- isMobile ? /* @__PURE__ */ jsx13(Box5, { sx: { display: "flex", alignItems: "center", flexShrink: 0 }, children: /* @__PURE__ */ jsx13(
2179
- IconButton,
2180
- {
2181
- "aria-label": t("menu"),
2182
- onClick: openMobileSidebar,
2183
- size: "small",
2184
- sx: { ml: -0.5 },
2185
- children: /* @__PURE__ */ jsx13(MenuIcon, { fontSize: "small" })
2186
- }
2187
- ) }) : null,
2179
+ /* @__PURE__ */ jsx13(SidebarMenuButton, {}),
2188
2180
  beforeTitle ? /* @__PURE__ */ jsx13(Box5, { sx: { display: "flex", alignItems: "center", flexShrink: 0 }, children: beforeTitle }) : null,
2189
2181
  /* @__PURE__ */ jsx13(
2190
2182
  Typography3,
@@ -2257,15 +2249,18 @@ function MainHeaderSkeleton({
2257
2249
  zIndex: 3
2258
2250
  },
2259
2251
  children: /* @__PURE__ */ jsxs7(Stack5, { spacing: 1, children: [
2260
- /* @__PURE__ */ jsx13(
2261
- Skeleton,
2262
- {
2263
- variant: "rounded",
2264
- width: titleWidth,
2265
- height: MAIN_HEADER_TITLE_HEIGHT,
2266
- sx: { transform: "none" }
2267
- }
2268
- ),
2252
+ /* @__PURE__ */ jsxs7(Stack5, { direction: "row", spacing: 1, sx: { alignItems: "center" }, children: [
2253
+ /* @__PURE__ */ jsx13(SidebarMenuButton, {}),
2254
+ /* @__PURE__ */ jsx13(
2255
+ Skeleton,
2256
+ {
2257
+ variant: "rounded",
2258
+ width: titleWidth,
2259
+ height: MAIN_HEADER_TITLE_HEIGHT,
2260
+ sx: { transform: "none" }
2261
+ }
2262
+ )
2263
+ ] }),
2269
2264
  /* @__PURE__ */ jsx13(
2270
2265
  Skeleton,
2271
2266
  {
@@ -2279,6 +2274,25 @@ function MainHeaderSkeleton({
2279
2274
  }
2280
2275
  );
2281
2276
  }
2277
+ function SidebarMenuButton() {
2278
+ const t = useAdminTranslation();
2279
+ const { hasSidebar, sidebarId, isSidebarOpen, toggleSidebar } = useShellContext();
2280
+ if (!hasSidebar) {
2281
+ return null;
2282
+ }
2283
+ return /* @__PURE__ */ jsx13(Box5, { sx: { display: "flex", alignItems: "center", flexShrink: 0 }, children: /* @__PURE__ */ jsx13(
2284
+ IconButton,
2285
+ {
2286
+ "aria-label": t("menu"),
2287
+ "aria-controls": sidebarId,
2288
+ "aria-expanded": isSidebarOpen,
2289
+ onClick: toggleSidebar,
2290
+ size: "small",
2291
+ sx: { ml: -0.5 },
2292
+ children: /* @__PURE__ */ jsx13(MenuIcon, { fontSize: "small" })
2293
+ }
2294
+ ) });
2295
+ }
2282
2296
 
2283
2297
  // src/components/OverviewPage.tsx
2284
2298
  import { jsx as jsx14, jsxs as jsxs8 } from "react/jsx-runtime";
@@ -5492,6 +5506,7 @@ function Shell({
5492
5506
  const location = useAdminLocation(resolvedRouter);
5493
5507
  const pathname = location.pathname;
5494
5508
  const isDesktopSidebar = useMediaQuery4(activeTheme.breakpoints.up("lg"));
5509
+ const [isDesktopSidebarOpen, setIsDesktopSidebarOpen] = useState13(true);
5495
5510
  const [isMobileSidebarOpen, setIsMobileSidebarOpen] = useState13(false);
5496
5511
  const [pendingPath, setPendingPath] = useState13(null);
5497
5512
  const [pendingView, setPendingView] = useState13(null);
@@ -5544,8 +5559,16 @@ function Shell({
5544
5559
  }
5545
5560
  }, [client, isLoggingOut, loginPath, onLogout, resolvedRouter]);
5546
5561
  const shellContextValue = useMemo11(() => ({
5547
- isMobile: !isDesktopSidebar,
5548
- openMobileSidebar: () => setIsMobileSidebarOpen(true),
5562
+ hasSidebar: true,
5563
+ sidebarId: isDesktopSidebar ? "xladmin-desktop-sidebar" : "xladmin-mobile-sidebar",
5564
+ isSidebarOpen: isDesktopSidebar ? isDesktopSidebarOpen : isMobileSidebarOpen,
5565
+ toggleSidebar: () => {
5566
+ if (isDesktopSidebar) {
5567
+ setIsDesktopSidebarOpen((current) => !current);
5568
+ return;
5569
+ }
5570
+ setIsMobileSidebarOpen((current) => !current);
5571
+ },
5549
5572
  pendingPath,
5550
5573
  pendingView,
5551
5574
  startPendingNavigation: (path, view = "generic") => {
@@ -5565,7 +5588,14 @@ function Shell({
5565
5588
  setPendingPath(null);
5566
5589
  setPendingView(null);
5567
5590
  }
5568
- }), [isDesktopSidebar, pathname, pendingPath, pendingView]);
5591
+ }), [
5592
+ isDesktopSidebar,
5593
+ isDesktopSidebarOpen,
5594
+ isMobileSidebarOpen,
5595
+ pathname,
5596
+ pendingPath,
5597
+ pendingView
5598
+ ]);
5569
5599
  return /* @__PURE__ */ jsx28(AdminRouterProvider, { router: resolvedRouter, children: /* @__PURE__ */ jsx28(ThemeProvider, { theme: activeTheme, children: /* @__PURE__ */ jsx28(AdminLocaleProvider, { locale, children: /* @__PURE__ */ jsx28(AdminDataProvider, { value: { locale: locale === "en" ? "en" : "ru", models, blocks }, children: /* @__PURE__ */ jsx28(ShellContextProvider, { value: shellContextValue, children: /* @__PURE__ */ jsxs20(AdminMessageProvider, { children: [
5570
5600
  /* @__PURE__ */ jsx28(CssBaseline, {}),
5571
5601
  /* @__PURE__ */ jsx28(
@@ -5625,9 +5655,10 @@ function Shell({
5625
5655
  spacing: 0,
5626
5656
  sx: { height: "100%", minHeight: 0, alignItems: "stretch" },
5627
5657
  children: [
5628
- /* @__PURE__ */ jsx28(
5658
+ isDesktopSidebarOpen ? /* @__PURE__ */ jsx28(
5629
5659
  Box17,
5630
5660
  {
5661
+ id: "xladmin-desktop-sidebar",
5631
5662
  sx: {
5632
5663
  display: { xs: "none", lg: "block" },
5633
5664
  width: 320,
@@ -5649,7 +5680,7 @@ function Shell({
5649
5680
  }
5650
5681
  )
5651
5682
  }
5652
- ),
5683
+ ) : null,
5653
5684
  /* @__PURE__ */ jsx28(
5654
5685
  Box17,
5655
5686
  {
@@ -5675,6 +5706,7 @@ function Shell({
5675
5706
  /* @__PURE__ */ jsx28(
5676
5707
  Drawer,
5677
5708
  {
5709
+ id: "xladmin-mobile-sidebar",
5678
5710
  anchor: "left",
5679
5711
  open: isMobileSidebarOpen,
5680
5712
  onClose: () => setIsMobileSidebarOpen(false),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xladmin",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "Framework-agnostic React + MUI admin frontend for xladmin.",
5
5
  "license": "MIT",
6
6
  "type": "module",