@itfin/components 2.0.8 → 2.0.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itfin/components",
3
- "version": "2.0.8",
3
+ "version": "2.0.10",
4
4
  "author": "Vitalii Savchuk <esvit666@gmail.com>",
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
@@ -1,30 +1,32 @@
1
1
  <template>
2
2
  <div class="itf-filter-panel d-flex flex-column gap-3 align-items-start">
3
3
  <div v-if="search" class="d-flex gap-2 justify-content-between w-100">
4
- <itf-text-field
5
- style="width: 300px"
6
- small
7
- :placeholder="searchPlaceholder"
8
- prepend-icon="search"
9
- :delay-input="250"
10
- clearable
11
- :value="filterValue.query"
12
- @input="(e) => onFilterChange({ type: 'text', name: 'query' }, { value: e })"
13
- />
4
+ <slot name="search">
5
+ <itf-text-field
6
+ style="width: 300px"
7
+ small
8
+ :placeholder="searchPlaceholder"
9
+ prepend-icon="search"
10
+ :delay-input="250"
11
+ clearable
12
+ :value="filterValue.query"
13
+ @input="(e) => onFilterChange({ type: 'text', name: 'query' }, { value: e })"
14
+ />
15
+ </slot>
14
16
  <div class="d-flex gap-2">
15
- <itf-button default icon class="position-relative" @click="showFilters = !showFilters">
17
+ <itf-button default icon class="position-relative" @click="toggleFilters">
16
18
  <itf-icon new name="filter" />
17
19
  <span v-if="activeFiltersCount" class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-primary">
18
20
  {{activeFiltersCount}}
19
- <span class="visually-hidden">unread messages</span>
21
+ <span class="visually-hidden">active filters</span>
20
22
  </span>
21
23
  </itf-button>
22
24
  <slot name="after-filter-btn"></slot>
23
25
  </div>
24
26
  </div>
25
- <div v-if="showFilters" class="d-flex gap-2 flex-wrap">
27
+ <div v-if="showFilters" class="d-flex gap-2 flex-nowrap">
26
28
  <filter-badge
27
- v-for="(facet, n) in filters"
29
+ v-for="(facet, n) in visibleFilters"
28
30
  :key="n"
29
31
  v-model="filter[facet.name]"
30
32
  :is-default="filter[facet.name].isDefault"
@@ -89,7 +91,9 @@ class FilterPanel extends Vue {
89
91
  @Prop({ type: Array }) staticFilters;
90
92
  @Prop({ type: String }) endpoint;
91
93
  @Prop() panel;
94
+ @Prop(String) stateName;
92
95
  @Prop(Boolean) search;
96
+ @Prop(Boolean) mini;
93
97
  @Prop({ type: String, default: function() { return this.$t('components.filter.search'); } }) searchPlaceholder;
94
98
 
95
99
  filter = {};
@@ -98,7 +102,27 @@ class FilterPanel extends Vue {
98
102
  loading = false;
99
103
  showFilters = true;
100
104
 
105
+ get visibleFilters() {
106
+ if (this.mini) {
107
+ return this.filters.filter(f => !f.options?.hidden).slice(0, 2);
108
+ }
109
+ return this.filters.filter(f => !f.options?.hidden);
110
+ }
111
+
112
+ get resetFilters() {
113
+ return this.filters.filter(f => !this.visibleFilters.find(vf => vf.name === f.name));
114
+ }
115
+
116
+ get localstorageKey() {
117
+ return `filter-panel-${this.stateName}-filters`;
118
+ }
119
+
101
120
  async mounted() {
121
+ if (this.stateName) {
122
+ const item = localStorage.getItem(this.localstorageKey);
123
+ this.showFilters = item ? JSON.parse(item) : this.showFilters;
124
+ }
125
+
102
126
  this.filters = this.staticFilters ?? [];
103
127
  if (this.endpoint) {
104
128
  this.loading = true;
@@ -116,18 +140,27 @@ class FilterPanel extends Vue {
116
140
  }
117
141
  }
118
142
 
143
+ toggleFilters() {
144
+ this.showFilters = !this.showFilters;
145
+ if (this.stateName) {
146
+ localStorage.setItem(this.localstorageKey, this.showFilters);
147
+ }
148
+ }
149
+
119
150
  loadFiltersValue() {
120
151
  const payload = this.panel ? this.panel.getPayload() : {};
121
152
  const filter = {};
122
153
  const filterValue = {};
123
- for (const item of this.filters) {
124
- if (item.type === 'period') {
125
- filter[item.name] = payload.from ? this.formatValue(item, { value: [payload.from, payload.to] }) : { isDefault: true, ...item.options.defaultValue };
126
- filterValue.from = payload.from;
127
- filterValue.to = payload.to;
128
- } else {
129
- filter[item.name] = payload[item.name] ? this.formatValue(item, { value: payload[item.name] }) : { isDefault: true, ...item.options.defaultValue };
130
- filterValue[item.name] = payload[item.name];
154
+ if (this.filters) {
155
+ for (const item of this.filters) {
156
+ if (item.type === 'period') {
157
+ filter[item.name] = payload.from ? this.formatValue(item, { value: [payload.from, payload.to] }) : { isDefault: true, ...item.options.defaultValue };
158
+ filterValue.from = payload.from;
159
+ filterValue.to = payload.to;
160
+ } else {
161
+ filter[item.name] = payload[item.name] ? this.formatValue(item, { value: payload[item.name] }) : { isDefault: true, ...item.options.defaultValue };
162
+ filterValue[item.name] = payload[item.name];
163
+ }
131
164
  }
132
165
  }
133
166
  if (this.search) {
@@ -175,7 +208,7 @@ class FilterPanel extends Vue {
175
208
  }
176
209
 
177
210
  get activeFiltersCount() {
178
- return Object.values(this.filter).filter(facet => !facet.isDefault).length;
211
+ return Object.values(this.filter).filter(facet => !facet.isDefault && !facet.hidden).length;
179
212
  }
180
213
 
181
214
  formatValue(facet, value) {
@@ -238,6 +271,7 @@ class FilterPanel extends Vue {
238
271
  value.value = value.value.length ? value.value : undefined;
239
272
  value.isDefault = !value.value;
240
273
  }
274
+ value.hidden = facet.options?.hidden ?? false;
241
275
  return value;
242
276
  }
243
277
  }
@@ -0,0 +1,4 @@
1
+ <template><svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M5.08422 11.626C4.97192 11.8628 4.97193 12.1375 5.08423 12.3743C6.303 14.9438 8.94045 16.7231 11.9977 16.7231C15.055 16.7231 17.6925 14.9437 18.9112 12.3741C19.0235 12.1373 19.0235 11.8625 18.9112 11.6258C17.6924 9.0562 15.055 7.27698 11.9978 7.27698C8.94046 7.27698 6.30294 9.05631 5.08422 11.626ZM15 12C15 13.6569 13.6569 15 12 15C10.3432 15 9.00003 13.6569 9.00003 12C9.00003 10.3432 10.3432 9.00002 12 9.00002C12.3075 9.00002 12.6042 9.04627 12.8834 9.1322C12.3625 9.36738 12 9.89137 12 10.5C12 11.3284 12.6716 12 13.5 12C14.1087 12 14.6327 11.6375 14.8678 11.1166C14.9538 11.3959 15 11.6926 15 12Z" fill="currentColor"/>
3
+ </svg>
4
+ </template>