@homebound/beam 2.295.0 → 2.296.0

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/dist/Css.d.ts CHANGED
@@ -408,6 +408,26 @@ declare class CssBuilder<T extends Properties> {
408
408
  boxShadow(value: Properties["boxShadow"]): CssBuilder<T & {
409
409
  boxShadow: import("csstype").Property.BoxShadow | undefined;
410
410
  }>;
411
+ /** Sets `containerType: "size"`. */
412
+ get cts(): CssBuilder<T & {
413
+ containerType: import("csstype").Property.ContainerType | undefined;
414
+ }>;
415
+ /** Sets `containerType: "inline-size"`. */
416
+ get ctis(): CssBuilder<T & {
417
+ containerType: import("csstype").Property.ContainerType | undefined;
418
+ }>;
419
+ /** Sets `containerType: "normal"`. */
420
+ get ctn(): CssBuilder<T & {
421
+ containerType: import("csstype").Property.ContainerType | undefined;
422
+ }>;
423
+ /** Sets `containerType: value`. */
424
+ ct(value: Properties["containerType"]): CssBuilder<T & {
425
+ containerType: import("csstype").Property.ContainerType | undefined;
426
+ }>;
427
+ /** Sets `containerName: value`. */
428
+ cn(value: Properties["containerName"]): CssBuilder<T & {
429
+ containerName: import("csstype").Property.ContainerName | undefined;
430
+ }>;
411
431
  /** Sets `top: "0px"`. */
412
432
  get top0(): CssBuilder<T & {
413
433
  top: import("csstype").Property.Top<string | 0> | undefined;
@@ -3993,6 +4013,7 @@ declare class CssBuilder<T extends Properties> {
3993
4013
  if(cond: boolean): CssBuilder<T>;
3994
4014
  if(attr: string, value: boolean | string): CssBuilder<T>;
3995
4015
  get onHover(): CssBuilder<T>;
4016
+ ifContainer(props: ContainerProps): CssBuilder<T>;
3996
4017
  get ifPrint(): CssBuilder<T>;
3997
4018
  get ifSm(): CssBuilder<T>;
3998
4019
  get ifMd(): CssBuilder<T>;
@@ -4102,4 +4123,22 @@ export declare enum Breakpoints {
4102
4123
  lg = "@media screen and (min-width:1025px)",
4103
4124
  mdOrLg = "@media screen and (min-width:600px)"
4104
4125
  }
4126
+ /**
4127
+ * Utility to help write `@container` queries
4128
+ *
4129
+ * @param name - The name of the container.
4130
+ * @param lt - The maximum width of the container inclusive.
4131
+ * @param gt - The minimum width of the container exclusive.
4132
+ */
4133
+ type ContainerProps = {
4134
+ name?: string;
4135
+ } & ({
4136
+ lt: number;
4137
+ } | {
4138
+ gt: number;
4139
+ } | {
4140
+ lt: number;
4141
+ gt: number;
4142
+ });
4143
+ export declare function Container(props: ContainerProps): string;
4105
4144
  export {};
package/dist/Css.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Breakpoints = exports.Css = exports.Palette = exports.px = exports.increment = exports.maybeInc = void 0;
3
+ exports.Container = exports.Breakpoints = exports.Css = exports.Palette = exports.px = exports.increment = exports.maybeInc = void 0;
4
4
  class CssBuilder {
5
5
  constructor(opts) {
6
6
  this.opts = opts;
@@ -399,6 +399,27 @@ class CssBuilder {
399
399
  boxShadow(value) {
400
400
  return this.add("boxShadow", value);
401
401
  }
402
+ // container
403
+ /** Sets `containerType: "size"`. */
404
+ get cts() {
405
+ return this.add("containerType", "size");
406
+ }
407
+ /** Sets `containerType: "inline-size"`. */
408
+ get ctis() {
409
+ return this.add("containerType", "inline-size");
410
+ }
411
+ /** Sets `containerType: "normal"`. */
412
+ get ctn() {
413
+ return this.add("containerType", "normal");
414
+ }
415
+ /** Sets `containerType: value`. */
416
+ ct(value) {
417
+ return this.add("containerType", value);
418
+ }
419
+ /** Sets `containerName: value`. */
420
+ cn(value) {
421
+ return this.add("containerName", value);
422
+ }
402
423
  // coordinates
403
424
  /** Sets `top: "0px"`. */
404
425
  get top0() {
@@ -3546,6 +3567,9 @@ class CssBuilder {
3546
3567
  get onHover() {
3547
3568
  return this.newCss({ selector: ":hover" });
3548
3569
  }
3570
+ ifContainer(props) {
3571
+ return this.newCss({ selector: Container(props) });
3572
+ }
3549
3573
  get ifPrint() {
3550
3574
  return this.newCss({ selector: "@media print" });
3551
3575
  }
@@ -3715,3 +3739,13 @@ var Breakpoints;
3715
3739
  Breakpoints["lg"] = "@media screen and (min-width:1025px)";
3716
3740
  Breakpoints["mdOrLg"] = "@media screen and (min-width:600px)";
3717
3741
  })(Breakpoints = exports.Breakpoints || (exports.Breakpoints = {}));
3742
+ function Container(props) {
3743
+ const { name = "" } = props;
3744
+ const lt = "lt" in props ? props.lt : undefined;
3745
+ const gt = "gt" in props ? props.gt : undefined;
3746
+ const ltQuery = lt !== undefined ? `(max-width: ${lt}px)` : "";
3747
+ const gtQuery = gt !== undefined ? `(min-width: ${gt + 1}px)` : "";
3748
+ const query = [ltQuery, gtQuery].filter(Boolean).join(" and ");
3749
+ return `@container ${name} ${query}`;
3750
+ }
3751
+ exports.Container = Container;
@@ -118,11 +118,14 @@ function DnDGrid(props) {
118
118
  if (!reorderViaKeyboard.current && dragEl.current && gridEl.current) {
119
119
  initReorder();
120
120
  // Determine the position of the pointer relative to the element being dragged.
121
+ const gridRect = gridEl.current.getBoundingClientRect();
121
122
  const rect = dragEl.current.getBoundingClientRect();
122
123
  const clientX = "clientX" in e ? e.clientX : e.touches[0].clientX;
123
124
  const clientY = "clientY" in e ? e.clientY : e.touches[0].clientY;
125
+ const top = rect.top - gridRect.top;
126
+ const left = rect.left - gridRect.left;
124
127
  // Store the pointer's offset from the tile being moved to help correctly position the element as we drag it around.
125
- transformFrom.current = { x: clientX - rect.left, y: clientY - rect.top };
128
+ transformFrom.current = { x: clientX - left, y: clientY - top };
126
129
  // Duplicate the draggable element as a placeholder to show as a drop target
127
130
  cloneEl.current = dragEl.current.cloneNode();
128
131
  (_a = cloneEl.current) === null || _a === void 0 ? void 0 : _a.setAttribute("style", `border-width: 2px; border-color: ${src_1.Palette.Gray400}; border-style: dashed; width:${rect.width}px; height:${rect.height}px;`);
@@ -136,7 +139,7 @@ function DnDGrid(props) {
136
139
  gridEl.current.insertBefore(cloneEl.current, dragEl.current.nextSibling);
137
140
  // Apply styles to the actual element to make it look like it's being dragged.
138
141
  // This will remove it from the normal flow of the page, allowing the clone above to take its place.
139
- dragEl.current.setAttribute("style", `pointer-events: none; position:fixed; z-index: 9999; top:${rect.top}px; left:${rect.left}px; width:${rect.width}px; height:${rect.height}px;`);
142
+ dragEl.current.setAttribute("style", `pointer-events: none; position:fixed; z-index: 9999; top:${top}px; left:${left}px; width:${rect.width}px; height:${rect.height}px;`);
140
143
  // Applies cursor styling to the Grid element.
141
144
  gridEl.current.style.cursor = "grabbing";
142
145
  // Add event listeners to move the element as the user drags it around.
@@ -224,7 +227,7 @@ function DnDGrid(props) {
224
227
  }
225
228
  }, [cancelReorder, commitReorder, initReorder, getGridItems]);
226
229
  return ((0, jsx_runtime_1.jsx)(DnDGridContext_1.DnDGridContext.Provider, { value: { dragEl, onDragHandleKeyDown }, children: (0, jsx_runtime_1.jsx)("div", { ref: gridEl, css: {
227
- ...src_1.Css.dg.addIn(`& .${activeGridItemClass}`, activeItemStyles !== null && activeItemStyles !== void 0 ? activeItemStyles : src_1.Css.bshModal.$).$,
230
+ ...src_1.Css.ctis.dg.addIn(`& .${activeGridItemClass}`, activeItemStyles !== null && activeItemStyles !== void 0 ? activeItemStyles : src_1.Css.bshModal.$).$,
228
231
  ...gridStyles,
229
232
  }, onTouchStart: onDragStart, onMouseDown: onDragStart, onTouchEnd: onDragEnd, onMouseUp: onDragEnd, ...tid, children: children }) }));
230
233
  }
@@ -0,0 +1,6 @@
1
+ import { PropsWithChildren } from "react";
2
+ import { useResponsiveGridProps } from "..";
3
+ export interface ResponsiveGridProps extends PropsWithChildren<useResponsiveGridProps> {
4
+ }
5
+ /** Helper component for generating a responsive grid */
6
+ export declare function ResponsiveGrid(props: ResponsiveGridProps): import("@emotion/react/jsx-runtime").JSX.Element;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ResponsiveGrid = void 0;
4
+ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
5
+ const components_1 = require("..");
6
+ /** Helper component for generating a responsive grid */
7
+ function ResponsiveGrid(props) {
8
+ const { children, ...hookProps } = props;
9
+ const { gridStyles } = (0, components_1.useResponsiveGrid)(hookProps);
10
+ return (0, jsx_runtime_1.jsx)("div", { css: { ...gridStyles }, children: children });
11
+ }
12
+ exports.ResponsiveGrid = ResponsiveGrid;
@@ -0,0 +1,7 @@
1
+ import { PropsWithChildren } from "react";
2
+ export interface ResponsiveGridItemProps extends PropsWithChildren<{
3
+ colSpan: number;
4
+ }> {
5
+ }
6
+ /** Helper component for generating grid items with the ResponsiveGrid */
7
+ export declare function ResponsiveGridItem(props: ResponsiveGridItemProps): import("@emotion/react/jsx-runtime").JSX.Element;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ResponsiveGridItem = void 0;
4
+ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
5
+ const src_1 = require("../..");
6
+ /** Helper component for generating grid items with the ResponsiveGrid */
7
+ function ResponsiveGridItem(props) {
8
+ const { colSpan, children } = props;
9
+ const { gridItemProps } = (0, src_1.useResponsiveGridItem)({ colSpan });
10
+ return (0, jsx_runtime_1.jsx)("div", { ...gridItemProps, children: children });
11
+ }
12
+ exports.ResponsiveGridItem = ResponsiveGridItem;
@@ -0,0 +1,7 @@
1
+ export { ResponsiveGrid } from "./ResponsiveGrid";
2
+ export type { ResponsiveGridProps } from "./ResponsiveGrid";
3
+ export { ResponsiveGridItem } from "./ResponsiveGridItem";
4
+ export type { ResponsiveGridItemProps } from "./ResponsiveGridItem";
5
+ export { useResponsiveGrid } from "./useResponsiveGrid";
6
+ export type { useResponsiveGridProps } from "./useResponsiveGrid";
7
+ export { useResponsiveGridItem } from "./useResponsiveGridItem";
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useResponsiveGridItem = exports.useResponsiveGrid = exports.ResponsiveGridItem = exports.ResponsiveGrid = void 0;
4
+ var ResponsiveGrid_1 = require("./ResponsiveGrid");
5
+ Object.defineProperty(exports, "ResponsiveGrid", { enumerable: true, get: function () { return ResponsiveGrid_1.ResponsiveGrid; } });
6
+ var ResponsiveGridItem_1 = require("./ResponsiveGridItem");
7
+ Object.defineProperty(exports, "ResponsiveGridItem", { enumerable: true, get: function () { return ResponsiveGridItem_1.ResponsiveGridItem; } });
8
+ var useResponsiveGrid_1 = require("./useResponsiveGrid");
9
+ Object.defineProperty(exports, "useResponsiveGrid", { enumerable: true, get: function () { return useResponsiveGrid_1.useResponsiveGrid; } });
10
+ var useResponsiveGridItem_1 = require("./useResponsiveGridItem");
11
+ Object.defineProperty(exports, "useResponsiveGridItem", { enumerable: true, get: function () { return useResponsiveGridItem_1.useResponsiveGridItem; } });
@@ -0,0 +1,13 @@
1
+ import { Properties } from "../..";
2
+ export interface useResponsiveGridProps {
3
+ minColumnWidth: number;
4
+ gap: number;
5
+ columns: number;
6
+ }
7
+ /**
8
+ * Returns the styles for a responsive grid.
9
+ * Use in tandem with the `useResponsiveGridItem` hook to generate props for each grid item to ensure proper behavior at breakpoints.
10
+ */
11
+ export declare function useResponsiveGrid(props: useResponsiveGridProps): {
12
+ gridStyles: Properties;
13
+ };
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useResponsiveGrid = void 0;
4
+ const react_1 = require("react");
5
+ const src_1 = require("../..");
6
+ const utils_1 = require("./utils");
7
+ /**
8
+ * Returns the styles for a responsive grid.
9
+ * Use in tandem with the `useResponsiveGridItem` hook to generate props for each grid item to ensure proper behavior at breakpoints.
10
+ */
11
+ function useResponsiveGrid(props) {
12
+ const { minColumnWidth, gap, columns } = props;
13
+ const gridStyles = (0, react_1.useMemo)(() => {
14
+ const gapCount = columns - 1;
15
+ const totalGapWidth = gap * gapCount;
16
+ const maxColumnWidth = `calc((100% - ${totalGapWidth}px) / ${columns})`;
17
+ const gridTemplateColumns = `repeat(auto-fill, minmax(max(${minColumnWidth}px, ${maxColumnWidth}), 1fr))`;
18
+ const gridGap = `${gap}px`;
19
+ // Generate the container queries for each possible colspan for grid items.
20
+ const gridItemSpanStyles = Array.from({ length: columns }, (_, i) => {
21
+ const span = i + 1;
22
+ // Generate the CSS selectors for each grid item that spans `span` columns.
23
+ const targets = Array.from({ length: columns - span }, (_, s) => `& > [${utils_1.gridItemDataAttribute}='${s + span + 1}']`).join(", ");
24
+ // Define the breakpoint values for the container query.
25
+ const minWidth = span === 1 ? 0 : minColumnWidth * span + gap * i;
26
+ const maxWidth = minColumnWidth * (span + 1) + gap * span;
27
+ const style = {
28
+ // Using the `targets` selector, add the container query for the grid item.
29
+ // `targets` may be empty when the span is the same as the number of columns.
30
+ ...(targets
31
+ ? src_1.Css.addIn(targets, src_1.Css.ifContainer({ gt: minWidth, lt: maxWidth }).gc(`span ${span}`).$).$
32
+ : undefined),
33
+ // Add the default style for the grid item as a helper for the implementer to not have to define their `grid-column: span X`
34
+ // Uses `&&` selector to change the selector value to avoid being overridden by above container query.
35
+ ...(span !== 1
36
+ ? src_1.Css.addIn(`&& > [${utils_1.gridItemDataAttribute}='${span}']`, src_1.Css.ifContainer({ gt: minWidth }).gc(`span ${span}`).$).$
37
+ : undefined),
38
+ };
39
+ return style;
40
+ }).filter((s) => Object.keys(s).length > 0);
41
+ return {
42
+ ...src_1.Css.dg.gtc(gridTemplateColumns).ctis.gap(gridGap).$,
43
+ ...Object.assign({}, ...gridItemSpanStyles),
44
+ };
45
+ }, [minColumnWidth, gap, columns]);
46
+ return { gridStyles };
47
+ }
48
+ exports.useResponsiveGrid = useResponsiveGrid;
@@ -0,0 +1,7 @@
1
+ export declare function useResponsiveGridItem({ colSpan }: {
2
+ colSpan?: number;
3
+ }): {
4
+ gridItemProps: {
5
+ "data-grid-item-span": number;
6
+ };
7
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useResponsiveGridItem = void 0;
4
+ const utils_1 = require("./utils");
5
+ function useResponsiveGridItem({ colSpan = 1 }) {
6
+ return { gridItemProps: { [utils_1.gridItemDataAttribute]: colSpan } };
7
+ }
8
+ exports.useResponsiveGridItem = useResponsiveGridItem;
@@ -0,0 +1 @@
1
+ export declare const gridItemDataAttribute = "data-grid-item-span";
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gridItemDataAttribute = void 0;
4
+ exports.gridItemDataAttribute = "data-grid-item-span";
@@ -17,6 +17,7 @@ export * from "./Copy";
17
17
  export * from "./CssReset";
18
18
  export * from "./DnDGrid";
19
19
  export * from "./Filters";
20
+ export * from "./Grid";
20
21
  export { HbLoadingSpinner, HbSpinnerProvider, HB_QUIPS_FLAVOR, HB_QUIPS_MISSION } from "./HbLoadingSpinner";
21
22
  export * from "./Icon";
22
23
  export * from "./IconButton";
@@ -35,6 +35,7 @@ __exportStar(require("./Copy"), exports);
35
35
  __exportStar(require("./CssReset"), exports);
36
36
  __exportStar(require("./DnDGrid"), exports);
37
37
  __exportStar(require("./Filters"), exports);
38
+ __exportStar(require("./Grid"), exports);
38
39
  var HbLoadingSpinner_1 = require("./HbLoadingSpinner");
39
40
  Object.defineProperty(exports, "HbLoadingSpinner", { enumerable: true, get: function () { return HbLoadingSpinner_1.HbLoadingSpinner; } });
40
41
  Object.defineProperty(exports, "HbSpinnerProvider", { enumerable: true, get: function () { return HbLoadingSpinner_1.HbSpinnerProvider; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.295.0",
3
+ "version": "2.296.0",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -77,7 +77,7 @@
77
77
  "@homebound/eslint-config": "1.6.1",
78
78
  "@homebound/rtl-react-router-utils": "1.0.3",
79
79
  "@homebound/rtl-utils": "^2.61.1",
80
- "@homebound/truss": "^1.128.1",
80
+ "@homebound/truss": "^1.129.0",
81
81
  "@homebound/tsconfig": "^1.0.3",
82
82
  "@semantic-release/exec": "^6.0.3",
83
83
  "@semantic-release/git": "^10.0.1",