@datalayer/primer-addons 1.0.57 → 1.0.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/README.md +66 -0
  2. package/lib/components/appearance/AppearanceControls.d.ts +3 -3
  3. package/lib/components/appearance/AppearanceControls.js +8 -4
  4. package/lib/components/appearance/AppearanceControls.stories.d.ts +1 -1
  5. package/lib/components/appearance/AppearanceControls.stories.js +1 -1
  6. package/lib/components/appearance/AppearanceMenu.d.ts +1 -1
  7. package/lib/components/buttons/Buttons.stories.d.ts +1 -0
  8. package/lib/components/buttons/Buttons.stories.js +10 -1
  9. package/lib/components/buttons/SplitButton.d.ts +82 -0
  10. package/lib/components/buttons/SplitButton.js +63 -0
  11. package/lib/components/buttons/index.d.ts +1 -0
  12. package/lib/components/buttons/index.js +1 -0
  13. package/lib/components/dialog/Dialog.d.ts +62 -0
  14. package/lib/components/dialog/Dialog.js +117 -0
  15. package/lib/components/dialog/index.d.ts +1 -0
  16. package/lib/components/dialog/index.js +5 -0
  17. package/lib/components/emoji/faceEmojis.js +14 -0
  18. package/lib/components/emoji/fluent/loaders.js +13 -0
  19. package/lib/components/emoji/fluent/svg/1f39e.d.ts +2 -0
  20. package/lib/components/emoji/fluent/svg/1f39e.js +9 -0
  21. package/lib/components/emoji/fluent/svg/1f3c3.d.ts +2 -0
  22. package/lib/components/emoji/fluent/svg/1f3c3.js +9 -0
  23. package/lib/components/emoji/fluent/svg/1f3d3.d.ts +2 -0
  24. package/lib/components/emoji/fluent/svg/1f3d3.js +9 -0
  25. package/lib/components/emoji/fluent/svg/1f3e8.d.ts +2 -0
  26. package/lib/components/emoji/fluent/svg/1f3e8.js +9 -0
  27. package/lib/components/emoji/fluent/svg/1f3ea.d.ts +2 -0
  28. package/lib/components/emoji/fluent/svg/1f3ea.js +9 -0
  29. package/lib/components/emoji/fluent/svg/1f50f.d.ts +2 -0
  30. package/lib/components/emoji/fluent/svg/1f50f.js +9 -0
  31. package/lib/components/emoji/fluent/svg/1f510.d.ts +2 -0
  32. package/lib/components/emoji/fluent/svg/1f510.js +9 -0
  33. package/lib/components/emoji/fluent/svg/1f516.d.ts +2 -0
  34. package/lib/components/emoji/fluent/svg/1f516.js +9 -0
  35. package/lib/components/emoji/fluent/svg/1f526.d.ts +2 -0
  36. package/lib/components/emoji/fluent/svg/1f526.js +9 -0
  37. package/lib/components/emoji/fluent/svg/1f6ce.d.ts +2 -0
  38. package/lib/components/emoji/fluent/svg/1f6ce.js +9 -0
  39. package/lib/components/emoji/fluent/svg/1f9fa.d.ts +2 -0
  40. package/lib/components/emoji/fluent/svg/1f9fa.js +9 -0
  41. package/lib/components/emoji/fluent/svg/21a9.d.ts +2 -0
  42. package/lib/components/emoji/fluent/svg/21a9.js +9 -0
  43. package/lib/components/emoji/fluent/svg/2708.d.ts +2 -0
  44. package/lib/components/emoji/fluent/svg/2708.js +9 -0
  45. package/lib/components/hover-card/HoverCardDetails.d.ts +7 -4
  46. package/lib/components/hover-card/HoverCardDetails.js +65 -41
  47. package/lib/components/hover-card/HoverCardLayer.d.ts +6 -5
  48. package/lib/components/hover-card/HoverCardLayer.js +21 -16
  49. package/lib/components/hover-card/useThemedPortalTarget.d.ts +20 -0
  50. package/lib/components/hover-card/useThemedPortalTarget.js +13 -0
  51. package/lib/components/index.d.ts +2 -0
  52. package/lib/components/index.js +2 -0
  53. package/lib/components/layout/Center.d.ts +32 -0
  54. package/lib/components/layout/Center.js +16 -0
  55. package/lib/components/layout/Cluster.d.ts +32 -0
  56. package/lib/components/layout/Cluster.js +14 -0
  57. package/lib/components/layout/Grid.d.ts +40 -0
  58. package/lib/components/layout/Grid.js +26 -0
  59. package/lib/components/layout/HolyGrail.d.ts +76 -0
  60. package/lib/components/layout/HolyGrail.js +51 -0
  61. package/lib/components/layout/Masonry.d.ts +92 -0
  62. package/lib/components/layout/Masonry.js +109 -0
  63. package/lib/components/layout/Sidebar.d.ts +51 -0
  64. package/lib/components/layout/Sidebar.js +18 -0
  65. package/lib/components/layout/Split.d.ts +42 -0
  66. package/lib/components/layout/Split.js +23 -0
  67. package/lib/components/layout/Stack.d.ts +41 -0
  68. package/lib/components/layout/Stack.js +16 -0
  69. package/lib/components/layout/Switcher.d.ts +31 -0
  70. package/lib/components/layout/Switcher.js +22 -0
  71. package/lib/components/layout/index.d.ts +18 -0
  72. package/lib/components/layout/index.js +22 -0
  73. package/lib/components/layout/layoutProps.d.ts +27 -0
  74. package/lib/components/layout/layoutProps.js +13 -0
  75. package/lib/components/layout/masonryEngine.d.ts +85 -0
  76. package/lib/components/layout/masonryEngine.js +240 -0
  77. package/lib/components/layout/masonryLayout.d.ts +45 -0
  78. package/lib/components/layout/masonryLayout.js +113 -0
  79. package/lib/components/sliding-panel/SlidingPanel.js +7 -2
  80. package/lib/theme/themes/metalThemeStyles.js +3 -0
  81. package/package.json +1 -1
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useLayoutEffect, useRef, useState } from "react";
3
+ import { THEME_SCOPE_ATTRIBUTE } from "../../utils/Portals";
4
+ /** A marker to render in place, and the element to portal into once it is known. */
5
+ export function useThemedPortalTarget() {
6
+ const ref = useRef(null);
7
+ const [target, setTarget] = useState(null);
8
+ useLayoutEffect(() => {
9
+ const themed = ref.current?.closest(`[${THEME_SCOPE_ATTRIBUTE}]`);
10
+ setTarget(themed ?? document.body);
11
+ }, []);
12
+ return { marker: _jsx("span", { ref: ref, hidden: true, "aria-hidden": "true" }), target };
13
+ }
@@ -16,6 +16,7 @@ export * from "./color";
16
16
  export * from "./color-picker";
17
17
  export * from "./content-loader/ContentLoader";
18
18
  export * from "./date-picker";
19
+ export * from "./dialog";
19
20
  export * from "./closeable-flash/CloseableFlash";
20
21
  export * from "./icons/CircleIcon";
21
22
  export * from "./side-overlay/SideOverlay";
@@ -29,6 +30,7 @@ export * from "./buttons";
29
30
  export * from "./display";
30
31
  export * from "./emoji";
31
32
  export * from "./labels";
33
+ export * from "./layout";
32
34
  export * from "./progress";
33
35
  export * from "./sparklines";
34
36
  export * from "./tabs";
@@ -20,6 +20,7 @@ export * from "./color";
20
20
  export * from "./color-picker";
21
21
  export * from "./content-loader/ContentLoader";
22
22
  export * from "./date-picker";
23
+ export * from "./dialog";
23
24
  export * from "./closeable-flash/CloseableFlash";
24
25
  export * from "./icons/CircleIcon";
25
26
  export * from "./side-overlay/SideOverlay";
@@ -33,6 +34,7 @@ export * from "./buttons";
33
34
  export * from "./display";
34
35
  export * from "./emoji";
35
36
  export * from "./labels";
37
+ export * from "./layout";
36
38
  export * from "./progress";
37
39
  export * from "./sparklines";
38
40
  export * from "./tabs";
@@ -0,0 +1,32 @@
1
+ import { type BoxStyleProps } from '../box/Box';
2
+ import type { LayoutBoxProps } from './layoutProps';
3
+ export type CenterProps = LayoutBoxProps<'maxWidth'> & {
4
+ /** The widest the column gets: one of Primer's sizes (`small` 544px, `medium` 768px, `large` 1012px, `xlarge` 1280px), pixels or CSS. `large` by default. */
5
+ maxWidth?: BoxStyleProps['maxWidth'];
6
+ /** The space kept on both sides: an index of the space scale or CSS. None by default. */
7
+ gutter?: BoxStyleProps['paddingInline'];
8
+ /** Also centre the children, each at its own width, and their text. */
9
+ intrinsic?: boolean;
10
+ };
11
+ export declare const Center: import("react").ForwardRefExoticComponent<Omit<BoxStyleProps, "maxWidth"> & {
12
+ hover?: BoxStyleProps | undefined;
13
+ focus?: BoxStyleProps | undefined;
14
+ focusVisible?: BoxStyleProps | undefined;
15
+ focusWithin?: BoxStyleProps | undefined;
16
+ active?: BoxStyleProps | undefined;
17
+ } & {
18
+ reducedMotion?: BoxStyleProps;
19
+ } & Omit<import("react").HTMLAttributes<HTMLElement>, "boxShadow" | "fontWeight" | "zIndex" | "alignContent" | "alignItems" | "alignSelf" | "animationDelay" | "appearance" | "aspectRatio" | "backdropFilter" | "backgroundColor" | "backgroundImage" | "backgroundRepeat" | "backgroundSize" | "borderBottomColor" | "borderBottomLeftRadius" | "borderBottomRightRadius" | "borderBottomStyle" | "borderBottomWidth" | "borderCollapse" | "borderLeftColor" | "borderLeftStyle" | "borderLeftWidth" | "borderRightColor" | "borderRightStyle" | "borderRightWidth" | "borderSpacing" | "borderTopColor" | "borderTopLeftRadius" | "borderTopRightRadius" | "borderTopStyle" | "borderTopWidth" | "bottom" | "boxSizing" | "clipPath" | "color" | "columnGap" | "cursor" | "display" | "fill" | "filter" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "float" | "fontFamily" | "fontSize" | "fontStyle" | "fontVariantNumeric" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridColumnEnd" | "gridColumnStart" | "gridRowEnd" | "gridRowStart" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "isolation" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lineHeight" | "listStylePosition" | "listStyleType" | "marginBottom" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "mixBlendMode" | "objectFit" | "objectPosition" | "opacity" | "order" | "outlineColor" | "outlineOffset" | "overflowWrap" | "overflowX" | "overflowY" | "overscrollBehaviorY" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingTop" | "pointerEvents" | "position" | "resize" | "right" | "rowGap" | "scrollMarginTop" | "scrollbarGutter" | "scrollbarWidth" | "stroke" | "tableLayout" | "textAlign" | "textOverflow" | "textShadow" | "textTransform" | "textUnderlineOffset" | "top" | "touchAction" | "transform" | "transformOrigin" | "userSelect" | "verticalAlign" | "visibility" | "whiteSpace" | "width" | "willChange" | "wordBreak" | "wordWrap" | "all" | "animation" | "background" | "backgroundPosition" | "border" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderStyle" | "borderTop" | "borderWidth" | "flex" | "flexFlow" | "font" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "gridTemplate" | "inset" | "listStyle" | "margin" | "outline" | "overflow" | "overscrollBehavior" | "padding" | "paddingBlock" | "paddingInline" | "placeContent" | "placeItems" | "placeSelf" | "textDecoration" | "textWrap" | "transition" | "clip" | "WebkitLineClamp" | "bg" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "p" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "size" | "gridColumnGap" | "gridGap" | "gridRowGap" | "WebkitBoxOrient" | "borderX" | "borderY" | "as"> & {
20
+ as?: import("react").ElementType;
21
+ sx?: import("..").BoxProps["sx"];
22
+ className?: string;
23
+ style?: import("react").CSSProperties;
24
+ children?: import("react").ReactNode;
25
+ } & {
26
+ /** The widest the column gets: one of Primer's sizes (`small` 544px, `medium` 768px, `large` 1012px, `xlarge` 1280px), pixels or CSS. `large` by default. */
27
+ maxWidth?: BoxStyleProps["maxWidth"];
28
+ /** The space kept on both sides: an index of the space scale or CSS. None by default. */
29
+ gutter?: BoxStyleProps["paddingInline"];
30
+ /** Also centre the children, each at its own width, and their text. */
31
+ intrinsic?: boolean;
32
+ } & import("react").RefAttributes<HTMLElement>>;
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /*
3
+ * Copyright (c) 2021-2026 Datalayer, Inc.
4
+ * Distributed under the terms of the Modified BSD License.
5
+ */
6
+ /**
7
+ * `Center`: a column no wider than a measure, in the middle of what holds
8
+ * it. The gutter is kept outside the measure (`content-box`), so the column
9
+ * is as wide as asked on a wide screen and never touches the edge of a
10
+ * narrow one.
11
+ */
12
+ import { forwardRef } from 'react';
13
+ import { Box } from '../box/Box';
14
+ export const Center = forwardRef(function Center({ maxWidth = 'large', gutter, intrinsic, ...rest }, ref) {
15
+ return (_jsx(Box, { ref: ref, boxSizing: "content-box", maxWidth: maxWidth, mx: "auto", paddingInline: gutter, ...(intrinsic ? { display: 'flex', flexDirection: 'column', alignItems: 'center', textAlign: 'center' } : {}), ...rest }));
16
+ });
@@ -0,0 +1,32 @@
1
+ import { type BoxStyleProps } from '../box/Box';
2
+ import type { LayoutBoxProps, LayoutGap } from './layoutProps';
3
+ export type ClusterProps = LayoutBoxProps<'gap'> & {
4
+ /** The space between two items, along a line and between lines: `2` (8px) by default. */
5
+ gap?: LayoutGap;
6
+ /** Across the line: `align-items`. `center` by default. */
7
+ align?: BoxStyleProps['alignItems'];
8
+ /** Along the line: `justify-content`. `flex-start` by default. */
9
+ justify?: BoxStyleProps['justifyContent'];
10
+ };
11
+ export declare const Cluster: import("react").ForwardRefExoticComponent<Omit<BoxStyleProps, "gap"> & {
12
+ hover?: BoxStyleProps | undefined;
13
+ focus?: BoxStyleProps | undefined;
14
+ focusVisible?: BoxStyleProps | undefined;
15
+ focusWithin?: BoxStyleProps | undefined;
16
+ active?: BoxStyleProps | undefined;
17
+ } & {
18
+ reducedMotion?: BoxStyleProps;
19
+ } & Omit<import("react").HTMLAttributes<HTMLElement>, "boxShadow" | "fontWeight" | "zIndex" | "alignContent" | "alignItems" | "alignSelf" | "animationDelay" | "appearance" | "aspectRatio" | "backdropFilter" | "backgroundColor" | "backgroundImage" | "backgroundRepeat" | "backgroundSize" | "borderBottomColor" | "borderBottomLeftRadius" | "borderBottomRightRadius" | "borderBottomStyle" | "borderBottomWidth" | "borderCollapse" | "borderLeftColor" | "borderLeftStyle" | "borderLeftWidth" | "borderRightColor" | "borderRightStyle" | "borderRightWidth" | "borderSpacing" | "borderTopColor" | "borderTopLeftRadius" | "borderTopRightRadius" | "borderTopStyle" | "borderTopWidth" | "bottom" | "boxSizing" | "clipPath" | "color" | "columnGap" | "cursor" | "display" | "fill" | "filter" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "float" | "fontFamily" | "fontSize" | "fontStyle" | "fontVariantNumeric" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridColumnEnd" | "gridColumnStart" | "gridRowEnd" | "gridRowStart" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "isolation" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lineHeight" | "listStylePosition" | "listStyleType" | "marginBottom" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "mixBlendMode" | "objectFit" | "objectPosition" | "opacity" | "order" | "outlineColor" | "outlineOffset" | "overflowWrap" | "overflowX" | "overflowY" | "overscrollBehaviorY" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingTop" | "pointerEvents" | "position" | "resize" | "right" | "rowGap" | "scrollMarginTop" | "scrollbarGutter" | "scrollbarWidth" | "stroke" | "tableLayout" | "textAlign" | "textOverflow" | "textShadow" | "textTransform" | "textUnderlineOffset" | "top" | "touchAction" | "transform" | "transformOrigin" | "userSelect" | "verticalAlign" | "visibility" | "whiteSpace" | "width" | "willChange" | "wordBreak" | "wordWrap" | "all" | "animation" | "background" | "backgroundPosition" | "border" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderStyle" | "borderTop" | "borderWidth" | "flex" | "flexFlow" | "font" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "gridTemplate" | "inset" | "listStyle" | "margin" | "outline" | "overflow" | "overscrollBehavior" | "padding" | "paddingBlock" | "paddingInline" | "placeContent" | "placeItems" | "placeSelf" | "textDecoration" | "textWrap" | "transition" | "clip" | "WebkitLineClamp" | "bg" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "p" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "size" | "gridColumnGap" | "gridGap" | "gridRowGap" | "WebkitBoxOrient" | "borderX" | "borderY" | "as"> & {
20
+ as?: import("react").ElementType;
21
+ sx?: import("..").BoxProps["sx"];
22
+ className?: string;
23
+ style?: import("react").CSSProperties;
24
+ children?: import("react").ReactNode;
25
+ } & {
26
+ /** The space between two items, along a line and between lines: `2` (8px) by default. */
27
+ gap?: LayoutGap;
28
+ /** Across the line: `align-items`. `center` by default. */
29
+ align?: BoxStyleProps["alignItems"];
30
+ /** Along the line: `justify-content`. `flex-start` by default. */
31
+ justify?: BoxStyleProps["justifyContent"];
32
+ } & import("react").RefAttributes<HTMLElement>>;
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /*
3
+ * Copyright (c) 2021-2026 Datalayer, Inc.
4
+ * Distributed under the terms of the Modified BSD License.
5
+ */
6
+ /**
7
+ * `Cluster`: items of their own width on a line that wraps — tags, buttons,
8
+ * a card's metadata — with the same gap along the line and between lines.
9
+ */
10
+ import { forwardRef } from 'react';
11
+ import { Box } from '../box/Box';
12
+ export const Cluster = forwardRef(function Cluster({ gap = 2, align = 'center', justify = 'flex-start', ...rest }, ref) {
13
+ return _jsx(Box, { ref: ref, display: "flex", flexWrap: "wrap", gap: gap, alignItems: align, justifyContent: justify, ...rest });
14
+ });
@@ -0,0 +1,40 @@
1
+ import { type BoxResponsive } from '../box/Box';
2
+ import { type LayoutBoxProps, type LayoutGap, type LayoutLength } from './layoutProps';
3
+ export type GridProps = LayoutBoxProps<'gap'> & {
4
+ /** A fixed number of columns, one or one per breakpoint. Wins over `minColumnWidth`. */
5
+ columns?: BoxResponsive<number>;
6
+ /** As many columns as fit, each at least this wide: 240px by default. */
7
+ minColumnWidth?: LayoutLength;
8
+ /** With `minColumnWidth`: `fill` (the default) keeps the empty columns of a short last row, `fit` lets the items share the whole row. */
9
+ auto?: 'fill' | 'fit';
10
+ /** The space between two cells: `3` (16px) by default. `rowGap` and `columnGap` set one of the two. */
11
+ gap?: LayoutGap;
12
+ };
13
+ /** `grid-template-columns` for as many columns as fit. */
14
+ export declare const gridAutoColumns: (minColumnWidth: LayoutLength, auto?: "fill" | "fit") => string;
15
+ /** `grid-template-columns` for a number of equal columns. */
16
+ export declare const gridFixedColumns: (columns: number) => string;
17
+ export declare const Grid: import("react").ForwardRefExoticComponent<Omit<import("..").BoxStyleProps, "gap"> & {
18
+ hover?: import("..").BoxStyleProps | undefined;
19
+ focus?: import("..").BoxStyleProps | undefined;
20
+ focusVisible?: import("..").BoxStyleProps | undefined;
21
+ focusWithin?: import("..").BoxStyleProps | undefined;
22
+ active?: import("..").BoxStyleProps | undefined;
23
+ } & {
24
+ reducedMotion?: import("..").BoxStyleProps;
25
+ } & Omit<import("react").HTMLAttributes<HTMLElement>, "boxShadow" | "fontWeight" | "zIndex" | "alignContent" | "alignItems" | "alignSelf" | "animationDelay" | "appearance" | "aspectRatio" | "backdropFilter" | "backgroundColor" | "backgroundImage" | "backgroundRepeat" | "backgroundSize" | "borderBottomColor" | "borderBottomLeftRadius" | "borderBottomRightRadius" | "borderBottomStyle" | "borderBottomWidth" | "borderCollapse" | "borderLeftColor" | "borderLeftStyle" | "borderLeftWidth" | "borderRightColor" | "borderRightStyle" | "borderRightWidth" | "borderSpacing" | "borderTopColor" | "borderTopLeftRadius" | "borderTopRightRadius" | "borderTopStyle" | "borderTopWidth" | "bottom" | "boxSizing" | "clipPath" | "color" | "columnGap" | "cursor" | "display" | "fill" | "filter" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "float" | "fontFamily" | "fontSize" | "fontStyle" | "fontVariantNumeric" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridColumnEnd" | "gridColumnStart" | "gridRowEnd" | "gridRowStart" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "isolation" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lineHeight" | "listStylePosition" | "listStyleType" | "marginBottom" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "mixBlendMode" | "objectFit" | "objectPosition" | "opacity" | "order" | "outlineColor" | "outlineOffset" | "overflowWrap" | "overflowX" | "overflowY" | "overscrollBehaviorY" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingTop" | "pointerEvents" | "position" | "resize" | "right" | "rowGap" | "scrollMarginTop" | "scrollbarGutter" | "scrollbarWidth" | "stroke" | "tableLayout" | "textAlign" | "textOverflow" | "textShadow" | "textTransform" | "textUnderlineOffset" | "top" | "touchAction" | "transform" | "transformOrigin" | "userSelect" | "verticalAlign" | "visibility" | "whiteSpace" | "width" | "willChange" | "wordBreak" | "wordWrap" | "all" | "animation" | "background" | "backgroundPosition" | "border" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderStyle" | "borderTop" | "borderWidth" | "flex" | "flexFlow" | "font" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "gridTemplate" | "inset" | "listStyle" | "margin" | "outline" | "overflow" | "overscrollBehavior" | "padding" | "paddingBlock" | "paddingInline" | "placeContent" | "placeItems" | "placeSelf" | "textDecoration" | "textWrap" | "transition" | "clip" | "WebkitLineClamp" | "bg" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "p" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "size" | "gridColumnGap" | "gridGap" | "gridRowGap" | "WebkitBoxOrient" | "borderX" | "borderY" | "as"> & {
26
+ as?: import("react").ElementType;
27
+ sx?: import("..").BoxProps["sx"];
28
+ className?: string;
29
+ style?: import("react").CSSProperties;
30
+ children?: import("react").ReactNode;
31
+ } & {
32
+ /** A fixed number of columns, one or one per breakpoint. Wins over `minColumnWidth`. */
33
+ columns?: BoxResponsive<number>;
34
+ /** As many columns as fit, each at least this wide: 240px by default. */
35
+ minColumnWidth?: LayoutLength;
36
+ /** With `minColumnWidth`: `fill` (the default) keeps the empty columns of a short last row, `fit` lets the items share the whole row. */
37
+ auto?: "fill" | "fit";
38
+ /** The space between two cells: `3` (16px) by default. `rowGap` and `columnGap` set one of the two. */
39
+ gap?: LayoutGap;
40
+ } & import("react").RefAttributes<HTMLElement>>;
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /*
3
+ * Copyright (c) 2021-2026 Datalayer, Inc.
4
+ * Distributed under the terms of the Modified BSD License.
5
+ */
6
+ /**
7
+ * `Grid`: equal columns. Either a number of them (one or one per
8
+ * breakpoint), or as many as fit with each at least `minColumnWidth` wide —
9
+ * which follows the width of what holds the grid, not the screen's, and
10
+ * needs no breakpoint. A column never overflows: its minimum is the lesser
11
+ * of `minColumnWidth` and the whole width, and a fixed column is
12
+ * `minmax(0, 1fr)`, so a long word shrinks its cell and not the page.
13
+ */
14
+ import { forwardRef } from 'react';
15
+ import { Box } from '../box/Box';
16
+ import { cssLength, mapResponsive } from './layoutProps';
17
+ /** `grid-template-columns` for as many columns as fit. */
18
+ export const gridAutoColumns = (minColumnWidth, auto = 'fill') => `repeat(auto-${auto}, minmax(min(${cssLength(minColumnWidth)}, 100%), 1fr))`;
19
+ /** `grid-template-columns` for a number of equal columns. */
20
+ export const gridFixedColumns = (columns) => `repeat(${Math.max(1, Math.floor(columns))}, minmax(0, 1fr))`;
21
+ export const Grid = forwardRef(function Grid({ columns, minColumnWidth = 240, auto = 'fill', gap = 3, ...rest }, ref) {
22
+ const template = columns === undefined || columns === null || columns === false
23
+ ? gridAutoColumns(minColumnWidth, auto)
24
+ : mapResponsive(columns, gridFixedColumns);
25
+ return _jsx(Box, { ref: ref, display: "grid", gridTemplateColumns: template, gap: gap, ...rest });
26
+ });
@@ -0,0 +1,76 @@
1
+ /**
2
+ * `HolyGrail`: a header, a footer, and between them the content with a
3
+ * side on its left, its right or both. The content takes the height the
4
+ * others leave, so the footer is at the bottom of a short page. When what
5
+ * holds it is narrower than `collapseBelow` (a container query: the
6
+ * holder's width, not the screen's) everything is one column — header, left,
7
+ * content, right, footer — which is also the order in the page, so the
8
+ * keyboard and a screen reader meet them in that order at any width.
9
+ */
10
+ import { type ElementType, type ReactNode } from 'react';
11
+ import { type LayoutBoxProps, type LayoutGap, type LayoutLength } from './layoutProps';
12
+ export type HolyGrailProps = LayoutBoxProps<'gap' | 'left' | 'right'> & {
13
+ header?: ReactNode;
14
+ footer?: ReactNode;
15
+ /** The side before the content. */
16
+ left?: ReactNode;
17
+ /** The side after the content. */
18
+ right?: ReactNode;
19
+ /** The left side's width beside the content: 240px by default. */
20
+ leftWidth?: LayoutLength;
21
+ /** The right side's width beside the content: 240px by default. */
22
+ rightWidth?: LayoutLength;
23
+ /** The holder's width under which everything is one column: 768px by default. */
24
+ collapseBelow?: LayoutLength;
25
+ /** The space between two areas: `3` (16px) by default. */
26
+ gap?: LayoutGap;
27
+ /** Render the areas as `header`, `aside`, `main` and `footer` rather than `div`s: for the layout of a whole page. */
28
+ landmarks?: boolean;
29
+ };
30
+ /** The grid of the wide layout: its columns and its areas, for the sides that are given. */
31
+ export declare function holyGrailTemplate(parts: {
32
+ header: boolean;
33
+ footer: boolean;
34
+ left: boolean;
35
+ right: boolean;
36
+ leftWidth: LayoutLength;
37
+ rightWidth: LayoutLength;
38
+ }): {
39
+ columns: string;
40
+ areas: string;
41
+ rows: string;
42
+ stackedAreas: string;
43
+ stackedRows: string;
44
+ };
45
+ export declare const HolyGrail: import("react").ForwardRefExoticComponent<Omit<import("..").BoxStyleProps, "left" | "right" | "gap"> & {
46
+ hover?: import("..").BoxStyleProps | undefined;
47
+ focus?: import("..").BoxStyleProps | undefined;
48
+ focusVisible?: import("..").BoxStyleProps | undefined;
49
+ focusWithin?: import("..").BoxStyleProps | undefined;
50
+ active?: import("..").BoxStyleProps | undefined;
51
+ } & {
52
+ reducedMotion?: import("..").BoxStyleProps;
53
+ } & Omit<import("react").HTMLAttributes<HTMLElement>, "boxShadow" | "fontWeight" | "zIndex" | "alignContent" | "alignItems" | "alignSelf" | "animationDelay" | "appearance" | "aspectRatio" | "backdropFilter" | "backgroundColor" | "backgroundImage" | "backgroundRepeat" | "backgroundSize" | "borderBottomColor" | "borderBottomLeftRadius" | "borderBottomRightRadius" | "borderBottomStyle" | "borderBottomWidth" | "borderCollapse" | "borderLeftColor" | "borderLeftStyle" | "borderLeftWidth" | "borderRightColor" | "borderRightStyle" | "borderRightWidth" | "borderSpacing" | "borderTopColor" | "borderTopLeftRadius" | "borderTopRightRadius" | "borderTopStyle" | "borderTopWidth" | "bottom" | "boxSizing" | "clipPath" | "color" | "columnGap" | "cursor" | "display" | "fill" | "filter" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "float" | "fontFamily" | "fontSize" | "fontStyle" | "fontVariantNumeric" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridColumnEnd" | "gridColumnStart" | "gridRowEnd" | "gridRowStart" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "isolation" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lineHeight" | "listStylePosition" | "listStyleType" | "marginBottom" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "mixBlendMode" | "objectFit" | "objectPosition" | "opacity" | "order" | "outlineColor" | "outlineOffset" | "overflowWrap" | "overflowX" | "overflowY" | "overscrollBehaviorY" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingTop" | "pointerEvents" | "position" | "resize" | "right" | "rowGap" | "scrollMarginTop" | "scrollbarGutter" | "scrollbarWidth" | "stroke" | "tableLayout" | "textAlign" | "textOverflow" | "textShadow" | "textTransform" | "textUnderlineOffset" | "top" | "touchAction" | "transform" | "transformOrigin" | "userSelect" | "verticalAlign" | "visibility" | "whiteSpace" | "width" | "willChange" | "wordBreak" | "wordWrap" | "all" | "animation" | "background" | "backgroundPosition" | "border" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderStyle" | "borderTop" | "borderWidth" | "flex" | "flexFlow" | "font" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "gridTemplate" | "inset" | "listStyle" | "margin" | "outline" | "overflow" | "overscrollBehavior" | "padding" | "paddingBlock" | "paddingInline" | "placeContent" | "placeItems" | "placeSelf" | "textDecoration" | "textWrap" | "transition" | "clip" | "WebkitLineClamp" | "bg" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "p" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "size" | "gridColumnGap" | "gridGap" | "gridRowGap" | "WebkitBoxOrient" | "borderX" | "borderY" | "as"> & {
54
+ as?: ElementType;
55
+ sx?: import("..").BoxProps["sx"];
56
+ className?: string;
57
+ style?: import("react").CSSProperties;
58
+ children?: ReactNode;
59
+ } & {
60
+ header?: ReactNode;
61
+ footer?: ReactNode;
62
+ /** The side before the content. */
63
+ left?: ReactNode;
64
+ /** The side after the content. */
65
+ right?: ReactNode;
66
+ /** The left side's width beside the content: 240px by default. */
67
+ leftWidth?: LayoutLength;
68
+ /** The right side's width beside the content: 240px by default. */
69
+ rightWidth?: LayoutLength;
70
+ /** The holder's width under which everything is one column: 768px by default. */
71
+ collapseBelow?: LayoutLength;
72
+ /** The space between two areas: `3` (16px) by default. */
73
+ gap?: LayoutGap;
74
+ /** Render the areas as `header`, `aside`, `main` and `footer` rather than `div`s: for the layout of a whole page. */
75
+ landmarks?: boolean;
76
+ } & import("react").RefAttributes<HTMLElement>>;
@@ -0,0 +1,51 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /*
3
+ * Copyright (c) 2021-2026 Datalayer, Inc.
4
+ * Distributed under the terms of the Modified BSD License.
5
+ */
6
+ /**
7
+ * `HolyGrail`: a header, a footer, and between them the content with a
8
+ * side on its left, its right or both. The content takes the height the
9
+ * others leave, so the footer is at the bottom of a short page. When what
10
+ * holds it is narrower than `collapseBelow` (a container query: the
11
+ * holder's width, not the screen's) everything is one column — header, left,
12
+ * content, right, footer — which is also the order in the page, so the
13
+ * keyboard and a screen reader meet them in that order at any width.
14
+ */
15
+ import { forwardRef } from 'react';
16
+ import { Box } from '../box/Box';
17
+ import { cssLength } from './layoutProps';
18
+ /** The grid of the wide layout: its columns and its areas, for the sides that are given. */
19
+ export function holyGrailTemplate(parts) {
20
+ const middle = [parts.left && 'left', 'main', parts.right && 'right'].filter(Boolean);
21
+ const across = (name) => `"${middle.map(() => name).join(' ')}"`;
22
+ const columns = [parts.left && cssLength(parts.leftWidth), 'minmax(0, 1fr)', parts.right && cssLength(parts.rightWidth)]
23
+ .filter(Boolean)
24
+ .join(' ');
25
+ const areas = [parts.header && across('header'), `"${middle.join(' ')}"`, parts.footer && across('footer')].filter(Boolean).join(' ');
26
+ const rows = [parts.header && 'auto', '1fr', parts.footer && 'auto'].filter(Boolean).join(' ');
27
+ const stacked = [parts.header && 'header', ...middle, parts.footer && 'footer'].filter(Boolean);
28
+ return {
29
+ columns,
30
+ areas,
31
+ rows,
32
+ stackedAreas: stacked.map(name => `"${name}"`).join(' '),
33
+ stackedRows: stacked.map(name => (name === 'main' ? '1fr' : 'auto')).join(' '),
34
+ };
35
+ }
36
+ export const HolyGrail = forwardRef(function HolyGrail({ header, footer, left, right, leftWidth = 240, rightWidth = 240, collapseBelow = 768, gap = 3, landmarks, children, ...rest }, ref) {
37
+ const has = (node) => node !== undefined && node !== null && node !== false;
38
+ const template = holyGrailTemplate({ header: has(header), footer: has(footer), left: has(left), right: has(right), leftWidth, rightWidth });
39
+ const area = (name, element, node) => (_jsx(Box, { as: landmarks ? element : 'div', "data-layout-part": name, gridArea: name, minWidth: 0, children: node }));
40
+ return (
41
+ // The holder the query reads; the grid is inside it, since an element cannot query itself.
42
+ _jsx(Box, { ref: ref, display: "flex", flexDirection: "column", ...rest, sx: { containerType: 'inline-size', ...rest.sx }, children: _jsxs(Box, { display: "grid", flexGrow: 1, gap: gap, gridTemplateColumns: "minmax(0, 1fr)", sx: {
43
+ gridTemplateAreas: template.stackedAreas,
44
+ gridTemplateRows: template.stackedRows,
45
+ [`@container (min-width: ${cssLength(collapseBelow)})`]: {
46
+ gridTemplateColumns: template.columns,
47
+ gridTemplateAreas: template.areas,
48
+ gridTemplateRows: template.rows,
49
+ },
50
+ }, children: [has(header) && area('header', 'header', header), has(left) && area('left', 'aside', left), area('main', 'main', children), has(right) && area('right', 'aside', right), has(footer) && area('footer', 'footer', footer)] }) }));
51
+ });
@@ -0,0 +1,92 @@
1
+ /**
2
+ * `Masonry`: columns of items of unequal heights, packed — each item at the
3
+ * top of the shortest column, so no row waits for its tallest card.
4
+ *
5
+ * ```tsx
6
+ * <Masonry minColumnWidth={280} gap={3}>
7
+ * {specs.map(spec => <Card key={spec.id} border>…</Card>)}
8
+ * </Masonry>
9
+ * ```
10
+ *
11
+ * - **Columns** — as many as fit with each at least `minColumnWidth` wide
12
+ * (the width of what holds the masonry, not the screen's; `maxColumns`
13
+ * caps them), or `columns`: a number, or one per breakpoint.
14
+ * - **Order** — items go in their order, each to the shortest column (the
15
+ * leftmost of those that are level). An item is never above the one
16
+ * before it, so the order reads down the page and left to right; the
17
+ * elements stay in that order, so Tab and a screen reader follow what is
18
+ * seen. (CSS columns would read down the first column, then the second.)
19
+ * - **Any item** — a child is an item: a `Card`, anything. It gets the
20
+ * column's width and keeps its own height. `Masonry.Item span="full"`
21
+ * takes the whole width (a heading between groups, an empty state).
22
+ * - **First paint** — before anything is measured (the server's HTML, a
23
+ * browser with no `ResizeObserver`, a masonry that is hidden) the items
24
+ * are a CSS grid of the same columns, each at its own height: the same
25
+ * items in the same order, rows not yet packed. In a browser the packing
26
+ * is done before the first paint.
27
+ * - **Later changes** — a picture that loads, a card that opens, a new
28
+ * width: one `ResizeObserver` sees them and one layout per frame moves
29
+ * only the items that move; see `masonryEngine.ts` for how.
30
+ *
31
+ * Every other prop is `Box`'s. The masonry is what its items are placed in:
32
+ * pad a parent rather than the masonry itself, and leave `display`,
33
+ * `position` and `height` to it.
34
+ */
35
+ import { type ReactNode } from 'react';
36
+ import type { LayoutBoxProps } from './layoutProps';
37
+ import { type MasonryEngineOptions, type MasonryLayoutInfo } from './masonryEngine';
38
+ import { type MasonryResponsive } from './masonryLayout';
39
+ export type MasonryProps = LayoutBoxProps<'gap' | 'display' | 'position' | 'height'> & {
40
+ /** A fixed number of columns, one or one per breakpoint (`[1, null, 2, 3]`). Wins over `minColumnWidth`. */
41
+ columns?: MasonryResponsive<number>;
42
+ /** As many columns as fit, each at least this wide, in pixels: 260 by default. */
43
+ minColumnWidth?: number;
44
+ /** With `minColumnWidth`: never more columns than this. */
45
+ maxColumns?: number;
46
+ /** The space between two items, across and down: an index of Primer's space scale (`3`, 16px, by default) or pixels. */
47
+ gap?: number;
48
+ /** Called after a layout that moved something, with what it came to and the time it took. */
49
+ onLayout?: (layout: MasonryLayoutInfo) => void;
50
+ };
51
+ export interface MasonryItemProps {
52
+ /** `full`: the item takes the whole width, under everything before it. */
53
+ span?: 'full';
54
+ children?: ReactNode;
55
+ }
56
+ /** An item with something to say about its place; any other child is an item as it is. */
57
+ declare function MasonryItem({ children }: MasonryItemProps): import("react").JSX.Element;
58
+ declare namespace MasonryItem {
59
+ var displayName: string;
60
+ }
61
+ /** The grid of the first paint: the same columns, from CSS alone. */
62
+ export declare function masonryFallbackColumns(options: Pick<MasonryEngineOptions, 'columns' | 'minColumnWidth' | 'maxColumns' | 'gap'>): string | Array<string | null>;
63
+ /** Columns of items of unequal heights, packed; see above. */
64
+ export declare const Masonry: import("react").ForwardRefExoticComponent<Omit<import("..").BoxStyleProps, "display" | "height" | "position" | "gap"> & {
65
+ hover?: import("..").BoxStyleProps | undefined;
66
+ focus?: import("..").BoxStyleProps | undefined;
67
+ focusVisible?: import("..").BoxStyleProps | undefined;
68
+ focusWithin?: import("..").BoxStyleProps | undefined;
69
+ active?: import("..").BoxStyleProps | undefined;
70
+ } & {
71
+ reducedMotion?: import("..").BoxStyleProps;
72
+ } & Omit<import("react").HTMLAttributes<HTMLElement>, "boxShadow" | "fontWeight" | "zIndex" | "alignContent" | "alignItems" | "alignSelf" | "animationDelay" | "appearance" | "aspectRatio" | "backdropFilter" | "backgroundColor" | "backgroundImage" | "backgroundRepeat" | "backgroundSize" | "borderBottomColor" | "borderBottomLeftRadius" | "borderBottomRightRadius" | "borderBottomStyle" | "borderBottomWidth" | "borderCollapse" | "borderLeftColor" | "borderLeftStyle" | "borderLeftWidth" | "borderRightColor" | "borderRightStyle" | "borderRightWidth" | "borderSpacing" | "borderTopColor" | "borderTopLeftRadius" | "borderTopRightRadius" | "borderTopStyle" | "borderTopWidth" | "bottom" | "boxSizing" | "clipPath" | "color" | "columnGap" | "cursor" | "display" | "fill" | "filter" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "float" | "fontFamily" | "fontSize" | "fontStyle" | "fontVariantNumeric" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridColumnEnd" | "gridColumnStart" | "gridRowEnd" | "gridRowStart" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "isolation" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lineHeight" | "listStylePosition" | "listStyleType" | "marginBottom" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "mixBlendMode" | "objectFit" | "objectPosition" | "opacity" | "order" | "outlineColor" | "outlineOffset" | "overflowWrap" | "overflowX" | "overflowY" | "overscrollBehaviorY" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingTop" | "pointerEvents" | "position" | "resize" | "right" | "rowGap" | "scrollMarginTop" | "scrollbarGutter" | "scrollbarWidth" | "stroke" | "tableLayout" | "textAlign" | "textOverflow" | "textShadow" | "textTransform" | "textUnderlineOffset" | "top" | "touchAction" | "transform" | "transformOrigin" | "userSelect" | "verticalAlign" | "visibility" | "whiteSpace" | "width" | "willChange" | "wordBreak" | "wordWrap" | "all" | "animation" | "background" | "backgroundPosition" | "border" | "borderBottom" | "borderColor" | "borderLeft" | "borderRadius" | "borderRight" | "borderStyle" | "borderTop" | "borderWidth" | "flex" | "flexFlow" | "font" | "gap" | "gridArea" | "gridColumn" | "gridRow" | "gridTemplate" | "inset" | "listStyle" | "margin" | "outline" | "overflow" | "overscrollBehavior" | "padding" | "paddingBlock" | "paddingInline" | "placeContent" | "placeItems" | "placeSelf" | "textDecoration" | "textWrap" | "transition" | "clip" | "WebkitLineClamp" | "bg" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "p" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "size" | "gridColumnGap" | "gridGap" | "gridRowGap" | "WebkitBoxOrient" | "borderX" | "borderY" | "as"> & {
73
+ as?: import("react").ElementType;
74
+ sx?: import("..").BoxProps["sx"];
75
+ className?: string;
76
+ style?: import("react").CSSProperties;
77
+ children?: ReactNode;
78
+ } & {
79
+ /** A fixed number of columns, one or one per breakpoint (`[1, null, 2, 3]`). Wins over `minColumnWidth`. */
80
+ columns?: MasonryResponsive<number>;
81
+ /** As many columns as fit, each at least this wide, in pixels: 260 by default. */
82
+ minColumnWidth?: number;
83
+ /** With `minColumnWidth`: never more columns than this. */
84
+ maxColumns?: number;
85
+ /** The space between two items, across and down: an index of Primer's space scale (`3`, 16px, by default) or pixels. */
86
+ gap?: number;
87
+ /** Called after a layout that moved something, with what it came to and the time it took. */
88
+ onLayout?: (layout: MasonryLayoutInfo) => void;
89
+ } & import("react").RefAttributes<HTMLElement>> & {
90
+ Item: typeof MasonryItem;
91
+ };
92
+ export {};
@@ -0,0 +1,109 @@
1
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ /*
3
+ * Copyright (c) 2021-2026 Datalayer, Inc.
4
+ * Distributed under the terms of the Modified BSD License.
5
+ */
6
+ /**
7
+ * `Masonry`: columns of items of unequal heights, packed — each item at the
8
+ * top of the shortest column, so no row waits for its tallest card.
9
+ *
10
+ * ```tsx
11
+ * <Masonry minColumnWidth={280} gap={3}>
12
+ * {specs.map(spec => <Card key={spec.id} border>…</Card>)}
13
+ * </Masonry>
14
+ * ```
15
+ *
16
+ * - **Columns** — as many as fit with each at least `minColumnWidth` wide
17
+ * (the width of what holds the masonry, not the screen's; `maxColumns`
18
+ * caps them), or `columns`: a number, or one per breakpoint.
19
+ * - **Order** — items go in their order, each to the shortest column (the
20
+ * leftmost of those that are level). An item is never above the one
21
+ * before it, so the order reads down the page and left to right; the
22
+ * elements stay in that order, so Tab and a screen reader follow what is
23
+ * seen. (CSS columns would read down the first column, then the second.)
24
+ * - **Any item** — a child is an item: a `Card`, anything. It gets the
25
+ * column's width and keeps its own height. `Masonry.Item span="full"`
26
+ * takes the whole width (a heading between groups, an empty state).
27
+ * - **First paint** — before anything is measured (the server's HTML, a
28
+ * browser with no `ResizeObserver`, a masonry that is hidden) the items
29
+ * are a CSS grid of the same columns, each at its own height: the same
30
+ * items in the same order, rows not yet packed. In a browser the packing
31
+ * is done before the first paint.
32
+ * - **Later changes** — a picture that loads, a card that opens, a new
33
+ * width: one `ResizeObserver` sees them and one layout per frame moves
34
+ * only the items that move; see `masonryEngine.ts` for how.
35
+ *
36
+ * Every other prop is `Box`'s. The masonry is what its items are placed in:
37
+ * pad a parent rather than the masonry itself, and leave `display`,
38
+ * `position` and `height` to it.
39
+ */
40
+ import { Children, forwardRef, isValidElement, useCallback, useEffect, useLayoutEffect, useRef } from 'react';
41
+ import { Box } from '../box/Box';
42
+ import { MASONRY_ITEM_ATTRIBUTE, MASONRY_SPAN_ATTRIBUTE, MasonryEngine } from './masonryEngine';
43
+ import { masonryGapPx } from './masonryLayout';
44
+ /** An item with something to say about its place; any other child is an item as it is. */
45
+ function MasonryItem({ children }) {
46
+ return _jsx(_Fragment, { children: children });
47
+ }
48
+ MasonryItem.displayName = 'Masonry.Item';
49
+ const useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
50
+ /** The grid of the first paint: the same columns, from CSS alone. */
51
+ export function masonryFallbackColumns(options) {
52
+ const fixed = (count) => `repeat(${Math.max(1, Math.floor(count))}, minmax(0, 1fr))`;
53
+ const { columns, minColumnWidth = 260, maxColumns } = options;
54
+ if (Array.isArray(columns)) {
55
+ return columns.map(count => (count === null || count === undefined ? null : fixed(count)));
56
+ }
57
+ if (typeof columns === 'number') {
58
+ return fixed(columns);
59
+ }
60
+ const min = maxColumns && maxColumns > 0
61
+ ? // No narrower than the share of the most columns allowed: never one more than that.
62
+ `max(${minColumnWidth}px, calc((100% - ${(Math.floor(maxColumns) - 1) * masonryGapPx(options.gap)}px) / ${Math.floor(maxColumns)}))`
63
+ : `${minColumnWidth}px`;
64
+ return `repeat(auto-fill, minmax(min(${min}, 100%), 1fr))`;
65
+ }
66
+ const ITEM_SELECTOR = `& > [${MASONRY_ITEM_ATTRIBUTE}]`;
67
+ const MasonryRoot = forwardRef(function Masonry({ columns, minColumnWidth = 260, maxColumns, gap = 3, onLayout, children, sx, ...rest }, ref) {
68
+ const node = useRef(null);
69
+ const setNode = useCallback((value) => {
70
+ node.current = value;
71
+ if (typeof ref === 'function') {
72
+ ref(value);
73
+ }
74
+ else if (ref) {
75
+ ref.current = value;
76
+ }
77
+ }, [ref]);
78
+ // The engine reads the latest props at each layout.
79
+ const options = useRef({ columns, minColumnWidth, maxColumns, gap, onLayout });
80
+ options.current = { columns, minColumnWidth, maxColumns, gap, onLayout };
81
+ const engine = useRef(null);
82
+ useIsomorphicLayoutEffect(() => {
83
+ if (!node.current || typeof ResizeObserver === 'undefined') {
84
+ return undefined;
85
+ }
86
+ const created = new MasonryEngine(node.current, () => options.current);
87
+ engine.current = created;
88
+ return () => {
89
+ created.destroy();
90
+ engine.current = null;
91
+ };
92
+ }, []);
93
+ // After every render: the items or the props may have changed. Before the paint.
94
+ useIsomorphicLayoutEffect(() => {
95
+ engine.current?.sync();
96
+ });
97
+ return (_jsx(Box, { ref: setNode, "data-masonry": "", ...rest, position: "relative", display: "grid", alignItems: "start", gap: gap, gridTemplateColumns: masonryFallbackColumns({ columns, minColumnWidth, maxColumns, gap }), sx: {
98
+ // An item is a one-cell grid: whatever the child is (a link, a button), it takes the column's width.
99
+ [ITEM_SELECTOR]: { display: 'grid', gridTemplateColumns: 'minmax(0, 1fr)', minWidth: 0, boxSizing: 'border-box' },
100
+ [`& > [${MASONRY_SPAN_ATTRIBUTE}="full"]`]: { gridColumn: '1 / -1' },
101
+ ...sx,
102
+ }, children: Children.toArray(children).map((child, index) => {
103
+ const item = isValidElement(child) && child.type === MasonryItem ? child : undefined;
104
+ const key = isValidElement(child) && child.key !== null ? child.key : index;
105
+ return (_jsx("div", { [MASONRY_ITEM_ATTRIBUTE]: '', ...(item?.props.span === 'full' ? { [MASONRY_SPAN_ATTRIBUTE]: 'full' } : {}), children: item ? item.props.children : child }, key));
106
+ }) }));
107
+ });
108
+ /** Columns of items of unequal heights, packed; see above. */
109
+ export const Masonry = Object.assign(MasonryRoot, { Item: MasonryItem });