@kcascend/liquid-ui 0.0.12 → 0.0.14

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.
Files changed (33) hide show
  1. package/README.md +19 -0
  2. package/dist/components/ApplicationInformationPanel/ApplicationInformationPanel.d.ts +3 -0
  3. package/dist/components/ApplicationInformationPanel/ApplicationInformationPanel.d.ts.map +1 -0
  4. package/dist/components/ApplicationInformationPanel/ApplicationInformationPanel.js +83 -0
  5. package/dist/components/GridLayout/layoutPatterns.d.ts +2 -1
  6. package/dist/components/GridLayout/layoutPatterns.d.ts.map +1 -1
  7. package/dist/components/GridLayout/layoutPatterns.js +7 -0
  8. package/dist/components/HeaderShell/HeaderShell.d.ts +1 -1
  9. package/dist/components/HeaderShell/HeaderShell.d.ts.map +1 -1
  10. package/dist/components/HeaderShell/HeaderShell.js +4 -2
  11. package/dist/components/ProductNavigationPanel/ProductNavigationPanel.d.ts +3 -0
  12. package/dist/components/ProductNavigationPanel/ProductNavigationPanel.d.ts.map +1 -0
  13. package/dist/components/ProductNavigationPanel/ProductNavigationPanel.js +61 -0
  14. package/dist/generated/tokens.d.ts +16962 -6609
  15. package/dist/generated/tokens.d.ts.map +1 -1
  16. package/dist/generated/tokens.js +16851 -6498
  17. package/dist/governance/applicationInformationPanelGovernance.d.ts +3 -0
  18. package/dist/governance/applicationInformationPanelGovernance.d.ts.map +1 -0
  19. package/dist/governance/applicationInformationPanelGovernance.js +9 -0
  20. package/dist/governance/headerShellGovernance.d.ts.map +1 -1
  21. package/dist/governance/headerShellGovernance.js +1 -0
  22. package/dist/governance/productNavigationPanelGovernance.d.ts +3 -0
  23. package/dist/governance/productNavigationPanelGovernance.d.ts.map +1 -0
  24. package/dist/governance/productNavigationPanelGovernance.js +9 -0
  25. package/dist/index.d.ts +6 -2
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +5 -1
  28. package/dist/styles.css +1461 -425
  29. package/dist/tokens/components.css +1177 -406
  30. package/dist/tokens/semantic.css +1 -0
  31. package/dist/types.d.ts +41 -0
  32. package/dist/types.d.ts.map +1 -1
  33. package/package.json +1 -1
package/README.md CHANGED
@@ -41,6 +41,25 @@ Supported layout features:
41
41
  - `subgrid` for nested grids that inherit the parent column scaffold.
42
42
  - Auto columns when a `GridColumn` is rendered without explicit breakpoint props.
43
43
 
44
+ ## Application shell geometry
45
+
46
+ The Figma application-shell pattern is the canonical geometry for product shells:
47
+
48
+ - Header: `48px`
49
+ - Left product-navigation panel: `256px`
50
+ - Right application-information panel: `256px`
51
+ - Compact transformation breakpoint: `672px`
52
+
53
+ Import `applicationShellGeometry` rather than reproducing these values in consumer CSS. The
54
+ geometry is sourced from Figma node `3307:3`; its runtime composition and accessibility behavior
55
+ remain governed by the exported shell components.
56
+
57
+ `ProductNavigationPanel` provides product-local destinations and expandable route groups, with
58
+ controlled or uncontrolled active-route and disclosure state. `ApplicationInformationPanel` provides
59
+ the separate application-wide utility disclosure. It requires `privacyHref`, `termsOfUseHref`, and
60
+ non-link `copyright` metadata; optional utility rows are supplied by the consumer. Pass the same
61
+ configuration through `HeaderShell.applicationInformation` to render its independent header trigger.
62
+
44
63
  Approved layout guidance:
45
64
 
46
65
  - Start application shells from `approvedShellRows`.
@@ -0,0 +1,3 @@
1
+ import type { ApplicationInformationPanelProps } from '../../types';
2
+ export declare function ApplicationInformationPanel({ className, copyright, defaultOpen, label, onOpenChange, open, privacyHref, termsOfUseHref, utilities, ...props }: ApplicationInformationPanelProps): import("react/jsx-runtime").JSX.Element;
3
+ //# sourceMappingURL=ApplicationInformationPanel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApplicationInformationPanel.d.ts","sourceRoot":"","sources":["../../../src/components/ApplicationInformationPanel/ApplicationInformationPanel.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,gCAAgC,EAEjC,MAAM,aAAa,CAAC;AAoCrB,wBAAgB,2BAA2B,CAAC,EAC1C,SAAS,EACT,SAAS,EACT,WAAmB,EACnB,KAAiC,EACjC,YAAY,EACZ,IAAI,EACJ,WAAW,EACX,cAAc,EACd,SAAc,EACd,GAAG,KAAK,EACT,EAAE,gCAAgC,2CAkHlC"}
@@ -0,0 +1,83 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useEffect, useId, useRef, useState } from 'react';
3
+ import { Icon } from '../Icon/Icon';
4
+ function getClassName(className) {
5
+ return ['liquid-application-information-panel', className]
6
+ .filter(Boolean)
7
+ .join(' ');
8
+ }
9
+ function getFocusableElements(container) {
10
+ return Array.from(container?.querySelectorAll('a[href], button:not([disabled]), [tabindex]:not([tabindex="-1"])') ?? []);
11
+ }
12
+ function useIsCompactViewport() {
13
+ const [isCompact, setIsCompact] = useState(false);
14
+ useEffect(() => {
15
+ const query = window.matchMedia('(max-width: 671px)');
16
+ const updateIsCompact = () => {
17
+ setIsCompact(query.matches);
18
+ };
19
+ updateIsCompact();
20
+ query.addEventListener('change', updateIsCompact);
21
+ return () => {
22
+ query.removeEventListener('change', updateIsCompact);
23
+ };
24
+ }, []);
25
+ return isCompact;
26
+ }
27
+ export function ApplicationInformationPanel({ className, copyright, defaultOpen = false, label = 'Application information', onOpenChange, open, privacyHref, termsOfUseHref, utilities = [], ...props }) {
28
+ const [internalOpen, setInternalOpen] = useState(defaultOpen);
29
+ const triggerRef = useRef(null);
30
+ const panelRef = useRef(null);
31
+ const panelId = useId();
32
+ const resolvedOpen = open ?? internalOpen;
33
+ const isCompactViewport = useIsCompactViewport();
34
+ const setPanelOpen = (nextOpen) => {
35
+ if (open === undefined) {
36
+ setInternalOpen(nextOpen);
37
+ }
38
+ onOpenChange?.(nextOpen);
39
+ };
40
+ useEffect(() => {
41
+ if (!resolvedOpen) {
42
+ return;
43
+ }
44
+ getFocusableElements(panelRef.current)[0]?.focus();
45
+ const handleKeyDown = (event) => {
46
+ if (event.key === 'Escape') {
47
+ setPanelOpen(false);
48
+ triggerRef.current?.focus();
49
+ }
50
+ };
51
+ window.addEventListener('keydown', handleKeyDown);
52
+ return () => {
53
+ window.removeEventListener('keydown', handleKeyDown);
54
+ };
55
+ }, [resolvedOpen]);
56
+ const handlePanelKeyDown = (event) => {
57
+ if (!isCompactViewport || event.key !== 'Tab') {
58
+ return;
59
+ }
60
+ const focusable = getFocusableElements(panelRef.current);
61
+ if (!focusable.length) {
62
+ return;
63
+ }
64
+ const first = focusable[0];
65
+ const last = focusable[focusable.length - 1];
66
+ if (event.shiftKey && document.activeElement === first) {
67
+ event.preventDefault();
68
+ last.focus();
69
+ }
70
+ else if (!event.shiftKey && document.activeElement === last) {
71
+ event.preventDefault();
72
+ first.focus();
73
+ }
74
+ };
75
+ return (_jsxs("div", { ...props, className: getClassName(className), children: [_jsx("button", { "aria-controls": panelId, "aria-expanded": resolvedOpen, "aria-haspopup": "dialog", "aria-label": label, className: "liquid-application-information-panel__trigger", "data-expanded": resolvedOpen || undefined, onClick: () => {
76
+ setPanelOpen(!resolvedOpen);
77
+ }, ref: triggerRef, type: "button", children: _jsx(Icon, { "aria-hidden": "true", name: "info", size: 24 }) }), resolvedOpen ? (_jsxs(_Fragment, { children: [_jsx("button", { "aria-label": `Close ${label}`, className: "liquid-application-information-panel__backdrop", onClick: () => {
78
+ setPanelOpen(false);
79
+ }, type: "button" }), _jsx("aside", { "aria-label": label, "aria-modal": isCompactViewport || undefined, className: "liquid-application-information-panel__panel", id: panelId, onKeyDown: handlePanelKeyDown, ref: panelRef, role: "dialog", children: _jsx("nav", { "aria-label": `${label} links`, children: _jsxs("ul", { className: "liquid-application-information-panel__list", children: [utilities.map((utility) => (_jsx(UtilityItem, { utility: utility }, utility.id))), _jsx("li", { children: _jsx("a", { href: privacyHref, children: "Privacy" }) }), _jsx("li", { children: _jsx("a", { href: termsOfUseHref, children: "Terms of Use" }) }), _jsx("li", { className: "liquid-application-information-panel__metadata", children: copyright })] }) }) })] })) : null] }));
80
+ }
81
+ function UtilityItem({ utility, }) {
82
+ return (_jsx("li", { children: _jsx("a", { href: utility.href, children: utility.label }) }));
83
+ }
@@ -1,5 +1,6 @@
1
- import type { ApprovedLegacyContentLayoutPatternName, CanonicalLayoutPattern, CanonicalLayoutPatternName, GridColumnProps, ApprovedContentLayoutPattern, ApprovedShellRowConfig } from '../../types';
1
+ import type { ApprovedLegacyContentLayoutPatternName, CanonicalLayoutPattern, CanonicalLayoutPatternName, GridColumnProps, ApprovedContentLayoutPattern, ApprovedShellRowConfig, ApplicationShellGeometry } from '../../types';
2
2
  export declare const approvedShellRows: Record<'header' | 'search' | 'results' | 'footer', ApprovedShellRowConfig>;
3
+ export declare const applicationShellGeometry: ApplicationShellGeometry;
3
4
  export declare const approvedContentLayoutPatterns: Record<ApprovedLegacyContentLayoutPatternName, ApprovedContentLayoutPattern>;
4
5
  export declare const canonicalModernizationLayoutPatterns: Record<CanonicalLayoutPatternName, CanonicalLayoutPattern>;
5
6
  export declare const legacyToCanonicalLayoutPatternMap: Record<ApprovedLegacyContentLayoutPatternName, CanonicalLayoutPatternName[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"layoutPatterns.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/layoutPatterns.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sCAAsC,EACtC,sBAAsB,EACtB,0BAA0B,EAC1B,eAAe,EAGf,4BAA4B,EAC5B,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAoBrB,eAAO,MAAM,iBAAiB,EAAE,MAAM,CACpC,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,EAC1C,sBAAsB,CAqBvB,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,MAAM,CAChD,sCAAsC,EACtC,4BAA4B,CA0D7B,CAAC;AAEF,eAAO,MAAM,oCAAoC,EAAE,MAAM,CACvD,0BAA0B,EAC1B,sBAAsB,CAoOvB,CAAC;AAEF,eAAO,MAAM,iCAAiC,EAAE,MAAM,CACpD,sCAAsC,EACtC,0BAA0B,EAAE,CAW7B,CAAC;AAEF,wBAAgB,sCAAsC,CACpD,WAAW,EAAE,0BAA0B,GACtC,sBAAsB,CAExB;AAED,wBAAgB,+BAA+B,CAC7C,WAAW,EAAE,MAAM,OAAO,6BAA6B,GACtD,MAAM,CAAC,SAAS,GAAG,WAAW,GAAG,UAAU,EAAE,eAAe,GAAG,SAAS,CAAC,CAY3E"}
1
+ {"version":3,"file":"layoutPatterns.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/layoutPatterns.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sCAAsC,EACtC,sBAAsB,EACtB,0BAA0B,EAC1B,eAAe,EAGf,4BAA4B,EAC5B,sBAAsB,EACtB,wBAAwB,EACzB,MAAM,aAAa,CAAC;AAoBrB,eAAO,MAAM,iBAAiB,EAAE,MAAM,CACpC,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,EAC1C,sBAAsB,CAqBvB,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,wBAMtC,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,MAAM,CAChD,sCAAsC,EACtC,4BAA4B,CA0D7B,CAAC;AAEF,eAAO,MAAM,oCAAoC,EAAE,MAAM,CACvD,0BAA0B,EAC1B,sBAAsB,CAoOvB,CAAC;AAEF,eAAO,MAAM,iCAAiC,EAAE,MAAM,CACpD,sCAAsC,EACtC,0BAA0B,EAAE,CAW7B,CAAC;AAEF,wBAAgB,sCAAsC,CACpD,WAAW,EAAE,0BAA0B,GACtC,sBAAsB,CAExB;AAED,wBAAgB,+BAA+B,CAC7C,WAAW,EAAE,MAAM,OAAO,6BAA6B,GACtD,MAAM,CAAC,SAAS,GAAG,WAAW,GAAG,UAAU,EAAE,eAAe,GAAG,SAAS,CAAC,CAY3E"}
@@ -25,6 +25,13 @@ export const approvedShellRows = {
25
25
  layout: pickLayoutProps({ fullWidth: true, withRowGap: false }),
26
26
  },
27
27
  };
28
+ export const applicationShellGeometry = {
29
+ figmaNodeId: '3307:3',
30
+ headerHeight: '48px',
31
+ leftPanelWidth: '256px',
32
+ rightPanelWidth: '256px',
33
+ compactBreakpoint: '672px',
34
+ };
28
35
  export const approvedContentLayoutPatterns = {
29
36
  single: {
30
37
  description: 'Single-column content for forms, detail views, and uninterrupted reading flows.',
@@ -1,3 +1,3 @@
1
1
  import type { HeaderShellProps } from '../../types';
2
- export declare function HeaderShell({ activeNavigationItemId, actions, brand, className, defaultActiveNavigationItemId, menuTriggerLabel, navigationItems, navLabel, onAction, onMenuTriggerClick, onNavigationChange, showMenuTrigger, showNav, showUtilities, style, ...props }: HeaderShellProps): import("react/jsx-runtime").JSX.Element;
2
+ export declare function HeaderShell({ activeNavigationItemId, applicationInformation, actions, brand, className, defaultActiveNavigationItemId, menuTriggerLabel, navigationItems, navLabel, onAction, onMenuTriggerClick, onNavigationChange, showMenuTrigger, showNav, showUtilities, style, ...props }: HeaderShellProps): import("react/jsx-runtime").JSX.Element;
3
3
  //# sourceMappingURL=HeaderShell.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"HeaderShell.d.ts","sourceRoot":"","sources":["../../../src/components/HeaderShell/HeaderShell.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,gBAAgB,EAGjB,MAAM,aAAa,CAAC;AA2KrB,wBAAgB,WAAW,CAAC,EAC1B,sBAAsB,EACtB,OAAO,EACP,KAAK,EACL,SAAS,EACT,6BAA6B,EAC7B,gBAA8B,EAC9B,eAAe,EACf,QAAoB,EACpB,QAAQ,EACR,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,OAAc,EACd,aAAoB,EACpB,KAAK,EACL,GAAG,KAAK,EACT,EAAE,gBAAgB,2CA+OlB"}
1
+ {"version":3,"file":"HeaderShell.d.ts","sourceRoot":"","sources":["../../../src/components/HeaderShell/HeaderShell.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,gBAAgB,EAGjB,MAAM,aAAa,CAAC;AA4KrB,wBAAgB,WAAW,CAAC,EAC1B,sBAAsB,EACtB,sBAAsB,EACtB,OAAO,EACP,KAAK,EACL,SAAS,EACT,6BAA6B,EAC7B,gBAA8B,EAC9B,eAAe,EACf,QAAoB,EACpB,QAAQ,EACR,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,OAAc,EACd,aAAoB,EACpB,KAAK,EACL,GAAG,KAAK,EACT,EAAE,gBAAgB,2CA4PlB"}
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useEffect, useId, useMemo, useRef, useState } from 'react';
3
+ import { ApplicationInformationPanel } from '../ApplicationInformationPanel/ApplicationInformationPanel';
3
4
  import { Icon } from '../Icon/Icon';
4
5
  function getClassName(className) {
5
6
  return ['liquid-header-shell', className].filter(Boolean).join(' ');
@@ -49,7 +50,7 @@ function HeaderUtilityAction({ action, showLabel = false, onAction, }) {
49
50
  }
50
51
  }, type: "button", children: [icon, showLabel ? (_jsx("span", { className: "liquid-header-shell__action-label", children: action.label })) : null] }));
51
52
  }
52
- export function HeaderShell({ activeNavigationItemId, actions, brand, className, defaultActiveNavigationItemId, menuTriggerLabel = 'Open menu', navigationItems, navLabel = 'Primary', onAction, onMenuTriggerClick, onNavigationChange, showMenuTrigger, showNav = true, showUtilities = true, style, ...props }) {
53
+ export function HeaderShell({ activeNavigationItemId, applicationInformation, actions, brand, className, defaultActiveNavigationItemId, menuTriggerLabel = 'Open menu', navigationItems, navLabel = 'Primary', onAction, onMenuTriggerClick, onNavigationChange, showMenuTrigger, showNav = true, showUtilities = true, style, ...props }) {
53
54
  const fallbackActiveId = useMemo(() => getFirstEnabledNavigationItem(navigationItems), [navigationItems]);
54
55
  const [internalActiveId, setInternalActiveId] = useState(defaultActiveNavigationItemId ?? fallbackActiveId);
55
56
  const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
@@ -126,7 +127,8 @@ export function HeaderShell({ activeNavigationItemId, actions, brand, className,
126
127
  const navigationContent = (_jsx(_Fragment, { children: navigationItems.map((item) => (_jsx(HeaderNavigationLink, { activeItemId: resolvedActiveId, item: item, onSelect: handleNavigationSelect }, item.id))) }));
127
128
  const actionsContent = actions?.length ? (_jsx(_Fragment, { children: actions.map((action) => (_jsx(HeaderUtilityAction, { action: action, onAction: handleAction }, action.id))) })) : null;
128
129
  const mobileActionsContent = actions?.length ? (_jsx(_Fragment, { children: actions.map((action) => (_jsx(HeaderUtilityAction, { action: action, showLabel: true, onAction: handleAction }, `mobile:${action.id}`))) })) : null;
129
- return (_jsxs("header", { ...props, className: getClassName(className), "data-mobile-menu-enabled": shouldShowMenuTrigger ? 'true' : undefined, style: style, children: [_jsxs("div", { className: "liquid-header-shell__inner", children: [_jsxs("div", { className: "liquid-header-shell__left", children: [shouldShowMenuTrigger ? (_jsx("button", { "aria-label": menuTriggerLabel, "aria-controls": mobileAccordionId, "aria-expanded": isMobileMenuOpen, className: "liquid-header-shell__action liquid-header-shell__menu-trigger", ref: menuTriggerRef, onClick: handleMenuTriggerClick, type: "button", children: _jsx(Icon, { name: isMobileMenuOpen ? 'close' : 'menu', size: 20 }) })) : null, _jsx("div", { className: "liquid-header-shell__brand", children: brand }), showNav ? (_jsx("nav", { "aria-label": navLabel, className: "liquid-header-shell__nav", children: _jsx("div", { className: "liquid-header-shell__nav-list", children: navigationContent }) })) : null] }), showUtilities && actionsContent ? (_jsx("div", { className: "liquid-header-shell__actions", children: actionsContent })) : null, shouldShowMenuTrigger ? (_jsx("div", { "aria-hidden": "true", className: "liquid-header-shell__right-spacer" })) : null] }), shouldShowMenuTrigger ? (_jsxs("div", { className: "liquid-header-shell__mobile-layer", "data-open": isMobileMenuOpen ? 'true' : undefined, hidden: !isMobileMenuOpen, children: [_jsx("button", { "aria-label": "Close menu", className: "liquid-header-shell__mobile-backdrop", onClick: () => {
130
+ const applicationInformationContent = applicationInformation ? (_jsx(ApplicationInformationPanel, { ...applicationInformation })) : null;
131
+ return (_jsxs("header", { ...props, className: getClassName(className), "data-application-information-enabled": applicationInformationContent ? 'true' : undefined, "data-mobile-menu-enabled": shouldShowMenuTrigger ? 'true' : undefined, style: style, children: [_jsxs("div", { className: "liquid-header-shell__inner", children: [_jsxs("div", { className: "liquid-header-shell__left", children: [shouldShowMenuTrigger ? (_jsx("button", { "aria-label": menuTriggerLabel, "aria-controls": mobileAccordionId, "aria-expanded": isMobileMenuOpen, className: "liquid-header-shell__action liquid-header-shell__menu-trigger", ref: menuTriggerRef, onClick: handleMenuTriggerClick, type: "button", children: _jsx(Icon, { name: isMobileMenuOpen ? 'close' : 'menu', size: 20 }) })) : null, _jsx("div", { className: "liquid-header-shell__brand", children: brand }), showNav ? (_jsx("nav", { "aria-label": navLabel, className: "liquid-header-shell__nav", children: _jsx("div", { className: "liquid-header-shell__nav-list", children: navigationContent }) })) : null] }), showUtilities && actionsContent ? (_jsx("div", { className: "liquid-header-shell__actions", children: actionsContent })) : null, showUtilities && applicationInformationContent ? (_jsx("div", { className: "liquid-header-shell__application-information", children: applicationInformationContent })) : null, shouldShowMenuTrigger && !applicationInformationContent ? (_jsx("div", { "aria-hidden": "true", className: "liquid-header-shell__right-spacer" })) : null] }), shouldShowMenuTrigger ? (_jsxs("div", { className: "liquid-header-shell__mobile-layer", "data-open": isMobileMenuOpen ? 'true' : undefined, hidden: !isMobileMenuOpen, children: [_jsx("button", { "aria-label": "Close menu", className: "liquid-header-shell__mobile-backdrop", onClick: () => {
130
132
  closeMobileMenu();
131
133
  }, type: "button" }), _jsxs("aside", { className: "liquid-header-shell__mobile-panel", id: mobileAccordionId, role: "dialog", "aria-modal": "true", "aria-label": navLabel, ref: mobilePanelRef, onClick: (event) => {
132
134
  const target = event.target;
@@ -0,0 +1,3 @@
1
+ import type { ProductNavigationPanelProps } from '../../types';
2
+ export declare function ProductNavigationPanel({ activeItemId, className, defaultActiveItemId, defaultExpandedItemIds, expandedItemIds, items, navLabel, onActiveItemChange, onExpandedItemIdsChange, style, ...props }: ProductNavigationPanelProps): import("react/jsx-runtime").JSX.Element;
3
+ //# sourceMappingURL=ProductNavigationPanel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProductNavigationPanel.d.ts","sourceRoot":"","sources":["../../../src/components/ProductNavigationPanel/ProductNavigationPanel.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAEV,2BAA2B,EAC5B,MAAM,aAAa,CAAC;AAarB,wBAAgB,sBAAsB,CAAC,EACrC,YAAY,EACZ,SAAS,EACT,mBAAmB,EACnB,sBAAsB,EACtB,eAAe,EACf,KAAK,EACL,QAA+B,EAC/B,kBAAkB,EAClB,uBAAuB,EACvB,KAAK,EACL,GAAG,KAAK,EACT,EAAE,2BAA2B,2CAqE7B"}
@@ -0,0 +1,61 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useId, useState } from 'react';
3
+ import { Icon } from '../Icon/Icon';
4
+ function getClassName(className) {
5
+ return ['liquid-product-navigation-panel', className]
6
+ .filter(Boolean)
7
+ .join(' ');
8
+ }
9
+ function getInitialExpandedItemIds(items) {
10
+ return items.filter((item) => item.defaultExpanded).map((item) => item.id);
11
+ }
12
+ export function ProductNavigationPanel({ activeItemId, className, defaultActiveItemId, defaultExpandedItemIds, expandedItemIds, items, navLabel = 'Product navigation', onActiveItemChange, onExpandedItemIdsChange, style, ...props }) {
13
+ const [internalActiveItemId, setInternalActiveItemId] = useState(defaultActiveItemId);
14
+ const [internalExpandedItemIds, setInternalExpandedItemIds] = useState(() => defaultExpandedItemIds ?? getInitialExpandedItemIds(items));
15
+ const resolvedActiveItemId = activeItemId ?? internalActiveItemId;
16
+ const resolvedExpandedItemIds = expandedItemIds ?? internalExpandedItemIds;
17
+ const updateActiveItem = (item) => {
18
+ if (item.disabled) {
19
+ return;
20
+ }
21
+ if (activeItemId === undefined) {
22
+ setInternalActiveItemId(item.id);
23
+ }
24
+ onActiveItemChange?.(item.id, item);
25
+ };
26
+ const updateExpandedItems = (itemId) => {
27
+ const nextItemIds = resolvedExpandedItemIds.includes(itemId)
28
+ ? resolvedExpandedItemIds.filter((id) => id !== itemId)
29
+ : [...resolvedExpandedItemIds, itemId];
30
+ if (expandedItemIds === undefined) {
31
+ setInternalExpandedItemIds(nextItemIds);
32
+ }
33
+ onExpandedItemIdsChange?.(nextItemIds);
34
+ };
35
+ return (_jsx("nav", { ...props, "aria-label": navLabel, className: getClassName(className), style: style, children: _jsx("ul", { className: "liquid-product-navigation-panel__list", children: items.map((item) => {
36
+ const isExpanded = resolvedExpandedItemIds.includes(item.id);
37
+ const isSelected = item.id === resolvedActiveItemId;
38
+ return (_jsx("li", { className: "liquid-product-navigation-panel__item", children: item.items?.length ? (_jsx(ProductNavigationGroup, { isExpanded: isExpanded, item: item, isSelected: isSelected, onToggle: () => {
39
+ updateExpandedItems(item.id);
40
+ }, onSelect: updateActiveItem, selectedItemId: resolvedActiveItemId })) : (_jsx(ProductNavigationDestination, { item: item, selected: isSelected, onSelect: updateActiveItem })) }, item.id));
41
+ }) }) }));
42
+ }
43
+ function ProductNavigationDestination({ item, onSelect, selected, }) {
44
+ const className = 'liquid-product-navigation-panel__destination';
45
+ if (item.href) {
46
+ return (_jsx("a", { "aria-current": selected ? 'page' : undefined, "aria-disabled": item.disabled || undefined, className: className, "data-selected": selected || undefined, href: item.href, onClick: (event) => {
47
+ if (item.disabled) {
48
+ event.preventDefault();
49
+ return;
50
+ }
51
+ onSelect(item);
52
+ }, children: item.label }));
53
+ }
54
+ return (_jsx("button", { "aria-current": selected ? 'page' : undefined, className: className, "data-selected": selected || undefined, disabled: item.disabled, onClick: () => {
55
+ onSelect(item);
56
+ }, type: "button", children: item.label }));
57
+ }
58
+ function ProductNavigationGroup({ isExpanded, isSelected, item, onSelect, onToggle, selectedItemId, }) {
59
+ const panelId = useId();
60
+ return (_jsxs(_Fragment, { children: [_jsxs("button", { "aria-controls": panelId, "aria-expanded": isExpanded, "aria-haspopup": "menu", className: "liquid-product-navigation-panel__group-trigger", "data-expanded": isExpanded || undefined, "data-selected": isSelected || undefined, disabled: item.disabled, onClick: onToggle, type: "button", children: [_jsx("span", { children: item.label }), _jsx(Icon, { "aria-hidden": "true", name: "chevron_down", size: 20 })] }), isExpanded ? (_jsx("ul", { className: "liquid-product-navigation-panel__sublist", id: panelId, role: "menu", children: item.items?.map((subItem) => (_jsx("li", { role: "none", children: _jsx(ProductNavigationDestination, { item: subItem, selected: subItem.id === selectedItemId, onSelect: onSelect }) }, subItem.id))) })) : null] }));
61
+ }