UNPKG

@harvest-profit/npk

Version:
96 lines 4.97 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); const icons_1 = require("../icons"); const Nav_module_css_1 = __importDefault(require("./Nav.module.css")); const Button_1 = __importDefault(require("../Button")); const NavigationContext_1 = __importStar(require("./NavigationContext")); const Placeholder_1 = __importDefault(require("../Placeholder")); const Nav = ({ children, variant = 'underline', ...props }) => { return ((0, jsx_runtime_1.jsx)("nav", { ...props, className: `${Nav_module_css_1.default.Nav} ${props.className || ''}`, "data-variant": variant, "data-component": "navigation", children: variant === 'underline' ? ((0, jsx_runtime_1.jsx)("ul", { "data-component": "nav-list", children: children })) : ((0, jsx_runtime_1.jsx)(Button_1.default.Context, { value: { block: true, align: 'start' }, children: children })) })); }; Nav.Group = ({ title = null, children, ...props }) => { const sectionProps = { ...props }; let generatedId = null; if (title) { generatedId = `${props.id || ''}nav-group-${title}`.replaceAll(' ', '-').toLowerCase(); sectionProps['aria-labelledby'] = generatedId; } else { if (!sectionProps['aria-label']) console.warn('Please provide an aria-label for this nav group.'); } return ((0, jsx_runtime_1.jsxs)("section", { ...sectionProps, children: [title && (0, jsx_runtime_1.jsx)("h3", { id: generatedId, children: title }), (0, jsx_runtime_1.jsx)("ul", { "data-component": "nav-list", children: children })] })); }; Nav.Button = ({ ignore, loading, ...props }) => { let navigation = (0, react_1.useContext)(NavigationContext_1.default) || NavigationContext_1.defaultNavigationConfig; navigation = { ...NavigationContext_1.defaultNavigationConfig, ...navigation }; if (loading) { return (0, jsx_runtime_1.jsx)("li", { children: (0, jsx_runtime_1.jsx)(Placeholder_1.default, { as: "a", className: Nav_module_css_1.default.NavLoadingButton }) }); } const href = props[navigation.hrefProp]; let isActive = navigation.matchWith(href, window.location.pathname, props); if (isActive && ignore) { if (ignore instanceof RegExp) { isActive = !ignore.test(window.location.pathname); } else if (typeof ignore === 'string') { isActive = !window.location.pathname.includes(ignore); } else if (typeof ignore === 'function') { isActive = !ignore(window.location.pathname, href); } } const buttonProps = { ...props }; buttonProps[navigation.hrefProp] = navigation.transformPath(buttonProps[navigation.hrefProp], window.location.pathname, props); if (isActive) { buttonProps['aria-current'] = 'page'; if (buttonProps.leadingVisual) { buttonProps.leadingVisual = (0, icons_1.attemptFilledIconForIcon)(buttonProps.leadingVisual) || buttonProps.leadingVisual; } } if (typeof buttonProps.leadingVisual === 'function' && (buttonProps.leadingVisual.name === 'leadingVisual')) { buttonProps.leadingVisual = buttonProps.leadingVisual({ active: isActive }); } return ((0, jsx_runtime_1.jsx)("li", { children: (0, jsx_runtime_1.jsx)(Button_1.default, { as: navigation.as, ...buttonProps }) })); }; Nav.displayName = 'Nav'; exports.default = Nav; //# sourceMappingURL=Nav.js.map