@brightspace-ui-labs/facet-filter-sort 6.1.3 → 6.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.
|
@@ -3,9 +3,12 @@ import '@brightspace-ui/core/components/inputs/input-search.js';
|
|
|
3
3
|
import '@brightspace-ui/core/components/menu/menu.js';
|
|
4
4
|
import { css, html, LitElement } from 'lit';
|
|
5
5
|
import { FilterLocalizeMixin } from '../localize-mixin.js';
|
|
6
|
+
import { getFlag } from '@brightspace-ui/core/helpers/flags.js';
|
|
6
7
|
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
7
8
|
import { TabPanelMixin } from '@brightspace-ui/core/components/tabs/tab-panel-mixin.js';
|
|
8
9
|
|
|
10
|
+
const useTabsNewStructure = getFlag('GAUD-7146-tabs-new-structure', false);
|
|
11
|
+
|
|
9
12
|
/**
|
|
10
13
|
* A component wrapping grouped filters
|
|
11
14
|
* @slot - Contains the filters (e.g., d2l-labs-filter-dropdown-option) that are in the category
|
|
@@ -102,9 +105,12 @@ class LabsFilterDropdownCategory extends FilterLocalizeMixin(TabPanelMixin(LitEl
|
|
|
102
105
|
this.selected = !this.selected;
|
|
103
106
|
this.__onSelect(e);
|
|
104
107
|
});
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
+
|
|
109
|
+
if (!useTabsNewStructure) {
|
|
110
|
+
this.addEventListener('d2l-tab-panel-selected', () => {
|
|
111
|
+
this._dispatchSelected();
|
|
112
|
+
});
|
|
113
|
+
}
|
|
108
114
|
}
|
|
109
115
|
|
|
110
116
|
render() {
|
|
@@ -2,12 +2,11 @@ import '@brightspace-ui/core/components/icons/icon.js';
|
|
|
2
2
|
import { css, html, LitElement } from 'lit';
|
|
3
3
|
import { MenuItemSelectableMixin } from '@brightspace-ui/core/components/menu/menu-item-selectable-mixin.js';
|
|
4
4
|
import { menuItemSelectableStyles } from '@brightspace-ui/core/components/menu/menu-item-selectable-styles.js';
|
|
5
|
-
import { RtlMixin } from '@brightspace-ui/core/mixins/rtl-mixin.js';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* A filter menu item component.
|
|
9
8
|
*/
|
|
10
|
-
class LabsFilterDropdownOption extends
|
|
9
|
+
class LabsFilterDropdownOption extends MenuItemSelectableMixin(LitElement) {
|
|
11
10
|
|
|
12
11
|
static get styles() {
|
|
13
12
|
return [menuItemSelectableStyles, css`
|
|
@@ -3,10 +3,14 @@ import '@brightspace-ui/core/components/colors/colors.js';
|
|
|
3
3
|
import '@brightspace-ui/core/components/dropdown/dropdown-button-subtle.js';
|
|
4
4
|
import '@brightspace-ui/core/components/dropdown/dropdown-tabs.js';
|
|
5
5
|
import '@brightspace-ui/core/components/tabs/tabs.js';
|
|
6
|
+
import '@brightspace-ui/core/components/tabs/tab.js';
|
|
6
7
|
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
|
|
8
|
+
import { getFlag } from '@brightspace-ui/core/helpers/flags.js';
|
|
7
9
|
import { LocalizeBehavior } from '../localize-behavior.js';
|
|
8
10
|
import { mixinBehaviors } from '@polymer/polymer/lib/legacy/class.js';
|
|
9
11
|
|
|
12
|
+
const useTabsNewStructure = getFlag('GAUD-7146-tabs-new-structure', false);
|
|
13
|
+
|
|
10
14
|
/**
|
|
11
15
|
* A component containing filter options and emitting selection events
|
|
12
16
|
* @slot - Contents of the dropdown, including filter categories and options
|
|
@@ -87,6 +91,14 @@ class D2LLabsFilterDropdown extends mixinBehaviors([LocalizeBehavior], PolymerEl
|
|
|
87
91
|
noPaddingFooter: {
|
|
88
92
|
type: Boolean,
|
|
89
93
|
value: false
|
|
94
|
+
},
|
|
95
|
+
_useNewStructure: {
|
|
96
|
+
type: Boolean,
|
|
97
|
+
value: useTabsNewStructure
|
|
98
|
+
},
|
|
99
|
+
_tabInfos: {
|
|
100
|
+
type: Array,
|
|
101
|
+
value: () => []
|
|
90
102
|
}
|
|
91
103
|
};
|
|
92
104
|
}
|
|
@@ -127,7 +139,15 @@ class D2LLabsFilterDropdown extends mixinBehaviors([LocalizeBehavior], PolymerEl
|
|
|
127
139
|
<d2l-button-subtle text="[[localize('clear')]]" hidden$="[[!totalSelectedOptionCount]]" on-click="clearFilters"></d2l-button-subtle>
|
|
128
140
|
</div>
|
|
129
141
|
<d2l-tabs>
|
|
130
|
-
<
|
|
142
|
+
<template is="dom-if" if="[[!_useNewStructure]]">
|
|
143
|
+
<slot></slot>
|
|
144
|
+
</template>
|
|
145
|
+
<template is="dom-if" if="[[_useNewStructure]]">
|
|
146
|
+
<template is="dom-repeat" items="[[_tabInfos]]" as="tab">
|
|
147
|
+
<d2l-tab id="[[tab.key]]" text="[[tab.text]]" slot="tabs" selected$="[[tab.selected]]"></d2l-tab>
|
|
148
|
+
</template>
|
|
149
|
+
<slot on-slotchange="_handleCategoriesSlotChange" slot="panels"></slot>
|
|
150
|
+
</template>
|
|
131
151
|
</d2l-tabs>
|
|
132
152
|
<slot name="footer" slot="[[_getFooterSlotValue(_hasFooter)]]" on-slotchange="_handleFooterSlotChange"></slot>
|
|
133
153
|
</d2l-dropdown-tabs>
|
|
@@ -137,7 +157,12 @@ class D2LLabsFilterDropdown extends mixinBehaviors([LocalizeBehavior], PolymerEl
|
|
|
137
157
|
|
|
138
158
|
attached() {
|
|
139
159
|
this.addEventListener('d2l-dropdown-close', this._handleDropdownClose);
|
|
140
|
-
|
|
160
|
+
|
|
161
|
+
if (this._useNewStructure) {
|
|
162
|
+
this.addEventListener('d2l-tab-selected', this._handleTabSelected);
|
|
163
|
+
} else {
|
|
164
|
+
this.addEventListener('d2l-tab-panel-selected', this._stopTabPanelSelectedEvent);
|
|
165
|
+
}
|
|
141
166
|
}
|
|
142
167
|
|
|
143
168
|
clearFilters() {
|
|
@@ -158,7 +183,19 @@ class D2LLabsFilterDropdown extends mixinBehaviors([LocalizeBehavior], PolymerEl
|
|
|
158
183
|
|
|
159
184
|
detached() {
|
|
160
185
|
this.removeEventListener('d2l-dropdown-close', this._handleDropdownClose);
|
|
161
|
-
|
|
186
|
+
|
|
187
|
+
if (this._useNewStructure) {
|
|
188
|
+
this.removeEventListener('d2l-tab-selected', this._handleTabSelected);
|
|
189
|
+
const categories = this.querySelectorAll('d2l-labs-filter-dropdown-category');
|
|
190
|
+
categories.forEach(cat => {
|
|
191
|
+
if (cat.__tabInfoObserver) {
|
|
192
|
+
cat.__tabInfoObserver.disconnect();
|
|
193
|
+
delete cat.__tabInfoObserver;
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
} else {
|
|
197
|
+
this.removeEventListener('d2l-tab-panel-selected', this._stopTabPanelSelectedEvent);
|
|
198
|
+
}
|
|
162
199
|
}
|
|
163
200
|
|
|
164
201
|
focus() {
|
|
@@ -181,6 +218,41 @@ class D2LLabsFilterDropdown extends mixinBehaviors([LocalizeBehavior], PolymerEl
|
|
|
181
218
|
return this._localizeOrAlt(openerTextMultiple, 'filterMultiple', 'numOptions', totalSelectedOptionCount);
|
|
182
219
|
}
|
|
183
220
|
|
|
221
|
+
async _handleCategoriesSlotChange() {
|
|
222
|
+
if (!this._useNewStructure) return;
|
|
223
|
+
|
|
224
|
+
const tabsContainer = this.shadowRoot.querySelector('d2l-tabs');
|
|
225
|
+
const categories = this.querySelectorAll('d2l-labs-filter-dropdown-category');
|
|
226
|
+
|
|
227
|
+
if (!tabsContainer || !categories || categories.length === 0) return;
|
|
228
|
+
|
|
229
|
+
// Build tabInfos which is used to render d2l-tab components
|
|
230
|
+
const tabInfos = [];
|
|
231
|
+
categories.forEach((category, index) => {
|
|
232
|
+
const key = category.getAttribute('key') || `category-${index}`;
|
|
233
|
+
const text = category.getAttribute('text');
|
|
234
|
+
const isSelected = category.hasAttribute('selected');
|
|
235
|
+
|
|
236
|
+
category.setAttribute('labelled-by', key);
|
|
237
|
+
tabInfos.push({ key, text, selected: isSelected });
|
|
238
|
+
|
|
239
|
+
if (!category.__tabInfoObserver) {
|
|
240
|
+
category.__tabInfoObserver = new MutationObserver(() => {
|
|
241
|
+
const newText = category.getAttribute('text');
|
|
242
|
+
const newSelected = category.hasAttribute('selected');
|
|
243
|
+
this._tabInfos = this._tabInfos.map(info => {
|
|
244
|
+
return info.key === key
|
|
245
|
+
? { ...info, text: newText, selected: newSelected }
|
|
246
|
+
: info;
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
category.__tabInfoObserver.observe(category, { attributes: true, attributeFilter: ['text', 'selected'] });
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
this._tabInfos = tabInfos;
|
|
254
|
+
}
|
|
255
|
+
|
|
184
256
|
_handleDropdownClose(e) {
|
|
185
257
|
e.stopPropagation();
|
|
186
258
|
this.dispatchEvent(
|
|
@@ -198,6 +270,19 @@ class D2LLabsFilterDropdown extends mixinBehaviors([LocalizeBehavior], PolymerEl
|
|
|
198
270
|
this._hasFooter = e.target.assignedNodes().length !== 0;
|
|
199
271
|
}
|
|
200
272
|
|
|
273
|
+
_handleTabSelected(e) {
|
|
274
|
+
e.stopPropagation();
|
|
275
|
+
if (!this._useNewStructure) return;
|
|
276
|
+
|
|
277
|
+
// Find the corresponding category and dispatch the selection event
|
|
278
|
+
const tabId = e.target.id;
|
|
279
|
+
const category = this.querySelector(`d2l-labs-filter-dropdown-category[key="${tabId}"]`);
|
|
280
|
+
|
|
281
|
+
if (category) {
|
|
282
|
+
category._dispatchSelected();
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
201
286
|
_localizeOrAlt(altText, ...args) {
|
|
202
287
|
if (!this.localize || !this.resources) return;
|
|
203
288
|
return altText ? altText : this.localize(...args);
|
|
@@ -2,12 +2,11 @@ import '@brightspace-ui/core/components/icons/icon.js';
|
|
|
2
2
|
import { html, LitElement } from 'lit';
|
|
3
3
|
import { MenuItemRadioMixin } from '@brightspace-ui/core/components/menu/menu-item-radio-mixin.js';
|
|
4
4
|
import { menuItemSelectableStyles } from '@brightspace-ui/core/components/menu/menu-item-selectable-styles.js';
|
|
5
|
-
import { RtlMixin } from '@brightspace-ui/core/mixins/rtl-mixin.js';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* A dropdown option menu item component.
|
|
9
8
|
*/
|
|
10
|
-
class LabsSortByDropdownOption extends
|
|
9
|
+
class LabsSortByDropdownOption extends MenuItemRadioMixin(LitElement) {
|
|
11
10
|
|
|
12
11
|
static get styles() {
|
|
13
12
|
return menuItemSelectableStyles;
|