@fluid-topics/ft-filter 1.3.28 → 1.3.29

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.
@@ -1,6 +1,10 @@
1
- import { ElementDefinitionsMap, FtLitElement } from "@fluid-topics/ft-wc-utils";
1
+ import { PropertyValues } from "lit";
2
+ import { Debouncer, ElementDefinitionsMap, FtLitElement } from "@fluid-topics/ft-wc-utils";
3
+ import { FtRadio } from "@fluid-topics/ft-radio";
2
4
  import { FtFilterOptionProperties } from "./ft-filter-option.properties";
3
- export declare class FtFilterLevel extends FtLitElement {
5
+ import { I18nAttributeValue } from "@fluid-topics/ft-i18n/build/decorators/i18nAttribute";
6
+ declare const FtFilterLevel_base: typeof FtLitElement & import("@fluid-topics/ft-wc-utils").Constructor<import("@fluid-topics/ft-wc-utils").FtLitElementWithAriaNotificationInterface> & import("@fluid-topics/ft-wc-utils").Constructor<import("@fluid-topics/ft-i18n").FtLitElementWithI18nInterface>;
7
+ export declare class FtFilterLevel extends FtFilterLevel_base {
4
8
  static elementDefinitions: ElementDefinitionsMap;
5
9
  static styles: import("lit").CSSResult;
6
10
  filterId: string;
@@ -11,19 +15,23 @@ export declare class FtFilterLevel extends FtLitElement {
11
15
  hideSelectedOptions: boolean;
12
16
  displayCount: boolean;
13
17
  preventNavigation: boolean;
14
- private filter;
15
- private moreValuesButtonLabel;
16
- private noValuesLabel?;
18
+ filter: string;
19
+ moreValuesButtonLabel: string;
20
+ noValuesLabel?: string;
21
+ filteredOptionsNumberAriaNotification?: I18nAttributeValue;
17
22
  displayedValuesLimit: number;
18
- private container?;
19
- private radios?;
20
- private displayedPages;
23
+ protected container?: HTMLDivElement;
24
+ protected radios?: FtRadio[];
25
+ protected displayedPages: number;
26
+ protected filteredOptions: FtFilterOptionProperties[];
27
+ protected ariaNotificationDebouncer: Debouncer;
21
28
  get hasHiddenValues(): boolean;
22
29
  private get limit();
23
30
  get height(): number;
24
31
  focusOnBackButton(): void;
25
32
  focusOnExpandButton(value: string): void;
26
33
  focusOnFirstOption(): void;
34
+ protected willUpdate(props: PropertyValues): void;
27
35
  protected render(): import("lit-html").TemplateResult<1>;
28
36
  private goBackOnKeyPress;
29
37
  private goBackOnClick;
@@ -33,4 +41,6 @@ export declare class FtFilterLevel extends FtLitElement {
33
41
  private onRadioKeyDown;
34
42
  private optionsChanged;
35
43
  private displayLevel;
44
+ protected updated(props: PropertyValues): void;
36
45
  }
46
+ export {};
@@ -7,15 +7,16 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  import { html, nothing } from "lit";
8
8
  import { property, query, state } from "lit/decorators.js";
9
9
  import { repeat } from "lit/directives/repeat.js";
10
- import { flatDeep, FtLitElement } from "@fluid-topics/ft-wc-utils";
10
+ import { Debouncer, flatDeep, FtLitElement, hasChanged, numberProperty, withAriaNotification } from "@fluid-topics/ft-wc-utils";
11
11
  import { FtButton } from "@fluid-topics/ft-button";
12
- import { FtTypography } from "@fluid-topics/ft-typography";
12
+ import { FtTypography, FtTypographyVariants } from "@fluid-topics/ft-typography";
13
13
  import { FtRipple } from "@fluid-topics/ft-ripple";
14
14
  import { FtIcon } from "@fluid-topics/ft-icon";
15
15
  import { FtCheckbox } from "@fluid-topics/ft-checkbox";
16
16
  import { FtRadio } from "@fluid-topics/ft-radio";
17
17
  import { levelStyles } from "./ft-filter-level.styles";
18
- class FtFilterLevel extends FtLitElement {
18
+ import { withI18n } from "@fluid-topics/ft-i18n";
19
+ class FtFilterLevel extends withI18n(withAriaNotification(FtLitElement)) {
19
20
  constructor() {
20
21
  super(...arguments);
21
22
  this.filterId = "";
@@ -29,9 +30,11 @@ class FtFilterLevel extends FtLitElement {
29
30
  this.moreValuesButtonLabel = "More";
30
31
  this.displayedValuesLimit = 0;
31
32
  this.displayedPages = 1;
33
+ this.filteredOptions = [];
34
+ this.ariaNotificationDebouncer = new Debouncer(500);
32
35
  }
33
36
  get hasHiddenValues() {
34
- let limit = this.limit;
37
+ const limit = this.limit;
35
38
  return limit != null && limit < this.options.length;
36
39
  }
37
40
  get limit() {
@@ -57,15 +60,23 @@ class FtFilterLevel extends FtLitElement {
57
60
  selector: `.ft-filter-level--option [part~="option"]`,
58
61
  };
59
62
  }
60
- render() {
61
- let options = [...this.options];
62
- if (this.hideSelectedOptions) {
63
- options = options.filter(o => !o.selected);
64
- }
65
- if (this.filter) {
66
- options = options.filter(o => o.label.toLowerCase().includes(this.filter.toLowerCase()));
63
+ willUpdate(props) {
64
+ super.willUpdate(props);
65
+ if (props.has("options") || props.has("hideSelectedOptions") || props.has("filter")) {
66
+ let options = [...this.options];
67
+ if (this.hideSelectedOptions) {
68
+ options = options.filter((o) => !o.selected);
69
+ }
70
+ if (this.filter) {
71
+ options = options.filter((o) => o.label.toLowerCase().includes(this.filter.toLowerCase()));
72
+ }
73
+ if (options != this.filteredOptions) {
74
+ this.filteredOptions = options;
75
+ }
67
76
  }
68
- const limitedOptions = options.slice(0, this.limit);
77
+ }
78
+ render() {
79
+ const limitedOptions = this.filteredOptions.slice(0, this.limit);
69
80
  return html `
70
81
  <div class="ft-filter-level--container ${this.disabled ? "ft-filter--disabled" : ""}">
71
82
  ${this.parent == null ? null : html `
@@ -79,15 +90,15 @@ class FtFilterLevel extends FtLitElement {
79
90
  @click=${this.goBackOnClick}>
80
91
  <ft-ripple></ft-ripple>
81
92
  <ft-icon>thin_arrow_left</ft-icon>
82
- <ft-typography variant="body2">${this.parent.label}</ft-typography>
93
+ <ft-typography variant="${FtTypographyVariants.body2}">${this.parent.label}</ft-typography>
83
94
  </div>
84
95
  `}
85
- ${this.options.length === 0 && this.noValuesLabel ? html `
86
- <ft-typography class="ft-filter-level--no-values" element="span" variant="body2">
96
+ ${this.filteredOptions.length === 0 && this.noValuesLabel ? html `
97
+ <ft-typography class="ft-filter-level--no-values" element="span" variant="${FtTypographyVariants.body2}">
87
98
  ${this.noValuesLabel}
88
99
  </ft-typography>
89
100
  ` : nothing}
90
- ${repeat(limitedOptions, option => option.value, option => {
101
+ ${repeat(limitedOptions, (option) => option.value, (option) => {
91
102
  var _a;
92
103
  return html `
93
104
  <div class="ft-filter-level--option" part="options" tabindex="-1">
@@ -108,7 +119,7 @@ class FtFilterLevel extends FtLitElement {
108
119
  </div>
109
120
  `;
110
121
  })}
111
- ${limitedOptions.length < options.length ? html `
122
+ ${limitedOptions.length < this.filteredOptions.length ? html `
112
123
  <ft-button
113
124
  class="ft-filter-level--display-more"
114
125
  icon="thin_arrow"
@@ -149,7 +160,7 @@ class FtFilterLevel extends FtLitElement {
149
160
  data-value="${option.value}"
150
161
  .checked=${option.selected}
151
162
  .disabled=${this.disabled}
152
- .indeterminate=${flatDeep((_a = option.subOptions) !== null && _a !== void 0 ? _a : [], o => { var _a; return (_a = o.subOptions) !== null && _a !== void 0 ? _a : []; }).some(o => o.selected)}
163
+ .indeterminate=${flatDeep((_a = option.subOptions) !== null && _a !== void 0 ? _a : [], (o) => { var _a; return (_a = o.subOptions) !== null && _a !== void 0 ? _a : []; }).some((o) => o.selected)}
153
164
  @change=${(e) => this.optionsChanged(e, option)}>
154
165
  ${option.renderOption ? option.renderOption : option.label}${this.displayCount ? ` (${option.count})` : ""}
155
166
  </ft-checkbox>
@@ -183,6 +194,21 @@ class FtFilterLevel extends FtLitElement {
183
194
  displayLevel(option) {
184
195
  this.dispatchEvent(new CustomEvent("display-level", { detail: option }));
185
196
  }
197
+ updated(props) {
198
+ super.updated(props);
199
+ if (props.has("filter")
200
+ && props.has("filteredOptions")
201
+ && props.get("filteredOptions") !== undefined
202
+ && props.get("filter") !== undefined) {
203
+ this.ariaNotificationDebouncer.run(async () => {
204
+ if (this.filteredOptionsNumberAriaNotification == undefined) {
205
+ return;
206
+ }
207
+ const notification = await this.awaitI18n({ ...this.filteredOptionsNumberAriaNotification, args: [this.filteredOptions.length] });
208
+ this.sendAriaNotification(notification);
209
+ });
210
+ }
211
+ }
186
212
  }
187
213
  FtFilterLevel.elementDefinitions = {
188
214
  "ft-button": FtButton,
@@ -201,7 +227,7 @@ __decorate([
201
227
  property({ type: Object })
202
228
  ], FtFilterLevel.prototype, "parent", void 0);
203
229
  __decorate([
204
- property({ type: Array })
230
+ property({ type: Array, hasChanged })
205
231
  ], FtFilterLevel.prototype, "options", void 0);
206
232
  __decorate([
207
233
  property({ type: Boolean })
@@ -228,7 +254,10 @@ __decorate([
228
254
  property({ type: String })
229
255
  ], FtFilterLevel.prototype, "noValuesLabel", void 0);
230
256
  __decorate([
231
- property({ type: Number })
257
+ property()
258
+ ], FtFilterLevel.prototype, "filteredOptionsNumberAriaNotification", void 0);
259
+ __decorate([
260
+ numberProperty()
232
261
  ], FtFilterLevel.prototype, "displayedValuesLimit", void 0);
233
262
  __decorate([
234
263
  query(".ft-filter-level--container")
@@ -239,4 +268,7 @@ __decorate([
239
268
  __decorate([
240
269
  state()
241
270
  ], FtFilterLevel.prototype, "displayedPages", void 0);
271
+ __decorate([
272
+ state()
273
+ ], FtFilterLevel.prototype, "filteredOptions", void 0);
242
274
  export { FtFilterLevel };
@@ -2,6 +2,7 @@ import { PropertyValues } from "lit";
2
2
  import { ElementDefinitionsMap, FtLitElement } from "@fluid-topics/ft-wc-utils";
3
3
  import { FtFilterProperties } from "./ft-filter.properties";
4
4
  import { FtFilterOptionProperties } from "./ft-filter-option.properties";
5
+ import { I18nAttributeValue } from "@fluid-topics/ft-i18n/build/decorators/i18nAttribute";
5
6
  export declare class FtFilterChangeEvent extends CustomEvent<Array<any>> {
6
7
  constructor(selectedValues: any[]);
7
8
  }
@@ -20,6 +21,7 @@ export declare class FtFilter extends FtLitElement implements FtFilterProperties
20
21
  raiseSelectedOptions: boolean;
21
22
  displayCount: boolean;
22
23
  displayedValuesLimit: number;
24
+ filteredOptionsNumberAriaNotification?: I18nAttributeValue;
23
25
  hideClearButton: boolean;
24
26
  private slotElement;
25
27
  private container?;
@@ -6,8 +6,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import { html } from "lit";
8
8
  import { property, query, queryAll, state } from "lit/decorators.js";
9
- import { Debouncer, deepEqual, flatDeep, FtLitElement, jsonProperty, waitUntil } from "@fluid-topics/ft-wc-utils";
10
- import { FtTypography } from "@fluid-topics/ft-typography";
9
+ import { Debouncer, deepEqual, flatDeep, FtLitElement, jsonProperty, numberProperty, waitUntil } from "@fluid-topics/ft-wc-utils";
10
+ import { FtTypography, FtTypographyVariants } from "@fluid-topics/ft-typography";
11
11
  import { FtFilterLevel } from "./ft-filter-level";
12
12
  import { FtButton } from "@fluid-topics/ft-button";
13
13
  import { FtSnapScroll } from "@fluid-topics/ft-snap-scroll";
@@ -43,16 +43,16 @@ class FtFilter extends FtLitElement {
43
43
  this.lastDispatchedValues = [];
44
44
  }
45
45
  get flatOptions() {
46
- return flatDeep(this.options, o => { var _a; return (_a = o.subOptions) !== null && _a !== void 0 ? _a : []; });
46
+ return flatDeep(this.options, (o) => { var _a; return (_a = o.subOptions) !== null && _a !== void 0 ? _a : []; });
47
47
  }
48
48
  get childrenFilteredFlatOptions() {
49
- return flatDeep(this.options, o => { var _a; return o.selected ? [] : ((_a = o.subOptions) !== null && _a !== void 0 ? _a : []); });
49
+ return flatDeep(this.options, (o) => { var _a; return o.selected ? [] : ((_a = o.subOptions) !== null && _a !== void 0 ? _a : []); });
50
50
  }
51
51
  get selectedValues() {
52
- return this.childrenFilteredFlatOptions.filter(o => o.selected).map(o => o.value);
52
+ return this.childrenFilteredFlatOptions.filter((o) => o.selected).map((o) => o.value);
53
53
  }
54
54
  render() {
55
- const valuesSelected = this.flatOptions.some(o => o.selected);
55
+ const valuesSelected = this.flatOptions.some((o) => o.selected);
56
56
  const showFilter = this.withScroll || this.filter || this.lastLevelHasHiddenvalues;
57
57
  const placeholder = this.filterPlaceHolder.replace("{0}", this.label);
58
58
  return html `
@@ -62,7 +62,7 @@ class FtFilter extends FtLitElement {
62
62
 
63
63
  <div class="ft-filter--header" part="header">
64
64
  <div class="filter-label" id="id-group-${this.id}">
65
- <ft-typography class="ft-filter--label" variant="overline" part="label">
65
+ <ft-typography class="ft-filter--label" variant="${FtTypographyVariants.overline}" part="label">
66
66
  ${this.label}
67
67
  </ft-typography>
68
68
  <slot name="label"></slot>
@@ -103,8 +103,8 @@ class FtFilter extends FtLitElement {
103
103
  update(props) {
104
104
  super.update(props);
105
105
  if (props.has("options")) {
106
- const newValues = new Set(this.flatOptions.map(o => o.value));
107
- this.displayedLevels = this.displayedLevels.filter(value => newValues.has(value));
106
+ const newValues = new Set(this.flatOptions.map((o) => o.value));
107
+ this.displayedLevels = this.displayedLevels.filter((value) => newValues.has(value));
108
108
  this.lastDispatchedValues = this.selectedValues;
109
109
  }
110
110
  }
@@ -138,7 +138,7 @@ class FtFilter extends FtLitElement {
138
138
  }
139
139
  renderLevels() {
140
140
  const allOptions = this.flatOptions;
141
- const selectedOptions = allOptions.filter(o => o.selected);
141
+ const selectedOptions = allOptions.filter((o) => o.selected);
142
142
  const currentLevelIndex = (this.slideIn || this.slideOut)
143
143
  ? this.displayedLevels.length - 2
144
144
  : this.displayedLevels.length - 1;
@@ -149,12 +149,13 @@ class FtFilter extends FtLitElement {
149
149
  filterId="${this.id}"
150
150
  ?multivalued=${this.multivalued}
151
151
  ?disabled=${this.disabled}
152
- ?displayCount="${this.displayCount}"
152
+ ?displayCount=${this.displayCount}
153
153
  preventNavigation
154
154
  .options=${selectedOptions}
155
155
  @change=${this.onChange}
156
156
  part="values selected-values"
157
157
  .exportpartsPrefixes=${["values", "selected-values"]}
158
+ .filteredOptionsNumberAriaNotification=${this.filteredOptionsNumberAriaNotification}
158
159
  ></ft-filter-level>
159
160
  <div class="ft-filter--separator">
160
161
  ` : null}
@@ -168,7 +169,7 @@ class FtFilter extends FtLitElement {
168
169
  })}>
169
170
  ${this.renderLevel(rootOptionsClass, this.options)}
170
171
  ${this.displayedLevels
171
- .map(optionValue => allOptions.find(o => o.value === optionValue))
172
+ .map((optionValue) => allOptions.find((o) => o.value === optionValue))
172
173
  .map((option, index) => {
173
174
  var _a;
174
175
  const className = (option === null || option === void 0 ? void 0 : option.value) === this.slideIn || (option === null || option === void 0 ? void 0 : option.value) === this.slideOut
@@ -186,12 +187,12 @@ class FtFilter extends FtLitElement {
186
187
  <ft-filter-level
187
188
  class="${className}"
188
189
  filterId="${this.id}"
189
- .filter="${this.filter}"
190
+ .filter=${this.filter}
190
191
  moreValuesButtonLabel="${this.moreValuesButtonLabel}"
191
192
  ?multivalued=${this.multivalued}
192
193
  ?disabled=${this.disabled || className !== "ft-filter--level-center"}
193
194
  ?hideSelectedOptions=${this.raiseSelectedOptions}
194
- ?displayCount="${this.displayCount}"
195
+ ?displayCount=${this.displayCount}
195
196
  .parent=${parent}
196
197
  .options=${options}
197
198
  .displayedValuesLimit=${this.displayedValuesLimit}
@@ -201,6 +202,7 @@ class FtFilter extends FtLitElement {
201
202
  part="values available-values"
202
203
  .exportpartsPrefixes=${["values", "available-values"]}
203
204
  noValuesLabel="${this.noValuesLabel}"
205
+ .filteredOptionsNumberAriaNotification=${this.filteredOptionsNumberAriaNotification}
204
206
  ></ft-filter-level>
205
207
  `;
206
208
  }
@@ -231,9 +233,9 @@ class FtFilter extends FtLitElement {
231
233
  });
232
234
  }
233
235
  clear() {
234
- this.flatOptions.forEach(o => o.selected = false);
236
+ this.flatOptions.forEach((o) => o.selected = false);
235
237
  if (this.displayedLevels.length > 0) {
236
- let currentLevel = this.displayedLevels[this.displayedLevels.length - 1];
238
+ const currentLevel = this.displayedLevels[this.displayedLevels.length - 1];
237
239
  this.displayedLevels = [currentLevel];
238
240
  this.slideOut = currentLevel;
239
241
  }
@@ -242,7 +244,7 @@ class FtFilter extends FtLitElement {
242
244
  onChange(e) {
243
245
  var _a;
244
246
  e.stopPropagation();
245
- const option = this.flatOptions.find(o => o.value === e.detail.value);
247
+ const option = this.flatOptions.find((o) => o.value === e.detail.value);
246
248
  option.selected = !option.selected;
247
249
  const clearOption = (o) => {
248
250
  var _a;
@@ -264,7 +266,7 @@ class FtFilter extends FtLitElement {
264
266
  var _a;
265
267
  this.sendEventIfValuesChanged();
266
268
  this.requestUpdate();
267
- (_a = this.levels) === null || _a === void 0 ? void 0 : _a.forEach(l => l.requestUpdate());
269
+ (_a = this.levels) === null || _a === void 0 ? void 0 : _a.forEach((l) => l.requestUpdate());
268
270
  });
269
271
  }
270
272
  sendEventIfValuesChanged() {
@@ -276,7 +278,7 @@ class FtFilter extends FtLitElement {
276
278
  }
277
279
  updateOptionsFromSlot(e) {
278
280
  e.stopPropagation();
279
- this.options = this.slotElement.assignedElements().map(n => n);
281
+ this.options = this.slotElement.assignedElements().map((n) => n);
280
282
  this.optionsChanged();
281
283
  }
282
284
  onFilterChange() {
@@ -331,8 +333,11 @@ __decorate([
331
333
  property({ type: Boolean })
332
334
  ], FtFilter.prototype, "displayCount", void 0);
333
335
  __decorate([
334
- property({ type: Number })
336
+ numberProperty()
335
337
  ], FtFilter.prototype, "displayedValuesLimit", void 0);
338
+ __decorate([
339
+ jsonProperty(undefined)
340
+ ], FtFilter.prototype, "filteredOptionsNumberAriaNotification", void 0);
336
341
  __decorate([
337
342
  property({ type: Boolean })
338
343
  ], FtFilter.prototype, "hideClearButton", void 0);