UNPKG

@primer/react

Version:

An implementation of GitHub's Primer Design System using React

1,460 lines (1,459 loc) • 44.5 kB
import { useMergedRefs } from "../hooks/useMergedRefs.js"; import { useId as useId$1 } from "../hooks/useId.js"; import { warning } from "../utils/warning.js"; import { isResponsiveValue } from "../hooks/useResponsiveValue.js"; import { useSlots } from "../hooks/useSlots.js"; import { useOverflow } from "../hooks/useOverflow.js"; import { getResponsiveAttributes } from "../internal/utils/getResponsiveAttributes.js"; import PageLayout_module_css_default from "./PageLayout.module.css.js"; import { isCustomWidthOptions, isPaneWidth, updateAriaValues, usePaneWidth } from "./usePaneWidth.js"; import { removeDraggingStyles, setDraggingStyles } from "./paneUtils.js"; import { c } from "react-compiler-runtime"; import { clsx } from "clsx"; import { jsx, jsxs } from "react/jsx-runtime"; import React, { memo, useRef } from "react"; //#region src/PageLayout/PageLayout.tsx const isArrowKey = (key) => key === "ArrowLeft" || key === "ArrowRight" || key === "ArrowUp" || key === "ArrowDown"; const isShrinkKey = (key) => key === "ArrowLeft" || key === "ArrowDown"; const PageLayoutContext = /*#__PURE__*/ React.createContext({ padding: "normal", rowGap: "normal", columnGap: "normal", paneRef: { current: null }, contentWrapperRef: { current: null }, sidebarRef: { current: null }, sidebarContentWrapperRef: { current: null } }); const Root = (t0) => { const $ = c(24); const { containerWidth: t1, padding: t2, rowGap: t3, columnGap: t4, children, className, style, _slotsConfig: slotsConfig } = t0; const containerWidth = t1 === void 0 ? "xlarge" : t1; const padding = t2 === void 0 ? "normal" : t2; const rowGap = t3 === void 0 ? "normal" : t3; const columnGap = t4 === void 0 ? "normal" : t4; const paneRef = useRef(null); const contentWrapperRef = useRef(null); const sidebarRef = useRef(null); const sidebarContentWrapperRef = useRef(null); let t5; if ($[0] !== slotsConfig) { t5 = slotsConfig !== null && slotsConfig !== void 0 ? slotsConfig : { header: Header, footer: Footer, sidebar: Sidebar }; $[0] = slotsConfig; $[1] = t5; } else t5 = $[1]; const [slots, rest] = useSlots(children, t5); let t6; if ($[2] !== columnGap || $[3] !== padding || $[4] !== rowGap) { t6 = { padding, rowGap, columnGap, paneRef, contentWrapperRef, sidebarRef, sidebarContentWrapperRef }; $[2] = columnGap; $[3] = padding; $[4] = rowGap; $[5] = t6; } else t6 = $[5]; const memoizedContextValue = t6; const t7 = !!slots.sidebar; const t8 = slots.sidebar; const t9 = slots.header; let t10; if ($[6] === Symbol.for("react.memo_cache_sentinel")) { t10 = clsx(PageLayout_module_css_default.PageLayoutContent); $[6] = t10; } else t10 = $[6]; let t11; if ($[7] !== rest) { t11 = /*#__PURE__*/ jsx("div", { className: t10, children: rest }); $[7] = rest; $[8] = t11; } else t11 = $[8]; let t12; if ($[9] !== containerWidth || $[10] !== slots.footer || $[11] !== slots.header || $[12] !== t11) { t12 = /*#__PURE__*/ jsxs("div", { ref: sidebarContentWrapperRef, className: PageLayout_module_css_default.PageLayoutWrapper, "data-width": containerWidth, children: [ t9, t11, slots.footer ] }); $[9] = containerWidth; $[10] = slots.footer; $[11] = slots.header; $[12] = t11; $[13] = t12; } else t12 = $[13]; let t13; if ($[14] !== className || $[15] !== padding || $[16] !== slots.sidebar || $[17] !== style || $[18] !== t12 || $[19] !== t7) { t13 = /*#__PURE__*/ jsxs(RootWrapper, { style, padding, className, hasSidebar: t7, children: [t8, t12] }); $[14] = className; $[15] = padding; $[16] = slots.sidebar; $[17] = style; $[18] = t12; $[19] = t7; $[20] = t13; } else t13 = $[20]; let t14; if ($[21] !== memoizedContextValue || $[22] !== t13) { t14 = /*#__PURE__*/ jsx(PageLayoutContext.Provider, { value: memoizedContextValue, children: t13 }); $[21] = memoizedContextValue; $[22] = t13; $[23] = t14; } else t14 = $[23]; return t14; }; const RootWrapper = /*#__PURE__*/ memo((t0) => { const $ = c(10); const { style, padding, children, className, hasSidebar } = t0; const t1 = `var(--spacing-${padding})`; let t2; if ($[0] !== style || $[1] !== t1) { t2 = { "--spacing": t1, ...style }; $[0] = style; $[1] = t1; $[2] = t2; } else t2 = $[2]; const t3 = t2; let t4; if ($[3] !== className) { t4 = clsx(PageLayout_module_css_default.PageLayoutRoot, className); $[3] = className; $[4] = t4; } else t4 = $[4]; const t5 = hasSidebar || void 0; let t6; if ($[5] !== children || $[6] !== t3 || $[7] !== t4 || $[8] !== t5) { t6 = /*#__PURE__*/ jsx("div", { style: t3, className: t4, "data-component": "PageLayout", "data-has-sidebar": t5, children }); $[5] = children; $[6] = t3; $[7] = t4; $[8] = t5; $[9] = t6; } else t6 = $[9]; return t6; }); Root.displayName = "PageLayout"; const HorizontalDivider = /*#__PURE__*/ memo((t0) => { const $ = c(14); const { variant: t1, className, position, style } = t0; const variant = t1 === void 0 ? "none" : t1; const { padding } = React.useContext(PageLayoutContext); let t2; if ($[0] !== className) { t2 = clsx(PageLayout_module_css_default.HorizontalDivider, className); $[0] = className; $[1] = t2; } else t2 = $[1]; let t3; if ($[2] !== variant) { t3 = getResponsiveAttributes("variant", variant); $[2] = variant; $[3] = t3; } else t3 = $[3]; let t4; if ($[4] !== position) { t4 = getResponsiveAttributes("position", position); $[4] = position; $[5] = t4; } else t4 = $[5]; const t5 = `var(--spacing-${padding})`; let t6; if ($[6] !== style || $[7] !== t5) { t6 = { "--spacing-divider": t5, ...style }; $[6] = style; $[7] = t5; $[8] = t6; } else t6 = $[8]; const t7 = t6; let t8; if ($[9] !== t2 || $[10] !== t3 || $[11] !== t4 || $[12] !== t7) { t8 = /*#__PURE__*/ jsx("div", { className: t2, "data-component": "PageLayout.HorizontalDivider", ...t3, ...t4, style: t7 }); $[9] = t2; $[10] = t3; $[11] = t4; $[12] = t7; $[13] = t8; } else t8 = $[13]; return t8; }); HorizontalDivider.displayName = "HorizontalDivider"; const VerticalDivider = /*#__PURE__*/ memo((t0) => { const $ = c(12); const { variant: t1, position, className, style, children } = t0; const variant = t1 === void 0 ? "none" : t1; let t2; if ($[0] !== className) { t2 = clsx(PageLayout_module_css_default.VerticalDivider, className); $[0] = className; $[1] = t2; } else t2 = $[1]; let t3; if ($[2] !== variant) { t3 = getResponsiveAttributes("variant", variant); $[2] = variant; $[3] = t3; } else t3 = $[3]; let t4; if ($[4] !== position) { t4 = getResponsiveAttributes("position", position); $[4] = position; $[5] = t4; } else t4 = $[5]; let t5; if ($[6] !== children || $[7] !== style || $[8] !== t2 || $[9] !== t3 || $[10] !== t4) { t5 = /*#__PURE__*/ jsx("div", { className: t2, "data-component": "PageLayout.VerticalDivider", ...t3, ...t4, style, children }); $[6] = children; $[7] = style; $[8] = t2; $[9] = t3; $[10] = t4; $[11] = t5; } else t5 = $[11]; return t5; }); VerticalDivider.displayName = "VerticalDivider"; const SidebarDivider = /*#__PURE__*/ memo(function SidebarDivider(t0) { const $ = c(22); const { position, divider, resizable, minPaneWidth, maxPaneWidth, currentWidth, currentWidthRef, handleRef, sidebarRef, dragStartClientXRef, dragStartWidthRef, dragMaxWidthRef, getMaxPaneWidth, getDefaultWidth, saveWidth } = t0; const { columnGap } = React.useContext(PageLayoutContext); const t1 = resizable ? "line" : divider; const t2 = `var(--spacing-${columnGap})`; let t3; if ($[0] !== t2) { t3 = { "--spacing": t2 }; $[0] = t2; $[1] = t3; } else t3 = $[1]; const t4 = t3; let t5; if ($[2] !== currentWidth || $[3] !== currentWidthRef || $[4] !== dragMaxWidthRef || $[5] !== dragStartClientXRef || $[6] !== dragStartWidthRef || $[7] !== getDefaultWidth || $[8] !== getMaxPaneWidth || $[9] !== handleRef || $[10] !== maxPaneWidth || $[11] !== minPaneWidth || $[12] !== position || $[13] !== resizable || $[14] !== saveWidth || $[15] !== sidebarRef) { t5 = resizable ? /*#__PURE__*/ jsx(DragHandle, { handleRef, "aria-valuemin": minPaneWidth, "aria-valuemax": maxPaneWidth, "aria-valuenow": currentWidth, onDragStart: (clientX) => { var _sidebarRef$current$g, _sidebarRef$current; dragStartClientXRef.current = clientX; dragStartWidthRef.current = (_sidebarRef$current$g = (_sidebarRef$current = sidebarRef.current) === null || _sidebarRef$current === void 0 ? void 0 : _sidebarRef$current.getBoundingClientRect().width) !== null && _sidebarRef$current$g !== void 0 ? _sidebarRef$current$g : currentWidthRef.current; dragMaxWidthRef.current = getMaxPaneWidth(); }, onDrag: (value, isKeyboard) => { const maxWidth = isKeyboard ? getMaxPaneWidth() : dragMaxWidthRef.current; if (isKeyboard) { const delta = position === "end" ? -value : value; const newWidth = Math.max(minPaneWidth, Math.min(maxWidth, currentWidthRef.current + delta)); if (newWidth !== currentWidthRef.current) { var _sidebarRef$current2; currentWidthRef.current = newWidth; (_sidebarRef$current2 = sidebarRef.current) === null || _sidebarRef$current2 === void 0 || _sidebarRef$current2.style.setProperty("--pane-width", `${newWidth}px`); updateAriaValues(handleRef.current, { current: newWidth, max: maxWidth }); } } else if (sidebarRef.current) { const deltaX = value - dragStartClientXRef.current; const directedDelta = position === "end" ? -deltaX : deltaX; const newWidth_0 = dragStartWidthRef.current + directedDelta; const clampedWidth = Math.max(minPaneWidth, Math.min(maxWidth, newWidth_0)); if (Math.round(clampedWidth) !== Math.round(currentWidthRef.current)) { sidebarRef.current.style.setProperty("--pane-width", `${clampedWidth}px`); currentWidthRef.current = clampedWidth; updateAriaValues(handleRef.current, { current: Math.round(clampedWidth), max: maxWidth }); } } }, onDragEnd: () => { saveWidth(currentWidthRef.current); }, onDoubleClick: () => { const resetWidth = getDefaultWidth(); if (sidebarRef.current) { sidebarRef.current.style.setProperty("--pane-width", `${resetWidth}px`); currentWidthRef.current = resetWidth; updateAriaValues(handleRef.current, { current: resetWidth }); } saveWidth(resetWidth); } }) : null; $[2] = currentWidth; $[3] = currentWidthRef; $[4] = dragMaxWidthRef; $[5] = dragStartClientXRef; $[6] = dragStartWidthRef; $[7] = getDefaultWidth; $[8] = getMaxPaneWidth; $[9] = handleRef; $[10] = maxPaneWidth; $[11] = minPaneWidth; $[12] = position; $[13] = resizable; $[14] = saveWidth; $[15] = sidebarRef; $[16] = t5; } else t5 = $[16]; let t6; if ($[17] !== position || $[18] !== t1 || $[19] !== t4 || $[20] !== t5) { t6 = /*#__PURE__*/ jsx(VerticalDivider, { variant: t1, position, className: PageLayout_module_css_default.SidebarVerticalDivider, style: t4, children: t5 }); $[17] = position; $[18] = t1; $[19] = t4; $[20] = t5; $[21] = t6; } else t6 = $[21]; return t6; }); /** * DragHandle - handles all pointer and keyboard interactions for resizing * ARIA values are set in JSX for SSR accessibility, * then updated via DOM manipulation during drag for performance */ const DragHandle = /*#__PURE__*/ memo(function DragHandle(t0) { const $ = c(35); const { handleRef, onDragStart, onDrag, onDragEnd, onDoubleClick, "aria-valuemin": ariaValueMin, "aria-valuemax": ariaValueMax, "aria-valuenow": ariaValueNow } = t0; const stableOnDragStart = React.useRef(onDragStart); const stableOnDrag = React.useRef(onDrag); const stableOnDragEnd = React.useRef(onDragEnd); let t1; if ($[0] !== onDrag || $[1] !== onDragEnd || $[2] !== onDragStart) { t1 = () => { stableOnDragStart.current = onDragStart; stableOnDrag.current = onDrag; stableOnDragEnd.current = onDragEnd; }; $[0] = onDrag; $[1] = onDragEnd; $[2] = onDragStart; $[3] = t1; } else t1 = $[3]; React.useEffect(t1); const { paneRef, contentWrapperRef } = React.useContext(PageLayoutContext); const isDraggingRef = React.useRef(false); let t2; if ($[4] !== contentWrapperRef || $[5] !== handleRef || $[6] !== paneRef) { t2 = () => { if (isDraggingRef.current) return; setDraggingStyles({ handle: handleRef.current, pane: paneRef.current, contentWrapper: contentWrapperRef.current }); isDraggingRef.current = true; }; $[4] = contentWrapperRef; $[5] = handleRef; $[6] = paneRef; $[7] = t2; } else t2 = $[7]; const startDragging = t2; let t3; if ($[8] !== contentWrapperRef || $[9] !== handleRef || $[10] !== paneRef) { t3 = () => { if (!isDraggingRef.current) return; removeDraggingStyles({ handle: handleRef.current, pane: paneRef.current, contentWrapper: contentWrapperRef.current }); isDraggingRef.current = false; }; $[8] = contentWrapperRef; $[9] = handleRef; $[10] = paneRef; $[11] = t3; } else t3 = $[11]; const endDragging = t3; let t4; if ($[12] !== startDragging) { t4 = (event) => { if (event.button !== 0) return; event.preventDefault(); const target = event.currentTarget; try { target.setPointerCapture(event.pointerId); } catch {} stableOnDragStart.current(event.clientX); startDragging(); }; $[12] = startDragging; $[13] = t4; } else t4 = $[13]; const handlePointerDown = t4; const rafIdRef = React.useRef(null); const pendingClientXRef = React.useRef(null); let t5; if ($[14] === Symbol.for("react.memo_cache_sentinel")) { t5 = (event_0) => { if (!isDraggingRef.current) return; event_0.preventDefault(); pendingClientXRef.current = event_0.clientX; if (rafIdRef.current === null) rafIdRef.current = requestAnimationFrame(() => { rafIdRef.current = null; if (pendingClientXRef.current !== null) { stableOnDrag.current(pendingClientXRef.current, false); pendingClientXRef.current = null; } }); }; $[14] = t5; } else t5 = $[14]; const handlePointerMove = t5; let t6; if ($[15] === Symbol.for("react.memo_cache_sentinel")) { t6 = (event_1) => { if (!isDraggingRef.current) return; event_1.preventDefault(); }; $[15] = t6; } else t6 = $[15]; const handlePointerUp = t6; let t7; if ($[16] !== endDragging) { t7 = () => { if (!isDraggingRef.current) return; if (rafIdRef.current !== null) { cancelAnimationFrame(rafIdRef.current); rafIdRef.current = null; pendingClientXRef.current = null; } endDragging(); stableOnDragEnd.current(); }; $[16] = endDragging; $[17] = t7; } else t7 = $[17]; const handleLostPointerCapture = t7; let t8; if ($[18] !== startDragging) { t8 = (event_2) => { if (!isArrowKey(event_2.key)) return; event_2.preventDefault(); const delta = isShrinkKey(event_2.key) ? -3 : 3; if (!isDraggingRef.current) startDragging(); stableOnDrag.current(delta, true); }; $[18] = startDragging; $[19] = t8; } else t8 = $[19]; const handleKeyDown = t8; let t9; if ($[20] !== endDragging) { t9 = (event_3) => { if (!isArrowKey(event_3.key)) return; event_3.preventDefault(); endDragging(); stableOnDragEnd.current(); }; $[20] = endDragging; $[21] = t9; } else t9 = $[21]; const handleKeyUp = t9; let t10; let t11; if ($[22] === Symbol.for("react.memo_cache_sentinel")) { t10 = () => () => { if (rafIdRef.current !== null) { cancelAnimationFrame(rafIdRef.current); rafIdRef.current = null; } }; t11 = []; $[22] = t10; $[23] = t11; } else { t10 = $[22]; t11 = $[23]; } React.useEffect(t10, t11); const t12 = ariaValueNow !== void 0 ? `Pane width ${ariaValueNow} pixels` : void 0; let t13; if ($[24] !== ariaValueMax || $[25] !== ariaValueMin || $[26] !== ariaValueNow || $[27] !== handleKeyDown || $[28] !== handleKeyUp || $[29] !== handleLostPointerCapture || $[30] !== handlePointerDown || $[31] !== handleRef || $[32] !== onDoubleClick || $[33] !== t12) { t13 = /*#__PURE__*/ jsx("div", { ref: handleRef, className: PageLayout_module_css_default.DraggableHandle, "data-component": "PageLayout.DragHandle", role: "slider", "aria-label": "Draggable pane splitter", "aria-valuemin": ariaValueMin, "aria-valuemax": ariaValueMax, "aria-valuenow": ariaValueNow, "aria-valuetext": t12, tabIndex: 0, onPointerDown: handlePointerDown, onPointerMove: handlePointerMove, onPointerUp: handlePointerUp, onLostPointerCapture: handleLostPointerCapture, onKeyDown: handleKeyDown, onKeyUp: handleKeyUp, onDoubleClick }); $[24] = ariaValueMax; $[25] = ariaValueMin; $[26] = ariaValueNow; $[27] = handleKeyDown; $[28] = handleKeyUp; $[29] = handleLostPointerCapture; $[30] = handlePointerDown; $[31] = handleRef; $[32] = onDoubleClick; $[33] = t12; $[34] = t13; } else t13 = $[34]; return t13; }); const Header = (t0) => { const $ = c(28); const { "aria-label": label, "aria-labelledby": labelledBy, padding: t1, divider: t2, dividerWhenNarrow: t3, hidden: t4, children, style, className } = t0; const padding = t1 === void 0 ? "none" : t1; const divider = t2 === void 0 ? "none" : t2; const dividerWhenNarrow = t3 === void 0 ? "inherit" : t3; const hidden = t4 === void 0 ? false : t4; let t5; if ($[0] !== divider || $[1] !== dividerWhenNarrow) { t5 = !isResponsiveValue(divider) && dividerWhenNarrow !== "inherit" ? { regular: divider, narrow: dividerWhenNarrow } : divider; $[0] = divider; $[1] = dividerWhenNarrow; $[2] = t5; } else t5 = $[2]; const dividerProp = t5; const { rowGap } = React.useContext(PageLayoutContext); let t6; if ($[3] !== hidden) { t6 = getResponsiveAttributes("hidden", hidden); $[3] = hidden; $[4] = t6; } else t6 = $[4]; let t7; if ($[5] !== className) { t7 = clsx(PageLayout_module_css_default.Header, className); $[5] = className; $[6] = t7; } else t7 = $[6]; const t8 = `var(--spacing-${rowGap})`; let t9; if ($[7] !== style || $[8] !== t8) { t9 = { "--spacing": t8, ...style }; $[7] = style; $[8] = t8; $[9] = t9; } else t9 = $[9]; const t10 = t9; const t11 = `var(--spacing-${padding})`; let t12; if ($[10] !== t11) { t12 = { "--spacing": t11 }; $[10] = t11; $[11] = t12; } else t12 = $[11]; const t13 = t12; let t14; if ($[12] !== children || $[13] !== t13) { t14 = /*#__PURE__*/ jsx("div", { className: PageLayout_module_css_default.HeaderContent, style: t13, children }); $[12] = children; $[13] = t13; $[14] = t14; } else t14 = $[14]; const t15 = `var(--spacing-${rowGap})`; let t16; if ($[15] !== t15) { t16 = { "--spacing": t15 }; $[15] = t15; $[16] = t16; } else t16 = $[16]; const t17 = t16; let t18; if ($[17] !== dividerProp || $[18] !== t17) { t18 = /*#__PURE__*/ jsx(HorizontalDivider, { variant: dividerProp, className: PageLayout_module_css_default.HeaderHorizontalDivider, style: t17 }); $[17] = dividerProp; $[18] = t17; $[19] = t18; } else t18 = $[19]; let t19; if ($[20] !== label || $[21] !== labelledBy || $[22] !== t10 || $[23] !== t14 || $[24] !== t18 || $[25] !== t6 || $[26] !== t7) { t19 = /*#__PURE__*/ jsxs("header", { "aria-label": label, "aria-labelledby": labelledBy, "data-component": "PageLayout.Header", ...t6, className: t7, style: t10, children: [t14, t18] }); $[20] = label; $[21] = labelledBy; $[22] = t10; $[23] = t14; $[24] = t18; $[25] = t6; $[26] = t7; $[27] = t19; } else t19 = $[27]; return t19; }; Header.displayName = "PageLayout.Header"; const Content = (t0) => { const $ = c(19); const { as: t1, "aria-label": label, "aria-labelledby": labelledBy, width: t2, padding: t3, hidden: t4, children, className, style } = t0; const as = t1 === void 0 ? "main" : t1; const width = t2 === void 0 ? "full" : t2; const padding = t3 === void 0 ? "none" : t3; const hidden = t4 === void 0 ? false : t4; const Component = as; const { contentWrapperRef } = React.useContext(PageLayoutContext); let t5; if ($[0] !== className) { t5 = clsx(PageLayout_module_css_default.ContentWrapper, className); $[0] = className; $[1] = t5; } else t5 = $[1]; let t6; if ($[2] !== hidden) { t6 = getResponsiveAttributes("is-hidden", hidden); $[2] = hidden; $[3] = t6; } else t6 = $[3]; const t7 = `var(--spacing-${padding})`; let t8; if ($[4] !== t7) { t8 = { "--spacing": t7 }; $[4] = t7; $[5] = t8; } else t8 = $[5]; const t9 = t8; let t10; if ($[6] !== children || $[7] !== t9 || $[8] !== width) { t10 = /*#__PURE__*/ jsx("div", { className: PageLayout_module_css_default.Content, "data-width": width, style: t9, children }); $[6] = children; $[7] = t9; $[8] = width; $[9] = t10; } else t10 = $[9]; let t11; if ($[10] !== Component || $[11] !== contentWrapperRef || $[12] !== label || $[13] !== labelledBy || $[14] !== style || $[15] !== t10 || $[16] !== t5 || $[17] !== t6) { t11 = /*#__PURE__*/ jsx(Component, { ref: contentWrapperRef, "aria-label": label, "aria-labelledby": labelledBy, "data-component": "PageLayout.Content", style, className: t5, ...t6, children: t10 }); $[10] = Component; $[11] = contentWrapperRef; $[12] = label; $[13] = labelledBy; $[14] = style; $[15] = t10; $[16] = t5; $[17] = t6; $[18] = t11; } else t11 = $[18]; return t11; }; Content.displayName = "PageLayout.Content"; const overflowProps = { tabIndex: 0, role: "region" }; const Pane = /*#__PURE__*/ React.forwardRef((t0, forwardRef) => { const $ = c(96); const { "aria-label": label, "aria-labelledby": labelledBy, position: t1, positionWhenNarrow: t2, width: t3, minWidth: t4, currentWidth: controlledWidth, onResizeEnd, padding: t5, resizable: t6, widthStorageKey: t7, divider: t8, dividerWhenNarrow: t9, sticky: t10, offsetHeader: t11, hidden: t12, children, id, className, style } = t0; const responsivePosition = t1 === void 0 ? "end" : t1; const positionWhenNarrow = t2 === void 0 ? "inherit" : t2; const width = t3 === void 0 ? "medium" : t3; const minWidth = t4 === void 0 ? 256 : t4; const padding = t5 === void 0 ? "none" : t5; const resizable = t6 === void 0 ? false : t6; const widthStorageKey = t7 === void 0 ? "paneWidth" : t7; const responsiveDivider = t8 === void 0 ? "none" : t8; const dividerWhenNarrow = t9 === void 0 ? "inherit" : t9; const sticky = t10 === void 0 ? false : t10; const offsetHeader = t11 === void 0 ? 0 : t11; const responsiveHidden = t12 === void 0 ? false : t12; let t13; if ($[0] !== positionWhenNarrow || $[1] !== responsivePosition) { t13 = !isResponsiveValue(responsivePosition) && positionWhenNarrow !== "inherit" ? { regular: responsivePosition, narrow: positionWhenNarrow } : responsivePosition; $[0] = positionWhenNarrow; $[1] = responsivePosition; $[2] = t13; } else t13 = $[2]; const positionProp = t13; let t14; if ($[3] !== dividerWhenNarrow || $[4] !== responsiveDivider) { t14 = !isResponsiveValue(responsiveDivider) && dividerWhenNarrow !== "inherit" ? { regular: responsiveDivider, narrow: dividerWhenNarrow } : responsiveDivider; $[3] = dividerWhenNarrow; $[4] = responsiveDivider; $[5] = t14; } else t14 = $[5]; const dividerProp = t14; let t15; if ($[6] !== positionProp) { t15 = isResponsiveValue(positionProp) ? "end" : positionProp; $[6] = positionProp; $[7] = t15; } else t15 = $[7]; const position = t15; let t16; if ($[8] !== dividerProp) { t16 = isResponsiveValue(dividerProp) ? "none" : dividerProp; $[8] = dividerProp; $[9] = t16; } else t16 = $[9]; const dividerVariant = t16; const { rowGap, columnGap, paneRef, contentWrapperRef } = React.useContext(PageLayoutContext); const handleRef = React.useRef(null); const dragStartClientXRef = React.useRef(0); const dragStartWidthRef = React.useRef(0); const dragMaxWidthRef = React.useRef(0); let t17; if ($[10] !== contentWrapperRef || $[11] !== controlledWidth || $[12] !== minWidth || $[13] !== onResizeEnd || $[14] !== paneRef || $[15] !== resizable || $[16] !== width || $[17] !== widthStorageKey) { t17 = { width, minWidth, resizable, widthStorageKey, paneRef, handleRef, contentWrapperRef, onResizeEnd, currentWidth: controlledWidth }; $[10] = contentWrapperRef; $[11] = controlledWidth; $[12] = minWidth; $[13] = onResizeEnd; $[14] = paneRef; $[15] = resizable; $[16] = width; $[17] = widthStorageKey; $[18] = t17; } else t17 = $[18]; const { currentWidth, currentWidthRef, minPaneWidth, maxPaneWidth, getMaxPaneWidth, saveWidth, getDefaultWidth } = usePaneWidth(t17); const mergedPaneRef = useMergedRefs(forwardRef, paneRef); const hasOverflow = useOverflow(paneRef); const paneId = useId$1(id); let labelProp; if ($[19] !== hasOverflow || $[20] !== label || $[21] !== labelledBy) { labelProp = {}; if (hasOverflow) { warning(label === void 0 && labelledBy === void 0, "The <PageLayout.Pane> has overflow and `aria-label` or `aria-labelledby` has not been set. Please provide `aria-label` or `aria-labelledby` to <PageLayout.Pane> in order to label this region."); if (labelledBy) labelProp["aria-labelledby"] = labelledBy; else if (label) labelProp["aria-label"] = label; } $[19] = hasOverflow; $[20] = label; $[21] = labelledBy; $[22] = labelProp; } else labelProp = $[22]; let t18; if ($[23] !== className) { t18 = clsx(PageLayout_module_css_default.PaneWrapper, className); $[23] = className; $[24] = t18; } else t18 = $[24]; const t19 = typeof offsetHeader === "number" ? `${offsetHeader}px` : offsetHeader; const t20 = `var(--spacing-${rowGap})`; const t21 = `var(--spacing-${columnGap})`; let t22; if ($[25] !== style || $[26] !== t19 || $[27] !== t20 || $[28] !== t21) { t22 = { "--offset-header": t19, "--spacing-row": t20, "--spacing-column": t21, ...style }; $[25] = style; $[26] = t19; $[27] = t20; $[28] = t21; $[29] = t22; } else t22 = $[29]; const t23 = t22; let t24; if ($[30] !== responsiveHidden) { t24 = getResponsiveAttributes("is-hidden", responsiveHidden); $[30] = responsiveHidden; $[31] = t24; } else t24 = $[31]; let t25; if ($[32] !== positionProp) { t25 = getResponsiveAttributes("position", positionProp); $[32] = positionProp; $[33] = t25; } else t25 = $[33]; const t26 = sticky || void 0; let t27; if ($[34] !== dividerProp || $[35] !== dividerVariant) { t27 = isResponsiveValue(dividerProp) ? dividerProp : { narrow: dividerVariant, regular: "none" }; $[34] = dividerProp; $[35] = dividerVariant; $[36] = t27; } else t27 = $[36]; const t28 = `var(--spacing-${rowGap})`; let t29; if ($[37] !== t28) { t29 = { "--spacing": t28 }; $[37] = t28; $[38] = t29; } else t29 = $[38]; const t30 = t29; let t31; if ($[39] !== positionProp || $[40] !== t27 || $[41] !== t30) { t31 = /*#__PURE__*/ jsx(HorizontalDivider, { variant: t27, className: PageLayout_module_css_default.PaneHorizontalDivider, style: t30, position: positionProp }); $[39] = positionProp; $[40] = t27; $[41] = t30; $[42] = t31; } else t31 = $[42]; const t32 = resizable === true && !onResizeEnd; let t33; if ($[43] !== hasOverflow) { t33 = hasOverflow ? overflowProps : {}; $[43] = hasOverflow; $[44] = t33; } else t33 = $[44]; let t34; if ($[45] !== id || $[46] !== paneId) { t34 = id && { id: paneId }; $[45] = id; $[46] = paneId; $[47] = t34; } else t34 = $[47]; const t35 = resizable || void 0; const t36 = `var(--spacing-${padding})`; const t37 = isCustomWidthOptions(width) ? width.min : `${minWidth}px`; const t38 = isCustomWidthOptions(width) ? width.max : "calc(100vw - var(--pane-max-width-diff))"; const t39 = isCustomWidthOptions(width) ? width.default : void 0; const t40 = `var(--pane-width-${isPaneWidth(width) ? width : "custom"})`; const t41 = `${currentWidth}px`; let t42; if ($[48] !== t36 || $[49] !== t37 || $[50] !== t38 || $[51] !== t39 || $[52] !== t40 || $[53] !== t41) { t42 = { "--spacing": t36, "--pane-min-width": t37, "--pane-max-width": t38, "--pane-width-custom": t39, "--pane-width-size": t40, "--pane-width": t41 }; $[48] = t36; $[49] = t37; $[50] = t38; $[51] = t39; $[52] = t40; $[53] = t41; $[54] = t42; } else t42 = $[54]; const t43 = t42; let t44; if ($[55] !== children || $[56] !== labelProp || $[57] !== mergedPaneRef || $[58] !== t32 || $[59] !== t33 || $[60] !== t34 || $[61] !== t35 || $[62] !== t43) { t44 = /*#__PURE__*/ jsx("div", { ref: mergedPaneRef, suppressHydrationWarning: t32, ...t33, ...labelProp, ...t34, className: PageLayout_module_css_default.Pane, "data-component": "PageLayout.Pane", "data-resizable": t35, style: t43, children }); $[55] = children; $[56] = labelProp; $[57] = mergedPaneRef; $[58] = t32; $[59] = t33; $[60] = t34; $[61] = t35; $[62] = t43; $[63] = t44; } else t44 = $[63]; let t45; if ($[64] !== dividerProp || $[65] !== dividerVariant || $[66] !== resizable) { t45 = isResponsiveValue(dividerProp) ? { narrow: "none", regular: resizable ? "line" : dividerProp.regular || "none", wide: resizable ? "line" : dividerProp.wide || dividerProp.regular || "none" } : { narrow: "none", regular: resizable ? "line" : dividerVariant }; $[64] = dividerProp; $[65] = dividerVariant; $[66] = resizable; $[67] = t45; } else t45 = $[67]; const t46 = `var(--spacing-${columnGap})`; let t47; if ($[68] !== t46) { t47 = { "--spacing": t46 }; $[68] = t46; $[69] = t47; } else t47 = $[69]; const t48 = t47; let t49; if ($[70] !== currentWidth || $[71] !== currentWidthRef || $[72] !== getDefaultWidth || $[73] !== getMaxPaneWidth || $[74] !== maxPaneWidth || $[75] !== minPaneWidth || $[76] !== paneRef || $[77] !== position || $[78] !== resizable || $[79] !== saveWidth) { t49 = resizable ? /*#__PURE__*/ jsx(DragHandle, { handleRef, "aria-valuemin": minPaneWidth, "aria-valuemax": maxPaneWidth, "aria-valuenow": currentWidth, onDragStart: (clientX) => { var _paneRef$current$getB, _paneRef$current; dragStartClientXRef.current = clientX; dragStartWidthRef.current = (_paneRef$current$getB = (_paneRef$current = paneRef.current) === null || _paneRef$current === void 0 ? void 0 : _paneRef$current.getBoundingClientRect().width) !== null && _paneRef$current$getB !== void 0 ? _paneRef$current$getB : currentWidthRef.current; dragMaxWidthRef.current = getMaxPaneWidth(); }, onDrag: (value, isKeyboard) => { const maxWidth = isKeyboard ? getMaxPaneWidth() : dragMaxWidthRef.current; if (isKeyboard) { const delta = value; const newWidth = Math.max(minPaneWidth, Math.min(maxWidth, currentWidthRef.current + delta)); if (newWidth !== currentWidthRef.current) { var _paneRef$current2; currentWidthRef.current = newWidth; (_paneRef$current2 = paneRef.current) === null || _paneRef$current2 === void 0 || _paneRef$current2.style.setProperty("--pane-width", `${newWidth}px`); updateAriaValues(handleRef.current, { current: newWidth, max: maxWidth }); } } else if (paneRef.current) { const deltaX = value - dragStartClientXRef.current; const directedDelta = position === "end" ? -deltaX : deltaX; const newWidth_0 = dragStartWidthRef.current + directedDelta; const clampedWidth = Math.max(minPaneWidth, Math.min(maxWidth, newWidth_0)); if (Math.round(clampedWidth) !== Math.round(currentWidthRef.current)) { paneRef.current.style.setProperty("--pane-width", `${clampedWidth}px`); currentWidthRef.current = clampedWidth; updateAriaValues(handleRef.current, { current: Math.round(clampedWidth), max: maxWidth }); } } }, onDragEnd: () => { saveWidth(currentWidthRef.current); }, onDoubleClick: () => { const resetWidth = getDefaultWidth(); if (paneRef.current) { paneRef.current.style.setProperty("--pane-width", `${resetWidth}px`); currentWidthRef.current = resetWidth; updateAriaValues(handleRef.current, { current: resetWidth }); } saveWidth(resetWidth); } }) : null; $[70] = currentWidth; $[71] = currentWidthRef; $[72] = getDefaultWidth; $[73] = getMaxPaneWidth; $[74] = maxPaneWidth; $[75] = minPaneWidth; $[76] = paneRef; $[77] = position; $[78] = resizable; $[79] = saveWidth; $[80] = t49; } else t49 = $[80]; let t50; if ($[81] !== positionProp || $[82] !== resizable || $[83] !== t45 || $[84] !== t48 || $[85] !== t49) { t50 = /*#__PURE__*/ jsx(VerticalDivider, { variant: t45, draggable: resizable, position: positionProp, className: PageLayout_module_css_default.PaneVerticalDivider, style: t48, children: t49 }); $[81] = positionProp; $[82] = resizable; $[83] = t45; $[84] = t48; $[85] = t49; $[86] = t50; } else t50 = $[86]; let t51; if ($[87] !== t18 || $[88] !== t23 || $[89] !== t24 || $[90] !== t25 || $[91] !== t26 || $[92] !== t31 || $[93] !== t44 || $[94] !== t50) { t51 = /*#__PURE__*/ jsxs("div", { className: t18, style: t23, ...t24, ...t25, "data-sticky": t26, children: [ t31, t44, t50 ] }); $[87] = t18; $[88] = t23; $[89] = t24; $[90] = t25; $[91] = t26; $[92] = t31; $[93] = t44; $[94] = t50; $[95] = t51; } else t51 = $[95]; return t51; }); Pane.displayName = "PageLayout.Pane"; const Sidebar = /*#__PURE__*/ React.forwardRef((t0, forwardRef) => { const $ = c(75); const { "aria-label": label, "aria-labelledby": labelledBy, position: t1, width: t2, minWidth: t3, currentWidth: controlledWidth, onResizeEnd, padding: t4, resizable: t5, widthStorageKey, divider: t6, sticky: t7, responsiveVariant: t8, hidden: t9, children, id, className, style } = t0; const position = t1 === void 0 ? "start" : t1; const width = t2 === void 0 ? "medium" : t2; const minWidth = t3 === void 0 ? 256 : t3; const padding = t4 === void 0 ? "none" : t4; const resizable = t5 === void 0 ? false : t5; const divider = t6 === void 0 ? "none" : t6; const sticky = t7 === void 0 ? false : t7; const responsiveVariant = t8 === void 0 ? "default" : t8; const responsiveHidden = t9 === void 0 ? false : t9; const { columnGap, sidebarRef, sidebarContentWrapperRef } = React.useContext(PageLayoutContext); const handleRef = React.useRef(null); const dragStartClientXRef = React.useRef(0); const dragStartWidthRef = React.useRef(0); const dragMaxWidthRef = React.useRef(0); let t10; if ($[0] !== controlledWidth || $[1] !== minWidth || $[2] !== onResizeEnd || $[3] !== resizable || $[4] !== sidebarContentWrapperRef || $[5] !== sidebarRef || $[6] !== width || $[7] !== widthStorageKey) { t10 = { width, minWidth, resizable, widthStorageKey, paneRef: sidebarRef, handleRef, contentWrapperRef: sidebarContentWrapperRef, constrainToViewport: true, onResizeEnd, currentWidth: controlledWidth }; $[0] = controlledWidth; $[1] = minWidth; $[2] = onResizeEnd; $[3] = resizable; $[4] = sidebarContentWrapperRef; $[5] = sidebarRef; $[6] = width; $[7] = widthStorageKey; $[8] = t10; } else t10 = $[8]; const { currentWidth, currentWidthRef, minPaneWidth, maxPaneWidth, getMaxPaneWidth, saveWidth, getDefaultWidth } = usePaneWidth(t10); const mergedSidebarRef = useMergedRefs(forwardRef, sidebarRef); const hasOverflow = useOverflow(sidebarRef); const sidebarId = useId$1(id); let labelProp; if ($[9] !== hasOverflow || $[10] !== label || $[11] !== labelledBy) { labelProp = {}; if (hasOverflow) { warning(label === void 0 && labelledBy === void 0, "The <PageLayout.Sidebar> has overflow and `aria-label` or `aria-labelledby` has not been set. Please provide `aria-label` or `aria-labelledby` to <PageLayout.Sidebar> in order to label this region."); if (labelledBy) labelProp["aria-labelledby"] = labelledBy; else if (label) labelProp["aria-label"] = label; } $[9] = hasOverflow; $[10] = label; $[11] = labelledBy; $[12] = labelProp; } else labelProp = $[12]; let t11; if ($[13] !== className) { t11 = clsx(PageLayout_module_css_default.SidebarWrapper, className); $[13] = className; $[14] = t11; } else t11 = $[14]; const t12 = `var(--spacing-${columnGap})`; let t13; if ($[15] !== style || $[16] !== t12) { t13 = { "--spacing-column": t12, ...style }; $[15] = style; $[16] = t12; $[17] = t13; } else t13 = $[17]; const t14 = t13; let t15; if ($[18] !== responsiveHidden) { t15 = getResponsiveAttributes("is-hidden", responsiveHidden); $[18] = responsiveHidden; $[19] = t15; } else t15 = $[19]; const t16 = sticky || void 0; const t17 = responsiveVariant !== "default" ? responsiveVariant : void 0; let t18; if ($[20] !== currentWidth || $[21] !== currentWidthRef || $[22] !== divider || $[23] !== getDefaultWidth || $[24] !== getMaxPaneWidth || $[25] !== maxPaneWidth || $[26] !== minPaneWidth || $[27] !== position || $[28] !== resizable || $[29] !== saveWidth || $[30] !== sidebarRef) { t18 = position === "end" && /*#__PURE__*/ jsx(SidebarDivider, { position, divider, resizable, minPaneWidth, maxPaneWidth, currentWidth, currentWidthRef, handleRef, sidebarRef, dragStartClientXRef, dragStartWidthRef, dragMaxWidthRef, getMaxPaneWidth, getDefaultWidth, saveWidth }); $[20] = currentWidth; $[21] = currentWidthRef; $[22] = divider; $[23] = getDefaultWidth; $[24] = getMaxPaneWidth; $[25] = maxPaneWidth; $[26] = minPaneWidth; $[27] = position; $[28] = resizable; $[29] = saveWidth; $[30] = sidebarRef; $[31] = t18; } else t18 = $[31]; const t19 = resizable === true && !!widthStorageKey && !onResizeEnd; let t20; if ($[32] !== hasOverflow) { t20 = hasOverflow ? overflowProps : {}; $[32] = hasOverflow; $[33] = t20; } else t20 = $[33]; let t21; if ($[34] !== id || $[35] !== sidebarId) { t21 = id && { id: sidebarId }; $[34] = id; $[35] = sidebarId; $[36] = t21; } else t21 = $[36]; const t22 = resizable || void 0; const t23 = `var(--spacing-${padding})`; const t24 = isCustomWidthOptions(width) ? width.min : `${minWidth}px`; const t25 = isCustomWidthOptions(width) ? width.max : "calc(100vw - var(--sidebar-max-width-diff))"; const t26 = isCustomWidthOptions(width) ? width.default : void 0; const t27 = `var(--pane-width-${isPaneWidth(width) ? width : "custom"})`; const t28 = `${currentWidth}px`; let t29; if ($[37] !== t23 || $[38] !== t24 || $[39] !== t25 || $[40] !== t26 || $[41] !== t27 || $[42] !== t28) { t29 = { "--spacing": t23, "--pane-min-width": t24, "--pane-max-width": t25, "--pane-width-custom": t26, "--pane-width-size": t27, "--pane-width": t28 }; $[37] = t23; $[38] = t24; $[39] = t25; $[40] = t26; $[41] = t27; $[42] = t28; $[43] = t29; } else t29 = $[43]; const t30 = t29; let t31; if ($[44] !== children || $[45] !== labelProp || $[46] !== mergedSidebarRef || $[47] !== t19 || $[48] !== t20 || $[49] !== t21 || $[50] !== t22 || $[51] !== t30) { t31 = /*#__PURE__*/ jsx("div", { ref: mergedSidebarRef, suppressHydrationWarning: t19, ...t20, ...labelProp, ...t21, className: PageLayout_module_css_default.Sidebar, "data-component": "PageLayout.Sidebar", "data-resizable": t22, style: t30, children }); $[44] = children; $[45] = labelProp; $[46] = mergedSidebarRef; $[47] = t19; $[48] = t20; $[49] = t21; $[50] = t22; $[51] = t30; $[52] = t31; } else t31 = $[52]; let t32; if ($[53] !== currentWidth || $[54] !== currentWidthRef || $[55] !== divider || $[56] !== getDefaultWidth || $[57] !== getMaxPaneWidth || $[58] !== maxPaneWidth || $[59] !== minPaneWidth || $[60] !== position || $[61] !== resizable || $[62] !== saveWidth || $[63] !== sidebarRef) { t32 = position === "start" && /*#__PURE__*/ jsx(SidebarDivider, { position, divider, resizable, minPaneWidth, maxPaneWidth, currentWidth, currentWidthRef, handleRef, sidebarRef, dragStartClientXRef, dragStartWidthRef, dragMaxWidthRef, getMaxPaneWidth, getDefaultWidth, saveWidth }); $[53] = currentWidth; $[54] = currentWidthRef; $[55] = divider; $[56] = getDefaultWidth; $[57] = getMaxPaneWidth; $[58] = maxPaneWidth; $[59] = minPaneWidth; $[60] = position; $[61] = resizable; $[62] = saveWidth; $[63] = sidebarRef; $[64] = t32; } else t32 = $[64]; let t33; if ($[65] !== position || $[66] !== t11 || $[67] !== t14 || $[68] !== t15 || $[69] !== t16 || $[70] !== t17 || $[71] !== t18 || $[72] !== t31 || $[73] !== t32) { t33 = /*#__PURE__*/ jsxs("div", { className: t11, style: t14, ...t15, "data-position": position, "data-sticky": t16, "data-responsive-variant": t17, children: [ t18, t31, t32 ] }); $[65] = position; $[66] = t11; $[67] = t14; $[68] = t15; $[69] = t16; $[70] = t17; $[71] = t18; $[72] = t31; $[73] = t32; $[74] = t33; } else t33 = $[74]; return t33; }); Sidebar.displayName = "PageLayout.Sidebar"; const Footer = (t0) => { const $ = c(28); const { "aria-label": label, "aria-labelledby": labelledBy, padding: t1, divider: t2, dividerWhenNarrow: t3, hidden: t4, children, className, style } = t0; const padding = t1 === void 0 ? "none" : t1; const divider = t2 === void 0 ? "none" : t2; const dividerWhenNarrow = t3 === void 0 ? "inherit" : t3; const hidden = t4 === void 0 ? false : t4; let t5; if ($[0] !== divider || $[1] !== dividerWhenNarrow) { t5 = !isResponsiveValue(divider) && dividerWhenNarrow !== "inherit" ? { regular: divider, narrow: dividerWhenNarrow } : divider; $[0] = divider; $[1] = dividerWhenNarrow; $[2] = t5; } else t5 = $[2]; const dividerProp = t5; const { rowGap } = React.useContext(PageLayoutContext); let t6; if ($[3] !== hidden) { t6 = getResponsiveAttributes("hidden", hidden); $[3] = hidden; $[4] = t6; } else t6 = $[4]; let t7; if ($[5] !== className) { t7 = clsx(PageLayout_module_css_default.FooterWrapper, className); $[5] = className; $[6] = t7; } else t7 = $[6]; const t8 = `var(--spacing-${rowGap})`; let t9; if ($[7] !== style || $[8] !== t8) { t9 = { "--spacing": t8, ...style }; $[7] = style; $[8] = t8; $[9] = t9; } else t9 = $[9]; const t10 = t9; const t11 = `var(--spacing-${rowGap})`; let t12; if ($[10] !== t11) { t12 = { "--spacing": t11 }; $[10] = t11; $[11] = t12; } else t12 = $[11]; const t13 = t12; let t14; if ($[12] !== dividerProp || $[13] !== t13) { t14 = /*#__PURE__*/ jsx(HorizontalDivider, { className: PageLayout_module_css_default.FooterHorizontalDivider, style: t13, variant: dividerProp }); $[12] = dividerProp; $[13] = t13; $[14] = t14; } else t14 = $[14]; const t15 = `var(--spacing-${padding})`; let t16; if ($[15] !== t15) { t16 = { "--spacing": t15 }; $[15] = t15; $[16] = t16; } else t16 = $[16]; const t17 = t16; let t18; if ($[17] !== children || $[18] !== t17) { t18 = /*#__PURE__*/ jsx("div", { className: PageLayout_module_css_default.FooterContent, style: t17, children }); $[17] = children; $[18] = t17; $[19] = t18; } else t18 = $[19]; let t19; if ($[20] !== label || $[21] !== labelledBy || $[22] !== t10 || $[23] !== t14 || $[24] !== t18 || $[25] !== t6 || $[26] !== t7) { t19 = /*#__PURE__*/ jsxs("footer", { "aria-label": label, "aria-labelledby": labelledBy, "data-component": "PageLayout.Footer", ...t6, className: t7, style: t10, children: [t14, t18] }); $[20] = label; $[21] = labelledBy; $[22] = t10; $[23] = t14; $[24] = t18; $[25] = t6; $[26] = t7; $[27] = t19; } else t19 = $[27]; return t19; }; Footer.displayName = "PageLayout.Footer"; const PageLayout = Object.assign(Root, { Header, Content, Pane, Sidebar, Footer }); Header.__SLOT__ = Symbol("PageLayout.Header"); Content.__SLOT__ = Symbol("PageLayout.Content"); Pane.__SLOT__ = Symbol("PageLayout.Pane"); Sidebar.__SLOT__ = Symbol("PageLayout.Sidebar"); Footer.__SLOT__ = Symbol("PageLayout.Footer"); //#endregion export { PageLayout };