@itfin/components 2.0.37 → 2.0.38

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.37",
3
+ "version": "2.0.38",
4
4
  "author": "Vitalii Savchuk <esvit666@gmail.com>",
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
@@ -20,16 +20,26 @@
20
20
  </div>
21
21
  </div>
22
22
  <div class="facets-list">
23
- <div v-for="(val, n) of mappedValues" :key="n" class="dropdown-item px-2" :class="{'active': val.isSelected}" @click="onFilterClick(val)">
24
- <span class="facet-name text-dark d-flex align-items-center">
25
- <itf-checkbox ungrouped :value="val.isSelected" class="m-0" />
26
- <div class="w-100 text-truncate">{{ val.label }} <span v-if="val.description" class="small"><br/>{{ val.description }}</span></div>
27
- </span>
28
- <span v-if="val.count" class="facet-stat">
29
- {{ val.count }}
30
- <span class="facet-bar"><span :style="{'--bar-width': `${getPercent(val)}%`}" class="facet-bar-progress" /></span>
31
- </span>
32
- </div>
23
+ <div v-for="(group, g) of groupedList">
24
+ <div v-if="group.group" class="dropdown-item ps-1 d-flex align-items-center"
25
+ :class="{'active': isGroupSelected(group.items)}" @click="groupSelected(!isGroupSelected(group.items), group.items)">
26
+ <span class="facet-name text-dark d-flex align-items-center">
27
+ <itf-checkbox ungrouped :value="isGroupSelected(group.items)" @input="groupSelected($event, group.items)" class="m-0" />
28
+ <div class="w-100 text-truncate">{{ group.group }}</div>
29
+ </span>
30
+ </div>
31
+
32
+ <div v-for="(val, n) of group.items" :key="n" class="dropdown-item ps-1" :class="{'active': val.isSelected, 'ps-4': group.group}" @click="onFilterClick(val)">
33
+ <span class="facet-name text-dark d-flex align-items-center">
34
+ <itf-checkbox ungrouped :value="val.isSelected" class="m-0" />
35
+ <div class="w-100 text-truncate">{{ val.label }} <span v-if="val.description" class="small"><br/>{{ val.description }}</span></div>
36
+ </span>
37
+ <span v-if="val.count" class="facet-stat">
38
+ {{ val.count }}
39
+ <span class="facet-bar"><span :style="{'--bar-width': `${getPercent(val)}%`}" class="facet-bar-progress" /></span>
40
+ </span>
41
+ </div>
42
+ </div>
33
43
  </div>
34
44
 
35
45
  <itf-button default class="mt-1" v-if="hasMore" small block @click="toggleMore">
@@ -111,6 +121,8 @@
111
121
  }
112
122
  </style>
113
123
  <script>
124
+ import uniq from 'lodash/uniq';
125
+ import sortBy from 'lodash/sortBy';
114
126
  import { Vue, Prop, Model, Component } from 'vue-property-decorator';
115
127
  import itfTextField from '../text-field/TextField.vue';
116
128
  import itfButton from '../button/Button';
@@ -149,6 +161,20 @@ class FilterFacetsList extends Vue {
149
161
  return this.visibleList.length > this.limit;
150
162
  }
151
163
 
164
+ get hasGroups() {
165
+ const groups = uniq(this.items && this.items.map(item => item.group).filter(Boolean));
166
+ return groups.length > 1
167
+ }
168
+
169
+ isGroupSelected(items) {
170
+ return items.every(item => item.isSelected);
171
+ }
172
+
173
+ groupSelected(value, items) {
174
+ const newVal = value ? items.map(item => `${item.value}`) : [];
175
+ this.$emit('input', this.multiple ? newVal : (newVal.length > 0 ? newVal[0] : null));
176
+ }
177
+
152
178
  get visibleList() {
153
179
  let list = this.items.map(val => {
154
180
  const isSelected = this.multiple
@@ -163,7 +189,22 @@ class FilterFacetsList extends Vue {
163
189
  if (this.isShowSelected) {
164
190
  return list.filter((val) => val.isSelected);
165
191
  }
166
- return list;
192
+ return sortBy(list, (item) => this.hasGroups ? item.group || item.label : item.label);
193
+ }
194
+
195
+ get groupedList() {
196
+ if (!this.hasGroups) {
197
+ return [{ items: this.mappedValues }];
198
+ }
199
+ const groups = {};
200
+ this.mappedValues.forEach((item) => {
201
+ const group = item.group || '';
202
+ if (!groups[group]) {
203
+ groups[group] = [];
204
+ }
205
+ groups[group].push(item);
206
+ });
207
+ return Object.entries(groups).map(([group, items]) => ({ group, items }));
167
208
  }
168
209
 
169
210
  get mappedValues() {
@@ -60,7 +60,7 @@ body[data-theme="dark"] {
60
60
  height: 100%;
61
61
  }
62
62
  .scroller {
63
- margin-bottom: .5rem;
63
+ margin-bottom: 12px;
64
64
  }
65
65
  .scrollable-x {
66
66
  overflow-x: scroll;