@cloudscape-design/board-components 3.0.23 → 3.0.25

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.
@@ -1,4 +1,4 @@
1
1
  export var PACKAGE_SOURCE = "board-components";
2
- export var PACKAGE_VERSION = "3.0.0 (1e40ad14)";
2
+ export var PACKAGE_VERSION = "3.0.0 (c4526c62)";
3
3
  export var THEME = "open-source-visual-refresh";
4
4
  export var ALWAYS_VISUAL_REFRESH = true;
@@ -3,27 +3,40 @@ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  import { useContainerQuery } from "@cloudscape-design/component-toolkit";
5
5
  import clsx from "clsx";
6
- import { Children } from "react";
6
+ import { Children, useRef } from "react";
7
+ import { useMergeRefs } from "../utils/use-merge-refs";
7
8
  import { zipTwoArrays } from "../utils/zip-arrays";
8
9
  import GridItem from "./item";
9
10
  import styles from "./styles.css.js";
11
+ import { useDensityMode } from "./use-density-mode";
10
12
  /* Matches grid gap in CSS. */
11
- const GRID_GAP = 16;
13
+ const GRID_GAP = {
14
+ comfortable: 20,
15
+ compact: 16,
16
+ };
12
17
  /* Matches grid-auto-rows in CSS. */
13
- const ROWSPAN_HEIGHT = 100;
18
+ const ROWSPAN_HEIGHT = {
19
+ comfortable: 96,
20
+ compact: 76,
21
+ };
14
22
  export default function Grid({ layout, children: render, columns }) {
23
+ const gridRef = useRef(null);
15
24
  const [gridWidth, containerQueryRef] = useContainerQuery((entry) => entry.contentBoxWidth, []);
25
+ const densityMode = useDensityMode(gridRef);
26
+ const gridGap = GRID_GAP[densityMode];
27
+ const rowspanHeight = ROWSPAN_HEIGHT[densityMode];
16
28
  // The below getters translate relative grid units into size/offset values in pixels.
17
29
  const getWidth = (colspan) => {
18
30
  colspan = Math.min(columns, colspan);
19
- const cellWidth = ((gridWidth || 0) - (columns - 1) * GRID_GAP) / columns;
20
- return colspan * cellWidth + (colspan - 1) * GRID_GAP;
31
+ const cellWidth = ((gridWidth || 0) - (columns - 1) * gridGap) / columns;
32
+ return colspan * cellWidth + (colspan - 1) * gridGap;
21
33
  };
22
- const getHeight = (rowspan) => rowspan * ROWSPAN_HEIGHT + (rowspan - 1) * GRID_GAP;
23
- const getColOffset = (x) => getWidth(x) + GRID_GAP;
24
- const getRowOffset = (y) => getHeight(y) + GRID_GAP;
34
+ const getHeight = (rowspan) => rowspan * rowspanHeight + (rowspan - 1) * gridGap;
35
+ const getColOffset = (x) => getWidth(x) + gridGap;
36
+ const getRowOffset = (y) => getHeight(y) + gridGap;
25
37
  const gridContext = { getWidth, getHeight, getColOffset, getRowOffset };
26
38
  const children = render === null || render === void 0 ? void 0 : render(gridContext);
27
39
  const zipped = zipTwoArrays(layout, Children.toArray(children));
28
- return (_jsx("div", { ref: containerQueryRef, className: clsx(styles.grid, styles[`columns-${columns}`]), children: zipped.map(([item, children]) => (_jsx(GridItem, { item: item, children: children }, item.id))) }));
40
+ const ref = useMergeRefs(gridRef, containerQueryRef);
41
+ return (_jsx("div", { ref: ref, className: clsx(styles.grid, styles[`grid-${densityMode}`], styles[`columns-${columns}`]), children: zipped.map(([item, children]) => (_jsx(GridItem, { item: item, children: children }, item.id))) }));
29
42
  }
@@ -1,11 +1,12 @@
1
1
 
2
2
  import './styles.scoped.css';
3
3
  export default {
4
- "grid": "awsui_grid_1hw7z_yec0l_1",
5
- "columns-1": "awsui_columns-1_1hw7z_yec0l_10",
6
- "columns-2": "awsui_columns-2_1hw7z_yec0l_14",
7
- "columns-4": "awsui_columns-4_1hw7z_yec0l_18",
8
- "columns-6": "awsui_columns-6_1hw7z_yec0l_22",
9
- "grid__item": "awsui_grid__item_1hw7z_yec0l_26"
4
+ "grid": "awsui_grid_1hw7z_1ywbc_1",
5
+ "grid-compact": "awsui_grid-compact_1hw7z_1ywbc_8",
6
+ "columns-1": "awsui_columns-1_1hw7z_1ywbc_13",
7
+ "columns-2": "awsui_columns-2_1hw7z_1ywbc_17",
8
+ "columns-4": "awsui_columns-4_1hw7z_1ywbc_21",
9
+ "columns-6": "awsui_columns-6_1hw7z_1ywbc_25",
10
+ "grid__item": "awsui_grid__item_1hw7z_1ywbc_29"
10
11
  };
11
12
 
@@ -1,29 +1,32 @@
1
- .awsui_grid_1hw7z_yec0l_1:not(#\9) {
1
+ .awsui_grid_1hw7z_1ywbc_1:not(#\9) {
2
2
  display: grid;
3
3
  /* Matches GRID_GAP constant used for calculations. */
4
- /* TODO: consider using different gaps for comfortable/compact which would require a mode observer. */
5
- gap: 16px;
4
+ gap: 20px;
6
5
  /* Matches ROWSPAN_HEIGHT constant used for calculations. */
7
- grid-auto-rows: 100px;
6
+ grid-auto-rows: 96px;
7
+ }
8
+ .awsui_grid-compact_1hw7z_1ywbc_8:not(#\9) {
9
+ gap: 16px;
10
+ grid-auto-rows: 76px;
8
11
  }
9
12
 
10
- .awsui_grid_1hw7z_yec0l_1.awsui_columns-1_1hw7z_yec0l_10:not(#\9) {
13
+ .awsui_grid_1hw7z_1ywbc_1.awsui_columns-1_1hw7z_1ywbc_13:not(#\9) {
11
14
  grid-template-columns: minmax(0, 1fr);
12
15
  }
13
16
 
14
- .awsui_grid_1hw7z_yec0l_1.awsui_columns-2_1hw7z_yec0l_14:not(#\9) {
17
+ .awsui_grid_1hw7z_1ywbc_1.awsui_columns-2_1hw7z_1ywbc_17:not(#\9) {
15
18
  grid-template-columns: repeat(2, minmax(0, 1fr));
16
19
  }
17
20
 
18
- .awsui_grid_1hw7z_yec0l_1.awsui_columns-4_1hw7z_yec0l_18:not(#\9) {
21
+ .awsui_grid_1hw7z_1ywbc_1.awsui_columns-4_1hw7z_1ywbc_21:not(#\9) {
19
22
  grid-template-columns: repeat(4, minmax(0, 1fr));
20
23
  }
21
24
 
22
- .awsui_grid_1hw7z_yec0l_1.awsui_columns-6_1hw7z_yec0l_22:not(#\9) {
25
+ .awsui_grid_1hw7z_1ywbc_1.awsui_columns-6_1hw7z_1ywbc_25:not(#\9) {
23
26
  grid-template-columns: repeat(6, minmax(0, 1fr));
24
27
  }
25
28
 
26
- .awsui_grid__item_1hw7z_yec0l_26:not(#\9) {
29
+ .awsui_grid__item_1hw7z_1ywbc_29:not(#\9) {
27
30
  display: block;
28
31
  position: relative;
29
32
  }
@@ -2,11 +2,12 @@
2
2
  // es-module interop with Babel and Typescript
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  module.exports.default = {
5
- "grid": "awsui_grid_1hw7z_yec0l_1",
6
- "columns-1": "awsui_columns-1_1hw7z_yec0l_10",
7
- "columns-2": "awsui_columns-2_1hw7z_yec0l_14",
8
- "columns-4": "awsui_columns-4_1hw7z_yec0l_18",
9
- "columns-6": "awsui_columns-6_1hw7z_yec0l_22",
10
- "grid__item": "awsui_grid__item_1hw7z_yec0l_26"
5
+ "grid": "awsui_grid_1hw7z_1ywbc_1",
6
+ "grid-compact": "awsui_grid-compact_1hw7z_1ywbc_8",
7
+ "columns-1": "awsui_columns-1_1hw7z_1ywbc_13",
8
+ "columns-2": "awsui_columns-2_1hw7z_1ywbc_17",
9
+ "columns-4": "awsui_columns-4_1hw7z_1ywbc_21",
10
+ "columns-6": "awsui_columns-6_1hw7z_1ywbc_25",
11
+ "grid__item": "awsui_grid__item_1hw7z_1ywbc_29"
11
12
  };
12
13
 
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare function useDensityMode(elementRef: React.RefObject<HTMLElement>): "comfortable" | "compact";
@@ -0,0 +1,59 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { findUpUntil } from "@cloudscape-design/component-toolkit/dom";
4
+ import { useEffect, useState } from "react";
5
+ import { unstable_batchedUpdates } from "react-dom";
6
+ import { useStableEventHandler } from "../utils/use-stable-event-handler";
7
+ // Matches: https://github.com/cloudscape-design/components/blob/main/src/internal/hooks/use-visual-mode/index.ts
8
+ export function useDensityMode(elementRef) {
9
+ const [value, setValue] = useState("comfortable");
10
+ useMutationObserver(elementRef, (node) => {
11
+ const compactModeParent = findUpUntil(node, (node) => node.classList.contains("awsui-polaris-compact-mode") || node.classList.contains("awsui-compact-mode"));
12
+ setValue(compactModeParent ? "compact" : "comfortable");
13
+ });
14
+ return value;
15
+ }
16
+ const useMutationSingleton = createSingletonHandler((handler) => {
17
+ const observer = new MutationObserver(() => handler());
18
+ observer.observe(document.body, { attributes: true, subtree: true });
19
+ return () => observer.disconnect();
20
+ });
21
+ function useMutationObserver(elementRef, onChange) {
22
+ const handler = useStableEventHandler(() => {
23
+ if (elementRef.current) {
24
+ onChange(elementRef.current);
25
+ }
26
+ });
27
+ useMutationSingleton(handler);
28
+ useEffect(() => {
29
+ handler();
30
+ }, [handler]);
31
+ }
32
+ function createSingletonHandler(factory) {
33
+ const listeners = [];
34
+ const callback = (value) => {
35
+ unstable_batchedUpdates(() => {
36
+ for (const listener of listeners) {
37
+ listener(value);
38
+ }
39
+ });
40
+ };
41
+ let cleanup;
42
+ return function useSingleton(listener) {
43
+ useEffect(() => {
44
+ if (listeners.length === 0) {
45
+ cleanup = factory(callback);
46
+ }
47
+ listeners.push(listener);
48
+ return () => {
49
+ listeners.splice(listeners.indexOf(listener), 1);
50
+ if (listeners.length === 0) {
51
+ cleanup();
52
+ cleanup = undefined;
53
+ }
54
+ };
55
+ // register handlers only on mount
56
+ // eslint-disable-next-line react-hooks/exhaustive-deps
57
+ }, []);
58
+ };
59
+ }
@@ -1,3 +1,3 @@
1
1
  {
2
- "commit": "1e40ad14e04fda613654941bcee13153a5724069"
2
+ "commit": "c4526c624ca8da79074743777269704dac807809"
3
3
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudscape-design/board-components",
3
- "version": "3.0.23",
3
+ "version": "3.0.25",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/cloudscape-design/board-components.git"