|
1 | 1 | <template> |
2 | 2 |
|
3 | 3 | <div> |
4 | | - <DropdownWrapper> |
| 4 | + <KMultiSelect |
| 5 | + v-if="!expanded" |
| 6 | + :value="autocompleteValues" |
| 7 | + :options="categoriesList" |
| 8 | + itemValue="value" |
| 9 | + itemText="text" |
| 10 | + :label="translateMetadataString('category')" |
| 11 | + :autoPromoteParent="false" |
| 12 | + clearable |
| 13 | + :noResultsText="$tr('noCategoryFoundText')" |
| 14 | + :messages="messages" |
| 15 | + @input="onKMultiSelectInput" |
| 16 | + > |
| 17 | + <template #chip="{ option, remove: removeChip }"> |
| 18 | + <span :ref="'category-chip-' + option.value"> |
| 19 | + <KChip |
| 20 | + :text="option.text" |
| 21 | + :removeLabel="$tr('removeCategory', { label: tooltipText(option.value) })" |
| 22 | + close |
| 23 | + @close="removeChip" |
| 24 | + @mousedown.native.prevent |
| 25 | + /> |
| 26 | + </span> |
| 27 | + <KTooltip |
| 28 | + :reference="'category-chip-' + option.value" |
| 29 | + :refs="$refs" |
| 30 | + placement="top" |
| 31 | + :text="tooltipText(option.value)" |
| 32 | + /> |
| 33 | + </template> |
| 34 | + </KMultiSelect> |
| 35 | + |
| 36 | + <DropdownWrapper v-if="expanded"> |
5 | 37 | <template #default="{ attach, menuProps }"> |
6 | 38 | <VAutocomplete |
7 | 39 | :value="autocompleteValues" |
|
18 | 50 | :menu-props="{ |
19 | 51 | ...menuProps, |
20 | 52 | zIndex: 4, |
21 | | - height: expanded ? 0 : 'auto', |
22 | | - maxHeight: expanded ? 0 : 300, |
| 53 | + height: 0, |
| 54 | + maxHeight: 0, |
23 | 55 | }" |
24 | 56 | :attach="attach" |
25 | 57 | @click:clear="$nextTick(() => removeAll())" |
|
44 | 76 | </div> |
45 | 77 | </VTooltip> |
46 | 78 | </template> |
47 | | - |
48 | | - <template #no-data> |
49 | | - <VListTile v-if="categoryText && categoryText.trim()"> |
50 | | - <VListTileContent> |
51 | | - <VListTileTitle> |
52 | | - {{ $tr('noCategoryFoundText', { text: categoryText.trim() }) }} |
53 | | - </VListTileTitle> |
54 | | - </VListTileContent> |
55 | | - </VListTile> |
56 | | - </template> |
57 | | - |
58 | | - <template #item="{ item }"> |
59 | | - <VListTile |
60 | | - :value="isSelected(item.value)" |
61 | | - :class="{ parentOption: !item.value.includes('.') }" |
62 | | - @mousedown.prevent |
63 | | - @click="onChange(item.value)" |
64 | | - > |
65 | | - <KCheckbox |
66 | | - :checked="isSelected(item.value)" |
67 | | - :label="item.text" |
68 | | - :value="item.value" |
69 | | - style="margin-top: 10px" |
70 | | - :style="treeItemStyle(item)" |
71 | | - :ripple="false" |
72 | | - /> |
73 | | - </VListTile> |
74 | | - </template> |
75 | 79 | </VAutocomplete> |
76 | 80 | </template> |
77 | 81 | </DropdownWrapper> |
|
104 | 108 | <script> |
105 | 109 |
|
106 | 110 | import camelCase from 'lodash/camelCase'; |
| 111 | + import KMultiSelect from 'kolibri-design-system/lib/candidate/multiselect/KMultiSelect'; |
| 112 | + import KChip from 'kolibri-design-system/lib/candidate/multiselect/KChip'; |
107 | 113 | import { getSortedCategories } from 'shared/utils/helpers'; |
| 114 | + import { commonStrings } from 'shared/strings/commonStrings'; |
| 115 | + import { communityChannelsStrings } from 'shared/strings/communityChannelsStrings'; |
108 | 116 | import DropdownWrapper from 'shared/views/form/DropdownWrapper'; |
109 | 117 | import { constantsTranslationMixin, metadataTranslationMixin } from 'shared/mixins'; |
110 | 118 |
|
111 | 119 | export default { |
112 | 120 | name: 'CategoryOptions', |
113 | | - components: { DropdownWrapper }, |
| 121 | + components: { KMultiSelect, KChip, DropdownWrapper }, |
114 | 122 | mixins: [constantsTranslationMixin, metadataTranslationMixin], |
115 | 123 | props: { |
116 | 124 | /** |
|
177 | 185 | option.text.toLowerCase().includes(searchQuery), |
178 | 186 | ); |
179 | 187 | }, |
| 188 | + messages() { |
| 189 | + const { |
| 190 | + openMenuAction$, |
| 191 | + closeMenuAction$, |
| 192 | + optionsClickableLabel$, |
| 193 | + allOptionsSelectedLabel$, |
| 194 | + allOptionsDeselectedLabel$, |
| 195 | + optionDeselectedLabel$, |
| 196 | + partiallySelectedLabel$, |
| 197 | + optionSelectedLabel$, |
| 198 | + optionRemovedLabel$, |
| 199 | + } = commonStrings; |
| 200 | + const { clearAllAction$ } = communityChannelsStrings; |
| 201 | + return { |
| 202 | + clearText: clearAllAction$, |
| 203 | + open: openMenuAction$, |
| 204 | + close: closeMenuAction$, |
| 205 | + clickable: optionsClickableLabel$, |
| 206 | + allOptionsSelected: allOptionsSelectedLabel$, |
| 207 | + allOptionsDeselected: allOptionsDeselectedLabel$, |
| 208 | + optionDeselected: optionDeselectedLabel$, |
| 209 | + partiallySelected: partiallySelectedLabel$, |
| 210 | + itemsSelected: ({ count }) => this.$tr('itemsSelected', { count }), |
| 211 | + selected: optionSelectedLabel$, |
| 212 | + removed: optionRemovedLabel$, |
| 213 | + cleared: () => this.$tr('allCategoriesCleared'), |
| 214 | + }; |
| 215 | + }, |
180 | 216 | }, |
181 | 217 | methods: { |
182 | 218 | treeItemStyle(item) { |
|
201 | 237 | removeAll() { |
202 | 238 | this.selected = {}; |
203 | 239 | }, |
| 240 | + // Dropdown mode is only rendered when a single node is edited, so every |
| 241 | + // selected category simply applies to all of nodeIds. |
| 242 | + onKMultiSelectInput(newValues) { |
| 243 | + this.selected = Object.fromEntries(newValues.map(value => [value, this.nodeIds])); |
| 244 | + }, |
204 | 245 | tooltipText(optionId) { |
205 | 246 | const option = this.categoriesList.find(option => option.value === optionId); |
206 | 247 | if (!option) { |
|
275 | 316 | }, |
276 | 317 | $trs: { |
277 | 318 | noCategoryFoundText: 'Category not found', |
| 319 | + itemsSelected: '{count, plural, one {# category selected} other {# categories selected}}', |
| 320 | + allCategoriesCleared: 'All categories cleared', |
| 321 | + removeCategory: 'Remove {label}', |
278 | 322 | }, |
279 | 323 | }; |
280 | 324 |
|
|
283 | 327 |
|
284 | 328 | <style lang="scss" scoped> |
285 | 329 |
|
286 | | - .parentOption:not(:first-child) { |
287 | | - border-top: 1px solid rgba(0, 0, 0, 0.12); |
288 | | - } |
289 | | -
|
290 | 330 | .checkbox-list-wrapper { |
291 | 331 | height: 250px; |
292 | 332 | overflow-y: auto; |
|
0 commit comments