@bitrise/bitkit-v2 0.3.546 → 0.3.548
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/AGENTS.md +2 -1
- package/dist/components/BitkitActionBar/BitkitActionBar.js +2 -1
- package/dist/components/BitkitActionBar/BitkitActionBar.js.map +1 -1
- package/dist/components/BitkitButton/BitkitButton.js +7 -2
- package/dist/components/BitkitButton/BitkitButton.js.map +1 -1
- package/dist/components/BitkitCalendar/BitkitCalendar.js +3 -2
- package/dist/components/BitkitCalendar/BitkitCalendar.js.map +1 -1
- package/dist/components/BitkitContentWrapper/BitkitContentWrapperStickyBar.d.ts +1 -1
- package/dist/components/BitkitContentWrapper/BitkitContentWrapperStickyBar.js.map +1 -1
- package/dist/components/BitkitDialog/DialogShell.js +2 -1
- package/dist/components/BitkitDialog/DialogShell.js.map +1 -1
- package/dist/components/BitkitDrawer/BitkitDrawer.js +5 -1
- package/dist/components/BitkitDrawer/BitkitDrawer.js.map +1 -1
- package/dist/components/BitkitIconButton/BitkitIconButton.js +7 -2
- package/dist/components/BitkitIconButton/BitkitIconButton.js.map +1 -1
- package/dist/components/BitkitLightbox/BitkitLightbox.js +2 -1
- package/dist/components/BitkitLightbox/BitkitLightbox.js.map +1 -1
- package/dist/components/BitkitPageHeader/BitkitPageHeader.d.ts +27 -23
- package/dist/components/BitkitPageHeader/BitkitPageHeader.js +42 -9
- package/dist/components/BitkitPageHeader/BitkitPageHeader.js.map +1 -1
- package/dist/components/BitkitPageHeader/pageHeaderBottom.d.ts +18 -0
- package/dist/components/BitkitPageHeader/pageHeaderBottom.js +21 -0
- package/dist/components/BitkitPageHeader/pageHeaderBottom.js.map +1 -0
- package/dist/components/BitkitPageHeader/usePageHeaderBottom.d.ts +7 -0
- package/dist/components/BitkitPageHeader/usePageHeaderBottom.js +38 -0
- package/dist/components/BitkitPageHeader/usePageHeaderBottom.js.map +1 -0
- package/dist/components/BitkitPageHeader/useSelfSticky.d.ts +16 -0
- package/dist/components/BitkitPageHeader/useSelfSticky.js +76 -0
- package/dist/components/BitkitPageHeader/useSelfSticky.js.map +1 -0
- package/dist/components/BitkitPageSidebar/BitkitPageSidebar.d.ts +6 -0
- package/dist/components/BitkitPageSidebar/BitkitPageSidebar.js +5 -2
- package/dist/components/BitkitPageSidebar/BitkitPageSidebar.js.map +1 -1
- package/dist/components/BitkitPopover/BitkitPopover.js +3 -2
- package/dist/components/BitkitPopover/BitkitPopover.js.map +1 -1
- package/dist/components/BitkitSplitButton/BitkitSplitButton.js +4 -1
- package/dist/components/BitkitSplitButton/BitkitSplitButton.js.map +1 -1
- package/dist/components/BitkitToggleButton/BitkitToggleButton.js +4 -1
- package/dist/components/BitkitToggleButton/BitkitToggleButton.js.map +1 -1
- package/dist/components/BitkitUIHeader/BitkitUIHeader.d.ts +1 -0
- package/dist/components/BitkitUIHeader/BitkitUIHeader.js +2 -1
- package/dist/components/BitkitUIHeader/BitkitUIHeader.js.map +1 -1
- package/dist/components/BitkitUIHeader/usePublishedBottom.d.ts +1 -0
- package/dist/components/BitkitUIHeader/usePublishedBottom.js +1 -1
- package/dist/components/BitkitUIHeader/usePublishedBottom.js.map +1 -1
- package/dist/components/BitkitUIHeader/useUiHeaderBottom.d.ts +6 -0
- package/dist/components/BitkitUIHeader/useUiHeaderBottom.js +29 -0
- package/dist/components/BitkitUIHeader/useUiHeaderBottom.js.map +1 -0
- package/dist/components/index.d.ts +2 -2
- package/dist/main.js +5 -2
- package/dist/theme/global-css.js +6 -0
- package/dist/theme/global-css.js.map +1 -1
- package/dist/theme/slot-recipes/Breadcrumb.recipe.js +5 -1
- package/dist/theme/slot-recipes/Breadcrumb.recipe.js.map +1 -1
- package/dist/theme/slot-recipes/PageHeader.recipe.js.map +1 -1
- package/dist/theme/slot-recipes/PageSidebar.recipe.d.ts +32 -0
- package/dist/theme/slot-recipes/PageSidebar.recipe.js +30 -0
- package/dist/theme/slot-recipes/PageSidebar.recipe.js.map +1 -1
- package/dist/theme/slot-recipes/index.d.ts +25 -0
- package/dist/theme/tokens/index.d.ts +3 -0
- package/dist/theme/tokens/keyframes.js +5 -0
- package/dist/theme/tokens/keyframes.js.map +1 -1
- package/dist/theme/tokens/zIndex.d.ts +3 -0
- package/dist/theme/tokens/zIndex.js +1 -0
- package/dist/theme/tokens/zIndex.js.map +1 -1
- package/dist/utilities/ControlSizeContext.d.ts +15 -0
- package/dist/utilities/ControlSizeContext.js +20 -0
- package/dist/utilities/ControlSizeContext.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import IconMenuHamburger from "../../icons/IconMenuHamburger.js";
|
|
2
|
+
import { ControlSizeContext } from "../../utilities/ControlSizeContext.js";
|
|
2
3
|
import { isEmptyNode } from "../../utilities/isEmptyNode.js";
|
|
3
4
|
import useIsTruncated from "../../utilities/useIsTruncated.js";
|
|
4
5
|
import BitkitIconButton from "../BitkitIconButton/BitkitIconButton.js";
|
|
5
6
|
import BitkitOverflowTooltip from "../BitkitOverflowTooltip/BitkitOverflowTooltip.js";
|
|
7
|
+
import "../BitkitUIHeader/usePublishedBottom.js";
|
|
8
|
+
import { pageHeaderBottom } from "./pageHeaderBottom.js";
|
|
9
|
+
import useSelfSticky from "./useSelfSticky.js";
|
|
10
|
+
import usePageHeaderBottom from "./usePageHeaderBottom.js";
|
|
6
11
|
import { useSlotRecipe } from "@chakra-ui/react/styled-system";
|
|
7
12
|
import { forwardRef } from "react";
|
|
8
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
9
14
|
import { Box } from "@chakra-ui/react/box";
|
|
10
15
|
import { Text } from "@chakra-ui/react/text";
|
|
11
16
|
// lib/components/BitkitPageHeader/BitkitPageHeader.tsx
|
|
12
17
|
var BitkitPageHeader = forwardRef((props, ref) => {
|
|
13
|
-
const { avatar, badge, breadcrumb, children, contentVariant, contentWidth, controls, css,
|
|
18
|
+
const { avatar, badge, breadcrumb, children, contentVariant, contentWidth, controls, css, onMenuClick, secondaryText, sectionTitle, showDivider = true, sticky, tabs, title, variant, ...rest } = props;
|
|
19
|
+
const { headerRef, isStuck, sentinelRef, spacerHeight } = useSelfSticky(ref, Boolean(sticky));
|
|
14
20
|
const hasAvatar = !isEmptyNode(avatar);
|
|
15
21
|
const hasBadge = !isEmptyNode(badge);
|
|
16
22
|
const hasBreadcrumb = !isEmptyNode(breadcrumb);
|
|
@@ -21,8 +27,9 @@ var BitkitPageHeader = forwardRef((props, ref) => {
|
|
|
21
27
|
const hasTabs = !isEmptyNode(tabs);
|
|
22
28
|
const { isTruncated: isTitleTruncated, ref: titleRef } = useIsTruncated(title);
|
|
23
29
|
const { isTruncated: isSecondaryTruncated, ref: secondaryRef } = useIsTruncated(secondaryText);
|
|
24
|
-
const isCollapsed = variant === "minimal" ||
|
|
30
|
+
const isCollapsed = variant === "minimal" || isStuck;
|
|
25
31
|
const showControls = !isEmptyNode(controls) && isCollapsed;
|
|
32
|
+
const actionSize = isCollapsed ? "sm" : sticky ? "md" : void 0;
|
|
26
33
|
const canShowTitleTooltip = isTitleTruncated && !(isCollapsed && hasBreadcrumb);
|
|
27
34
|
const styles = useSlotRecipe({ key: "pageHeader" })({
|
|
28
35
|
contentVariant,
|
|
@@ -31,7 +38,7 @@ var BitkitPageHeader = forwardRef((props, ref) => {
|
|
|
31
38
|
hasDivider: showDivider || hasTabs,
|
|
32
39
|
hasSidebar,
|
|
33
40
|
alignsToContent: Boolean(contentWidth),
|
|
34
|
-
isSticky,
|
|
41
|
+
isSticky: isStuck,
|
|
35
42
|
variant
|
|
36
43
|
});
|
|
37
44
|
const controlsNode = showControls ? /* @__PURE__ */ jsx(Box, {
|
|
@@ -75,17 +82,25 @@ var BitkitPageHeader = forwardRef((props, ref) => {
|
|
|
75
82
|
})]
|
|
76
83
|
})]
|
|
77
84
|
});
|
|
78
|
-
|
|
85
|
+
const header = /* @__PURE__ */ jsxs(Box, {
|
|
79
86
|
as: "header",
|
|
80
87
|
css: [styles.root, css],
|
|
81
|
-
ref,
|
|
88
|
+
ref: headerRef,
|
|
89
|
+
...sticky && {
|
|
90
|
+
insetBlockStart: "var(--bitkit-ui-header-bottom, 0px)",
|
|
91
|
+
position: {
|
|
92
|
+
base: "static",
|
|
93
|
+
tablet: "sticky"
|
|
94
|
+
},
|
|
95
|
+
zIndex: "pageHeader"
|
|
96
|
+
},
|
|
82
97
|
...rest,
|
|
83
98
|
children: [/* @__PURE__ */ jsxs(Box, {
|
|
84
99
|
css: styles.headerBlock,
|
|
85
100
|
maxWidth: contentWidth,
|
|
86
101
|
children: [
|
|
87
102
|
hasBreadcrumb && /* @__PURE__ */ jsx(Box, {
|
|
88
|
-
css: styles.breadcrumb,
|
|
103
|
+
css: [styles.breadcrumb, sticky && !isCollapsed && { "& li:has([aria-current=\"page\"])": { display: "none" } }],
|
|
89
104
|
children: breadcrumb
|
|
90
105
|
}),
|
|
91
106
|
hasBreadcrumb && controlsNode,
|
|
@@ -116,7 +131,10 @@ var BitkitPageHeader = forwardRef((props, ref) => {
|
|
|
116
131
|
!hasBreadcrumb && controlsNode,
|
|
117
132
|
hasActions && /* @__PURE__ */ jsx(Box, {
|
|
118
133
|
css: styles.actionBlock,
|
|
119
|
-
children
|
|
134
|
+
children: /* @__PURE__ */ jsx(ControlSizeContext.Provider, {
|
|
135
|
+
value: actionSize,
|
|
136
|
+
children
|
|
137
|
+
})
|
|
120
138
|
})
|
|
121
139
|
]
|
|
122
140
|
})
|
|
@@ -127,8 +145,23 @@ var BitkitPageHeader = forwardRef((props, ref) => {
|
|
|
127
145
|
children: tabs
|
|
128
146
|
})]
|
|
129
147
|
});
|
|
148
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
149
|
+
sticky && /* @__PURE__ */ jsx(Box, {
|
|
150
|
+
"aria-hidden": true,
|
|
151
|
+
ref: sentinelRef
|
|
152
|
+
}),
|
|
153
|
+
header,
|
|
154
|
+
sticky && /* @__PURE__ */ jsx(Box, {
|
|
155
|
+
"aria-hidden": true,
|
|
156
|
+
display: {
|
|
157
|
+
base: "none",
|
|
158
|
+
tablet: "block"
|
|
159
|
+
},
|
|
160
|
+
height: `${spacerHeight}px`
|
|
161
|
+
})
|
|
162
|
+
] });
|
|
130
163
|
});
|
|
131
164
|
BitkitPageHeader.displayName = "BitkitPageHeader";
|
|
132
|
-
export { BitkitPageHeader as default };
|
|
165
|
+
export { BitkitPageHeader as default, pageHeaderBottom, usePageHeaderBottom };
|
|
133
166
|
|
|
134
167
|
//# sourceMappingURL=BitkitPageHeader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitkitPageHeader.js","names":[],"sources":["../../../lib/components/BitkitPageHeader/BitkitPageHeader.tsx"],"sourcesContent":["import { Box, type BoxProps } from '@chakra-ui/react/box';\nimport { useSlotRecipe } from '@chakra-ui/react/styled-system';\nimport { Text } from '@chakra-ui/react/text';\nimport { forwardRef, type ReactNode } from 'react';\n\nimport IconMenuHamburger from '../../icons/IconMenuHamburger';\nimport { isEmptyNode } from '../../utilities/isEmptyNode';\nimport useIsTruncated from '../../utilities/useIsTruncated';\nimport { type BitkitContentWidth } from '../BitkitContentWrapper/BitkitContentWrapper';\nimport BitkitIconButton from '../BitkitIconButton/BitkitIconButton';\nimport BitkitOverflowTooltip from '../BitkitOverflowTooltip/BitkitOverflowTooltip';\n\nexport interface BitkitPageHeaderProps extends Omit<BoxProps, 'title'> {\n /**\n * Avatar, app icon or thumbnail rendered before the title. Hidden in the collapsed layout.\n *\n * Belongs to the sub-page layouts: the design's main-page header is a title and its subtitle with\n * no avatar, so pass this alongside a `breadcrumb`.\n *\n * Size it to match the design's two sub-page cards, since the node is yours to build: `size=\"40\"`\n * (8px radius) against a bare title, and `size=\"48\"` (10px radius) once `secondaryText` is\n * present — the same avatar the `app` and `user` content shapes use.\n */\n avatar?: ReactNode;\n /** Badge rendered next to the title. Hidden in the collapsed layout. */\n badge?: ReactNode;\n /**\n * Breadcrumb trail above the title — pass a `BitkitBreadcrumb`. Its presence is what switches the\n * header from the design's main-page layout to a sub-page one, so there is no separate page-type\n * prop: the recipe's own `hasBreadcrumb` variant is derived from it.\n *\n * The two layouts carry more than the trail. A main-page header is a title and its subtitle —\n * top-level pages and product overviews — with no avatar and no `app`/`user` content shape. Those\n * belong to sub-pages, so pass them together with a trail.\n */\n breadcrumb?: ReactNode;\n /**\n * Trailing action buttons. Stacked full-width below the title on mobile, primary action on top.\n *\n * The collapsed row is built for `size=\"sm\"` buttons and the expanded header for `size=\"md\"`.\n * Actions arrive as children, so the component cannot set that for you — pass a flat `size=\"sm\"`\n * whenever `minimal` or `isSticky` is in play.\n *\n * Flat, not responsive: Bitkit icons render a different SVG asset per size, so `BitkitButton`\n * resolves `size` in JS and a `{ base, tablet }` object matches no key, falling through to a 24px\n * icon in a 32px button. Since the header collapses in CSS from `tablet` up, a `sm` action is a\n * little small in the expanded mobile layout — but the design draws no mobile frame for the\n * collapsed variants, so `sm` is the closer of the two.\n */\n children?: ReactNode;\n /**\n * Shape of the title block, mirroring the design's `content` property. `title` is a page title\n * with an optional subtitle; `app` and `user` are the tighter entity layouts — a larger avatar\n * centred against a smaller title and 14px secondary text. They differ only in the gap between\n * the avatar and the text, 16 and 12 respectively.\n */\n contentVariant?: 'title' | 'app' | 'user';\n /**\n * Lines the header's content up with the page content below it: pass the `BitkitContentWrapper`'s value. The title,\n * the actions and the tabs are capped at that width and centred, while the background and the bottom border still run\n * edge to edge. `layout/maxWidth/full` keeps the same 32px inset without a cap. Without it the header keeps the default inset, which\n * lines up with a sidebar below it.\n */\n contentWidth?: BitkitContentWidth;\n /**\n * Inline controls between the trail and the actions — a view switcher, filters, a settings menu.\n * Their presence spreads the row into three groups instead of the usual trail-and-actions pair,\n * which is the shape the design file calls `PageHeader-WFE`.\n *\n * Belongs to the collapsed row, so it is honoured by `variant=\"minimal\"` *and* by `isSticky` —\n * the two produce the same row — and ignored in the expanded layouts, which the design draws no\n * controls in.\n */\n controls?: ReactNode;\n /**\n * Renders the compact single-row layout used while the header is stuck to the top of the viewport.\n * Appearance only — the consumer owns scroll detection and any portalling, since the sticky offset\n * and header container are application concerns.\n *\n * Ignored below the `tablet` breakpoint, where the header always stays expanded.\n *\n * Pair it with `size=\"sm\"` actions — see `children`.\n */\n isSticky?: boolean;\n /**\n * Opens the page's sidebar on mobile. Its presence switches the header to the design's\n * `hasSidebar` layout below `tablet`: the title shrinks beside a menu button, and the\n * `sectionTitle` takes over as the large heading under a rule, with the actions below it. Wire it\n * to a `BitkitPageSidebar`'s `open` / `onOpenChange`. From `tablet` the button is hidden and the\n * header is the ordinary one — the sidebar is beside the page there.\n */\n onMenuClick?: () => void;\n /**\n * Descriptive text below the title. Hidden in the collapsed layout.\n *\n * A string, like `title`, so it can be truncated to one line and carried in full by the tooltip\n * that appears when it does not fit.\n */\n secondaryText?: string;\n /**\n * Draws the line along the header's bottom edge. Set it to `false` for a header that flows\n * straight into the page, and the bottom padding goes with the line: the header's background is\n * the page's, so without the line that padding would only be a margin the page cannot shrink. The\n * page spaces its content from the header itself.\n *\n * The collapsed row keeps its padding, which centres the row rather than spacing the page, and from\n * `tablet` a header with `isSticky` keeps its line as well, since content scrolls under it. Below\n * `tablet` `isSticky` is ignored, so there the line goes too.\n *\n * Ignored with `tabs`, whose list sits on that edge. That includes `variant=\"minimal\"`, which hides\n * the tab list from `tablet`: the line stays although no tabs show above it.\n */\n showDivider?: boolean;\n /**\n * The sidebar section the page is showing, for the `hasSidebar` layout — see `onMenuClick`. It\n * is the page's visible `h2` on mobile, where the sidebar that would name it is behind the menu\n * button. Not rendered from `tablet`, and never without `onMenuClick`.\n */\n sectionTitle?: string;\n /**\n * Tab bar along the bottom edge — pass a `BitkitTabs.List`. Hidden in the collapsed layout.\n *\n * The node is rendered inside the header, so tab panels cannot be siblings of the row. To drive\n * page content from it, put `BitkitTabs.Root` around the header *and* the content, and pass only\n * the list here — `BitkitTabs.List` reads its Root from context and throws without an ancestor:\n *\n * ```tsx\n * <BitkitTabs.Root defaultValue=\"overview\">\n * <BitkitPageHeader tabs={<BitkitTabs.List>…</BitkitTabs.List>} title=\"Build Hub\" />\n * <BitkitTabs.ContentGroup>\n * <BitkitTabs.Content padding=\"32\" value=\"overview\">…</BitkitTabs.Content>\n * </BitkitTabs.ContentGroup>\n * </BitkitTabs.Root>\n * ```\n *\n * Only the row is hidden when the header collapses — the panels live outside it and keep\n * rendering, so the page never blanks.\n */\n tabs?: ReactNode;\n /**\n * The page title, as a string. Everything passed here lands inside the `h1`, so it is the\n * heading's accessible name and nothing else belongs in it — the avatar, badge and secondary\n * text each have their own slot. Required: it is what gives the header a page heading at every\n * breakpoint.\n *\n * Truncated to a single line with an ellipsis. When it does not fit, hovering or focusing it\n * shows the full string in a tooltip — so a long title never grows the header.\n *\n * In the collapsed layout (`minimal` or `isSticky`) *with* a `breadcrumb`, the design shows the\n * title in the trail rather than as a heading, so end the breadcrumb with a\n * `BitkitBreadcrumb.CurrentItem` carrying it — the title is then rendered as a visually hidden\n * `h1`, since `Breadcrumb.CurrentLink` is a link and not a heading. Below `tablet` the header\n * never collapses and the visible heading is used instead (`BitkitBreadcrumb` drops its\n * `CurrentItem` on mobile).\n */\n title: string;\n /**\n * `minimal` collapses the header to the single breadcrumb row used by sub-pages that don't repeat\n * their title as a heading. Like `isSticky`, it only collapses from `tablet` up, and expects\n * `size=\"sm\"` actions — see `children`.\n */\n variant?: 'default' | 'minimal';\n}\n\nconst BitkitPageHeader = forwardRef<HTMLElement, BitkitPageHeaderProps>((props, ref) => {\n const {\n avatar,\n badge,\n breadcrumb,\n children,\n contentVariant,\n contentWidth,\n controls,\n css,\n isSticky,\n onMenuClick,\n secondaryText,\n sectionTitle,\n showDivider = true,\n tabs,\n title,\n variant,\n ...rest\n } = props;\n\n // Which slots the collapsed row drops, and whether it collapses at all, is decided entirely by\n // the recipe's `tablet`-scoped styles. Nothing here branches on the viewport: a breakpoint hook\n // would render the wrong layout on first paint, since Chakra's `useMediaQuery` returns its\n // fallback until after mount.\n\n // A slot's presence is its own toggle, so all of them share one emptiness test rather than plain\n // truthiness: an array whose entries all render nothing — `items.map()` where every branch is\n // `null` — is still truthy, and would otherwise render a wrapper that only contributes gap. For\n // `controls` it would also spread the row into three groups around an empty middle one.\n const hasAvatar = !isEmptyNode(avatar);\n const hasBadge = !isEmptyNode(badge);\n const hasBreadcrumb = !isEmptyNode(breadcrumb);\n const hasActions = !isEmptyNode(children);\n const hasSecondaryText = !isEmptyNode(secondaryText);\n const hasSidebar = onMenuClick !== undefined;\n const hasSectionTitle = hasSidebar && !isEmptyNode(sectionTitle);\n const hasTabs = !isEmptyNode(tabs);\n\n // `BitkitOverflowTooltip` does no measuring of its own — it shows the tooltip unless told not to,\n // so each truncating text reports whether it is actually clipped and suppresses its own tooltip\n // when it is not. Keyed on the text so a change re-measures without waiting for a resize.\n const { isTruncated: isTitleTruncated, ref: titleRef } = useIsTruncated<HTMLHeadingElement>(title);\n const { isTruncated: isSecondaryTruncated, ref: secondaryRef } = useIsTruncated<HTMLParagraphElement>(secondaryText);\n\n // The design only draws inline controls in the collapsed row, so they are ignored in the\n // expanded layouts rather than left to land somewhere undesigned. `minimal` and `isSticky`\n // produce that row through the same `collapsedSlots`, so both have to honour them — gating on\n // `minimal` alone left `isSticky` rendering the identical row with the middle group missing.\n const isCollapsed = variant === 'minimal' || Boolean(isSticky);\n const showControls = !isEmptyNode(controls) && isCollapsed;\n\n // The collapsed row with a trail makes the title block `srOnly`, which is a 1px box — so the\n // measurement reports \"truncated\" for a heading nobody can see. Left alone that puts a tab stop\n // on an invisible element and opens a tooltip against it. The trail already carries the title as\n // its current item in exactly that layout, so there is nothing to surface anyway.\n const canShowTitleTooltip = isTitleTruncated && !(isCollapsed && hasBreadcrumb);\n\n const recipe = useSlotRecipe({ key: 'pageHeader' });\n const styles = recipe({\n contentVariant,\n hasBreadcrumb,\n hasControls: showControls,\n hasDivider: showDivider || hasTabs,\n hasSidebar,\n alignsToContent: Boolean(contentWidth),\n isSticky,\n variant,\n });\n\n // The controls are the middle of three groups, so they follow whichever element holds the left\n // slot: the trail when there is one, otherwise the title — which lives inside `contentBlock`, so\n // they have to go in there with it rather than beside it.\n const controlsNode = showControls ? <Box css={styles.controls}>{controls}</Box> : null;\n\n // With a sidebar the menu button shares the title's row, so the block gets a wrapper the content\n // row treats as the title block. Other headers keep their DOM.\n const titleBlock = (\n <Box css={styles.titleBlock}>\n {hasAvatar && <Box css={styles.avatar}>{avatar}</Box>}\n\n <Box css={styles.textBlock}>\n <Box css={styles.titleRow}>\n {/*\n `bottom-start` rather than the tooltip's default `right`: these texts are\n full-width rows, so a right-hand tooltip lands over the actions. Opening below and\n aligned to the text's start keeps it clear of them and lines it up with the text\n it repeats.\n */}\n <BitkitOverflowTooltip disabled={!canShowTitleTooltip} placement=\"bottom-start\" text={title}>\n {/*\n `tabIndex` only while truncated: the tooltip trigger is rendered `asChild`, so an\n `h1` stays unfocusable and the full title would be mouse-only. Adding the tab\n stop unconditionally would put one in every header for no benefit.\n */}\n <Text as=\"h1\" css={styles.title} ref={titleRef} tabIndex={canShowTitleTooltip ? 0 : undefined}>\n {title}\n </Text>\n </BitkitOverflowTooltip>\n {hasBadge && <Box css={styles.badge}>{badge}</Box>}\n </Box>\n\n {hasSecondaryText && secondaryText !== undefined && (\n <BitkitOverflowTooltip disabled={!isSecondaryTruncated} placement=\"bottom-start\" text={secondaryText}>\n <Text css={styles.secondaryText} ref={secondaryRef} tabIndex={isSecondaryTruncated ? 0 : undefined}>\n {secondaryText}\n </Text>\n </BitkitOverflowTooltip>\n )}\n </Box>\n </Box>\n );\n\n return (\n <Box as=\"header\" css={[styles.root, css]} ref={ref} {...rest}>\n <Box css={styles.headerBlock} maxWidth={contentWidth}>\n {hasBreadcrumb && <Box css={styles.breadcrumb}>{breadcrumb}</Box>}\n\n {hasBreadcrumb && controlsNode}\n\n <Box css={styles.contentBlock}>\n {hasSidebar ? (\n <Box css={styles.titleBar}>\n {titleBlock}\n <Box css={styles.menuButton}>\n <BitkitIconButton\n icon={IconMenuHamburger}\n label=\"Open navigation\"\n onClick={onMenuClick}\n size=\"sm\"\n variant=\"secondary\"\n />\n </Box>\n </Box>\n ) : (\n titleBlock\n )}\n\n {hasSectionTitle && (\n <Box css={styles.sectionBlock}>\n <Text as=\"h2\" css={styles.sectionTitle}>\n {sectionTitle}\n </Text>\n </Box>\n )}\n\n {!hasBreadcrumb && controlsNode}\n\n {hasActions && <Box css={styles.actionBlock}>{children}</Box>}\n </Box>\n </Box>\n\n {hasTabs && (\n <Box css={styles.tabs} maxWidth={contentWidth}>\n {tabs}\n </Box>\n )}\n </Box>\n );\n});\n\nBitkitPageHeader.displayName = 'BitkitPageHeader';\n\nexport default BitkitPageHeader;\n"],"mappings":";;;;;;;;;;;AAoKA,IAAM,mBAAmB,YAAgD,OAAO,QAAQ;CACtF,MAAM,EACJ,QACA,OACA,YACA,UACA,gBACA,cACA,UACA,KACA,UACA,aACA,eACA,cACA,cAAc,MACd,MACA,OACA,SACA,GAAG,SACD;CAWJ,MAAM,YAAY,CAAC,YAAY,MAAM;CACrC,MAAM,WAAW,CAAC,YAAY,KAAK;CACnC,MAAM,gBAAgB,CAAC,YAAY,UAAU;CAC7C,MAAM,aAAa,CAAC,YAAY,QAAQ;CACxC,MAAM,mBAAmB,CAAC,YAAY,aAAa;CACnD,MAAM,aAAa,gBAAgB,KAAA;CACnC,MAAM,kBAAkB,cAAc,CAAC,YAAY,YAAY;CAC/D,MAAM,UAAU,CAAC,YAAY,IAAI;CAKjC,MAAM,EAAE,aAAa,kBAAkB,KAAK,aAAa,eAAmC,KAAK;CACjG,MAAM,EAAE,aAAa,sBAAsB,KAAK,iBAAiB,eAAqC,aAAa;CAMnH,MAAM,cAAc,YAAY,aAAa,QAAQ,QAAQ;CAC7D,MAAM,eAAe,CAAC,YAAY,QAAQ,KAAK;CAM/C,MAAM,sBAAsB,oBAAoB,EAAE,eAAe;CAGjE,MAAM,SAD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iB;IAElB,qBAAC,KAAD;KAAK,KAAK,OAAO;KAAjB,UAAA;MACG,aACC,qBAAC,KAAD;OAAK,KAAK,OAAO;OAAjB,UAAA,CACG,YACD,oBAAC,KAAD;QAAK,KAAK,OAAO;QACf,UAAA,oBAAC,kBAAD;SACE,MAAM;SACN,OAAM;SACN,SAAS;SACT,MAAK;SACL,SAAQ;QACT,CAAA;OACE,CAAA,CACF;MAEL,CAAA,IAAA;MAGD,mBACC,oBAAC,KAAD;OAAK,KAAK,OAAO;OACf,UAAA,oBAAC,MAAD;QAAM,IAAG;QAAK,KAAK,OAAO;QACvB,UAAA;OACG,CAAA;MACH,CAAA;MAGN,CAAC,iBAAiB;MAElB,cAAc,oBAAC,KAAD;OAAK,KAAK,OAAO;OAAc;MAAc,CAAA;KACzD;;GACF;EAEJ,CAAA,GAAA,WACC,oBAAC,KAAD;GAAK,KAAK,OAAO;GAAM,UAAU;GAC9B,UAAA;EACE,CAAA,CAEJ;;AAET,CAAC;AAED,iBAAiB,cAAc"}
|
|
1
|
+
{"version":3,"file":"BitkitPageHeader.js","names":["_Fragment"],"sources":["../../../lib/components/BitkitPageHeader/BitkitPageHeader.tsx"],"sourcesContent":["import { Box, type BoxProps } from '@chakra-ui/react/box';\nimport { useSlotRecipe } from '@chakra-ui/react/styled-system';\nimport { Text } from '@chakra-ui/react/text';\nimport { forwardRef, type ReactNode } from 'react';\n\nimport IconMenuHamburger from '../../icons/IconMenuHamburger';\nimport { ControlSizeContext } from '../../utilities/ControlSizeContext';\nimport { isEmptyNode } from '../../utilities/isEmptyNode';\nimport useIsTruncated from '../../utilities/useIsTruncated';\nimport { type BitkitContentWidth } from '../BitkitContentWrapper/BitkitContentWrapper';\nimport BitkitIconButton from '../BitkitIconButton/BitkitIconButton';\nimport BitkitOverflowTooltip from '../BitkitOverflowTooltip/BitkitOverflowTooltip';\nimport { uiHeaderBottom } from '../BitkitUIHeader/usePublishedBottom';\nimport useSelfSticky from './useSelfSticky';\n\nexport interface BitkitPageHeaderProps extends Omit<BoxProps, 'title'> {\n /**\n * Avatar, app icon or thumbnail rendered before the title. Hidden in the collapsed layout.\n *\n * Belongs to the sub-page layouts: the design's main-page header is a title and its subtitle with\n * no avatar, so pass this alongside a `breadcrumb`.\n *\n * Size it to match the design's two sub-page cards, since the node is yours to build: `size=\"40\"`\n * (8px radius) against a bare title, and `size=\"48\"` (10px radius) once `secondaryText` is\n * present — the same avatar the `app` and `user` content shapes use.\n */\n avatar?: ReactNode;\n /** Badge rendered next to the title. Hidden in the collapsed layout. */\n badge?: ReactNode;\n /**\n * Breadcrumb trail above the title — pass a `BitkitBreadcrumb`. Its presence is what switches the\n * header from the design's main-page layout to a sub-page one, so there is no separate page-type\n * prop: the recipe's own `hasBreadcrumb` variant is derived from it.\n *\n * The two layouts carry more than the trail. A main-page header is a title and its subtitle —\n * top-level pages and product overviews — with no avatar and no `app`/`user` content shape. Those\n * belong to sub-pages, so pass them together with a trail.\n */\n breadcrumb?: ReactNode;\n /**\n * Trailing action buttons. Stacked full-width below the title on mobile, primary action on top.\n *\n * The collapsed row is built for `size=\"sm\"` buttons and the expanded header for `size=\"md\"`.\n * A `sticky` or `minimal` header sizes its actions itself, unless they set a size of their own.\n *\n * `minimal` sizes them `sm` on mobile too, where it doesn't collapse: a little small in the\n * expanded mobile layout, but the design draws no mobile frame for it, so `sm` is the closer of\n * the two. Pass a flat `size` to override, not a responsive one: Bitkit icons render a different\n * SVG asset per size, so `BitkitButton` resolves `size` in JS and a `{ base, tablet }` object\n * matches no key.\n */\n children?: ReactNode;\n /**\n * Shape of the title block, mirroring the design's `content` property. `title` is a page title\n * with an optional subtitle; `app` and `user` are the tighter entity layouts — a larger avatar\n * centred against a smaller title and 14px secondary text. They differ only in the gap between\n * the avatar and the text, 16 and 12 respectively.\n */\n contentVariant?: 'title' | 'app' | 'user';\n /**\n * Lines the header's content up with the page content below it: pass the `BitkitContentWrapper`'s value. The title,\n * the actions and the tabs are capped at that width and centred, while the background and the bottom border still run\n * edge to edge. `layout/maxWidth/full` keeps the same 32px inset without a cap. Without it the header keeps the default inset, which\n * lines up with a sidebar below it.\n */\n contentWidth?: BitkitContentWidth;\n /**\n * Inline controls between the trail and the actions — a view switcher, filters, a settings menu.\n * Their presence spreads the row into three groups instead of the usual trail-and-actions pair,\n * which is the shape the design file calls `PageHeader-WFE`.\n *\n * Belongs to the collapsed row, so it is honoured by `variant=\"minimal\"` *and* by a stuck\n * `sticky` header — the two produce the same row — and ignored in the expanded layouts, which the\n * design draws no controls in.\n */\n controls?: ReactNode;\n /**\n * Makes the header stick by itself: from `tablet` it sticks right below a pinned\n * `BitkitUIHeader` (`uiHeaderBottom`), collapses into the compact row once scrolled to it, and\n * its actions shrink to `sm` unless they set a size of their own. No scroll detection on the\n * page's side.\n *\n * End the `breadcrumb` with a `BitkitBreadcrumb.CurrentItem` carrying the title, always, and use\n * `CurrentItem` for nothing else: the expanded header hides it (the title is its heading there),\n * the collapsed row shows it. Render the header as a direct child of the page's column, not inside\n * a wrapper (it would stick to the wrapper) or a `gap` stack (its sentinel and spacer would take\n * gaps).\n */\n sticky?: boolean;\n /**\n * Opens the page's sidebar on mobile. Its presence switches the header to the design's\n * `hasSidebar` layout below `tablet`: the title shrinks beside a menu button, and the\n * `sectionTitle` takes over as the large heading under a rule, with the actions below it. Wire it\n * to a `BitkitPageSidebar`'s `open` / `onOpenChange`. From `tablet` the button is hidden and the\n * header is the ordinary one — the sidebar is beside the page there.\n */\n onMenuClick?: () => void;\n /**\n * Descriptive text below the title. Hidden in the collapsed layout.\n *\n * A string, like `title`, so it can be truncated to one line and carried in full by the tooltip\n * that appears when it does not fit.\n */\n secondaryText?: string;\n /**\n * Draws the line along the header's bottom edge. Set it to `false` for a header that flows\n * straight into the page, and the bottom padding goes with the line: the header's background is\n * the page's, so without the line that padding would only be a margin the page cannot shrink. The\n * page spaces its content from the header itself.\n *\n * The collapsed row keeps its padding, which centres the row rather than spacing the page, and from\n * `tablet` a stuck `sticky` header keeps its line as well, since content scrolls under it. Below\n * `tablet` the header doesn't stick, so there the line goes too.\n *\n * Ignored with `tabs`, whose list sits on that edge. That includes `variant=\"minimal\"`, which hides\n * the tab list from `tablet`: the line stays although no tabs show above it.\n */\n showDivider?: boolean;\n /**\n * The sidebar section the page is showing, for the `hasSidebar` layout — see `onMenuClick`. It\n * is the page's visible `h2` on mobile, where the sidebar that would name it is behind the menu\n * button. Not rendered from `tablet`, and never without `onMenuClick`.\n */\n sectionTitle?: string;\n /**\n * Tab bar along the bottom edge — pass a `BitkitTabs.List`. Hidden in the collapsed layout.\n *\n * The node is rendered inside the header, so tab panels cannot be siblings of the row. To drive\n * page content from it, put `BitkitTabs.Root` around the header *and* the content, and pass only\n * the list here — `BitkitTabs.List` reads its Root from context and throws without an ancestor:\n *\n * ```tsx\n * <BitkitTabs.Root defaultValue=\"overview\">\n * <BitkitPageHeader tabs={<BitkitTabs.List>…</BitkitTabs.List>} title=\"Build Hub\" />\n * <BitkitTabs.ContentGroup>\n * <BitkitTabs.Content padding=\"32\" value=\"overview\">…</BitkitTabs.Content>\n * </BitkitTabs.ContentGroup>\n * </BitkitTabs.Root>\n * ```\n *\n * Only the row is hidden when the header collapses — the panels live outside it and keep\n * rendering, so the page never blanks.\n */\n tabs?: ReactNode;\n /**\n * The page title, as a string. Everything passed here lands inside the `h1`, so it is the\n * heading's accessible name and nothing else belongs in it — the avatar, badge and secondary\n * text each have their own slot. Required: it is what gives the header a page heading at every\n * breakpoint.\n *\n * Truncated to a single line with an ellipsis. When it does not fit, hovering or focusing it\n * shows the full string in a tooltip — so a long title never grows the header.\n *\n * In the collapsed layout (`minimal` or a stuck `sticky` header) *with* a `breadcrumb`, the design shows the\n * title in the trail rather than as a heading, so end the breadcrumb with a\n * `BitkitBreadcrumb.CurrentItem` carrying it — the title is then rendered as a visually hidden\n * `h1`, since `Breadcrumb.CurrentLink` is a link and not a heading. Below `tablet` the header\n * never collapses and the visible heading is used instead (`BitkitBreadcrumb` drops its\n * `CurrentItem` on mobile).\n */\n title: string;\n /**\n * `minimal` collapses the header to the single breadcrumb row used by sub-pages that don't repeat\n * their title as a heading. Like `sticky`, it only collapses from `tablet` up. Its actions are\n * `sm` — see `children`.\n */\n variant?: 'default' | 'minimal';\n}\n\nconst BitkitPageHeader = forwardRef<HTMLElement, BitkitPageHeaderProps>((props, ref) => {\n const {\n avatar,\n badge,\n breadcrumb,\n children,\n contentVariant,\n contentWidth,\n controls,\n css,\n onMenuClick,\n secondaryText,\n sectionTitle,\n showDivider = true,\n sticky,\n tabs,\n title,\n variant,\n ...rest\n } = props;\n\n const { headerRef, isStuck, sentinelRef, spacerHeight } = useSelfSticky(ref, Boolean(sticky));\n\n // Which slots the collapsed row drops, and whether it collapses at all, is decided entirely by\n // the recipe's `tablet`-scoped styles. Nothing here branches on the viewport: a breakpoint hook\n // would render the wrong layout on first paint, since Chakra's `useMediaQuery` returns its\n // fallback until after mount.\n\n // A slot's presence is its own toggle, so all of them share one emptiness test rather than plain\n // truthiness: an array whose entries all render nothing — `items.map()` where every branch is\n // `null` — is still truthy, and would otherwise render a wrapper that only contributes gap. For\n // `controls` it would also spread the row into three groups around an empty middle one.\n const hasAvatar = !isEmptyNode(avatar);\n const hasBadge = !isEmptyNode(badge);\n const hasBreadcrumb = !isEmptyNode(breadcrumb);\n const hasActions = !isEmptyNode(children);\n const hasSecondaryText = !isEmptyNode(secondaryText);\n const hasSidebar = onMenuClick !== undefined;\n const hasSectionTitle = hasSidebar && !isEmptyNode(sectionTitle);\n const hasTabs = !isEmptyNode(tabs);\n\n // `BitkitOverflowTooltip` does no measuring of its own — it shows the tooltip unless told not to,\n // so each truncating text reports whether it is actually clipped and suppresses its own tooltip\n // when it is not. Keyed on the text so a change re-measures without waiting for a resize.\n const { isTruncated: isTitleTruncated, ref: titleRef } = useIsTruncated<HTMLHeadingElement>(title);\n const { isTruncated: isSecondaryTruncated, ref: secondaryRef } = useIsTruncated<HTMLParagraphElement>(secondaryText);\n\n // The design only draws inline controls in the collapsed row, so they are ignored in the\n // expanded layouts rather than left to land somewhere undesigned. `minimal` and a stuck header\n // produce that row through the same `collapsedSlots`, so both have to honour them.\n const isCollapsed = variant === 'minimal' || isStuck;\n const showControls = !isEmptyNode(controls) && isCollapsed;\n\n // The collapsed row takes `sm` actions, a sticky header's expanded one `md`. A plain header leaves\n // them to the consumer.\n const actionSize = isCollapsed ? 'sm' : sticky ? 'md' : undefined;\n\n // The collapsed row with a trail makes the title block `srOnly`, which is a 1px box — so the\n // measurement reports \"truncated\" for a heading nobody can see. Left alone that puts a tab stop\n // on an invisible element and opens a tooltip against it. The trail already carries the title as\n // its current item in exactly that layout, so there is nothing to surface anyway.\n const canShowTitleTooltip = isTitleTruncated && !(isCollapsed && hasBreadcrumb);\n\n const recipe = useSlotRecipe({ key: 'pageHeader' });\n const styles = recipe({\n contentVariant,\n hasBreadcrumb,\n hasControls: showControls,\n hasDivider: showDivider || hasTabs,\n hasSidebar,\n alignsToContent: Boolean(contentWidth),\n isSticky: isStuck,\n variant,\n });\n\n // The controls are the middle of three groups, so they follow whichever element holds the left\n // slot: the trail when there is one, otherwise the title — which lives inside `contentBlock`, so\n // they have to go in there with it rather than beside it.\n const controlsNode = showControls ? <Box css={styles.controls}>{controls}</Box> : null;\n\n // With a sidebar the menu button shares the title's row, so the block gets a wrapper the content\n // row treats as the title block. Other headers keep their DOM.\n const titleBlock = (\n <Box css={styles.titleBlock}>\n {hasAvatar && <Box css={styles.avatar}>{avatar}</Box>}\n\n <Box css={styles.textBlock}>\n <Box css={styles.titleRow}>\n {/*\n `bottom-start` rather than the tooltip's default `right`: these texts are\n full-width rows, so a right-hand tooltip lands over the actions. Opening below and\n aligned to the text's start keeps it clear of them and lines it up with the text\n it repeats.\n */}\n <BitkitOverflowTooltip disabled={!canShowTitleTooltip} placement=\"bottom-start\" text={title}>\n {/*\n `tabIndex` only while truncated: the tooltip trigger is rendered `asChild`, so an\n `h1` stays unfocusable and the full title would be mouse-only. Adding the tab\n stop unconditionally would put one in every header for no benefit.\n */}\n <Text as=\"h1\" css={styles.title} ref={titleRef} tabIndex={canShowTitleTooltip ? 0 : undefined}>\n {title}\n </Text>\n </BitkitOverflowTooltip>\n {hasBadge && <Box css={styles.badge}>{badge}</Box>}\n </Box>\n\n {hasSecondaryText && secondaryText !== undefined && (\n <BitkitOverflowTooltip disabled={!isSecondaryTruncated} placement=\"bottom-start\" text={secondaryText}>\n <Text css={styles.secondaryText} ref={secondaryRef} tabIndex={isSecondaryTruncated ? 0 : undefined}>\n {secondaryText}\n </Text>\n </BitkitOverflowTooltip>\n )}\n </Box>\n </Box>\n );\n\n const header = (\n <Box\n as=\"header\"\n css={[styles.root, css]}\n ref={headerRef}\n {...(sticky && {\n insetBlockStart: uiHeaderBottom,\n position: { base: 'static', tablet: 'sticky' },\n zIndex: 'pageHeader',\n })}\n {...rest}\n >\n <Box css={styles.headerBlock} maxWidth={contentWidth}>\n {hasBreadcrumb && (\n <Box\n css={[\n styles.breadcrumb,\n // A self-sticky header takes a trail that always ends in the title (`CurrentItem`): the\n // collapsed row shows it there, the expanded one already has the title as its heading.\n sticky && !isCollapsed && { '& li:has([aria-current=\"page\"])': { display: 'none' } },\n ]}\n >\n {breadcrumb}\n </Box>\n )}\n\n {hasBreadcrumb && controlsNode}\n\n <Box css={styles.contentBlock}>\n {hasSidebar ? (\n <Box css={styles.titleBar}>\n {titleBlock}\n <Box css={styles.menuButton}>\n <BitkitIconButton\n icon={IconMenuHamburger}\n label=\"Open navigation\"\n onClick={onMenuClick}\n size=\"sm\"\n variant=\"secondary\"\n />\n </Box>\n </Box>\n ) : (\n titleBlock\n )}\n\n {hasSectionTitle && (\n <Box css={styles.sectionBlock}>\n <Text as=\"h2\" css={styles.sectionTitle}>\n {sectionTitle}\n </Text>\n </Box>\n )}\n\n {!hasBreadcrumb && controlsNode}\n\n {hasActions && (\n <Box css={styles.actionBlock}>\n <ControlSizeContext.Provider value={actionSize}>{children}</ControlSizeContext.Provider>\n </Box>\n )}\n </Box>\n </Box>\n\n {hasTabs && (\n <Box css={styles.tabs} maxWidth={contentWidth}>\n {tabs}\n </Box>\n )}\n </Box>\n );\n\n // The header keeps its place in the tree either way, so switching `sticky` doesn't remount it.\n return (\n <>\n {sticky && <Box aria-hidden ref={sentinelRef} />}\n {header}\n {/* Holds the height the header gave up by collapsing, so the content below doesn't jump. */}\n {sticky && <Box aria-hidden display={{ base: 'none', tablet: 'block' }} height={`${spacerHeight}px`} />}\n </>\n );\n});\n\nexport { pageHeaderBottom } from './pageHeaderBottom';\nexport { default as usePageHeaderBottom } from './usePageHeaderBottom';\n\nBitkitPageHeader.displayName = 'BitkitPageHeader';\n\nexport default BitkitPageHeader;\n"],"mappings":";;;;;;;;;;;;;;;;AAyKA,IAAM,mBAAmB,YAAgD,OAAO,QAAQ;CACtF,MAAM,EACJ,QACA,OACA,YACA,UACA,gBACA,cACA,UACA,KACA,aACA,eACA,cACA,cAAc,MACd,QACA,MACA,OACA,SACA,GAAG,SACD;CAEJ,MAAM,EAAE,WAAW,SAAS,aAAa,iBAAiB,cAAc,KAAK,QAAQ,MAAM,CAAC;CAW5F,MAAM,YAAY,CAAC,YAAY,MAAM;CACrC,MAAM,WAAW,CAAC,YAAY,KAAK;CACnC,MAAM,gBAAgB,CAAC,YAAY,UAAU;CAC7C,MAAM,aAAa,CAAC,YAAY,QAAQ;CACxC,MAAM,mBAAmB,CAAC,YAAY,aAAa;CACnD,MAAM,aAAa,gBAAgB,KAAA;CACnC,MAAM,kBAAkB,cAAc,CAAC,YAAY,YAAY;CAC/D,MAAM,UAAU,CAAC,YAAY,IAAI;CAKjC,MAAM,EAAE,aAAa,kBAAkB,KAAK,aAAa,eAAmC,KAAK;CACjG,MAAM,EAAE,aAAa,sBAAsB,KAAK,iBAAiB,eAAqC,aAAa;CAKnH,MAAM,cAAc,YAAY,aAAa;CAC7C,MAAM,eAAe,CAAC,YAAY,QAAQ,KAAK;CAI/C,MAAM,aAAa,cAAc,OAAO,SAAS,OAAO,KAAA;CAMxD,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`). */
|
|
2
|
+
export declare const pageHeaderCollapsedRowPx = 72;
|
|
3
|
+
/** The collapsed row plus the 1px line a stuck header keeps. */
|
|
4
|
+
export declare const pageHeaderCollapsedHeight: string;
|
|
5
|
+
/** `pageHeaderCollapsedHeight` in px at the page's root font size, for JS that can't wait to measure it. */
|
|
6
|
+
export declare const getPageHeaderCollapsedHeightPx: () => number;
|
|
7
|
+
/** Set on the document root while a `sticky` page header is mounted; `global-css.ts` keys the variable on it. */
|
|
8
|
+
export declare const stickyPageHeaderMarker = "data-bitkit-sticky-page-header";
|
|
9
|
+
export declare const pageHeaderBottomVar = "--bitkit-page-header-bottom";
|
|
10
|
+
/**
|
|
11
|
+
* Where content below the page header can start: under a `sticky` page header when the page has one
|
|
12
|
+
* (from `tablet`, where it sticks), otherwise under a pinned `BitkitUIHeader`, otherwise `0`. Use it
|
|
13
|
+
* for a row that sticks under the header (`insetBlockStart`) or a `scrollMarginTop`.
|
|
14
|
+
*/
|
|
15
|
+
export declare const pageHeaderBottom = "var(--bitkit-page-header-bottom, var(--bitkit-ui-header-bottom, 0px))";
|
|
16
|
+
/** How much height a `sticky` page header gives up by collapsing (expanded − collapsed), set while one is mounted. */
|
|
17
|
+
export declare const pageHeaderCollapseDistanceVar = "--bitkit-page-header-collapse-distance";
|
|
18
|
+
export declare const pageHeaderCollapseDistance = "var(--bitkit-page-header-collapse-distance, 0px)";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { rem } from "../../theme/themeUtils.js";
|
|
2
|
+
import { uiHeaderBottom } from "../BitkitUIHeader/usePublishedBottom.js";
|
|
3
|
+
/** The collapsed row plus the 1px line a stuck header keeps. */
|
|
4
|
+
var pageHeaderCollapsedHeight = `calc(${rem(72)} + 1px)`;
|
|
5
|
+
/** `pageHeaderCollapsedHeight` in px at the page's root font size, for JS that can't wait to measure it. */
|
|
6
|
+
var getPageHeaderCollapsedHeightPx = () => 72 / 16 * (parseFloat(getComputedStyle(document.documentElement).fontSize) || 16) + 1;
|
|
7
|
+
/** Set on the document root while a `sticky` page header is mounted; `global-css.ts` keys the variable on it. */
|
|
8
|
+
var stickyPageHeaderMarker = "data-bitkit-sticky-page-header";
|
|
9
|
+
var pageHeaderBottomVar = "--bitkit-page-header-bottom";
|
|
10
|
+
/**
|
|
11
|
+
* Where content below the page header can start: under a `sticky` page header when the page has one
|
|
12
|
+
* (from `tablet`, where it sticks), otherwise under a pinned `BitkitUIHeader`, otherwise `0`. Use it
|
|
13
|
+
* for a row that sticks under the header (`insetBlockStart`) or a `scrollMarginTop`.
|
|
14
|
+
*/
|
|
15
|
+
var pageHeaderBottom = `var(${pageHeaderBottomVar}, ${uiHeaderBottom})`;
|
|
16
|
+
/** How much height a `sticky` page header gives up by collapsing (expanded − collapsed), set while one is mounted. */
|
|
17
|
+
var pageHeaderCollapseDistanceVar = "--bitkit-page-header-collapse-distance";
|
|
18
|
+
var pageHeaderCollapseDistance = `var(${pageHeaderCollapseDistanceVar}, 0px)`;
|
|
19
|
+
export { getPageHeaderCollapsedHeightPx, pageHeaderBottom, pageHeaderBottomVar, pageHeaderCollapseDistance, pageHeaderCollapseDistanceVar, pageHeaderCollapsedHeight, stickyPageHeaderMarker };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=pageHeaderBottom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pageHeaderBottom.js","names":[],"sources":["../../../lib/components/BitkitPageHeader/pageHeaderBottom.ts"],"sourcesContent":["import { rem } from '../../theme/themeUtils';\nimport { uiHeaderBottom } from '../BitkitUIHeader/usePublishedBottom';\n\n/** The collapsed row's height, fixed by the design (`PageHeader.recipe.ts`). */\nexport const pageHeaderCollapsedRowPx = 72;\n\n/** The collapsed row plus the 1px line a stuck header keeps. */\nexport const pageHeaderCollapsedHeight = `calc(${rem(pageHeaderCollapsedRowPx)} + 1px)`;\n\n/** `pageHeaderCollapsedHeight` in px at the page's root font size, for JS that can't wait to measure it. */\nexport const getPageHeaderCollapsedHeightPx = () =>\n (pageHeaderCollapsedRowPx / 16) * (parseFloat(getComputedStyle(document.documentElement).fontSize) || 16) + 1;\n\n/** Set on the document root while a `sticky` page header is mounted; `global-css.ts` keys the variable on it. */\nexport const stickyPageHeaderMarker = 'data-bitkit-sticky-page-header';\n\nexport const pageHeaderBottomVar = '--bitkit-page-header-bottom';\n\n/**\n * Where content below the page header can start: under a `sticky` page header when the page has one\n * (from `tablet`, where it sticks), otherwise under a pinned `BitkitUIHeader`, otherwise `0`. Use it\n * for a row that sticks under the header (`insetBlockStart`) or a `scrollMarginTop`.\n */\nexport const pageHeaderBottom = `var(${pageHeaderBottomVar}, ${uiHeaderBottom})`;\n\n/** How much height a `sticky` page header gives up by collapsing (expanded − collapsed), set while one is mounted. */\nexport const pageHeaderCollapseDistanceVar = '--bitkit-page-header-collapse-distance';\n\nexport const pageHeaderCollapseDistance = `var(${pageHeaderCollapseDistanceVar}, 0px)`;\n"],"mappings":";;;AAOA,IAAa,4BAA4B,QAAQ,IAAA,EAA4B,EAAE;;AAG/E,IAAa,uCAAA,KACiB,MAAO,WAAW,iBAAiB,SAAS,eAAe,CAAC,CAAC,QAAQ,KAAK,MAAM;;AAG9G,IAAa,yBAAyB;AAEtC,IAAa,sBAAsB;;;;;;AAOnC,IAAa,mBAAmB,OAAO,oBAAoB,IAAI,eAAe;;AAG9E,IAAa,gCAAgC;AAE7C,IAAa,6BAA6B,OAAO,8BAA8B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `pageHeaderBottom` as a number of px, for JS that needs one, such as an `IntersectionObserver`
|
|
3
|
+
* margin or a scroll offset. It follows the same rules as the CSS value: under a `sticky` page
|
|
4
|
+
* header from `tablet`, otherwise under the pinned `BitkitUIHeader`. CSS takes `pageHeaderBottom`.
|
|
5
|
+
*/
|
|
6
|
+
declare const usePageHeaderBottom: () => number;
|
|
7
|
+
export default usePageHeaderBottom;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import breakpoints from "../../theme/breakpoints.js";
|
|
2
|
+
import useUiHeaderBottom from "../BitkitUIHeader/useUiHeaderBottom.js";
|
|
3
|
+
import { getPageHeaderCollapsedHeightPx, stickyPageHeaderMarker } from "./pageHeaderBottom.js";
|
|
4
|
+
import { useSyncExternalStore } from "react";
|
|
5
|
+
import { useMediaQuery } from "@chakra-ui/react/hooks";
|
|
6
|
+
// lib/components/BitkitPageHeader/usePageHeaderBottom.ts
|
|
7
|
+
var read = () => document.documentElement.hasAttribute(stickyPageHeaderMarker);
|
|
8
|
+
var readOnServer = () => false;
|
|
9
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
10
|
+
var observer;
|
|
11
|
+
var subscribe = (listener) => {
|
|
12
|
+
listeners.add(listener);
|
|
13
|
+
if (!observer) {
|
|
14
|
+
observer = new MutationObserver(() => listeners.forEach((notify) => notify()));
|
|
15
|
+
observer.observe(document.documentElement, { attributeFilter: [stickyPageHeaderMarker] });
|
|
16
|
+
}
|
|
17
|
+
return () => {
|
|
18
|
+
listeners.delete(listener);
|
|
19
|
+
if (listeners.size === 0) {
|
|
20
|
+
observer?.disconnect();
|
|
21
|
+
observer = void 0;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* `pageHeaderBottom` as a number of px, for JS that needs one, such as an `IntersectionObserver`
|
|
27
|
+
* margin or a scroll offset. It follows the same rules as the CSS value: under a `sticky` page
|
|
28
|
+
* header from `tablet`, otherwise under the pinned `BitkitUIHeader`. CSS takes `pageHeaderBottom`.
|
|
29
|
+
*/
|
|
30
|
+
var usePageHeaderBottom = () => {
|
|
31
|
+
const uiHeaderBottomPx = useUiHeaderBottom();
|
|
32
|
+
const hasStickyHeader = useSyncExternalStore(subscribe, read, readOnServer);
|
|
33
|
+
const [isFromTablet] = useMediaQuery([`(min-width: ${breakpoints.tablet})`]);
|
|
34
|
+
return hasStickyHeader && isFromTablet ? uiHeaderBottomPx + getPageHeaderCollapsedHeightPx() : uiHeaderBottomPx;
|
|
35
|
+
};
|
|
36
|
+
export { usePageHeaderBottom as default };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=usePageHeaderBottom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePageHeaderBottom.js","names":[],"sources":["../../../lib/components/BitkitPageHeader/usePageHeaderBottom.ts"],"sourcesContent":["import { useMediaQuery } from '@chakra-ui/react/hooks';\nimport { useSyncExternalStore } from 'react';\n\nimport breakpoints from '../../theme/breakpoints';\nimport useUiHeaderBottom from '../BitkitUIHeader/useUiHeaderBottom';\nimport { getPageHeaderCollapsedHeightPx, stickyPageHeaderMarker } from './pageHeaderBottom';\n\nconst read = () => document.documentElement.hasAttribute(stickyPageHeaderMarker);\nconst readOnServer = () => false;\n\n// One observer for every caller, connected while anyone listens.\nconst listeners = new Set<() => void>();\nlet observer: MutationObserver | undefined;\n\nconst subscribe = (listener: () => void) => {\n listeners.add(listener);\n if (!observer) {\n observer = new MutationObserver(() => listeners.forEach((notify) => notify()));\n observer.observe(document.documentElement, { attributeFilter: [stickyPageHeaderMarker] });\n }\n return () => {\n listeners.delete(listener);\n if (listeners.size === 0) {\n observer?.disconnect();\n observer = undefined;\n }\n };\n};\n\n/**\n * `pageHeaderBottom` as a number of px, for JS that needs one, such as an `IntersectionObserver`\n * margin or a scroll offset. It follows the same rules as the CSS value: under a `sticky` page\n * header from `tablet`, otherwise under the pinned `BitkitUIHeader`. CSS takes `pageHeaderBottom`.\n */\nconst usePageHeaderBottom = () => {\n const uiHeaderBottomPx = useUiHeaderBottom();\n const hasStickyHeader = useSyncExternalStore(subscribe, read, readOnServer);\n const [isFromTablet] = useMediaQuery([`(min-width: ${breakpoints.tablet})`]);\n\n return hasStickyHeader && isFromTablet ? uiHeaderBottomPx + getPageHeaderCollapsedHeightPx() : uiHeaderBottomPx;\n};\n\nexport default usePageHeaderBottom;\n"],"mappings":";;;;;;AAOA,IAAM,aAAa,SAAS,gBAAgB,aAAa,sBAAsB;AAC/E,IAAM,qBAAqB;AAG3B,IAAM,4BAAY,IAAI,IAAgB;AACtC,IAAI;AAEJ,IAAM,aAAa,aAAyB;CAC1C,UAAU,IAAI,QAAQ;CACtB,IAAI,CAAC,UAAU;EACb,WAAW,IAAI,uBAAuB,UAAU,SAAS,WAAW,OAAO,CAAC,CAAC;EAC7E,SAAS,QAAQ,SAAS,iBAAiB,EAAE,iBAAiB,CAAC,sBAAsB,EAAE,CAAC;CAC1F;CACA,aAAa;EACX,UAAU,OAAO,QAAQ;EACzB,IAAI,UAAU,SAAS,GAAG;GACxB,UAAU,WAAW;GACrB,WAAW,KAAA;EACb;CACF;AACF;;;;;;AAOA,IAAM,4BAA4B;CAChC,MAAM,mBAAmB,kBAAkB;CAC3C,MAAM,kBAAkB,qBAAqB,WAAW,MAAM,YAAY;CAC1E,MAAM,CAAC,gBAAgB,cAAc,CAAC,eAAe,YAAY,OAAO,EAAE,CAAC;CAE3E,OAAO,mBAAmB,eAAe,mBAAmB,+BAA+B,IAAI;AACjG"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ForwardedRef } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* The scroll side of `BitkitPageHeader`'s `sticky`: whether the header has reached the pinned UI
|
|
4
|
+
* header, and how much height it gave up by collapsing. Off below `tablet`, where the header doesn't
|
|
5
|
+
* stick.
|
|
6
|
+
*
|
|
7
|
+
* A zero-height sentinel sits right above the header; once it scrolls past the UI header's bottom edge
|
|
8
|
+
* the header is stuck. The observer is rebuilt when that edge moves (a banner comes or goes).
|
|
9
|
+
*/
|
|
10
|
+
declare const useSelfSticky: (forwardedRef: ForwardedRef<HTMLElement>, isEnabled: boolean) => {
|
|
11
|
+
headerRef: import('react').RefObject<HTMLElement | null>;
|
|
12
|
+
isStuck: boolean;
|
|
13
|
+
sentinelRef: import('react').RefObject<HTMLDivElement | null>;
|
|
14
|
+
spacerHeight: number;
|
|
15
|
+
};
|
|
16
|
+
export default useSelfSticky;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import breakpoints from "../../theme/breakpoints.js";
|
|
2
|
+
import useUiHeaderBottom from "../BitkitUIHeader/useUiHeaderBottom.js";
|
|
3
|
+
import { getPageHeaderCollapsedHeightPx, pageHeaderCollapseDistanceVar, stickyPageHeaderMarker } from "./pageHeaderBottom.js";
|
|
4
|
+
import { useEffect, useImperativeHandle, useLayoutEffect, useRef, useState } from "react";
|
|
5
|
+
import { useMediaQuery } from "@chakra-ui/react/hooks";
|
|
6
|
+
// lib/components/BitkitPageHeader/useSelfSticky.ts
|
|
7
|
+
/**
|
|
8
|
+
* The scroll side of `BitkitPageHeader`'s `sticky`: whether the header has reached the pinned UI
|
|
9
|
+
* header, and how much height it gave up by collapsing. Off below `tablet`, where the header doesn't
|
|
10
|
+
* stick.
|
|
11
|
+
*
|
|
12
|
+
* A zero-height sentinel sits right above the header; once it scrolls past the UI header's bottom edge
|
|
13
|
+
* the header is stuck. The observer is rebuilt when that edge moves (a banner comes or goes).
|
|
14
|
+
*/
|
|
15
|
+
var useSelfSticky = (forwardedRef, isEnabled) => {
|
|
16
|
+
const headerRef = useRef(null);
|
|
17
|
+
const sentinelRef = useRef(null);
|
|
18
|
+
const [isStuck, setIsStuck] = useState(false);
|
|
19
|
+
const [expandedHeight, setExpandedHeight] = useState(0);
|
|
20
|
+
const isStuckRef = useRef(false);
|
|
21
|
+
const [isFromTablet] = useMediaQuery([`(min-width: ${breakpoints.tablet})`]);
|
|
22
|
+
const isActive = isEnabled && isFromTablet;
|
|
23
|
+
const uiHeaderBottomPx = useUiHeaderBottom();
|
|
24
|
+
useImperativeHandle(forwardedRef, () => headerRef.current, []);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (!isEnabled) return;
|
|
27
|
+
const root = document.documentElement;
|
|
28
|
+
root.setAttribute(stickyPageHeaderMarker, "");
|
|
29
|
+
return () => {
|
|
30
|
+
root.removeAttribute(stickyPageHeaderMarker);
|
|
31
|
+
root.style.removeProperty(pageHeaderCollapseDistanceVar);
|
|
32
|
+
};
|
|
33
|
+
}, [isEnabled]);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const sentinel = sentinelRef.current;
|
|
36
|
+
if (!isActive || !sentinel) {
|
|
37
|
+
setIsStuck(false);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const observer = new IntersectionObserver((entries) => {
|
|
41
|
+
const entry = entries[entries.length - 1];
|
|
42
|
+
setIsStuck(!entry.isIntersecting && entry.boundingClientRect.top < uiHeaderBottomPx);
|
|
43
|
+
}, {
|
|
44
|
+
root: document,
|
|
45
|
+
rootMargin: `-${Math.floor(uiHeaderBottomPx)}px 0px 0px 0px`
|
|
46
|
+
});
|
|
47
|
+
observer.observe(sentinel);
|
|
48
|
+
return () => observer.disconnect();
|
|
49
|
+
}, [isActive, uiHeaderBottomPx]);
|
|
50
|
+
useLayoutEffect(() => {
|
|
51
|
+
isStuckRef.current = isStuck;
|
|
52
|
+
}, [isStuck]);
|
|
53
|
+
useLayoutEffect(() => {
|
|
54
|
+
const header = headerRef.current;
|
|
55
|
+
if (!isEnabled || !header || typeof ResizeObserver === "undefined") return;
|
|
56
|
+
const observer = new ResizeObserver(() => {
|
|
57
|
+
if (!isStuckRef.current) setExpandedHeight(header.offsetHeight);
|
|
58
|
+
});
|
|
59
|
+
observer.observe(header);
|
|
60
|
+
return () => observer.disconnect();
|
|
61
|
+
}, [isEnabled]);
|
|
62
|
+
const collapseDistance = isEnabled && expandedHeight > 0 ? Math.max(expandedHeight - getPageHeaderCollapsedHeightPx(), 0) : 0;
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (isEnabled) document.documentElement.style.setProperty(pageHeaderCollapseDistanceVar, `${collapseDistance}px`);
|
|
65
|
+
}, [collapseDistance, isEnabled]);
|
|
66
|
+
const isStuckNow = isActive && isStuck;
|
|
67
|
+
return {
|
|
68
|
+
headerRef,
|
|
69
|
+
isStuck: isStuckNow,
|
|
70
|
+
sentinelRef,
|
|
71
|
+
spacerHeight: isStuckNow ? collapseDistance : 0
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
export { useSelfSticky as default };
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=useSelfSticky.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSelfSticky.js","names":[],"sources":["../../../lib/components/BitkitPageHeader/useSelfSticky.ts"],"sourcesContent":["import { useMediaQuery } from '@chakra-ui/react/hooks';\nimport { type ForwardedRef, useEffect, useImperativeHandle, useLayoutEffect, useRef, useState } from 'react';\n\nimport breakpoints from '../../theme/breakpoints';\nimport useUiHeaderBottom from '../BitkitUIHeader/useUiHeaderBottom';\nimport {\n getPageHeaderCollapsedHeightPx,\n pageHeaderCollapseDistanceVar,\n stickyPageHeaderMarker,\n} from './pageHeaderBottom';\n\n/**\n * The scroll side of `BitkitPageHeader`'s `sticky`: whether the header has reached the pinned UI\n * header, and how much height it gave up by collapsing. Off below `tablet`, where the header doesn't\n * stick.\n *\n * A zero-height sentinel sits right above the header; once it scrolls past the UI header's bottom edge\n * the header is stuck. The observer is rebuilt when that edge moves (a banner comes or goes).\n */\nconst useSelfSticky = (forwardedRef: ForwardedRef<HTMLElement>, isEnabled: boolean) => {\n const headerRef = useRef<HTMLElement>(null);\n const sentinelRef = useRef<HTMLDivElement>(null);\n const [isStuck, setIsStuck] = useState(false);\n const [expandedHeight, setExpandedHeight] = useState(0);\n const isStuckRef = useRef(false);\n\n const [isFromTablet] = useMediaQuery([`(min-width: ${breakpoints.tablet})`]);\n const isActive = isEnabled && isFromTablet;\n const uiHeaderBottomPx = useUiHeaderBottom();\n\n useImperativeHandle(forwardedRef, () => headerRef.current as HTMLElement, []);\n\n // Tells the global stylesheet to publish `--bitkit-page-header-bottom` while the header is sticky.\n useEffect(() => {\n if (!isEnabled) {\n return undefined;\n }\n const root = document.documentElement;\n root.setAttribute(stickyPageHeaderMarker, '');\n return () => {\n root.removeAttribute(stickyPageHeaderMarker);\n root.style.removeProperty(pageHeaderCollapseDistanceVar);\n };\n }, [isEnabled]);\n\n useEffect(() => {\n const sentinel = sentinelRef.current;\n if (!isActive || !sentinel) {\n setIsStuck(false);\n return undefined;\n }\n const observer = new IntersectionObserver(\n (entries) => {\n const entry = entries[entries.length - 1];\n setIsStuck(!entry.isIntersecting && entry.boundingClientRect.top < uiHeaderBottomPx);\n },\n // An explicit `document` root: with the implicit one, a page inside an iframe (Storybook) gets no\n // `rootMargin`, so the header would only collapse once it had left the frame. Floored, because the\n // browser rounds a fractional margin, which can start the sentinel outside the root.\n { root: document, rootMargin: `-${Math.floor(uiHeaderBottomPx)}px 0px 0px 0px` },\n );\n observer.observe(sentinel);\n return () => observer.disconnect();\n }, [isActive, uiHeaderBottomPx]);\n\n useLayoutEffect(() => {\n isStuckRef.current = isStuck;\n }, [isStuck]);\n\n // The expanded height is the one to hold on to, so it is only taken while the header is expanded.\n useLayoutEffect(() => {\n const header = headerRef.current;\n if (!isEnabled || !header || typeof ResizeObserver === 'undefined') {\n return undefined;\n }\n const observer = new ResizeObserver(() => {\n if (!isStuckRef.current) {\n setExpandedHeight(header.offsetHeight);\n }\n });\n observer.observe(header);\n return () => observer.disconnect();\n }, [isEnabled]);\n\n // How far the header shrinks when it collapses, for the sidebar's scroll-driven height.\n // Only once measured: before that (and on the server) there is nothing to read the font size from.\n const collapseDistance =\n isEnabled && expandedHeight > 0 ? Math.max(expandedHeight - getPageHeaderCollapsedHeightPx(), 0) : 0;\n useEffect(() => {\n if (isEnabled) {\n document.documentElement.style.setProperty(pageHeaderCollapseDistanceVar, `${collapseDistance}px`);\n }\n }, [collapseDistance, isEnabled]);\n\n // The spacer has to be right in the render that collapses the header: a frame late, the content\n // jumps, scroll anchoring scrolls back to make up for it, and the header expands again. So it uses\n // the collapsed row's fixed height rather than waiting to measure it.\n const isStuckNow = isActive && isStuck;\n return {\n headerRef,\n isStuck: isStuckNow,\n sentinelRef,\n spacerHeight: isStuckNow ? collapseDist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F,MAAM,WAAW,IAAI,qBAAqB;GACxC,IAAI,CAAC,WAAW,SACd,kBAAkB,OAAO,YAAY;EAEzC,CAAC;EACD,SAAS,QAAQ,MAAM;EACvB,aAAa,SAAS,WAAW;CACnC,GAAG,CAAC,SAAS,CAAC;CAId,MAAM,mBACJ,aAAa,iBAAiB,IAAI,KAAK,IAAI,iBAAiB,+BAA+B,GAAG,CAAC,IAAI;CACrG,gBAAgB;EACd,IAAI,WACF,SAAS,gBAAgB,MAAM,YAAY,+BAA+B,GAAG,iBAAiB,GAAG;CAErG,GAAG,CAAC,kBAAkB,SAAS,CAAC;CAKhC,MAAM,aAAa,YAAY;CAC/B,OAAO;EACL;EACA,SAAS;EACT;EACA,cAAc,aAAa,mBAAmB;CAChD;AACF"}
|
|
@@ -22,6 +22,12 @@ export interface BitkitPageSidebarProps extends BoxProps {
|
|
|
22
22
|
*/
|
|
23
23
|
onOpenChange?: (open: boolean) => void;
|
|
24
24
|
open?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* For a sidebar below a `sticky` `BitkitPageHeader`: from `tablet` it sticks right under the header
|
|
27
|
+
* and fits the viewport below it, scrolling on its own, so its footer stays in view. Its height
|
|
28
|
+
* follows the page's scroll from the top, so the page header has to start the page.
|
|
29
|
+
*/
|
|
30
|
+
sticky?: boolean;
|
|
25
31
|
}
|
|
26
32
|
interface BitkitPageSidebarItemCommonProps {
|
|
27
33
|
badge?: ReactNode;
|
|
@@ -62,12 +62,15 @@ var showAtMobile = { display: {
|
|
|
62
62
|
* and a `drawerHeader` naming the page. Both props are ignored from `tablet` up.
|
|
63
63
|
*/
|
|
64
64
|
var BitkitPageSidebar = forwardRef((props, ref) => {
|
|
65
|
-
const { children, css, drawerHeader, onOpenChange, open = false, ...rest } = props;
|
|
65
|
+
const { children, css, drawerHeader, onOpenChange, open = false, sticky, ...rest } = props;
|
|
66
66
|
const { isMobile } = useResponsive();
|
|
67
67
|
const { splitCssProps } = useChakraContext();
|
|
68
68
|
const hasDrawer = onOpenChange !== void 0;
|
|
69
69
|
const isDrawer = isMobile && hasDrawer;
|
|
70
|
-
const styles = useSlotRecipe({ key: "pageSidebar" })({
|
|
70
|
+
const styles = useSlotRecipe({ key: "pageSidebar" })({
|
|
71
|
+
isSticky: sticky && !isDrawer,
|
|
72
|
+
layout: isDrawer ? "drawer" : hasDrawer ? "hidden" : "static"
|
|
73
|
+
});
|
|
71
74
|
if (!isDrawer) return /* @__PURE__ */ jsx(Box, {
|
|
72
75
|
ref,
|
|
73
76
|
"aria-label": "Page navigation",
|