@brightspace-ui-labs/facet-filter-sort 4.1.5 → 4.2.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.
package/README.md CHANGED
@@ -28,14 +28,64 @@ npm install @brightspace-ui-labs/facet-filter-sort
28
28
 
29
29
  ## Components
30
30
 
31
- - [d2l-labs-filter-dropdown](#d2l-labs-filter-dropdown)
32
31
  - [d2l-labs-search-facets](#d2l-labs-search-facets)
33
32
  - [d2l-labs-search-results-count](#d2l-labs-search-results-count)
34
33
  - [d2l-labs-sort-by-dropdown](#d2l-labs-sort-by-dropdown)
34
+ - [d2l-labs-applied-core-filters](#d2l-labs-applied-core-filters)
35
+
36
+ ### d2l-labs-search-facets
37
+
38
+ <img src="/images/d2l-labs-search-facets.png?raw=true" width="450">
39
+
40
+ #### Usage
41
+
42
+ To Do
43
+
44
+ ### d2l-labs-search-results-count
45
+
46
+ <img src="/images/d2l-labs-search-results-count.png?raw=true" width="450">
47
+
48
+ #### Usage
49
+
50
+ To Do
51
+
52
+ ### d2l-labs-sort-by-dropdown
53
+
54
+ <img src="/images/d2l-labs-sort-by-dropdown.png?raw=true" width="450">
55
+
56
+ #### Usage
57
+
58
+ To Do
59
+
60
+ ### d2l-labs-applied-core-filters
61
+
62
+ The same design as the deprecated `d2l-labs-applied-filters` below, but this version works with the `d2l-filter` component in `core`. It supports hooking up to multiple filters and will be migrated to `core` once designs are finalized.
63
+
64
+ #### Attributes
65
+
66
+ - `filter-ids`: Ids (space-delimited) of the filter components to subscribe to
67
+ - `label-text` (optional): The text displayed in this component's label. Defaults to "Applied Filters:".
68
+
69
+ #### Usage
70
+
71
+ Set the `filter-ids` param to the ids of the `d2l-filter`s that you want to track.
72
+ The `d2l-filter`s must be in the same DOM scope.
73
+
74
+ ```html
75
+ <d2l-filter id="course"> ... </d2l-filter>
76
+ <d2l-filter id="role"> ... </d2l-filter>
77
+ <d2l-labs-applied-core-filters filter-ids="course role"></d2l-labs-applied-core-filters>
78
+ ```
79
+
80
+ ## Deprecated Components
81
+
82
+ - [d2l-labs-filter-dropdown](#d2l-labs-filter-dropdown)
35
83
  - [d2l-labs-applied-filters](#d2l-labs-applied-filters)
36
84
 
37
85
  ### d2l-labs-filter-dropdown
38
86
 
87
+ **DEPRECATED: Use [`d2l-filter`](https://github.com/BrightspaceUI/core/tree/main/components/filter) in `BrightspaceUI/core`.**
88
+
39
89
  <img src="/images/d2l-labs-filter-dropdown.png?raw=true" width="450">
40
90
 
41
91
  #### Usage
@@ -124,33 +174,9 @@ Note that for the header and opener text overrides, if the terms are to reflect
124
174
  - `d2l-labs-filter-dropdown-category-searched`: Fired when a filter category is searched.
125
175
  - `d2l-labs-filter-dropdown-option-change`: Fired when a filter option is selected.
126
176
 
127
- ### d2l-labs-search-facets
128
-
129
- <img src="/images/d2l-labs-search-facets.png?raw=true" width="450">
130
-
131
- #### Usage
132
-
133
- To Do
134
-
135
- ### d2l-labs-search-results-count
136
-
137
- <img src="/images/d2l-labs-search-results-count.png?raw=true" width="450">
138
-
139
- #### Usage
140
-
141
- To Do
142
-
143
- ### d2l-labs-sort-by-dropdown
144
-
145
- <img src="/images/d2l-labs-sort-by-dropdown.png?raw=true" width="450">
146
-
147
- #### Usage
148
-
149
- To Do
150
-
151
177
  ### d2l-labs-applied-filters
152
178
 
153
- A multi-select-list allowing the user to see (and remove) the currently applied filters.
179
+ A multi-select-list allowing the user to see (and remove) the currently applied filters. Works with the `d2l-labs-filter-dropdown` above. If you are using `d2l-filter` from `core`, see [d2l-labs-applied-core-filters](#d2l-labs-applied-core-filters).
154
180
 
155
181
  NOTE: This component uses the `slotchange` event and so will not work if you require IE support
156
182
 
@@ -166,7 +192,6 @@ NOTE: This component uses the `slotchange` event and so will not work if you req
166
192
  Set the `for` param to be the id of the `d2l-labs-filter-dropdown` that you want to track.
167
193
  This also works if the `d2l-labs-filter-dropdown` is a child in the shadow-dom of the element referenced by the id.
168
194
 
169
-
170
195
  ```html
171
196
  <d2l-labs-applied-filters for="filter"></d2l-labs-applied-filters>
172
197
  <d2l-labs-filter-dropdown id="filter"> ... </d2l-labs-filter-dropdown>
@@ -0,0 +1,204 @@
1
+ /* eslint sort-imports: ["error", {"allowSeparatedGroups": true}] */
2
+ import '@brightspace-ui-labs/multi-select/multi-select-list.js';
3
+ import '@brightspace-ui-labs/multi-select/multi-select-list-item.js';
4
+ import { LitElement, css, html } from 'lit-element';
5
+ import { IdSubscriberController } from '@brightspace-ui/core/controllers/subscriber/subscriberControllers.js';
6
+ import { LocalizeStaticMixin } from '@brightspace-ui/core/mixins/localize-static-mixin.js';
7
+ import { RtlMixin } from '@brightspace-ui/core/mixins/rtl-mixin.js';
8
+ import { announce } from '@brightspace-ui/core/helpers/announce.js';
9
+ import { bodyCompactStyles } from '@brightspace-ui/core/components/typography/styles.js';
10
+
11
+ import ar from './lang/ar-sa.js';
12
+ import de from './lang/de.js';
13
+ import en from './lang/en.js';
14
+ import es from './lang/es.js';
15
+ import esMx from './lang/es-mx.js';
16
+ import fi from './lang/fi.js';
17
+ import fr from './lang/fr.js';
18
+ import frCa from './lang/fr-ca.js';
19
+ import ja from './lang/ja.js';
20
+ import ko from './lang/ko.js';
21
+ import nb from './lang/nb.js';
22
+ import nl from './lang/nl.js';
23
+ import pt from './lang/pt-br.js';
24
+ import sv from './lang/sv.js';
25
+ import tr from './lang/tr.js';
26
+ import zhCn from './lang/zh-cn.js';
27
+ import zhTw from './lang/zh-tw.js';
28
+
29
+ const CLEAR_FILTERS_THRESHOLD = 4;
30
+
31
+ /**
32
+ * A multi-select-list allowing the user to see (and remove) the currently applied filters, adjusted to work with the new core d2l-filter.
33
+ */
34
+ class D2lLabsAppliedCoreFilters extends RtlMixin(LocalizeStaticMixin(LitElement)) {
35
+ static get properties() {
36
+ return {
37
+ /**
38
+ * Ids (space-delimited) of the filter components to subscribe to
39
+ * @type {string}
40
+ */
41
+ filterIds: { type: String, attribute: 'filter-ids' },
42
+ /**
43
+ * Optional: The text displayed in this component's label. Default: "Applied Filters:"
44
+ */
45
+ labelText: { type: String, attribute: 'label-text' }
46
+ };
47
+ }
48
+
49
+ static get styles() {
50
+ return [bodyCompactStyles, css`
51
+ :host {
52
+ display: block;
53
+ }
54
+
55
+ d2l-labs-multi-select-list {
56
+ flex: 1;
57
+ }
58
+
59
+ .d2l-labs-applied-filters-wrapper {
60
+ display: flex;
61
+ }
62
+
63
+ .d2l-labs-applied-filters-label {
64
+ margin-right: 0.25rem;
65
+ display: inline-block;
66
+ padding-top: 0.3rem;
67
+ font-weight: bold;
68
+ }
69
+
70
+ :host([dir="rtl"]) .d2l-labs-applied-filters-label {
71
+ margin-right: 0;
72
+ margin-left: 0.25rem;
73
+ }
74
+
75
+ .d2l-labs-applied-filters-none-label {
76
+ display: inline-block;
77
+ padding-top: 0.3rem;
78
+ font-style: italic;
79
+ color: var(--d2l-color-corundum);
80
+ }
81
+
82
+ #d2l-clear-filters-button {
83
+ margin-left: 3px;
84
+ margin-right: 3px;
85
+ }
86
+
87
+ #d2l-list-holder {
88
+ flex: 1;
89
+ }
90
+
91
+ :host([hidden]) {
92
+ display: none;
93
+ }
94
+
95
+ [hidden] {
96
+ display: none;
97
+ }
98
+ `];
99
+ }
100
+
101
+ static get resources() {
102
+ return {
103
+ 'ar': ar,
104
+ 'de': de,
105
+ 'en': en,
106
+ 'es': es,
107
+ 'es-mx': esMx,
108
+ 'fi': fi,
109
+ 'fr': fr,
110
+ 'fr-ca': frCa,
111
+ 'ja': ja,
112
+ 'ko': ko,
113
+ 'nb': nb,
114
+ 'nl': nl,
115
+ 'pt': pt,
116
+ 'sv': sv,
117
+ 'tr': tr,
118
+ 'zh-cn': zhCn,
119
+ 'zh-tw': zhTw,
120
+ };
121
+ }
122
+
123
+ constructor() {
124
+ super();
125
+ this.labelText = '';
126
+
127
+ this._allActiveFilters = new Map();
128
+ this._filters = new IdSubscriberController(this,
129
+ { onUnsubscribe: this._removeLostFilter.bind(this) },
130
+ { idPropertyName: 'filterIds' }
131
+ );
132
+ }
133
+
134
+ disconnectedCallback() {
135
+ super.disconnectedCallback();
136
+ this._filters.hostDisconnected();
137
+ }
138
+
139
+ render() {
140
+ let numActiveFilters = 0;
141
+ const allActiveFilters = Array.from(this._allActiveFilters);
142
+ let filters = html`
143
+ <d2l-labs-multi-select-list
144
+ collapsable
145
+ aria-labelledby="d2l-labs-applied-filters-label">
146
+ ${allActiveFilters.map(filter => filter[1].map((value, index) => { numActiveFilters++; return html`
147
+ <d2l-labs-multi-select-list-item
148
+ text="${value.text}"
149
+ deletable
150
+ data-filter-id="${filter[0]}"
151
+ data-index="${index}"
152
+ @d2l-labs-multi-select-list-item-deleted="${this._multiSelectItemDeleted}">
153
+ </d2l-labs-multi-select-list-item>
154
+ `;}))}
155
+ </d2l-labs-multi-select-list>
156
+ `;
157
+ if (numActiveFilters === 0) filters = html`<span class="d2l-labs-applied-filters-none-label d2l-body-compact">${this.localize('noActiveFilters')}</span>`;
158
+
159
+ return html`
160
+ <div class="d2l-labs-applied-filters-wrapper">
161
+ <span id="d2l-labs-applied-filters-label" class="d2l-labs-applied-filters-label d2l-body-compact">${this.labelText || this.localize('appliedFilters')}</span>
162
+ <div id="d2l-list-holder">
163
+ ${filters}
164
+ <d2l-button-subtle id="d2l-clear-filters-button" text="${this.localize('clearFilters')}" ?hidden="${numActiveFilters < CLEAR_FILTERS_THRESHOLD}" @click="${this._clearFiltersClicked}"></d2l-button-subtle>
165
+ </div>
166
+ </div>
167
+ `;
168
+ }
169
+
170
+ updated(changedProperties) {
171
+ super.updated(changedProperties);
172
+ this._filters.hostUpdated(changedProperties);
173
+ }
174
+
175
+ updateActiveFilters(filterId, activeFilters) {
176
+ this._allActiveFilters.set(filterId, activeFilters);
177
+ this.requestUpdate();
178
+ }
179
+
180
+ _clearFiltersClicked() {
181
+ this._filters.registries.forEach((filter, index) => {
182
+ if (index === 0) filter.focus();
183
+ filter.requestFilterClearAll();
184
+ });
185
+ }
186
+
187
+ _multiSelectItemDeleted(e) {
188
+ const filterId = e.target.getAttribute('data-filter-id');
189
+ const filterValueIndex = e.target.getAttribute('data-index');
190
+ const filterValue = this._allActiveFilters.get(filterId)[filterValueIndex];
191
+ const filter = this._filters.registries.find(filter => filter.id === filterId);
192
+ filter.requestFilterValueClear(filterValue.keyObject);
193
+
194
+ announce(this.localize('filterRemoved', 'filterText', e.target.text));
195
+ }
196
+
197
+ _removeLostFilter(filterId) {
198
+ this._allActiveFilters.delete(filterId);
199
+ this.requestUpdate();
200
+ }
201
+
202
+ }
203
+
204
+ customElements.define('d2l-labs-applied-core-filters', D2lLabsAppliedCoreFilters);
@@ -1,6 +1,39 @@
1
1
  {
2
2
  "version": "experimental",
3
3
  "tags": [
4
+ {
5
+ "name": "d2l-labs-applied-core-filters",
6
+ "path": "./components/applied-filters/applied-core-filters.js",
7
+ "description": "A multi-select-list allowing the user to see (and remove) the currently applied filters, adjusted to work with the new core d2l-filter.",
8
+ "attributes": [
9
+ {
10
+ "name": "filter-ids",
11
+ "description": "Ids (space-delimited) of the filter components to subscribe to",
12
+ "type": "string"
13
+ },
14
+ {
15
+ "name": "label-text",
16
+ "description": "Optional: The text displayed in this component's label. Default: \"Applied Filters:\"",
17
+ "type": "string",
18
+ "default": "\"\""
19
+ }
20
+ ],
21
+ "properties": [
22
+ {
23
+ "name": "filterIds",
24
+ "attribute": "filter-ids",
25
+ "description": "Ids (space-delimited) of the filter components to subscribe to",
26
+ "type": "string"
27
+ },
28
+ {
29
+ "name": "labelText",
30
+ "attribute": "label-text",
31
+ "description": "Optional: The text displayed in this component's label. Default: \"Applied Filters:\"",
32
+ "type": "string",
33
+ "default": "\"\""
34
+ }
35
+ ]
36
+ },
4
37
  {
5
38
  "name": "d2l-labs-applied-filters",
6
39
  "path": "./components/applied-filters/applied-filters.js",
package/package.json CHANGED
@@ -34,7 +34,7 @@
34
34
  "polymer-cli": "^1",
35
35
  "wct-browser-legacy": "^1"
36
36
  },
37
- "version": "4.1.5",
37
+ "version": "4.2.0",
38
38
  "dependencies": {
39
39
  "@brightspace-ui/core": "^1",
40
40
  "d2l-localize-behavior": "BrightspaceUI/localize-behavior#semver:^2",