@brightspace-ui/labs 2.37.0 → 2.37.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.
package/package.json CHANGED
@@ -114,5 +114,5 @@
114
114
  "resize-observer-polyfill": "^1",
115
115
  "webvtt-parser": "^2.1.2"
116
116
  },
117
- "version": "2.37.0"
117
+ "version": "2.37.1"
118
118
  }
@@ -4,8 +4,10 @@ import './navigation-link-back.js';
4
4
  import { css, html, LitElement } from 'lit';
5
5
  import { bodyCompactStyles } from '@brightspace-ui/core/components/typography/styles.js';
6
6
  import { classMap } from 'lit/directives/class-map.js';
7
+ import { getFlag } from '@brightspace-ui/core/helpers/flags.js';
7
8
  import { navigationSharedStyle } from './navigation-shared-styles.js';
8
9
  import ResizeObserver from 'resize-observer-polyfill/dist/ResizeObserver.es.js';
10
+ import { styleMap } from 'lit/directives/style-map.js';
9
11
 
10
12
  const mediaQueryList = window.matchMedia('(max-width: 615px)');
11
13
 
@@ -35,6 +37,7 @@ class NavigationImmersive extends LitElement {
35
37
  type: String,
36
38
  reflect: true
37
39
  },
40
+ _dynamicSpacingHeight: { state: true },
38
41
  _middleHidden: { state: true },
39
42
  _middleNoRightBorder: { state: true },
40
43
  _smallWidth: { state: true }
@@ -170,7 +173,14 @@ class NavigationImmersive extends LitElement {
170
173
  this._middleNoRightBorder = true;
171
174
  this._middleObserver = new ResizeObserver(this._onMiddleResize.bind(this));
172
175
  this._rightObserver = new ResizeObserver(this._onRightResize.bind(this));
176
+
177
+ // Only create navigation observer if feature flag is enabled
178
+ if (getFlag('GAUD-8465-immersive-nav-text-spacing', true)) {
179
+ this._navigationObserver = new ResizeObserver(this._onNavigationResize.bind(this));
180
+ }
181
+
173
182
  this._smallWidth = false;
183
+ this._dynamicSpacingHeight = undefined;
174
184
  }
175
185
 
176
186
  connectedCallback() {
@@ -181,9 +191,10 @@ class NavigationImmersive extends LitElement {
181
191
 
182
192
  disconnectedCallback() {
183
193
  super.disconnectedCallback();
184
- if (this._middleObserver) this._middleObserver.disconnect();
185
- if (this._rightObserver) this._rightObserver.disconnect();
186
- if (mediaQueryList.removeEventListener) mediaQueryList.removeEventListener('change', this._handlePageResize);
194
+ this._middleObserver?.disconnect();
195
+ this._rightObserver?.disconnect();
196
+ this._navigationObserver?.disconnect();
197
+ mediaQueryList.removeEventListener?.('change', this._handlePageResize);
187
198
  }
188
199
 
189
200
  firstUpdated(changedProperties) {
@@ -199,6 +210,7 @@ class NavigationImmersive extends LitElement {
199
210
  'd2l-labs-navigation-immersive-middle-no-right-border': this._middleNoRightBorder
200
211
  };
201
212
  const backLinkText = this._smallWidth ? (this.backLinkTextShort || this.backLinkText) : this.backLinkText;
213
+ const spacingStyles = { height: (this._dynamicSpacingHeight ? `${this._dynamicSpacingHeight}px` : undefined) };
202
214
  return html`
203
215
  <div class="d2l-navigiation-immersive-fixed">
204
216
  <d2l-labs-navigation>
@@ -219,10 +231,12 @@ class NavigationImmersive extends LitElement {
219
231
  </div>
220
232
  </d2l-labs-navigation>
221
233
  </div>
222
- <div class="d2l-labs-navigation-immersive-spacing"></div>
234
+ <div class="d2l-labs-navigation-immersive-spacing" style="${styleMap(spacingStyles)}"></div>
223
235
  `;
224
236
  }
225
237
 
238
+ #prevHeight = 0;
239
+
226
240
  _handleBackClick() {
227
241
  this.dispatchEvent(
228
242
  new CustomEvent(
@@ -243,6 +257,23 @@ class NavigationImmersive extends LitElement {
243
257
  this._middleHidden = (entries[0].contentRect.height < 1);
244
258
  }
245
259
 
260
+ _onNavigationResize(entries) {
261
+ if (!entries || entries.length === 0) {
262
+ return;
263
+ }
264
+
265
+ const newHeight = entries[0].contentRect.height;
266
+ if (this.#prevHeight === 0) {
267
+ this.#prevHeight = newHeight;
268
+ return;
269
+ } else if (this.#prevHeight === newHeight) {
270
+ return;
271
+ }
272
+
273
+ this.#prevHeight = newHeight;
274
+ this._dynamicSpacingHeight = newHeight + 5; // 5px is the standard spacing buffer
275
+ }
276
+
246
277
  _onRightResize(entries) {
247
278
  if (!entries || entries.length === 0) {
248
279
  return;
@@ -259,6 +290,14 @@ class NavigationImmersive extends LitElement {
259
290
  if (right) {
260
291
  this._rightObserver.observe(right);
261
292
  }
293
+
294
+ if (this._navigationObserver) {
295
+ // does not need to be nested within if statement after GAUD-8465-immersive-nav-text-spacing is cleaned up
296
+ const navigation = this.shadowRoot?.querySelector('.d2l-navigiation-immersive-fixed');
297
+ if (navigation) {
298
+ this._navigationObserver.observe(navigation);
299
+ }
300
+ }
262
301
  }
263
302
 
264
303
  }