@boostdev/design-system-components 2.2.0 → 2.2.1

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,5 @@
1
1
  import {
2
+ Context,
2
3
  ElementType,
3
4
  ComponentPropsWithoutRef,
4
5
  CSSProperties,
@@ -23,9 +24,14 @@ export type GridContextValue = {
23
24
  autoSpanMedia: boolean;
24
25
  };
25
26
 
26
- export const GridContext = createContext<GridContextValue>({
27
- autoSpanMedia: false,
28
- });
27
+ // Lazy-initialised so the module can be evaluated in Next.js Server Components
28
+ // without calling `createContext` at import time (which crashes RSC — `react-server`
29
+ // export conditions don't expose `createContext`).
30
+ let _GridContext: Context<GridContextValue>;
31
+ export function getGridContext(): Context<GridContextValue> {
32
+ _GridContext ??= createContext<GridContextValue>({ autoSpanMedia: false });
33
+ return _GridContext;
34
+ }
29
35
 
30
36
  type GridOwnProps = WithClassName & {
31
37
  variant?: GridVariant;
@@ -75,6 +81,7 @@ export function Grid<C extends ElementType = 'div'>({
75
81
 
76
82
  const Component = as ?? 'div';
77
83
 
84
+ const GridContext = getGridContext();
78
85
  const ctx = useMemo<GridContextValue>(() => ({ autoSpanMedia }), [autoSpanMedia]);
79
86
 
80
87
  return (
@@ -10,7 +10,7 @@ import {
10
10
  import css from './Grid.module.css';
11
11
  import { cn } from '@boostdev/design-system-foundation';
12
12
  import type { WithClassName } from '../../../types';
13
- import { GridContext } from './Grid';
13
+ import { getGridContext } from './Grid';
14
14
  import {
15
15
  aspectToColumnSpan,
16
16
  findMediaChild,
@@ -75,7 +75,7 @@ export function GridItem<C extends ElementType = 'div'>({
75
75
  style,
76
76
  ...rest
77
77
  }: GridItemProps<C>) {
78
- const { autoSpanMedia } = useContext(GridContext);
78
+ const { autoSpanMedia } = useContext(getGridContext());
79
79
  const effectiveSpan: GridItemSpanValue =
80
80
  columnSpan ?? (autoSpanMedia ? 'auto' : 'full');
81
81
 
@@ -53,10 +53,14 @@ export function applyMasonryLayout(container: HTMLElement, rawChildren: HTMLElem
53
53
  );
54
54
 
55
55
  // Pass 1 — clear prior row-span overrides so items measure at their natural height.
56
+ // Also force `align-self: start`: the default `stretch` would grow each item to fill
57
+ // the 1px track, making `offsetHeight` return 1 for every child. Keeping `start` after
58
+ // the span is assigned also prevents items from stretching into the gap region.
56
59
  for (const child of children) {
57
60
  child.style.gridRow = '';
58
61
  child.style.gridRowStart = '';
59
62
  child.style.gridRowEnd = '';
63
+ child.style.alignSelf = 'start';
60
64
  }
61
65
 
62
66
  // Pass 2 — read all heights in a tight loop. The first offsetHeight read forces one
@@ -81,6 +85,7 @@ export function clearMasonryLayout(container: HTMLElement, rawChildren: HTMLElem
81
85
  child.style.gridRow = '';
82
86
  child.style.gridRowStart = '';
83
87
  child.style.gridRowEnd = '';
88
+ child.style.alignSelf = '';
84
89
  }
85
90
  }
86
91