@brightspace-ui/core 3.327.2 → 3.328.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.
@@ -0,0 +1,136 @@
1
+ import '../tooltip/tooltip.js';
2
+ import { css, html, LitElement, nothing } from 'lit';
3
+ import { classMap } from 'lit/directives/class-map.js';
4
+ import { DropdownOpenerMixin } from '../dropdown/dropdown-opener-mixin.js';
5
+ import { dropdownOpenerStyles } from '../dropdown/dropdown-opener-styles.js';
6
+ import { FocusMixin } from '../../mixins/focus/focus-mixin.js';
7
+ import { offscreenStyles } from '../offscreen/offscreen.js';
8
+ import { PropertyRequiredMixin } from '../../mixins/property-required/property-required-mixin.js';
9
+ import { SlottedIconMixin } from '../icons/slotted-icon-mixin.js';
10
+ import { ThemeMixin } from '../../mixins/theme/theme-mixin.js';
11
+ import { toolbarButtonStyles } from './toolbar-item-styles.js';
12
+ import { ToolbarItemMixin } from './toolbar-item-mixin.js';
13
+
14
+ /**
15
+ * A toolbar button that opens a dropdown
16
+ */
17
+ class ToolbarDropdown extends FocusMixin(DropdownOpenerMixin(SlottedIconMixin(ToolbarItemMixin(ThemeMixin(PropertyRequiredMixin(LitElement)))))) {
18
+
19
+ static properties = {
20
+ /**
21
+ * Disables the toolbar button
22
+ * @type {boolean}
23
+ */
24
+ disabled: { type: Boolean },
25
+ /**
26
+ * ACCESSIBILITY: REQUIRED: Accessible text for the button
27
+ * @type {string}
28
+ */
29
+ text: { type: String, required: true },
30
+ /**
31
+ * Text describing the value
32
+ * @type {string}
33
+ */
34
+ valueText: { type: String, attribute: 'value-text' }
35
+ };
36
+
37
+ static styles = [super.styles, dropdownOpenerStyles, offscreenStyles, toolbarButtonStyles, css`
38
+ :host {
39
+ font-size: 1rem;
40
+ }
41
+ button {
42
+ align-items: center;
43
+ display: flex;
44
+ font-size: 0.7rem;
45
+ gap: 3px;
46
+ justify-content: center;
47
+ overflow: hidden;
48
+ padding-inline: 6px 4px;
49
+ text-align: start;
50
+ width: 100%;
51
+ }
52
+ button > .value-text {
53
+ flex: auto;
54
+ overflow: hidden;
55
+ text-overflow: ellipsis;
56
+ white-space: nowrap;
57
+ }
58
+ button[aria-expanded="true"] .background {
59
+ background-color: var(--d2l-theme-background-color-interactive-secondary-default);
60
+ transform: scale(1, 1);
61
+ }
62
+ :host([theme="dark"]) button[aria-expanded="true"] .background {
63
+ background-color: var(--d2l-color-tungsten);
64
+ transform: scale(1, 1);
65
+ }
66
+ .tooltip-hidden {
67
+ display: none;
68
+ }
69
+ `];
70
+
71
+ constructor() {
72
+ super();
73
+ this.disabled = false;
74
+ this.text = '';
75
+ }
76
+
77
+ static get focusElementSelector() {
78
+ return 'button';
79
+ }
80
+
81
+ get opened() {
82
+ return this.dropdownOpened;
83
+ }
84
+
85
+ render() {
86
+ const tooltipClasses = {
87
+ 'tooltip-hidden': this.opened,
88
+ 'vdiff-target': true
89
+ };
90
+ return html`
91
+ <button
92
+ aria-disabled="${this.disabled ? 'true' : 'false'}"
93
+ aria-label="${this.text}"
94
+ id="opener"
95
+ @keydown="${this.#handleKeyDown}"
96
+ tabindex="${this._activeFocusable ? 0 : -1}"
97
+ type="button">
98
+ <div class="background"></div>
99
+ ${this._renderIcon()}
100
+ ${this.valueText ? html`<div class="value-text">${this.valueText}</div>` : nothing}
101
+ <d2l-icon icon="tier1:chevron-down-small"></d2l-icon>
102
+ </button>
103
+ <d2l-tooltip class="${classMap(tooltipClasses)}" for="opener">
104
+ ${this.text}
105
+ <span class="d2l-offscreen">${this.valueText}</span>
106
+ </d2l-tooltip>
107
+ <slot></slot>
108
+ `;
109
+ }
110
+
111
+ updated(changedProperties) {
112
+ if (changedProperties.has('disabled') && this.disabled && this.opened) {
113
+ this.closeDropdown(false);
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Gets the "button" opener element (required by dropdown-opener-mixin).
119
+ * @return {HTMLElement}
120
+ */
121
+ getOpenerElement() {
122
+ return this.shadowRoot?.querySelector('button');
123
+ }
124
+
125
+ #handleKeyDown(e) {
126
+ if (e.key !== 'ArrowUp' && e.key !== 'ArrowDown') return;
127
+
128
+ // prevent scroll for up & down keys
129
+ e.preventDefault();
130
+
131
+ if ((e.key === 'ArrowDown' && !this.opened) || (e.key === 'ArrowUp' && this.opened)) this.toggleOpen(true);
132
+ }
133
+
134
+ }
135
+
136
+ customElements.define('d2l-toolbar-dropdown', ToolbarDropdown);
@@ -44,11 +44,10 @@ export const toolbarButtonStyles = css`
44
44
  .background {
45
45
  background-color: transparent;
46
46
  border-radius: 4px;
47
- height: 100%;
47
+ inset: 0;
48
48
  position: absolute;
49
49
  transform: scale(0.89, 0.89);
50
50
  transition: background-color 100ms linear, transform 100ms linear;
51
- width: 100%;
52
51
  z-index: -1;
53
52
  }
54
53
  ${getFocusRingStyles('button')}
@@ -17590,6 +17590,117 @@
17590
17590
  }
17591
17591
  ]
17592
17592
  },
17593
+ {
17594
+ "name": "d2l-toolbar-dropdown",
17595
+ "path": "./components/toolbar/toolbar-dropdown.js",
17596
+ "description": "A toolbar button that opens a dropdown",
17597
+ "attributes": [
17598
+ {
17599
+ "name": "value-text",
17600
+ "description": "Text describing the value",
17601
+ "type": "string"
17602
+ },
17603
+ {
17604
+ "name": "text",
17605
+ "description": "ACCESSIBILITY: REQUIRED: Accessible text for the button",
17606
+ "type": "string",
17607
+ "default": "\"\""
17608
+ },
17609
+ {
17610
+ "name": "no-auto-open",
17611
+ "description": "Prevents the dropdown from opening automatically on or on key press",
17612
+ "type": "boolean",
17613
+ "default": "false"
17614
+ },
17615
+ {
17616
+ "name": "open-on-hover",
17617
+ "description": "Optionally open dropdown on click or hover action",
17618
+ "type": "boolean",
17619
+ "default": "false"
17620
+ },
17621
+ {
17622
+ "name": "disabled",
17623
+ "description": "Disables the toolbar button",
17624
+ "type": "boolean",
17625
+ "default": "false"
17626
+ },
17627
+ {
17628
+ "name": "icon",
17629
+ "description": "Preset icon key (e.g. \"tier1:gear\")",
17630
+ "type": "string"
17631
+ }
17632
+ ],
17633
+ "properties": [
17634
+ {
17635
+ "name": "valueText",
17636
+ "attribute": "value-text",
17637
+ "description": "Text describing the value",
17638
+ "type": "string"
17639
+ },
17640
+ {
17641
+ "name": "styles",
17642
+ "type": "array",
17643
+ "default": "[\"styles\",\"dropdownOpenerStyles\",\"offscreenStyles\",\"toolbarButtonStyles\",null]"
17644
+ },
17645
+ {
17646
+ "name": "opened"
17647
+ },
17648
+ {
17649
+ "name": "text",
17650
+ "attribute": "text",
17651
+ "description": "ACCESSIBILITY: REQUIRED: Accessible text for the button",
17652
+ "type": "string",
17653
+ "default": "\"\""
17654
+ },
17655
+ {
17656
+ "name": "dropdownOpener",
17657
+ "type": "boolean",
17658
+ "default": "true"
17659
+ },
17660
+ {
17661
+ "name": "noAutoOpen",
17662
+ "attribute": "no-auto-open",
17663
+ "description": "Prevents the dropdown from opening automatically on or on key press",
17664
+ "type": "boolean",
17665
+ "default": "false"
17666
+ },
17667
+ {
17668
+ "name": "openOnHover",
17669
+ "attribute": "open-on-hover",
17670
+ "description": "Optionally open dropdown on click or hover action",
17671
+ "type": "boolean",
17672
+ "default": "false"
17673
+ },
17674
+ {
17675
+ "name": "disabled",
17676
+ "attribute": "disabled",
17677
+ "description": "Disables the toolbar button",
17678
+ "type": "boolean",
17679
+ "default": "false"
17680
+ },
17681
+ {
17682
+ "name": "dropdownOpened",
17683
+ "type": "boolean",
17684
+ "default": "false"
17685
+ },
17686
+ {
17687
+ "name": "icon",
17688
+ "attribute": "icon",
17689
+ "description": "Preset icon key (e.g. \"tier1:gear\")",
17690
+ "type": "string"
17691
+ },
17692
+ {
17693
+ "name": "isToolbarItem",
17694
+ "type": "boolean"
17695
+ }
17696
+ ],
17697
+ "events": [
17698
+ {
17699
+ "name": "d2l-dropdown-opener-click",
17700
+ "description": "Dispatched when the opener is clicked, useful for when no-auto-open is enabled"
17701
+ }
17702
+ ]
17703
+ },
17593
17704
  {
17594
17705
  "name": "d2l-toolbar-separator",
17595
17706
  "path": "./components/toolbar/toolbar-separator.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "3.327.2",
3
+ "version": "3.328.0",
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",