@brightspace-ui/core 2.190.0 → 3.0.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.
@@ -200,8 +200,20 @@
200
200
  </d2l-dropdown>
201
201
  </template>
202
202
  </d2l-demo-snippet>
203
+
204
+ <h2>Generic Dropdown, wide opener with brief content, end align</h2>
205
+ <d2l-demo-snippet>
206
+ <template>
207
+ <d2l-dropdown>
208
+ <d2l-button class="d2l-dropdown-opener">Lorem ipsum dolor sit amet consectetur adipiscing elit</d2l-button>
209
+ <d2l-dropdown-content align="end">
210
+ <p>Content</p>
211
+ </d2l-dropdown-content>
212
+ </d2l-dropdown>
213
+ </template>
214
+ </d2l-demo-snippet>
203
215
  </d2l-demo-page>
204
216
 
205
217
  </body>
206
218
 
207
- </html>
219
+ </html>
@@ -10,6 +10,7 @@ import { LocalizeCoreElement } from '../../helpers/localize-core-element.js';
10
10
  import { RtlMixin } from '../../mixins/rtl/rtl-mixin.js';
11
11
  import { styleMap } from 'lit/directives/style-map.js';
12
12
  import { tryGetIfrauBackdropService } from '../../helpers/ifrauBackdropService.js';
13
+ import { visualReady } from '../../helpers/visualReady.js';
13
14
 
14
15
  const reduceMotion = matchMedia('(prefers-reduced-motion: reduce)').matches;
15
16
  const minBackdropHeightMobile = 42;
@@ -320,6 +321,11 @@ export const DropdownContentMixin = superclass => class extends LocalizeCoreElem
320
321
  this.addEventListener('d2l-dropdown-position', this.__toggleScrollStyles);
321
322
  }
322
323
 
324
+ async getUpdateComplete() {
325
+ await super.getUpdateComplete();
326
+ await visualReady;
327
+ }
328
+
323
329
  updated(changedProperties) {
324
330
  changedProperties.forEach((_, propName) => {
325
331
  if (propName === 'verticalOffset') {
@@ -682,8 +688,7 @@ export const DropdownContentMixin = superclass => class extends LocalizeCoreElem
682
688
  this.openedAbove = this._getOpenedAbove(spaceAround, spaceAroundScroll, spaceRequired);
683
689
  }
684
690
 
685
- const centerDelta = contentRect.width - targetRect.width;
686
- const position = this._getPosition(spaceAround, centerDelta);
691
+ const position = this._getPosition(spaceAround, targetRect.width, contentRect.width);
687
692
  if (position !== null) {
688
693
  this._position = position;
689
694
  }
@@ -973,13 +978,13 @@ export const DropdownContentMixin = superclass => class extends LocalizeCoreElem
973
978
  return false;
974
979
  }
975
980
 
976
- _getPosition(spaceAround, centerDelta) {
977
-
981
+ _getPosition(spaceAround, targetWidth, contentWidth) {
982
+ const centerDelta = contentWidth - targetWidth;
978
983
  const contentXAdjustment = centerDelta / 2;
979
- if (centerDelta <= 0) {
984
+ if (!this.align && centerDelta <= 0) {
980
985
  return contentXAdjustment * -1;
981
986
  }
982
- if (spaceAround.left > contentXAdjustment && spaceAround.right > contentXAdjustment) {
987
+ if (!this.align && spaceAround.left > contentXAdjustment && spaceAround.right > contentXAdjustment) {
983
988
  // center with target
984
989
  return contentXAdjustment * -1;
985
990
  }
@@ -1001,6 +1006,14 @@ export const DropdownContentMixin = superclass => class extends LocalizeCoreElem
1001
1006
  return spaceAround.right * -1;
1002
1007
  }
1003
1008
  }
1009
+ if (this.align === 'start' || this.align === 'end') {
1010
+ const shift = Math.min((targetWidth / 2) - (20 + 16 / 2), 0); // 20 ~= 1rem, 16 = pointer size
1011
+ if (this.align === 'start') {
1012
+ return shift;
1013
+ } else {
1014
+ return targetWidth - contentWidth - shift;
1015
+ }
1016
+ }
1004
1017
  return null;
1005
1018
  }
1006
1019
 
@@ -1,6 +1,9 @@
1
1
  import '../colors/colors.js';
2
2
  import { css } from 'lit';
3
3
 
4
+ const pointerLength = 16;
5
+ const pointerRotatedLength = Math.SQRT2 * parseFloat(pointerLength);
6
+
4
7
  export const dropdownContentStyles = css`
5
8
 
6
9
  :host {
@@ -61,16 +64,26 @@ export const dropdownContentStyles = css`
61
64
  top: -7px;
62
65
  z-index: 1;
63
66
  }
67
+ :host([align="start"]) .d2l-dropdown-content-pointer,
68
+ :host([align="end"][dir="rtl"]) .d2l-dropdown-content-pointer {
69
+ left: min(calc(1rem + ${(pointerRotatedLength - pointerLength) / 2}px), calc(50% - ${pointerLength / 2}px)); /* 1rem corresponds to .d2l-dropdown-content-container padding */
70
+ right: auto;
71
+ }
72
+ :host([align="end"]) .d2l-dropdown-content-pointer,
73
+ :host([align="start"][dir="rtl"]) .d2l-dropdown-content-pointer {
74
+ left: auto;
75
+ right: min(calc(1rem + ${(pointerRotatedLength - pointerLength) / 2}px), calc(50% - ${pointerLength / 2}px)); /* 1rem corresponds to .d2l-dropdown-content-container padding */
76
+ }
64
77
 
65
78
  .d2l-dropdown-content-pointer > div {
66
79
  background-color: var(--d2l-dropdown-background-color);
67
80
  border: 1px solid var(--d2l-dropdown-border-color);
68
81
  border-radius: 0.1rem;
69
82
  box-shadow: -4px -4px 12px -5px rgba(32, 33, 34, 0.2); /* ferrite */
70
- height: 16px;
83
+ height: ${pointerLength}px;
71
84
  -webkit-transform: rotate(45deg);
72
85
  transform: rotate(45deg);
73
- width: 16px;
86
+ width: ${pointerLength}px;
74
87
  }
75
88
 
76
89
  :host([opened-above]) .d2l-dropdown-content-pointer {
package/helpers/README.md CHANGED
@@ -280,3 +280,17 @@ import '@brightspace-ui/core/helpers/viewport-size.js';
280
280
  min-width: calc(var(--d2l-vw, 1vw) * 100);
281
281
  }
282
282
  ```
283
+
284
+ ## Visual Ready
285
+
286
+ A helper for determining that the page is visually "ready" (i.e., necessary pieces are loaded) and calculations can be done. Currently it handles waiting for fonts to be ready, but going forward it can have other pieces added as needed. This is useful in places like the tooltip, where the fonts being loaded has an impact on the tooltip position calculation.
287
+
288
+ Example usage within a component:
289
+ ```javascript
290
+ import { visualReady } from '../../helpers/visualReady.js';
291
+
292
+ async getUpdateComplete() {
293
+ await super.getUpdateComplete();
294
+ await visualReady;
295
+ }
296
+ ```
@@ -0,0 +1,3 @@
1
+ [...document.fonts].forEach(font => font.load());
2
+
3
+ export const visualReady = Promise.all([document.fonts.ready]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "2.190.0",
3
+ "version": "3.0.1",
4
4
  "description": "A collection of accessible, free, open-source web components for building Brightspace applications",
5
5
  "type": "module",
6
6
  "repository": "https://github.com/BrightspaceUI/core.git",
@@ -51,7 +51,7 @@
51
51
  "@rollup/plugin-dynamic-import-vars": "^2",
52
52
  "@rollup/plugin-node-resolve": "^15",
53
53
  "@rollup/plugin-replace": "^5",
54
- "@web/dev-server": "^0.2",
54
+ "@web/dev-server": "^0.4",
55
55
  "chalk": "^5",
56
56
  "eslint": "^8",
57
57
  "eslint-config-brightspace": "^1",
@@ -61,7 +61,7 @@
61
61
  "rollup": "^4",
62
62
  "rollup-plugin-copy": "^3",
63
63
  "rollup-plugin-delete": "^2",
64
- "sinon": "^17",
64
+ "sinon": "^18",
65
65
  "stylelint": "^16",
66
66
  "web-component-analyzer": "^2"
67
67
  },
@@ -71,7 +71,7 @@
71
71
  "@open-wc/dedupe-mixin": "^1",
72
72
  "ifrau": "^0.41",
73
73
  "intl-messageformat": "^10",
74
- "lit": "^2",
74
+ "lit": "^3",
75
75
  "prismjs": "^1",
76
76
  "resize-observer-polyfill": "^1"
77
77
  }