@boostdev/design-system-components 2.2.1 → 2.3.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.
@@ -99,4 +99,18 @@ describe('bds-grid-item', () => {
99
99
  expect(item.style.gridColumn).toBe('span var(--bds-grid_columns-33)');
100
100
  cleanup(grid);
101
101
  });
102
+
103
+ it('marks data-column-span-auto when column-span is not set', async () => {
104
+ const el = (await fixture('<bds-grid-item></bds-grid-item>')) as BdsGridItem;
105
+ expect(el.hasAttribute('data-column-span-auto')).toBe(true);
106
+ cleanup(el);
107
+ });
108
+
109
+ it('clears data-column-span-auto when column-span is set', async () => {
110
+ const el = (await fixture(
111
+ '<bds-grid-item column-span="half"></bds-grid-item>',
112
+ )) as BdsGridItem;
113
+ expect(el.hasAttribute('data-column-span-auto')).toBe(false);
114
+ cleanup(el);
115
+ });
102
116
  });
@@ -161,6 +161,13 @@ export class BdsGridItem extends LitElement {
161
161
 
162
162
  this.style.gridColumn = gridColumn;
163
163
  this.style.gridRow = this.rowSpan !== undefined ? `span ${this.rowSpan}` : '';
164
+
165
+ // Marker the masonry polyfill reads to know this item's span wasn't set by
166
+ // the consumer — it may override with the parent `masonry-preferred-column-span`.
167
+ const isColumnSpanAuto =
168
+ (this.columnSpan === undefined || this.columnSpan === null) && !hasExplicitRange;
169
+ if (isColumnSpanAuto) this.setAttribute('data-column-span-auto', '');
170
+ else this.removeAttribute('data-column-span-auto');
164
171
  }
165
172
 
166
173
  render() {
@@ -59,4 +59,12 @@ describe('bds-grid', () => {
59
59
  expect(el.shadowRoot!.querySelector('.grid')!.classList.contains('--masonry')).toBe(true);
60
60
  cleanup(el);
61
61
  });
62
+
63
+ it('reflects masonry-preferred-column-span as a number property', async () => {
64
+ const el = await fixture(
65
+ '<bds-grid is-masonry masonry-preferred-column-span="2"></bds-grid>',
66
+ ) as BdsGrid;
67
+ expect(el.masonryPreferredColumnSpan).toBe(2);
68
+ cleanup(el);
69
+ });
62
70
  });
@@ -16,6 +16,9 @@ export type GridVariant = 'main' | 'page' | 'funnel' | 'custom';
16
16
  * auto-span-media — boolean; child `<bds-grid-item>`s without a `column-span`
17
17
  * attribute resolve their span from the intrinsic aspect
18
18
  * ratio of their first `<img>`/`<video>` child.
19
+ * masonry-preferred-column-span — number; masonry only. Child items without a
20
+ * `column-span` attribute try to span this many columns; an
21
+ * item at row-end is demoted to the remaining column count.
19
22
  *
20
23
  * Slots:
21
24
  * (default) — grid content; typically `<bds-grid-item>` children
@@ -76,6 +79,11 @@ export class BdsGrid extends LitElement {
76
79
  isCentered: { type: Boolean, attribute: 'is-centered', reflect: true },
77
80
  isMasonry: { type: Boolean, attribute: 'is-masonry', reflect: true },
78
81
  autoSpanMedia: { type: Boolean, attribute: 'auto-span-media', reflect: true },
82
+ masonryPreferredColumnSpan: {
83
+ type: Number,
84
+ attribute: 'masonry-preferred-column-span',
85
+ reflect: true,
86
+ },
79
87
  };
80
88
 
81
89
  declare variant: GridVariant;
@@ -83,6 +91,7 @@ export class BdsGrid extends LitElement {
83
91
  declare isCentered: boolean;
84
92
  declare isMasonry: boolean;
85
93
  declare autoSpanMedia: boolean;
94
+ declare masonryPreferredColumnSpan: number | undefined;
86
95
 
87
96
  private _ro?: ResizeObserver;
88
97
  private _mo?: MutationObserver;
@@ -95,6 +104,7 @@ export class BdsGrid extends LitElement {
95
104
  this.isCentered = false;
96
105
  this.isMasonry = false;
97
106
  this.autoSpanMedia = false;
107
+ this.masonryPreferredColumnSpan = undefined;
98
108
  }
99
109
 
100
110
  disconnectedCallback() {
@@ -144,7 +154,11 @@ export class BdsGrid extends LitElement {
144
154
  cancelAnimationFrame(this._frame);
145
155
  this._frame = requestAnimationFrame(() => {
146
156
  const container = this._gridEl();
147
- if (container) applyMasonryLayout(container, this._items());
157
+ if (container) {
158
+ applyMasonryLayout(container, this._items(), {
159
+ preferredColumnSpan: this.masonryPreferredColumnSpan,
160
+ });
161
+ }
148
162
  });
149
163
  }
150
164