@weni/unnnic-system 3.36.0 → 3.36.1-alpha.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/dist/components/MultiSelect/MultiSelectOption.css +1 -1
- package/dist/components/MultiSelect/MultiSelectOption.vue.mjs +2 -2
- package/dist/components/MultiSelect/MultiSelectOption.vue2.mjs +41 -15
- package/dist/components/MultiSelect/MultiSelectTreeOptions.css +1 -0
- package/dist/components/MultiSelect/MultiSelectTreeOptions.vue.mjs +7 -0
- package/dist/components/MultiSelect/MultiSelectTreeOptions.vue2.mjs +50 -0
- package/dist/components/MultiSelect/index.css +1 -1
- package/dist/components/MultiSelect/index.vue.mjs +2 -2
- package/dist/components/MultiSelect/index.vue2.mjs +126 -114
- package/dist/composables/useMultiSelectRows.mjs +74 -0
- package/dist/composables/useMultiSelectSelection.mjs +44 -0
- package/dist/composables/useSelectBase.mjs +44 -39
- package/dist/composables/useSelectKeyboard.mjs +70 -35
- package/dist/composables/useTreeExpansion.mjs +24 -0
- package/dist/lib/tree-selection.mjs +66 -0
- package/dist/locales/en.json.mjs +9 -5
- package/dist/style.css +4 -2
- package/dist/unnnic.umd.js +19 -19
- package/package.json +2 -2
- package/src/components/MultiSelect/MultiSelectOption.vue +66 -3
- package/src/components/MultiSelect/MultiSelectTreeOptions.vue +73 -0
- package/src/components/MultiSelect/__tests__/MultiSelect.spec.js +556 -0
- package/src/components/MultiSelect/__tests__/MultiSelectOption.spec.js +55 -1
- package/src/components/MultiSelect/__tests__/__snapshots__/MultiSelectOption.spec.js.snap +5 -0
- package/src/components/MultiSelect/index.vue +57 -50
- package/src/components/Select/_select-shared.scss +8 -0
- package/src/components/Select/types.ts +1 -0
- package/src/composables/useMultiSelectRows.ts +121 -0
- package/src/composables/useMultiSelectSelection.ts +97 -0
- package/src/composables/useSelectBase.ts +40 -16
- package/src/composables/useSelectKeyboard.ts +92 -18
- package/src/composables/useTreeExpansion.ts +44 -0
- package/src/lib/__tests__/tree-selection.spec.ts +141 -0
- package/src/lib/tree-selection.ts +156 -0
- package/src/locales/en.json +3 -1
- package/src/stories/MultiSelect.stories.js +62 -1
package/package.json
CHANGED
|
@@ -1,16 +1,43 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div
|
|
2
|
+
<div
|
|
3
|
+
:class="[
|
|
4
|
+
'unnnic-multi-select-option',
|
|
5
|
+
{ 'unnnic-multi-select-option--level-2': props.level === 2 },
|
|
6
|
+
]"
|
|
7
|
+
>
|
|
8
|
+
<button
|
|
9
|
+
v-if="props.expandable"
|
|
10
|
+
type="button"
|
|
11
|
+
class="unnnic-multi-select-option__expand"
|
|
12
|
+
tabindex="-1"
|
|
13
|
+
:aria-expanded="props.expanded"
|
|
14
|
+
:aria-label="props.expanded ? $t('collapse') : $t('expand')"
|
|
15
|
+
@click.stop="emit('update:expanded', !props.expanded)"
|
|
16
|
+
>
|
|
17
|
+
<UnnnicIcon
|
|
18
|
+
:icon="props.expanded ? 'keyboard_arrow_down' : 'keyboard_arrow_right'"
|
|
19
|
+
size="ant"
|
|
20
|
+
scheme="fg-base"
|
|
21
|
+
/>
|
|
22
|
+
</button>
|
|
23
|
+
<span
|
|
24
|
+
v-else-if="props.level === 1"
|
|
25
|
+
class="unnnic-multi-select-option__expand-spacer"
|
|
26
|
+
aria-hidden="true"
|
|
27
|
+
/>
|
|
3
28
|
<UnnnicCheckbox
|
|
4
29
|
:modelValue="props.active"
|
|
5
30
|
:disabled="props.disabled"
|
|
6
31
|
:label="props.label"
|
|
7
|
-
@update:model-value="emit('update:modelValue',
|
|
32
|
+
@update:model-value="emit('update:modelValue', props.active !== true)"
|
|
8
33
|
/>
|
|
9
34
|
</div>
|
|
10
35
|
</template>
|
|
11
36
|
|
|
12
37
|
<script setup lang="ts">
|
|
13
38
|
import UnnnicCheckbox from '../Checkbox/Checkbox.vue';
|
|
39
|
+
import type { CheckboxValue } from '../Checkbox/Checkbox.vue';
|
|
40
|
+
import UnnnicIcon from '../Icon.vue';
|
|
14
41
|
|
|
15
42
|
defineOptions({
|
|
16
43
|
name: 'UnnnicMultiSelectOption',
|
|
@@ -18,24 +45,32 @@ defineOptions({
|
|
|
18
45
|
|
|
19
46
|
const emit = defineEmits<{
|
|
20
47
|
'update:modelValue': [boolean];
|
|
48
|
+
'update:expanded': [boolean];
|
|
21
49
|
}>();
|
|
22
50
|
|
|
23
51
|
interface SelectOptionProps {
|
|
24
52
|
label: string;
|
|
25
53
|
disabled?: boolean;
|
|
26
|
-
active?:
|
|
54
|
+
active?: CheckboxValue;
|
|
27
55
|
focused?: boolean;
|
|
56
|
+
level?: 1 | 2;
|
|
57
|
+
expandable?: boolean;
|
|
58
|
+
expanded?: boolean;
|
|
28
59
|
}
|
|
29
60
|
|
|
30
61
|
const props = withDefaults(defineProps<SelectOptionProps>(), {
|
|
31
62
|
disabled: false,
|
|
32
63
|
active: false,
|
|
33
64
|
focused: false,
|
|
65
|
+
level: undefined,
|
|
66
|
+
expandable: false,
|
|
67
|
+
expanded: false,
|
|
34
68
|
});
|
|
35
69
|
</script>
|
|
36
70
|
|
|
37
71
|
<style lang="scss" scoped>
|
|
38
72
|
@use '@/assets/scss/unnnic' as *;
|
|
73
|
+
|
|
39
74
|
* {
|
|
40
75
|
margin: 0;
|
|
41
76
|
padding: 0;
|
|
@@ -43,7 +78,35 @@ const props = withDefaults(defineProps<SelectOptionProps>(), {
|
|
|
43
78
|
}
|
|
44
79
|
|
|
45
80
|
.unnnic-multi-select-option {
|
|
81
|
+
display: flex;
|
|
82
|
+
align-items: center;
|
|
83
|
+
gap: $unnnic-space-2;
|
|
46
84
|
border-radius: $unnnic-radius-1;
|
|
47
85
|
font: $unnnic-font-emphasis;
|
|
86
|
+
|
|
87
|
+
&--level-2 {
|
|
88
|
+
padding-left: $unnnic-space-7;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
&__expand {
|
|
92
|
+
display: inline-flex;
|
|
93
|
+
align-items: center;
|
|
94
|
+
justify-content: center;
|
|
95
|
+
flex-shrink: 0;
|
|
96
|
+
width: $unnnic-icon-size-5;
|
|
97
|
+
height: $unnnic-icon-size-5;
|
|
98
|
+
padding: 0;
|
|
99
|
+
border: none;
|
|
100
|
+
background: transparent;
|
|
101
|
+
cursor: pointer;
|
|
102
|
+
color: $unnnic-color-fg-base;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
&__expand-spacer {
|
|
106
|
+
display: inline-block;
|
|
107
|
+
flex-shrink: 0;
|
|
108
|
+
width: $unnnic-icon-size-5;
|
|
109
|
+
height: $unnnic-icon-size-5;
|
|
110
|
+
}
|
|
48
111
|
}
|
|
49
112
|
</style>
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
class="unnnic-multi-select__options"
|
|
4
|
+
role="tree"
|
|
5
|
+
aria-multiselectable="true"
|
|
6
|
+
>
|
|
7
|
+
<div
|
|
8
|
+
v-for="group in props.groups"
|
|
9
|
+
:key="String(group[0].option[props.itemValue])"
|
|
10
|
+
class="unnnic-multi-select__option-group"
|
|
11
|
+
>
|
|
12
|
+
<UnnnicMultiSelectOption
|
|
13
|
+
v-for="row in group"
|
|
14
|
+
:key="String(row.option[props.itemValue])"
|
|
15
|
+
:data-option-index="row.index"
|
|
16
|
+
:label="String(row.option[props.itemLabel] ?? '')"
|
|
17
|
+
:active="row.checkState"
|
|
18
|
+
:focused="props.focusedIndex === row.index"
|
|
19
|
+
:disabled="row.option.disabled"
|
|
20
|
+
:level="row.level"
|
|
21
|
+
:expandable="row.hasChildren"
|
|
22
|
+
:expanded="row.isExpanded"
|
|
23
|
+
role="treeitem"
|
|
24
|
+
:aria-level="row.level"
|
|
25
|
+
:aria-checked="toAriaChecked(row.checkState)"
|
|
26
|
+
:aria-expanded="row.hasChildren ? row.isExpanded : undefined"
|
|
27
|
+
@update:model-value="emit('select', row.option, $event)"
|
|
28
|
+
@update:expanded="emit('expand', row.option, $event)"
|
|
29
|
+
/>
|
|
30
|
+
</div>
|
|
31
|
+
</div>
|
|
32
|
+
</template>
|
|
33
|
+
|
|
34
|
+
<script setup lang="ts">
|
|
35
|
+
import UnnnicMultiSelectOption from './MultiSelectOption.vue';
|
|
36
|
+
|
|
37
|
+
import type { OptionRow } from '../../composables/useMultiSelectRows';
|
|
38
|
+
import type { CheckboxValue } from '../Checkbox/Checkbox.vue';
|
|
39
|
+
import type { SelectOption } from '../Select/types';
|
|
40
|
+
|
|
41
|
+
defineOptions({
|
|
42
|
+
name: 'UnnnicMultiSelectTreeOptions',
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
interface MultiSelectTreeOptionsProps {
|
|
46
|
+
groups: OptionRow[][];
|
|
47
|
+
itemLabel: string;
|
|
48
|
+
itemValue: string;
|
|
49
|
+
focusedIndex: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const props = defineProps<MultiSelectTreeOptionsProps>();
|
|
53
|
+
|
|
54
|
+
const emit = defineEmits<{
|
|
55
|
+
select: [option: SelectOption, selected: boolean];
|
|
56
|
+
expand: [option: SelectOption, expanded: boolean];
|
|
57
|
+
}>();
|
|
58
|
+
|
|
59
|
+
function toAriaChecked(state: CheckboxValue) {
|
|
60
|
+
if (state === 'less') return 'mixed';
|
|
61
|
+
return state ? 'true' : 'false';
|
|
62
|
+
}
|
|
63
|
+
</script>
|
|
64
|
+
|
|
65
|
+
<style lang="scss" scoped>
|
|
66
|
+
@use '@/assets/scss/unnnic' as *;
|
|
67
|
+
|
|
68
|
+
.unnnic-multi-select__option-group {
|
|
69
|
+
display: flex;
|
|
70
|
+
flex-direction: column;
|
|
71
|
+
gap: $unnnic-space-4;
|
|
72
|
+
}
|
|
73
|
+
</style>
|