@datalayer/primer-addons 1.0.58 → 1.0.60
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/README.md +33 -0
- package/lib/components/index.d.ts +1 -0
- package/lib/components/index.js +1 -0
- package/lib/components/layout/Center.d.ts +32 -0
- package/lib/components/layout/Center.js +16 -0
- package/lib/components/layout/Cluster.d.ts +32 -0
- package/lib/components/layout/Cluster.js +14 -0
- package/lib/components/layout/Grid.d.ts +40 -0
- package/lib/components/layout/Grid.js +26 -0
- package/lib/components/layout/HolyGrail.d.ts +76 -0
- package/lib/components/layout/HolyGrail.js +51 -0
- package/lib/components/layout/Masonry.d.ts +92 -0
- package/lib/components/layout/Masonry.js +109 -0
- package/lib/components/layout/Sidebar.d.ts +51 -0
- package/lib/components/layout/Sidebar.js +18 -0
- package/lib/components/layout/Split.d.ts +42 -0
- package/lib/components/layout/Split.js +23 -0
- package/lib/components/layout/Stack.d.ts +41 -0
- package/lib/components/layout/Stack.js +16 -0
- package/lib/components/layout/Switcher.d.ts +31 -0
- package/lib/components/layout/Switcher.js +22 -0
- package/lib/components/layout/index.d.ts +18 -0
- package/lib/components/layout/index.js +22 -0
- package/lib/components/layout/layoutProps.d.ts +27 -0
- package/lib/components/layout/layoutProps.js +13 -0
- package/lib/components/layout/masonryEngine.d.ts +85 -0
- package/lib/components/layout/masonryEngine.js +240 -0
- package/lib/components/layout/masonryLayout.d.ts +45 -0
- package/lib/components/layout/masonryLayout.js +113 -0
- package/package.json +1 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Sidebar`: a side of a set width beside the content, which takes the rest.
|
|
3
|
+
* When the content would get narrower than `contentMin`, the two stack, each
|
|
4
|
+
* the whole width — decided by the width of what holds them, with no
|
|
5
|
+
* breakpoint, so it is right in a page, a panel or a dialog alike.
|
|
6
|
+
*/
|
|
7
|
+
import { type ReactNode } from 'react';
|
|
8
|
+
import { type BoxStyleProps } from '../box/Box';
|
|
9
|
+
import { type LayoutBoxProps, type LayoutGap, type LayoutLength } from './layoutProps';
|
|
10
|
+
export type SidebarProps = LayoutBoxProps<'gap'> & {
|
|
11
|
+
/** What the side holds; the children are the content. */
|
|
12
|
+
aside: ReactNode;
|
|
13
|
+
/** Which side: `start` (the default, the left in a left-to-right page) or `end`. Stacked, a `start` side is above. */
|
|
14
|
+
side?: 'start' | 'end';
|
|
15
|
+
/** The side's width beside the content: 280px by default. */
|
|
16
|
+
sideWidth?: LayoutLength;
|
|
17
|
+
/** The narrowest the content gets before the two stack: `50%` by default. */
|
|
18
|
+
contentMin?: LayoutLength;
|
|
19
|
+
/** The space between the two: `3` (16px) by default. */
|
|
20
|
+
gap?: LayoutGap;
|
|
21
|
+
/** Across the row: `align-items`. `stretch` by default, so the two are the same height. */
|
|
22
|
+
align?: BoxStyleProps['alignItems'];
|
|
23
|
+
};
|
|
24
|
+
export declare const Sidebar: import("react").ForwardRefExoticComponent<Omit<BoxStyleProps, "gap"> & {
|
|
25
|
+
hover?: BoxStyleProps | undefined;
|
|
26
|
+
focus?: BoxStyleProps | undefined;
|
|
27
|
+
focusVisible?: BoxStyleProps | undefined;
|
|
28
|
+
focusWithin?: BoxStyleProps | undefined;
|
|
29
|
+
active?: BoxStyleProps | undefined;
|
|
30
|
+
} & {
|
|
31
|
+
reducedMotion?: BoxStyleProps;
|
|
32
|
+
} & 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"> & {
|
|
33
|
+
as?: import("react").ElementType;
|
|
34
|
+
sx?: import("..").BoxProps["sx"];
|
|
35
|
+
className?: string;
|
|
36
|
+
style?: import("react").CSSProperties;
|
|
37
|
+
children?: ReactNode;
|
|
38
|
+
} & {
|
|
39
|
+
/** What the side holds; the children are the content. */
|
|
40
|
+
aside: ReactNode;
|
|
41
|
+
/** Which side: `start` (the default, the left in a left-to-right page) or `end`. Stacked, a `start` side is above. */
|
|
42
|
+
side?: "start" | "end";
|
|
43
|
+
/** The side's width beside the content: 280px by default. */
|
|
44
|
+
sideWidth?: LayoutLength;
|
|
45
|
+
/** The narrowest the content gets before the two stack: `50%` by default. */
|
|
46
|
+
contentMin?: LayoutLength;
|
|
47
|
+
/** The space between the two: `3` (16px) by default. */
|
|
48
|
+
gap?: LayoutGap;
|
|
49
|
+
/** Across the row: `align-items`. `stretch` by default, so the two are the same height. */
|
|
50
|
+
align?: BoxStyleProps["alignItems"];
|
|
51
|
+
} & import("react").RefAttributes<HTMLElement>>;
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
* `Sidebar`: a side of a set width beside the content, which takes the rest.
|
|
8
|
+
* When the content would get narrower than `contentMin`, the two stack, each
|
|
9
|
+
* the whole width — decided by the width of what holds them, with no
|
|
10
|
+
* breakpoint, so it is right in a page, a panel or a dialog alike.
|
|
11
|
+
*/
|
|
12
|
+
import { forwardRef } from 'react';
|
|
13
|
+
import { Box } from '../box/Box';
|
|
14
|
+
import { cssLength } from './layoutProps';
|
|
15
|
+
export const Sidebar = forwardRef(function Sidebar({ aside, side = 'start', sideWidth = 280, contentMin = '50%', gap = 3, align, children, ...rest }, ref) {
|
|
16
|
+
const asideBox = (_jsx(Box, { "data-layout-part": "aside", flexGrow: 1, flexBasis: cssLength(sideWidth), minWidth: 0, children: aside }));
|
|
17
|
+
return (_jsxs(Box, { ref: ref, display: "flex", flexWrap: "wrap", gap: gap, alignItems: align, ...rest, children: [side === 'start' && asideBox, _jsx(Box, { "data-layout-part": "main", flexGrow: 999, flexBasis: 0, minWidth: `min(${cssLength(contentMin)}, 100%)`, children: children }), side === 'end' && asideBox] }));
|
|
18
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type BoxStyleProps } from '../box/Box';
|
|
2
|
+
import { type LayoutBoxProps, type LayoutGap, type LayoutLength } from './layoutProps';
|
|
3
|
+
export type SplitProps = LayoutBoxProps<'gap'> & {
|
|
4
|
+
/** How the panes share the width: `[1, 1]` by default, `[2, 1]` for two thirds and one. */
|
|
5
|
+
ratio?: readonly [number, number];
|
|
6
|
+
/** The holder's width under which the panes stack: 544px by default. */
|
|
7
|
+
collapseBelow?: LayoutLength;
|
|
8
|
+
/** The space between the panes: `3` (16px) by default. */
|
|
9
|
+
gap?: LayoutGap;
|
|
10
|
+
/** Across the row: `align-items`. `stretch` by default. */
|
|
11
|
+
align?: BoxStyleProps['alignItems'];
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* The basis that switches a row to a column: far below zero (so nothing)
|
|
15
|
+
* while the holder is wider than the threshold, far above its width (so a
|
|
16
|
+
* line each) once it is narrower.
|
|
17
|
+
*/
|
|
18
|
+
export declare const switchBasis: (threshold: LayoutLength) => string;
|
|
19
|
+
export declare const Split: import("react").ForwardRefExoticComponent<Omit<BoxStyleProps, "gap"> & {
|
|
20
|
+
hover?: BoxStyleProps | undefined;
|
|
21
|
+
focus?: BoxStyleProps | undefined;
|
|
22
|
+
focusVisible?: BoxStyleProps | undefined;
|
|
23
|
+
focusWithin?: BoxStyleProps | undefined;
|
|
24
|
+
active?: BoxStyleProps | undefined;
|
|
25
|
+
} & {
|
|
26
|
+
reducedMotion?: BoxStyleProps;
|
|
27
|
+
} & 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"> & {
|
|
28
|
+
as?: import("react").ElementType;
|
|
29
|
+
sx?: import("..").BoxProps["sx"];
|
|
30
|
+
className?: string;
|
|
31
|
+
style?: import("react").CSSProperties;
|
|
32
|
+
children?: import("react").ReactNode;
|
|
33
|
+
} & {
|
|
34
|
+
/** How the panes share the width: `[1, 1]` by default, `[2, 1]` for two thirds and one. */
|
|
35
|
+
ratio?: readonly [number, number];
|
|
36
|
+
/** The holder's width under which the panes stack: 544px by default. */
|
|
37
|
+
collapseBelow?: LayoutLength;
|
|
38
|
+
/** The space between the panes: `3` (16px) by default. */
|
|
39
|
+
gap?: LayoutGap;
|
|
40
|
+
/** Across the row: `align-items`. `stretch` by default. */
|
|
41
|
+
align?: BoxStyleProps["alignItems"];
|
|
42
|
+
} & import("react").RefAttributes<HTMLElement>>;
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
* `Split`: two panes side by side, sharing the width by a ratio, and one
|
|
8
|
+
* above the other when what holds them is narrower than `collapseBelow` —
|
|
9
|
+
* the holder's width, not the screen's, with no breakpoint.
|
|
10
|
+
*/
|
|
11
|
+
import { Children, forwardRef } from 'react';
|
|
12
|
+
import { Box } from '../box/Box';
|
|
13
|
+
import { cssLength } from './layoutProps';
|
|
14
|
+
/**
|
|
15
|
+
* The basis that switches a row to a column: far below zero (so nothing)
|
|
16
|
+
* while the holder is wider than the threshold, far above its width (so a
|
|
17
|
+
* line each) once it is narrower.
|
|
18
|
+
*/
|
|
19
|
+
export const switchBasis = (threshold) => `calc((${cssLength(threshold)} - 100%) * 999)`;
|
|
20
|
+
export const Split = forwardRef(function Split({ ratio = [1, 1], collapseBelow = 544, gap = 3, align, children, ...rest }, ref) {
|
|
21
|
+
const basis = switchBasis(collapseBelow);
|
|
22
|
+
return (_jsx(Box, { ref: ref, display: "flex", flexWrap: "wrap", gap: gap, alignItems: align, ...rest, children: Children.toArray(children).map((child, index) => (_jsx(Box, { "data-layout-part": "pane", flexGrow: ratio[index] ?? 1, flexBasis: basis, minWidth: 0, children: child }, index))) }));
|
|
23
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type BoxResponsive, type BoxStyleProps } from '../box/Box';
|
|
2
|
+
import { type LayoutBoxProps, type LayoutGap } from './layoutProps';
|
|
3
|
+
export type StackDirection = 'vertical' | 'horizontal';
|
|
4
|
+
export type StackProps = LayoutBoxProps<'gap'> & {
|
|
5
|
+
/** Down the page (`vertical`, the default) or along a line; one or one per breakpoint. */
|
|
6
|
+
direction?: BoxResponsive<StackDirection>;
|
|
7
|
+
/** The space between two children: `3` (16px) by default. */
|
|
8
|
+
gap?: LayoutGap;
|
|
9
|
+
/** Across the direction: `align-items`. `stretch` by default. */
|
|
10
|
+
align?: BoxStyleProps['alignItems'];
|
|
11
|
+
/** Along the direction: `justify-content`. */
|
|
12
|
+
justify?: BoxStyleProps['justifyContent'];
|
|
13
|
+
/** Whether a line that is full goes on to the next. */
|
|
14
|
+
wrap?: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare const Stack: import("react").ForwardRefExoticComponent<Omit<BoxStyleProps, "gap"> & {
|
|
17
|
+
hover?: BoxStyleProps | undefined;
|
|
18
|
+
focus?: BoxStyleProps | undefined;
|
|
19
|
+
focusVisible?: BoxStyleProps | undefined;
|
|
20
|
+
focusWithin?: BoxStyleProps | undefined;
|
|
21
|
+
active?: BoxStyleProps | undefined;
|
|
22
|
+
} & {
|
|
23
|
+
reducedMotion?: BoxStyleProps;
|
|
24
|
+
} & 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"> & {
|
|
25
|
+
as?: import("react").ElementType;
|
|
26
|
+
sx?: import("..").BoxProps["sx"];
|
|
27
|
+
className?: string;
|
|
28
|
+
style?: import("react").CSSProperties;
|
|
29
|
+
children?: import("react").ReactNode;
|
|
30
|
+
} & {
|
|
31
|
+
/** Down the page (`vertical`, the default) or along a line; one or one per breakpoint. */
|
|
32
|
+
direction?: BoxResponsive<StackDirection>;
|
|
33
|
+
/** The space between two children: `3` (16px) by default. */
|
|
34
|
+
gap?: LayoutGap;
|
|
35
|
+
/** Across the direction: `align-items`. `stretch` by default. */
|
|
36
|
+
align?: BoxStyleProps["alignItems"];
|
|
37
|
+
/** Along the direction: `justify-content`. */
|
|
38
|
+
justify?: BoxStyleProps["justifyContent"];
|
|
39
|
+
/** Whether a line that is full goes on to the next. */
|
|
40
|
+
wrap?: boolean;
|
|
41
|
+
} & 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
|
+
* `Stack`: children one after the other with one gap between them, down the
|
|
8
|
+
* page or along a line. The direction takes a value per breakpoint, so a
|
|
9
|
+
* stack can be a column on a phone and a row beside it.
|
|
10
|
+
*/
|
|
11
|
+
import { forwardRef } from 'react';
|
|
12
|
+
import { Box } from '../box/Box';
|
|
13
|
+
import { mapResponsive } from './layoutProps';
|
|
14
|
+
export const Stack = forwardRef(function Stack({ direction = 'vertical', gap = 3, align, justify, wrap, ...rest }, ref) {
|
|
15
|
+
return (_jsx(Box, { ref: ref, display: "flex", flexDirection: mapResponsive(direction, one => (one === 'horizontal' ? 'row' : 'column')), flexWrap: wrap ? 'wrap' : undefined, gap: gap, alignItems: align, justifyContent: justify, ...rest }));
|
|
16
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type LayoutBoxProps, type LayoutGap, type LayoutLength } from './layoutProps';
|
|
2
|
+
export type SwitcherProps = LayoutBoxProps<'gap'> & {
|
|
3
|
+
/** The holder's width under which the row becomes a column: 544px by default. */
|
|
4
|
+
threshold?: LayoutLength;
|
|
5
|
+
/** The most children a row takes; with more, they stack at any width. No limit by default. */
|
|
6
|
+
limit?: number;
|
|
7
|
+
/** The space between two children: `3` (16px) by default. */
|
|
8
|
+
gap?: LayoutGap;
|
|
9
|
+
};
|
|
10
|
+
export declare const Switcher: import("react").ForwardRefExoticComponent<Omit<import("..").BoxStyleProps, "gap"> & {
|
|
11
|
+
hover?: import("..").BoxStyleProps | undefined;
|
|
12
|
+
focus?: import("..").BoxStyleProps | undefined;
|
|
13
|
+
focusVisible?: import("..").BoxStyleProps | undefined;
|
|
14
|
+
focusWithin?: import("..").BoxStyleProps | undefined;
|
|
15
|
+
active?: import("..").BoxStyleProps | undefined;
|
|
16
|
+
} & {
|
|
17
|
+
reducedMotion?: import("..").BoxStyleProps;
|
|
18
|
+
} & 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"> & {
|
|
19
|
+
as?: import("react").ElementType;
|
|
20
|
+
sx?: import("..").BoxProps["sx"];
|
|
21
|
+
className?: string;
|
|
22
|
+
style?: import("react").CSSProperties;
|
|
23
|
+
children?: import("react").ReactNode;
|
|
24
|
+
} & {
|
|
25
|
+
/** The holder's width under which the row becomes a column: 544px by default. */
|
|
26
|
+
threshold?: LayoutLength;
|
|
27
|
+
/** The most children a row takes; with more, they stack at any width. No limit by default. */
|
|
28
|
+
limit?: number;
|
|
29
|
+
/** The space between two children: `3` (16px) by default. */
|
|
30
|
+
gap?: LayoutGap;
|
|
31
|
+
} & import("react").RefAttributes<HTMLElement>>;
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
* `Switcher`: children in one row of equal shares, or in one column — never
|
|
8
|
+
* something between. The row holds while what holds it is at least
|
|
9
|
+
* `threshold` wide (the holder's width, with no breakpoint) and while there
|
|
10
|
+
* are no more than `limit` children.
|
|
11
|
+
*/
|
|
12
|
+
import { forwardRef } from 'react';
|
|
13
|
+
import { Box } from '../box/Box';
|
|
14
|
+
import { switchBasis } from './Split';
|
|
15
|
+
export const Switcher = forwardRef(function Switcher({ threshold = 544, limit, gap = 3, sx, ...rest }, ref) {
|
|
16
|
+
const over = limit && limit > 0 ? `& > :nth-last-child(n+${Math.floor(limit) + 1})` : undefined;
|
|
17
|
+
return (_jsx(Box, { ref: ref, display: "flex", flexWrap: "wrap", gap: gap, sx: {
|
|
18
|
+
'& > *': { flexGrow: 1, flexBasis: switchBasis(threshold), minWidth: 0 },
|
|
19
|
+
...(over ? { [`${over}, ${over} ~ *`]: { flexBasis: '100%' } } : {}),
|
|
20
|
+
...sx,
|
|
21
|
+
}, ...rest }));
|
|
22
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The layouts: how a page, or a part of one, places what it holds. Each is
|
|
3
|
+
* a `Box` with a few props of its own, takes every other `Box` prop, uses
|
|
4
|
+
* the theme's space scale for its gaps, and is responsive without being
|
|
5
|
+
* told: most by the width of what holds them rather than the screen's.
|
|
6
|
+
*/
|
|
7
|
+
export * from './layoutProps';
|
|
8
|
+
export * from './Stack';
|
|
9
|
+
export * from './Cluster';
|
|
10
|
+
export * from './Center';
|
|
11
|
+
export * from './Grid';
|
|
12
|
+
export * from './Sidebar';
|
|
13
|
+
export * from './Split';
|
|
14
|
+
export * from './Switcher';
|
|
15
|
+
export * from './HolyGrail';
|
|
16
|
+
export * from './Masonry';
|
|
17
|
+
export * from './masonryLayout';
|
|
18
|
+
export { MasonryEngine, MASONRY_ITEM_ATTRIBUTE, MASONRY_SPAN_ATTRIBUTE, type MasonryEngineOptions, type MasonryLayoutInfo } from './masonryEngine';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021-2026 Datalayer, Inc.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The layouts: how a page, or a part of one, places what it holds. Each is
|
|
7
|
+
* a `Box` with a few props of its own, takes every other `Box` prop, uses
|
|
8
|
+
* the theme's space scale for its gaps, and is responsive without being
|
|
9
|
+
* told: most by the width of what holds them rather than the screen's.
|
|
10
|
+
*/
|
|
11
|
+
export * from './layoutProps';
|
|
12
|
+
export * from './Stack';
|
|
13
|
+
export * from './Cluster';
|
|
14
|
+
export * from './Center';
|
|
15
|
+
export * from './Grid';
|
|
16
|
+
export * from './Sidebar';
|
|
17
|
+
export * from './Split';
|
|
18
|
+
export * from './Switcher';
|
|
19
|
+
export * from './HolyGrail';
|
|
20
|
+
export * from './Masonry';
|
|
21
|
+
export * from './masonryLayout';
|
|
22
|
+
export { MasonryEngine, MASONRY_ITEM_ATTRIBUTE, MASONRY_SPAN_ATTRIBUTE } from './masonryEngine';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the layouts share: their `Box` props and the few values they resolve
|
|
3
|
+
* themselves (a length, a value per breakpoint).
|
|
4
|
+
*/
|
|
5
|
+
import type { ElementType, HTMLAttributes, ReactNode, CSSProperties } from 'react';
|
|
6
|
+
import type { BoxProps, BoxPseudoProps, BoxResponsive, BoxStyleProps } from '../box/Box';
|
|
7
|
+
/**
|
|
8
|
+
* `Box`'s props without the ones a layout sets itself. Spelled out rather
|
|
9
|
+
* than `Omit<BoxProps, …>`: `BoxProps` has an index signature, and `Omit`
|
|
10
|
+
* over one drops every named key.
|
|
11
|
+
*/
|
|
12
|
+
export type LayoutBoxProps<Own extends keyof BoxStyleProps = never> = Omit<BoxStyleProps, Own> & BoxPseudoProps & Omit<HTMLAttributes<HTMLElement>, keyof BoxStyleProps | 'as'> & {
|
|
13
|
+
/** The element or component to render, `div` by default. */
|
|
14
|
+
as?: ElementType;
|
|
15
|
+
sx?: BoxProps['sx'];
|
|
16
|
+
className?: string;
|
|
17
|
+
style?: CSSProperties;
|
|
18
|
+
children?: ReactNode;
|
|
19
|
+
};
|
|
20
|
+
/** A gap: an index of Primer's space scale (`3` is 16px), pixels past its end, or CSS; one or one per breakpoint. */
|
|
21
|
+
export type LayoutGap = BoxStyleProps['gap'];
|
|
22
|
+
/** A length: a number is pixels, a string is CSS as written. */
|
|
23
|
+
export type LayoutLength = number | string;
|
|
24
|
+
/** A length as CSS. */
|
|
25
|
+
export declare const cssLength: (value: LayoutLength) => string;
|
|
26
|
+
/** A value, or one per breakpoint, through `map`; the gaps (`null`) are kept. */
|
|
27
|
+
export declare function mapResponsive<T, U>(value: BoxResponsive<T>, map: (one: T) => U): U | Array<U | null> | undefined;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021-2026 Datalayer, Inc.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
/** A length as CSS. */
|
|
6
|
+
export const cssLength = (value) => (typeof value === 'number' ? (value === 0 ? '0' : `${value}px`) : value);
|
|
7
|
+
/** A value, or one per breakpoint, through `map`; the gaps (`null`) are kept. */
|
|
8
|
+
export function mapResponsive(value, map) {
|
|
9
|
+
if (Array.isArray(value)) {
|
|
10
|
+
return value.map(one => one === null || one === undefined || one === false ? null : map(one));
|
|
11
|
+
}
|
|
12
|
+
return value === null || value === undefined || value === false ? undefined : map(value);
|
|
13
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What lays a masonry out in the page: it reads the widths and heights,
|
|
3
|
+
* asks {@link masonryPlacement} where each item goes and writes that on the
|
|
4
|
+
* items. React renders the items and never their place — no state, no
|
|
5
|
+
* re-render per layout.
|
|
6
|
+
*
|
|
7
|
+
* ## How it stays fast
|
|
8
|
+
*
|
|
9
|
+
* - **One observer.** A single `ResizeObserver` watches the masonry (its
|
|
10
|
+
* width) and every item (its height): a picture that loads late, a font
|
|
11
|
+
* that arrives, a card that opens. It hands over the new sizes, so a
|
|
12
|
+
* change of height costs no read of the page at all.
|
|
13
|
+
* - **One layout per frame.** Whatever changed, and however many items, the
|
|
14
|
+
* observer and the window's `resize` ask for one `requestAnimationFrame`;
|
|
15
|
+
* the layout runs once in it. (Not in the observer's own callback: writing
|
|
16
|
+
* the masonry's height there is a size change of an observed element, the
|
|
17
|
+
* "ResizeObserver loop" error.)
|
|
18
|
+
* - **Reads, then writes — never mixed.** When the column width changes:
|
|
19
|
+
* write every item's width, read every height (the one reflow), write the
|
|
20
|
+
* places. When only heights changed: no read, the places only.
|
|
21
|
+
* - **Only what moved is written.** Each item's last width and place are
|
|
22
|
+
* kept; an item that stays where it was is not touched.
|
|
23
|
+
* - **O(items × columns)** arithmetic on plain numbers.
|
|
24
|
+
*
|
|
25
|
+
* The first layout, and the one after React changed the items, is done by
|
|
26
|
+
* {@link MasonryEngine.sync} in a layout effect: before the browser paints,
|
|
27
|
+
* so no item is ever seen out of place.
|
|
28
|
+
*
|
|
29
|
+
* Sizes are read as `clientWidth` and `offsetHeight`, which an ancestor's
|
|
30
|
+
* transform (a dialog scaling in) does not distort.
|
|
31
|
+
*/
|
|
32
|
+
import { type MasonryResponsive } from './masonryLayout';
|
|
33
|
+
/** What a layout is made from; read at each layout, so always the latest props. */
|
|
34
|
+
export interface MasonryEngineOptions {
|
|
35
|
+
columns?: MasonryResponsive<number>;
|
|
36
|
+
minColumnWidth?: number;
|
|
37
|
+
maxColumns?: number;
|
|
38
|
+
/** An index of Primer's space scale, or pixels. */
|
|
39
|
+
gap: number;
|
|
40
|
+
onLayout?: (layout: MasonryLayoutInfo) => void;
|
|
41
|
+
}
|
|
42
|
+
/** What a layout came to. */
|
|
43
|
+
export interface MasonryLayoutInfo {
|
|
44
|
+
/** How many columns. */
|
|
45
|
+
columns: number;
|
|
46
|
+
/** The width of one, in pixels. */
|
|
47
|
+
columnWidth: number;
|
|
48
|
+
/** The height of the whole, in pixels. */
|
|
49
|
+
height: number;
|
|
50
|
+
/** How many items. */
|
|
51
|
+
items: number;
|
|
52
|
+
/** How many items were moved or resized by this layout. */
|
|
53
|
+
moved: number;
|
|
54
|
+
/** The time the layout took, reads and writes included, in milliseconds. */
|
|
55
|
+
duration: number;
|
|
56
|
+
}
|
|
57
|
+
/** The attribute of a masonry's items. */
|
|
58
|
+
export declare const MASONRY_ITEM_ATTRIBUTE = "data-masonry-item";
|
|
59
|
+
/** The attribute of an item that takes the whole width: `full`. */
|
|
60
|
+
export declare const MASONRY_SPAN_ATTRIBUTE = "data-masonry-span";
|
|
61
|
+
export declare class MasonryEngine {
|
|
62
|
+
private readonly root;
|
|
63
|
+
private readonly options;
|
|
64
|
+
private records;
|
|
65
|
+
private observed;
|
|
66
|
+
private observer;
|
|
67
|
+
private frame;
|
|
68
|
+
private active;
|
|
69
|
+
private width;
|
|
70
|
+
private height;
|
|
71
|
+
constructor(root: HTMLElement, options: () => MasonryEngineOptions);
|
|
72
|
+
/** The items, in the order of the page. */
|
|
73
|
+
private items;
|
|
74
|
+
/** The observer's sizes: kept, and a layout asked for if any is new. */
|
|
75
|
+
private observe;
|
|
76
|
+
/** One layout in the next frame, however many times it is asked. */
|
|
77
|
+
private schedule;
|
|
78
|
+
/** After React rendered: watch the items that are there now, and lay out at once (before the paint). */
|
|
79
|
+
sync(): void;
|
|
80
|
+
private layout;
|
|
81
|
+
/** Back to the grid of the first paint: every style this engine wrote is taken off. */
|
|
82
|
+
private release;
|
|
83
|
+
/** Stop watching, and leave the page as the first paint had it. */
|
|
84
|
+
destroy(): void;
|
|
85
|
+
}
|