@withpotter/pages-admin 0.13.0-next.74 → 0.13.0-next.76
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/admin/_shell/nav-fold.js +1 -1
- package/dist/admin/_shell/nav-fold.js.map +1 -1
- package/dist/admin/_shell/nav-group.js +2 -2
- package/dist/admin/_shell/nav-group.js.map +1 -1
- package/dist/admin/_shell/sidebar.js +6 -3
- package/dist/admin/_shell/sidebar.js.map +1 -1
- package/dist/admin/_shell/use-open-groups.js +20 -0
- package/dist/admin/_shell/use-open-groups.js.map +1 -0
- package/package.json +4 -4
- package/dist/admin/_shell/use-open-group.js +0 -16
- package/dist/admin/_shell/use-open-group.js.map +0 -1
|
@@ -5,7 +5,7 @@ const FOLDABLE_GROUPS = /* @__PURE__ */ new Set([
|
|
|
5
5
|
"Platform"
|
|
6
6
|
]);
|
|
7
7
|
const foldsGroup = (label, rows, collapsed) => label !== null && FOLDABLE_GROUPS.has(label) && rows > 1 && !collapsed;
|
|
8
|
-
const isGroupOpen = (
|
|
8
|
+
const isGroupOpen = (choices, label, containsActive) => choices[label] ?? containsActive;
|
|
9
9
|
export {
|
|
10
10
|
FOLDABLE_GROUPS,
|
|
11
11
|
foldsGroup,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/admin/_shell/nav-fold.ts"],"sourcesContent":["/**\n * Which sidebar groups fold, and which one is open. Pure, so it is tested\n * without a browser. The merchant rail's hubs follow the same rules.\n */\n\n
|
|
1
|
+
{"version":3,"sources":["../../../src/admin/_shell/nav-fold.ts"],"sourcesContent":["/**\n * Which sidebar groups fold, and which one is open. Pure, so it is tested\n * without a browser. The merchant rail's hubs follow the same rules.\n */\n\n/**\n * The groups the admin opened or closed by hand, by label. A group not listed\n * has no choice yet, and each group is chosen on its own.\n */\nexport type GroupChoices = Record<string, boolean>;\n\n/** The groups that fold; every other group keeps its plain heading. */\nexport const FOLDABLE_GROUPS: ReadonlySet<string> = new Set([\n 'Workspaces',\n 'Operations',\n 'Inbox',\n 'Platform',\n]);\n\n/**\n * A group folds only when it is one of those, has more than one row to hide,\n * and the rail is wide: the icon-only rail has no headings to press.\n */\nexport const foldsGroup = (\n label: string | null,\n rows: number,\n collapsed: boolean,\n): label is string =>\n label !== null && FOLDABLE_GROUPS.has(label) && rows > 1 && !collapsed;\n\n/**\n * A group the admin chose is as they left it, whatever the others are doing.\n * With no choice yet it is open when it owns the current page, so the page\n * you are on always has a lit row.\n */\nexport const isGroupOpen = (\n choices: GroupChoices,\n label: string,\n containsActive: boolean,\n) => choices[label] ?? containsActive;\n"],"mappings":"AAYO,MAAM,kBAAuC,oBAAI,IAAI;AAAA,EAC1D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAMM,MAAM,aAAa,CACxB,OACA,MACA,cAEA,UAAU,QAAQ,gBAAgB,IAAI,KAAK,KAAK,OAAO,KAAK,CAAC;AAOxD,MAAM,cAAc,CACzB,SACA,OACA,mBACG,QAAQ,KAAK,KAAK;","names":[]}
|
|
@@ -12,7 +12,7 @@ function NavGroupView({
|
|
|
12
12
|
pathname,
|
|
13
13
|
collapsed,
|
|
14
14
|
canSupport,
|
|
15
|
-
|
|
15
|
+
choices,
|
|
16
16
|
onToggle
|
|
17
17
|
}) {
|
|
18
18
|
const reduced = useReducedMotion();
|
|
@@ -33,7 +33,7 @@ function NavGroupView({
|
|
|
33
33
|
label && /* @__PURE__ */ jsx("div", { className: styles.groupLabel, children: label }),
|
|
34
34
|
rows
|
|
35
35
|
] });
|
|
36
|
-
const open = isGroupOpen(
|
|
36
|
+
const open = isGroupOpen(choices, label, containsActive);
|
|
37
37
|
return /* @__PURE__ */ jsxs("div", { className: styles.group, children: [
|
|
38
38
|
/* @__PURE__ */ jsxs(
|
|
39
39
|
"button",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/admin/_shell/nav-group.tsx"],"sourcesContent":["'use client';\n\nimport { ChevronDown } from 'lucide-react';\nimport { AnimatePresence, motion, useReducedMotion } from 'motion/react';\nimport { eases } from '@withpotter/lib/motion';\nimport type { NavGroup } from './nav-config';\nimport { isActive } from './nav-filter';\nimport { foldsGroup, isGroupOpen, type
|
|
1
|
+
{"version":3,"sources":["../../../src/admin/_shell/nav-group.tsx"],"sourcesContent":["'use client';\n\nimport { ChevronDown } from 'lucide-react';\nimport { AnimatePresence, motion, useReducedMotion } from 'motion/react';\nimport { eases } from '@withpotter/lib/motion';\nimport type { NavGroup } from './nav-config';\nimport { isActive } from './nav-filter';\nimport { foldsGroup, isGroupOpen, type GroupChoices } from './nav-fold';\nimport { NavRow } from './nav-row';\nimport styles from './sidebar.module.css';\n\n/**\n * One sidebar group. With a heading and more than one row, the heading is a\n * button that opens and closes the rows, on its own: no other group moves.\n * The group holding the current page starts open, and the icon-only rail shows\n * every row.\n */\nexport function NavGroupView({\n group,\n pathname,\n collapsed,\n canSupport,\n choices,\n onToggle,\n}: {\n group: NavGroup;\n pathname: string;\n collapsed: boolean;\n canSupport: boolean;\n choices: GroupChoices;\n onToggle: (label: string, next: boolean) => void;\n}) {\n const reduced = useReducedMotion();\n const { label, items } = group;\n const containsActive = items.some((item) => isActive(item, pathname));\n\n const rows = items.map((item) => (\n <NavRow\n key={item.href}\n item={item}\n active={isActive(item, pathname)}\n collapsed={collapsed}\n canSupport={canSupport}\n />\n ));\n\n if (!foldsGroup(label, items.length, collapsed))\n return (\n <div className={styles.group}>\n {label && <div className={styles.groupLabel}>{label}</div>}\n {rows}\n </div>\n );\n\n const open = isGroupOpen(choices, label, containsActive);\n\n return (\n <div className={styles.group}>\n <button\n type=\"button\"\n className={`${styles.groupLabel} ${styles.groupToggle}`}\n aria-expanded={open}\n onClick={() => onToggle(label, !open)}\n >\n <span>{label}</span>\n <ChevronDown size={14} className={styles.groupChevron} aria-hidden />\n </button>\n {/* The rows grow and collapse rather than blink, as the merchant rail's\n hubs do: height so the groups below move with them, opacity finishing\n early on the way in. Clipped, or the rows spill past the closing box. */}\n <AnimatePresence initial={false}>\n {open && (\n <motion.div\n className={styles.groupRows}\n initial={{ height: 0, opacity: 0 }}\n animate={{ height: 'auto', opacity: 1 }}\n exit={{ height: 0, opacity: 0 }}\n transition={\n reduced\n ? { duration: 0 }\n : {\n height: { duration: 0.24, ease: eases.settle },\n opacity: { duration: 0.16, ease: eases.out },\n }\n }\n style={{ overflow: 'hidden' }}\n >\n {rows}\n </motion.div>\n )}\n </AnimatePresence>\n </div>\n );\n}\n"],"mappings":";AAqCI,cAWE,YAXF;AAnCJ,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB,QAAQ,wBAAwB;AAC1D,SAAS,aAAa;AAEtB,SAAS,gBAAgB;AACzB,SAAS,YAAY,mBAAsC;AAC3D,SAAS,cAAc;AACvB,OAAO,YAAY;AAQZ,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAOG;AACD,QAAM,UAAU,iBAAiB;AACjC,QAAM,EAAE,OAAO,MAAM,IAAI;AACzB,QAAM,iBAAiB,MAAM,KAAK,CAAC,SAAS,SAAS,MAAM,QAAQ,CAAC;AAEpE,QAAM,OAAO,MAAM,IAAI,CAAC,SACtB;AAAA,IAAC;AAAA;AAAA,MAEC;AAAA,MACA,QAAQ,SAAS,MAAM,QAAQ;AAAA,MAC/B;AAAA,MACA;AAAA;AAAA,IAJK,KAAK;AAAA,EAKZ,CACD;AAED,MAAI,CAAC,WAAW,OAAO,MAAM,QAAQ,SAAS;AAC5C,WACE,qBAAC,SAAI,WAAW,OAAO,OACpB;AAAA,eAAS,oBAAC,SAAI,WAAW,OAAO,YAAa,iBAAM;AAAA,MACnD;AAAA,OACH;AAGJ,QAAM,OAAO,YAAY,SAAS,OAAO,cAAc;AAEvD,SACE,qBAAC,SAAI,WAAW,OAAO,OACrB;AAAA;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL,WAAW,GAAG,OAAO,UAAU,IAAI,OAAO,WAAW;AAAA,QACrD,iBAAe;AAAA,QACf,SAAS,MAAM,SAAS,OAAO,CAAC,IAAI;AAAA,QAEpC;AAAA,8BAAC,UAAM,iBAAM;AAAA,UACb,oBAAC,eAAY,MAAM,IAAI,WAAW,OAAO,cAAc,eAAW,MAAC;AAAA;AAAA;AAAA,IACrE;AAAA,IAIA,oBAAC,mBAAgB,SAAS,OACvB,kBACC;AAAA,MAAC,OAAO;AAAA,MAAP;AAAA,QACC,WAAW,OAAO;AAAA,QAClB,SAAS,EAAE,QAAQ,GAAG,SAAS,EAAE;AAAA,QACjC,SAAS,EAAE,QAAQ,QAAQ,SAAS,EAAE;AAAA,QACtC,MAAM,EAAE,QAAQ,GAAG,SAAS,EAAE;AAAA,QAC9B,YACE,UACI,EAAE,UAAU,EAAE,IACd;AAAA,UACE,QAAQ,EAAE,UAAU,MAAM,MAAM,MAAM,OAAO;AAAA,UAC7C,SAAS,EAAE,UAAU,MAAM,MAAM,MAAM,IAAI;AAAA,QAC7C;AAAA,QAEN,OAAO,EAAE,UAAU,SAAS;AAAA,QAE3B;AAAA;AAAA,IACH,GAEJ;AAAA,KACF;AAEJ;","names":[]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { isActive } from "./nav-filter";
|
|
4
4
|
import { NavGroupView } from "./nav-group";
|
|
5
|
-
import {
|
|
5
|
+
import { useOpenGroups } from "./use-open-groups";
|
|
6
6
|
import { SidebarFooter } from "./sidebar-footer";
|
|
7
7
|
import { useFluidHover } from "./use-fluid-hover";
|
|
8
8
|
import { UserMenu } from "./user-menu";
|
|
@@ -18,12 +18,15 @@ function Sidebar({
|
|
|
18
18
|
onSearch
|
|
19
19
|
}) {
|
|
20
20
|
const hover = useFluidHover();
|
|
21
|
-
const { choice, setGroupOpen } = useOpenGroup(pathname);
|
|
22
21
|
const settings = groups.flatMap((group) => group.items).find((item) => item.href === FOOT_HREF);
|
|
23
22
|
const navGroups = groups.map((group) => ({
|
|
24
23
|
...group,
|
|
25
24
|
items: group.items.filter((item) => item.href !== FOOT_HREF)
|
|
26
25
|
})).filter((group) => group.items.length);
|
|
26
|
+
const activeGroup = navGroups.find(
|
|
27
|
+
(group) => group.items.some((item) => isActive(item, pathname))
|
|
28
|
+
)?.label ?? null;
|
|
29
|
+
const { choices, setGroupOpen } = useOpenGroups(pathname, activeGroup);
|
|
27
30
|
return /* @__PURE__ */ jsxs("aside", { className: styles.sidebar, "data-collapsed": collapsed, children: [
|
|
28
31
|
/* @__PURE__ */ jsx(UserMenu, { email, role, collapsed }),
|
|
29
32
|
/* @__PURE__ */ jsxs(
|
|
@@ -53,7 +56,7 @@ function Sidebar({
|
|
|
53
56
|
pathname,
|
|
54
57
|
collapsed,
|
|
55
58
|
canSupport,
|
|
56
|
-
|
|
59
|
+
choices,
|
|
57
60
|
onToggle: setGroupOpen
|
|
58
61
|
},
|
|
59
62
|
group.label ?? index
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/admin/_shell/sidebar.tsx"],"sourcesContent":["'use client';\n\nimport type { NavGroup } from './nav-config';\nimport { isActive } from './nav-filter';\nimport { NavGroupView } from './nav-group';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/admin/_shell/sidebar.tsx"],"sourcesContent":["'use client';\n\nimport type { NavGroup } from './nav-config';\nimport { isActive } from './nav-filter';\nimport { NavGroupView } from './nav-group';\nimport { useOpenGroups } from './use-open-groups';\nimport { SidebarFooter } from './sidebar-footer';\nimport { useFluidHover } from './use-fluid-hover';\nimport { UserMenu } from './user-menu';\nimport styles from './sidebar.module.css';\n\n/** Settings lives in the pinned foot, beside the theme switch. */\nconst FOOT_HREF = '/admin/settings';\n\nexport function Sidebar({\n groups,\n pathname,\n canSupport,\n collapsed,\n email,\n role,\n onSearch,\n}: {\n groups: NavGroup[];\n pathname: string;\n canSupport: boolean;\n collapsed: boolean;\n email: string;\n role: string;\n onSearch: () => void;\n}) {\n const hover = useFluidHover();\n const settings = groups\n .flatMap((group) => group.items)\n .find((item) => item.href === FOOT_HREF);\n const navGroups = groups\n .map((group) => ({\n ...group,\n items: group.items.filter((item) => item.href !== FOOT_HREF),\n }))\n .filter((group) => group.items.length);\n const activeGroup =\n navGroups.find((group) =>\n group.items.some((item) => isActive(item, pathname)),\n )?.label ?? null;\n const { choices, setGroupOpen } = useOpenGroups(pathname, activeGroup);\n\n return (\n <aside className={styles.sidebar} data-collapsed={collapsed}>\n <UserMenu email={email} role={role} collapsed={collapsed} />\n\n <nav\n className={styles.nav}\n aria-label=\"Admin\"\n onPointerMove={hover.onPointerMove}\n onPointerLeave={hover.onPointerLeave}\n >\n <span\n aria-hidden\n className={styles.glide}\n data-visible={Boolean(hover.rect)}\n style={\n hover.rect\n ? {\n transform: `translateY(${hover.rect.top}px)`,\n height: hover.rect.height,\n }\n : undefined\n }\n />\n {navGroups.map((group, index) => (\n <NavGroupView\n key={group.label ?? index}\n group={group}\n pathname={pathname}\n collapsed={collapsed}\n canSupport={canSupport}\n choices={choices}\n onToggle={setGroupOpen}\n />\n ))}\n </nav>\n\n <SidebarFooter\n collapsed={collapsed}\n showSettings={Boolean(settings)}\n settingsActive={settings ? isActive(settings, pathname) : false}\n onSearch={onSearch}\n />\n </aside>\n );\n}\n"],"mappings":";AAiDM,cAEA,YAFA;AA9CN,SAAS,gBAAgB;AACzB,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AACzB,OAAO,YAAY;AAGnB,MAAM,YAAY;AAEX,SAAS,QAAQ;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAQG;AACD,QAAM,QAAQ,cAAc;AAC5B,QAAM,WAAW,OACd,QAAQ,CAAC,UAAU,MAAM,KAAK,EAC9B,KAAK,CAAC,SAAS,KAAK,SAAS,SAAS;AACzC,QAAM,YAAY,OACf,IAAI,CAAC,WAAW;AAAA,IACf,GAAG;AAAA,IACH,OAAO,MAAM,MAAM,OAAO,CAAC,SAAS,KAAK,SAAS,SAAS;AAAA,EAC7D,EAAE,EACD,OAAO,CAAC,UAAU,MAAM,MAAM,MAAM;AACvC,QAAM,cACJ,UAAU;AAAA,IAAK,CAAC,UACd,MAAM,MAAM,KAAK,CAAC,SAAS,SAAS,MAAM,QAAQ,CAAC;AAAA,EACrD,GAAG,SAAS;AACd,QAAM,EAAE,SAAS,aAAa,IAAI,cAAc,UAAU,WAAW;AAErE,SACE,qBAAC,WAAM,WAAW,OAAO,SAAS,kBAAgB,WAChD;AAAA,wBAAC,YAAS,OAAc,MAAY,WAAsB;AAAA,IAE1D;AAAA,MAAC;AAAA;AAAA,QACC,WAAW,OAAO;AAAA,QAClB,cAAW;AAAA,QACX,eAAe,MAAM;AAAA,QACrB,gBAAgB,MAAM;AAAA,QAEtB;AAAA;AAAA,YAAC;AAAA;AAAA,cACC,eAAW;AAAA,cACX,WAAW,OAAO;AAAA,cAClB,gBAAc,QAAQ,MAAM,IAAI;AAAA,cAChC,OACE,MAAM,OACF;AAAA,gBACE,WAAW,cAAc,MAAM,KAAK,GAAG;AAAA,gBACvC,QAAQ,MAAM,KAAK;AAAA,cACrB,IACA;AAAA;AAAA,UAER;AAAA,UACC,UAAU,IAAI,CAAC,OAAO,UACrB;AAAA,YAAC;AAAA;AAAA,cAEC;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA,UAAU;AAAA;AAAA,YANL,MAAM,SAAS;AAAA,UAOtB,CACD;AAAA;AAAA;AAAA,IACH;AAAA,IAEA;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA,cAAc,QAAQ,QAAQ;AAAA,QAC9B,gBAAgB,WAAW,SAAS,UAAU,QAAQ,IAAI;AAAA,QAC1D;AAAA;AAAA,IACF;AAAA,KACF;AAEJ;","names":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
function useOpenGroups(pathname, activeGroup) {
|
|
4
|
+
const [choices, setChoices] = useState({});
|
|
5
|
+
const setGroupOpen = (label, next) => setChoices((current) => ({ ...current, [label]: next }));
|
|
6
|
+
const [choiceRoute, setChoiceRoute] = useState(pathname);
|
|
7
|
+
if (choiceRoute !== pathname) {
|
|
8
|
+
setChoiceRoute(pathname);
|
|
9
|
+
if (activeGroup && activeGroup in choices) {
|
|
10
|
+
const next = { ...choices };
|
|
11
|
+
delete next[activeGroup];
|
|
12
|
+
setChoices(next);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return { choices, setGroupOpen };
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
useOpenGroups
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=use-open-groups.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/admin/_shell/use-open-groups.ts"],"sourcesContent":["'use client';\n\nimport { useState } from 'react';\nimport type { GroupChoices } from './nav-fold';\n\n/**\n * Which sidebar groups the admin has opened or closed by hand, each on its\n * own: pressing one never moves another. `activeGroup` is the group holding the\n * current page, or null.\n */\nexport function useOpenGroups(pathname: string, activeGroup: string | null) {\n const [choices, setChoices] = useState<GroupChoices>({});\n const setGroupOpen = (label: string, next: boolean) =>\n setChoices((current) => ({ ...current, [label]: next }));\n // Arriving on a page retires the choice for its own group only, or a group\n // closed by hand would hide the row you just landed on. The other groups\n // stay as they were. Adjusted during render, not in an effect, so no stale\n // frame paints first.\n const [choiceRoute, setChoiceRoute] = useState(pathname);\n\n if (choiceRoute !== pathname) {\n setChoiceRoute(pathname);\n\n if (activeGroup && activeGroup in choices) {\n const next = { ...choices };\n\n delete next[activeGroup];\n setChoices(next);\n }\n }\n\n return { choices, setGroupOpen };\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AAQlB,SAAS,cAAc,UAAkB,aAA4B;AAC1E,QAAM,CAAC,SAAS,UAAU,IAAI,SAAuB,CAAC,CAAC;AACvD,QAAM,eAAe,CAAC,OAAe,SACnC,WAAW,CAAC,aAAa,EAAE,GAAG,SAAS,CAAC,KAAK,GAAG,KAAK,EAAE;AAKzD,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,QAAQ;AAEvD,MAAI,gBAAgB,UAAU;AAC5B,mBAAe,QAAQ;AAEvB,QAAI,eAAe,eAAe,SAAS;AACzC,YAAM,OAAO,EAAE,GAAG,QAAQ;AAE1B,aAAO,KAAK,WAAW;AACvB,iBAAW,IAAI;AAAA,IACjB;AAAA,EACF;AAEA,SAAO,EAAE,SAAS,aAAa;AACjC;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@withpotter/pages-admin",
|
|
3
|
-
"version": "0.13.0-next.
|
|
3
|
+
"version": "0.13.0-next.76",
|
|
4
4
|
"description": "Box console platform-admin routes: overview, revenue, accounts, tenants, admins, roles, audit.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@radix-ui/react-popover": "^1.1.23",
|
|
33
33
|
"@tanstack/react-query": "^5.90.20",
|
|
34
|
-
"@withpotter/lib": "^0.13.0-next.
|
|
35
|
-
"@withpotter/platform-admin": "^0.13.0-next.
|
|
36
|
-
"@withpotter/ui-kit": "^0.13.0-next.
|
|
34
|
+
"@withpotter/lib": "^0.13.0-next.76",
|
|
35
|
+
"@withpotter/platform-admin": "^0.13.0-next.76",
|
|
36
|
+
"@withpotter/ui-kit": "^0.13.0-next.76",
|
|
37
37
|
"lucide-react": "^0.562.0",
|
|
38
38
|
"motion": "^12.42.2"
|
|
39
39
|
},
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
function useOpenGroup(pathname) {
|
|
4
|
-
const [choice, setChoice] = useState(void 0);
|
|
5
|
-
const setGroupOpen = (label, next) => setChoice(next ? label : null);
|
|
6
|
-
const [choiceRoute, setChoiceRoute] = useState(pathname);
|
|
7
|
-
if (choiceRoute !== pathname) {
|
|
8
|
-
setChoiceRoute(pathname);
|
|
9
|
-
setChoice(void 0);
|
|
10
|
-
}
|
|
11
|
-
return { choice, setGroupOpen };
|
|
12
|
-
}
|
|
13
|
-
export {
|
|
14
|
-
useOpenGroup
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=use-open-group.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/admin/_shell/use-open-group.ts"],"sourcesContent":["'use client';\n\nimport { useState } from 'react';\nimport type { GroupChoice } from './nav-fold';\n\n/**\n * Which sidebar group is showing its rows: ONE, none, or \"not said yet\"\n * (`undefined`, which leaves the group owning the current page open). The\n * merchant rail's useOpenHub, for the admin's groups.\n */\nexport function useOpenGroup(pathname: string) {\n const [choice, setChoice] = useState<GroupChoice>(undefined);\n const setGroupOpen = (label: string, next: boolean) =>\n setChoice(next ? label : null);\n // A new route retires the choice, or arriving from inside the page would\n // leave the rail on the last group pressed, with the current row hidden.\n // Adjusted during render, not in an effect, so no stale frame paints first.\n const [choiceRoute, setChoiceRoute] = useState(pathname);\n\n if (choiceRoute !== pathname) {\n setChoiceRoute(pathname);\n setChoice(undefined);\n }\n\n return { choice, setGroupOpen };\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AAQlB,SAAS,aAAa,UAAkB;AAC7C,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAsB,MAAS;AAC3D,QAAM,eAAe,CAAC,OAAe,SACnC,UAAU,OAAO,QAAQ,IAAI;AAI/B,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,QAAQ;AAEvD,MAAI,gBAAgB,UAAU;AAC5B,mBAAe,QAAQ;AACvB,cAAU,MAAS;AAAA,EACrB;AAEA,SAAO,EAAE,QAAQ,aAAa;AAChC;","names":[]}
|