@nexxtmove/ui 0.1.42 → 0.1.43
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/index.d.ts +9 -1
- package/dist/index.js +843 -825
- package/package.json +1 -1
- package/src/components/DropdownButton/DropdownButton.vue +55 -15
package/package.json
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { ref, onMounted, onUnmounted, computed } from 'vue'
|
|
3
3
|
import NexxtIcon from '../Icon/Icon.vue'
|
|
4
|
+
import NexxtCheckbox from '../Checkbox/Checkbox.vue'
|
|
4
5
|
|
|
5
6
|
interface NexxtDropdownButton {
|
|
6
7
|
label: string
|
|
7
8
|
action: string | (() => void)
|
|
8
9
|
icon?: InstanceType<typeof NexxtIcon>['name']
|
|
9
10
|
selected?: boolean
|
|
11
|
+
checkbox?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface NexxtDropdownButtonGroup {
|
|
15
|
+
title: string
|
|
16
|
+
items: NexxtDropdownButton[]
|
|
10
17
|
}
|
|
11
18
|
|
|
12
19
|
type NexxtDropdownButtonBase = {
|
|
13
20
|
variant?: 'primary' | 'secondary'
|
|
14
|
-
options: NexxtDropdownButton[]
|
|
21
|
+
options: NexxtDropdownButton[] | NexxtDropdownButtonGroup[]
|
|
15
22
|
placement?: 'left' | 'right'
|
|
16
23
|
triggerIcon?: InstanceType<typeof NexxtIcon>['name']
|
|
17
24
|
icon?: InstanceType<typeof NexxtIcon>['name']
|
|
@@ -34,10 +41,12 @@ const {
|
|
|
34
41
|
|
|
35
42
|
const emit = defineEmits<{
|
|
36
43
|
navigate: [url: string]
|
|
44
|
+
checkboxChange: [label: string, checked: boolean]
|
|
37
45
|
}>()
|
|
38
46
|
|
|
39
47
|
const isOpen = ref(false)
|
|
40
48
|
const wrapperRef = ref<HTMLElement | null>(null)
|
|
49
|
+
const checkedItems = ref<Record<string, boolean>>({})
|
|
41
50
|
|
|
42
51
|
const handleAction = (action: string | (() => void)) => {
|
|
43
52
|
if (typeof action === 'function') {
|
|
@@ -51,9 +60,15 @@ const toggleDropdown = () => {
|
|
|
51
60
|
isOpen.value = !isOpen.value
|
|
52
61
|
}
|
|
53
62
|
|
|
54
|
-
const handleOptionClick = (
|
|
55
|
-
|
|
56
|
-
|
|
63
|
+
const handleOptionClick = (option: NexxtDropdownButton) => {
|
|
64
|
+
if (option.checkbox) {
|
|
65
|
+
const newValue = !checkedItems.value[option.label]
|
|
66
|
+
checkedItems.value[option.label] = newValue
|
|
67
|
+
emit('checkboxChange', option.label, newValue)
|
|
68
|
+
} else {
|
|
69
|
+
isOpen.value = false
|
|
70
|
+
}
|
|
71
|
+
handleAction(option.action)
|
|
57
72
|
}
|
|
58
73
|
|
|
59
74
|
const handleClickOutside = (event: MouseEvent) => {
|
|
@@ -70,6 +85,15 @@ onUnmounted(() => {
|
|
|
70
85
|
document.removeEventListener('mousedown', handleClickOutside)
|
|
71
86
|
})
|
|
72
87
|
|
|
88
|
+
const isGrouped = (
|
|
89
|
+
opts: NexxtDropdownButton[] | NexxtDropdownButtonGroup[],
|
|
90
|
+
): opts is NexxtDropdownButtonGroup[] => opts.length > 0 && 'items' in opts[0]
|
|
91
|
+
|
|
92
|
+
const groupedOptions = computed<NexxtDropdownButtonGroup[]>(() => {
|
|
93
|
+
if (isGrouped(options)) return options
|
|
94
|
+
return [{ title: '', items: options }]
|
|
95
|
+
})
|
|
96
|
+
|
|
73
97
|
const componentClasses = computed(() => {
|
|
74
98
|
if (variant === 'primary') {
|
|
75
99
|
return 'bg-button-bg-primary-default text-button-text-primary-default'
|
|
@@ -154,17 +178,33 @@ const transitionClasses = computed(() => {
|
|
|
154
178
|
class="absolute top-full z-10 mt-2.5 min-w-full rounded-md border border-gray-200 bg-white whitespace-nowrap"
|
|
155
179
|
:class="placement === 'right' ? 'right-0' : 'left-0'"
|
|
156
180
|
>
|
|
157
|
-
<
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
<
|
|
166
|
-
|
|
167
|
-
|
|
181
|
+
<template v-for="(group, groupIndex) in groupedOptions" :key="group.title || groupIndex">
|
|
182
|
+
<div
|
|
183
|
+
v-if="group.title"
|
|
184
|
+
class="border-b border-gray-100 px-4 py-1.5 extra-small-normal text-gray-600"
|
|
185
|
+
:class="groupIndex > 0 ? 'mt-1 border-t pt-2' : ''"
|
|
186
|
+
>
|
|
187
|
+
{{ group.title }}
|
|
188
|
+
</div>
|
|
189
|
+
<button
|
|
190
|
+
v-for="option in group.items"
|
|
191
|
+
:key="option.label"
|
|
192
|
+
:role="option.checkbox ? 'menuitemcheckbox' : 'menuitem'"
|
|
193
|
+
:aria-checked="option.checkbox ? (checkedItems[option.label] ?? false) : undefined"
|
|
194
|
+
class="flex w-full min-w-42 cursor-pointer items-center gap-2 px-4 py-2 text-left text-sm whitespace-nowrap text-gray-700 transition-colors duration-200 hover:bg-gray-100 hover:text-purple-600 focus:bg-gray-100 focus:outline-none"
|
|
195
|
+
:class="!option.checkbox && option.selected ? 'bg-cornflower-blue-100' : ''"
|
|
196
|
+
@click="handleOptionClick(option)"
|
|
197
|
+
>
|
|
198
|
+
<template v-if="option.checkbox">
|
|
199
|
+
<NexxtCheckbox
|
|
200
|
+
:model-value="checkedItems[option.label] ?? false"
|
|
201
|
+
class="pointer-events-none"
|
|
202
|
+
/>
|
|
203
|
+
</template>
|
|
204
|
+
<NexxtIcon v-else-if="option.icon" :name="option.icon" aria-hidden="true" />
|
|
205
|
+
{{ option.label }}
|
|
206
|
+
</button>
|
|
207
|
+
</template>
|
|
168
208
|
</div>
|
|
169
209
|
</Transition>
|
|
170
210
|
</div>
|