@teammodlr/ui-kit 1.0.2
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/env.d.ts +1 -0
- package/lib/__storybook__/argTypes.d.ts +31 -0
- package/lib/__storybook__/createStory.d.ts +8 -0
- package/lib/__storybook__/index.d.ts +2 -0
- package/lib/components/avatar/Avatar.vue.d.ts +70 -0
- package/lib/components/avatargroup/AvatarGroup.vue.d.ts +34 -0
- package/lib/components/breadcrumb/Breadcrumb.vue.d.ts +25 -0
- package/lib/components/breadcrumbitem/BreadcrumbItem.vue.d.ts +18 -0
- package/lib/components/breadcrumbitem/index.d.ts +1 -0
- package/lib/components/button/Button.vue.d.ts +121 -0
- package/lib/components/buttongroup/ButtonGroup.vue.d.ts +29 -0
- package/lib/components/checkbox/Checkbox.vue.d.ts +97 -0
- package/lib/components/dropdown/Dropdown.vue.d.ts +114 -0
- package/lib/components/dropdown/DropdownItem.vue.d.ts +61 -0
- package/lib/components/dropdown/DropdownList.vue.d.ts +2 -0
- package/lib/components/dropdown/DropdownWrapper.vue.d.ts +2 -0
- package/lib/components/dropdown/hooks.d.ts +2 -0
- package/lib/components/form/Form.vue.d.ts +67 -0
- package/lib/components/image/Image.vue.d.ts +50 -0
- package/lib/components/index.d.ts +26 -0
- package/lib/components/input/Input.vue.d.ts +126 -0
- package/lib/components/link/Link.vue.d.ts +51 -0
- package/lib/components/messageprovider/Message.vue.d.ts +61 -0
- package/lib/components/messageprovider/MessageProvider.vue.d.ts +51 -0
- package/lib/components/messageprovider/types.d.ts +28 -0
- package/lib/components/messageprovider/useMessage.d.ts +2 -0
- package/lib/components/select/Select.vue.d.ts +180 -0
- package/lib/components/skeleton/Skeleton.vue.d.ts +39 -0
- package/lib/components/tab/Tab.vue.d.ts +41 -0
- package/lib/components/tab/TabGroup.vue.d.ts +43 -0
- package/lib/components/table/Table.vue.d.ts +63 -0
- package/lib/components/table/TableBody.vue.d.ts +2 -0
- package/lib/components/table/TableCell.vue.d.ts +2 -0
- package/lib/components/table/TableHead.vue.d.ts +20 -0
- package/lib/components/table/TableHeadRow.vue.d.ts +2 -0
- package/lib/components/table/TableRow.vue.d.ts +2 -0
- package/lib/components/table/types/index.d.ts +5 -0
- package/lib/components/tooltip/Tooltip.vue.d.ts +54 -0
- package/lib/components/virtualscroll/VirtualScroll.vue.d.ts +43 -0
- package/lib/composables/element.d.ts +2 -0
- package/lib/composables/useCachedUid.d.ts +13 -0
- package/lib/composables/useEventListener.d.ts +1 -0
- package/lib/composables/useInput.d.ts +36 -0
- package/lib/composables/useIsServer.d.ts +1 -0
- package/lib/composables/useMount.d.ts +13 -0
- package/lib/composables/usePopper.d.ts +31 -0
- package/lib/create.d.ts +9 -0
- package/lib/index.cjs.js +5 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.es.js +3164 -0
- package/lib/install.d.ts +4 -0
- package/lib/nuxt.js +33 -0
- package/lib/nuxt.plugin.js +8 -0
- package/lib/style.css +1 -0
- package/lib/types/props.d.ts +2 -0
- package/package.json +75 -0
- package/src/__storybook__/argTypes.ts +42 -0
- package/src/__storybook__/createStory.ts +15 -0
- package/src/__storybook__/index.ts +2 -0
- package/src/components/avatar/Avatar.css +69 -0
- package/src/components/avatar/Avatar.vue +102 -0
- package/src/components/avatargroup/AvatarGroup.css +8 -0
- package/src/components/avatargroup/AvatarGroup.vue +32 -0
- package/src/components/breadcrumb/Breadcrumb.css +46 -0
- package/src/components/breadcrumb/Breadcrumb.vue +51 -0
- package/src/components/breadcrumbitem/BreadcrumbItem.vue +66 -0
- package/src/components/breadcrumbitem/index.ts +1 -0
- package/src/components/button/Button.css +378 -0
- package/src/components/button/Button.vue +108 -0
- package/src/components/buttongroup/ButtonGroup.vue +47 -0
- package/src/components/checkbox/Checkbox.css +185 -0
- package/src/components/checkbox/Checkbox.vue +140 -0
- package/src/components/dropdown/Dropdown.css +68 -0
- package/src/components/dropdown/Dropdown.vue +237 -0
- package/src/components/dropdown/DropdownItem.vue +118 -0
- package/src/components/dropdown/DropdownList.vue +20 -0
- package/src/components/dropdown/DropdownWrapper.vue +17 -0
- package/src/components/dropdown/hooks.ts +30 -0
- package/src/components/form/Form.vue +141 -0
- package/src/components/image/Image.vue +71 -0
- package/src/components/index.ts +27 -0
- package/src/components/input/Input.css +173 -0
- package/src/components/input/Input.vue +176 -0
- package/src/components/link/Link.css +147 -0
- package/src/components/link/Link.vue +54 -0
- package/src/components/messageprovider/Message.vue +76 -0
- package/src/components/messageprovider/MessageProvider.css +36 -0
- package/src/components/messageprovider/MessageProvider.vue +142 -0
- package/src/components/messageprovider/types.ts +39 -0
- package/src/components/messageprovider/useMessage.ts +12 -0
- package/src/components/select/Select.css +226 -0
- package/src/components/select/Select.vue +474 -0
- package/src/components/skeleton/Skeleton.css +73 -0
- package/src/components/skeleton/Skeleton.vue +47 -0
- package/src/components/tab/Tab.css +113 -0
- package/src/components/tab/Tab.vue +98 -0
- package/src/components/tab/TabGroup.vue +90 -0
- package/src/components/table/Table.css +45 -0
- package/src/components/table/Table.vue +108 -0
- package/src/components/table/TableBody.vue +13 -0
- package/src/components/table/TableCell.vue +13 -0
- package/src/components/table/TableHead.vue +22 -0
- package/src/components/table/TableHeadRow.vue +15 -0
- package/src/components/table/TableRow.vue +13 -0
- package/src/components/table/types/index.ts +5 -0
- package/src/components/tooltip/Tooltip.css +49 -0
- package/src/components/tooltip/Tooltip.vue +85 -0
- package/src/components/virtualscroll/VirtualScroll.css +13 -0
- package/src/components/virtualscroll/VirtualScroll.vue +61 -0
- package/src/composables/element.ts +13 -0
- package/src/composables/useCachedUid.ts +48 -0
- package/src/composables/useEventListener.ts +14 -0
- package/src/composables/useInput.ts +134 -0
- package/src/composables/useIsServer.ts +7 -0
- package/src/composables/useMount.ts +43 -0
- package/src/composables/usePopper.ts +194 -0
- package/src/create.ts +34 -0
- package/src/css/components.css +14 -0
- package/src/css/index.css +4 -0
- package/src/css/normalize.css +379 -0
- package/src/css/transitions.css +40 -0
- package/src/css/variables.css +80 -0
- package/src/exports/nuxt.js +33 -0
- package/src/exports/nuxt.plugin.js +8 -0
- package/src/index.ts +5 -0
- package/src/install.ts +8 -0
- package/src/shims-vue.d.ts +6 -0
- package/src/types/props.ts +3 -0
- package/volar.d.ts +16 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div ref="checkboxRef" :class="wrapperComputedClasses">
|
|
3
|
+
<div :class="checkboxComputedClass" @click.prevent="toggle">
|
|
4
|
+
<input
|
|
5
|
+
v-model="checked"
|
|
6
|
+
type="checkbox"
|
|
7
|
+
:aria-checked="checked ? 'true' : 'false'"
|
|
8
|
+
:aria-disabled="(disabled || loading) ? 'true' : 'false'"
|
|
9
|
+
:aria-labelledby="`${id}-label`"
|
|
10
|
+
:disabled="disabled || loading"
|
|
11
|
+
:name="name"
|
|
12
|
+
:id="id"
|
|
13
|
+
/>
|
|
14
|
+
<span></span>
|
|
15
|
+
<div class="m-checkbox__label" :id="`${id}-label`">
|
|
16
|
+
<template v-if="hasSlot">
|
|
17
|
+
<slot />
|
|
18
|
+
</template>
|
|
19
|
+
<template v-else>
|
|
20
|
+
{{ label }}
|
|
21
|
+
</template>
|
|
22
|
+
</div>
|
|
23
|
+
</div>
|
|
24
|
+
<p v-if="inputError" class="m-input__error">
|
|
25
|
+
{{ inputError }}
|
|
26
|
+
</p>
|
|
27
|
+
</div>
|
|
28
|
+
</template>
|
|
29
|
+
|
|
30
|
+
<script lang="ts">
|
|
31
|
+
import { defineComponent, toRef, ref, type PropType, watch, computed } from 'vue';
|
|
32
|
+
import { useInput } from '@/composables/useInput';
|
|
33
|
+
import type { Size, Color } from '@/types/props';
|
|
34
|
+
|
|
35
|
+
export default defineComponent({
|
|
36
|
+
name: "Checkbox",
|
|
37
|
+
emits: useInput.emits(),
|
|
38
|
+
props: {
|
|
39
|
+
...useInput.props(),
|
|
40
|
+
label: {
|
|
41
|
+
type: String
|
|
42
|
+
},
|
|
43
|
+
size: {
|
|
44
|
+
type: String as PropType<Size>,
|
|
45
|
+
default: 'md',
|
|
46
|
+
},
|
|
47
|
+
color: {
|
|
48
|
+
type: String as PropType<Color>,
|
|
49
|
+
default: 'blue',
|
|
50
|
+
},
|
|
51
|
+
disabled: {
|
|
52
|
+
type: Boolean,
|
|
53
|
+
default: false
|
|
54
|
+
},
|
|
55
|
+
loading: {
|
|
56
|
+
type: Boolean,
|
|
57
|
+
default: false
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
setup(props, { slots, emit }) {
|
|
61
|
+
const focus = () => { };
|
|
62
|
+
|
|
63
|
+
const {
|
|
64
|
+
id,
|
|
65
|
+
insideForm,
|
|
66
|
+
reset,
|
|
67
|
+
validate,
|
|
68
|
+
setError,
|
|
69
|
+
formError,
|
|
70
|
+
formDisabled,
|
|
71
|
+
formLoading
|
|
72
|
+
} = useInput(props, { focus, emit, withListeners: false });
|
|
73
|
+
|
|
74
|
+
const disabled = computed(() => formDisabled || props.disabled);
|
|
75
|
+
const loading = computed(() => formLoading || props.loading);
|
|
76
|
+
const name = toRef(props, 'name');
|
|
77
|
+
const checked = ref(false);
|
|
78
|
+
const checkboxRef = ref<HTMLElement | null>(null);
|
|
79
|
+
const hasSlot = computed(() => !!(slots.default));
|
|
80
|
+
|
|
81
|
+
const wrapperComputedClasses = computed(() => {
|
|
82
|
+
return [
|
|
83
|
+
'm-checkbox__container',
|
|
84
|
+
{
|
|
85
|
+
'm-form__input': insideForm
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const checkboxComputedClass = computed(() => {
|
|
91
|
+
return {
|
|
92
|
+
'm-checkbox': true,
|
|
93
|
+
'm-checkbox--checked': checked.value,
|
|
94
|
+
'm-checkbox--disabled': disabled.value || loading.value,
|
|
95
|
+
'm-checkbox--error': formError.value,
|
|
96
|
+
[`m-checkbox--${props.size}`]: true,
|
|
97
|
+
[`m-checkbox--${props.color}`]: true,
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const inputError = computed(() => {
|
|
102
|
+
return formError.value || props.error;
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
watch(() => props.modelValue, (value) => {
|
|
106
|
+
checked.value = !!value;
|
|
107
|
+
}, { immediate: true });
|
|
108
|
+
|
|
109
|
+
watch(() => checked.value, (value) => {
|
|
110
|
+
emit('update:modelValue', value);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
function toggle() {
|
|
114
|
+
if (disabled.value) return;
|
|
115
|
+
checked.value = !checked.value;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
id,
|
|
121
|
+
formError,
|
|
122
|
+
insideForm,
|
|
123
|
+
reset,
|
|
124
|
+
validate,
|
|
125
|
+
setError,
|
|
126
|
+
disabled,
|
|
127
|
+
loading,
|
|
128
|
+
name,
|
|
129
|
+
checked,
|
|
130
|
+
checkboxRef,
|
|
131
|
+
inputError,
|
|
132
|
+
toggle,
|
|
133
|
+
|
|
134
|
+
wrapperComputedClasses,
|
|
135
|
+
checkboxComputedClass,
|
|
136
|
+
hasSlot
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
</script>
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
.m-dropdown {
|
|
2
|
+
position: relative;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.m-dropdown-menu {
|
|
6
|
+
--dropdown-menu-width: 200px;
|
|
7
|
+
--dropdown-menu-padding: 6px;
|
|
8
|
+
--dropdown-menu-background-color: var(--white);
|
|
9
|
+
--dropdown-menu-box-shadow: 0px 4px 10px 1px rgb(154 161 171 / 20%);
|
|
10
|
+
--dropdown-menu-border-radius: 4px;
|
|
11
|
+
--dropdown-menu-border: 1px solid var(--gray-200);
|
|
12
|
+
|
|
13
|
+
--dropdown-menu-item-font-size: 15px;
|
|
14
|
+
--dropdown-menu-item-height: 34px;
|
|
15
|
+
--dropdown-menu-item-line-height: 34px;
|
|
16
|
+
--dropdown-menu-item-color: var(--gray-600);
|
|
17
|
+
--dropdown-menu-item-background-color: var(--white);
|
|
18
|
+
--dropdown-menu-item-border-radius: 4px;
|
|
19
|
+
--dropdown-menu-item-padding: 0px 8px;
|
|
20
|
+
--dropdown-menu-gap: 4px;
|
|
21
|
+
|
|
22
|
+
position: relative;
|
|
23
|
+
background-color: var(--dropdown-menu-background-color);
|
|
24
|
+
box-shadow: var(--dropdown-menu-box-shadow);
|
|
25
|
+
border-radius: var(--dropdown-menu-border-radius);
|
|
26
|
+
min-width: var(--dropdown-menu-width);
|
|
27
|
+
padding: var(--dropdown-menu-padding);
|
|
28
|
+
border: var(--dropdown-menu-border);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.m-dropdown-menu ul {
|
|
32
|
+
list-style: none;
|
|
33
|
+
margin: 0;
|
|
34
|
+
padding: 0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.m-dropdown-menu ul .m-dropdown-item {
|
|
38
|
+
position: relative;
|
|
39
|
+
display: flex;
|
|
40
|
+
align-items: center;
|
|
41
|
+
cursor: pointer;
|
|
42
|
+
|
|
43
|
+
font-size: var(--dropdown-menu-item-font-size);
|
|
44
|
+
height: var(--dropdown-menu-item-height);
|
|
45
|
+
line-height: var(--dropdown-menu-item-line-height);
|
|
46
|
+
color: var(--dropdown-menu-item-color);
|
|
47
|
+
background-color: var(--dropdown-menu-item-background-color);
|
|
48
|
+
border-radius: var(--dropdown-menu-item-border-radius);
|
|
49
|
+
padding: var(--dropdown-menu-item-padding);
|
|
50
|
+
gap: var(--dropdown-menu-gap);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.m-dropdown-menu ul .m-dropdown-item .m-dropdown__text {
|
|
54
|
+
white-space: nowrap;
|
|
55
|
+
flex: 1;
|
|
56
|
+
z-index: 1;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.m-dropdown-menu ul .m-dropdown-item:hover {
|
|
60
|
+
--dropdown-menu-item-color: var(--blue);
|
|
61
|
+
--dropdown-menu-item-background-color: var(--gray-100);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.m-dropdown__icon-right,
|
|
65
|
+
.m-dropdown__icon-left {
|
|
66
|
+
display: flex;
|
|
67
|
+
align-items: center;
|
|
68
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div ref="wrapper" :class="computedWrapperClasses">
|
|
3
|
+
<div ref="referenceRef" :class="computedReferenceClasses" @click="toggleDropdown">
|
|
4
|
+
<slot />
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
<DropdownWrapper>
|
|
8
|
+
<Teleport :disabled="isNested" to="body">
|
|
9
|
+
<transition :name="transitionName">
|
|
10
|
+
<div v-show="isOpen" ref="popper" :class="[
|
|
11
|
+
'm-dropdown-menu',
|
|
12
|
+
`m-dropdown-menu--${placement}`
|
|
13
|
+
]">
|
|
14
|
+
<slot name="menu" />
|
|
15
|
+
</div>
|
|
16
|
+
</transition>
|
|
17
|
+
</Teleport>
|
|
18
|
+
</DropdownWrapper>
|
|
19
|
+
</div>
|
|
20
|
+
</template>
|
|
21
|
+
|
|
22
|
+
<script lang="ts">
|
|
23
|
+
import { usePopper } from '@/composables/usePopper';
|
|
24
|
+
import type { Placement, VirtualElement } from '@popperjs/core';
|
|
25
|
+
import { defineComponent, inject, ref, type PropType, provide, watch, onMounted, nextTick, computed, Teleport, toRef, onUnmounted } from 'vue';
|
|
26
|
+
import { onClickOutside, useEventListener } from '@vueuse/core';
|
|
27
|
+
import DropdownWrapper from './DropdownWrapper.vue';
|
|
28
|
+
import { useLabel } from './hooks';
|
|
29
|
+
|
|
30
|
+
export default defineComponent({
|
|
31
|
+
name: 'Dropdown',
|
|
32
|
+
components: {
|
|
33
|
+
DropdownWrapper
|
|
34
|
+
},
|
|
35
|
+
props: {
|
|
36
|
+
open: {
|
|
37
|
+
type: Boolean,
|
|
38
|
+
default: false
|
|
39
|
+
},
|
|
40
|
+
placement: {
|
|
41
|
+
type: String as PropType<Placement>,
|
|
42
|
+
default: 'bottom-start'
|
|
43
|
+
},
|
|
44
|
+
transfer: {
|
|
45
|
+
type: Boolean,
|
|
46
|
+
default: false
|
|
47
|
+
},
|
|
48
|
+
trigger: {
|
|
49
|
+
type: String as PropType<'click' | 'hover'>,
|
|
50
|
+
default: 'click'
|
|
51
|
+
},
|
|
52
|
+
virtual: {
|
|
53
|
+
type: [Object],
|
|
54
|
+
default: null
|
|
55
|
+
},
|
|
56
|
+
x: {
|
|
57
|
+
type: Number,
|
|
58
|
+
default: 0
|
|
59
|
+
},
|
|
60
|
+
y: {
|
|
61
|
+
type: Number,
|
|
62
|
+
default: 0
|
|
63
|
+
},
|
|
64
|
+
label: {
|
|
65
|
+
default: null,
|
|
66
|
+
static: true
|
|
67
|
+
},
|
|
68
|
+
transitionName: {
|
|
69
|
+
type: String,
|
|
70
|
+
default: 'fade'
|
|
71
|
+
},
|
|
72
|
+
onSelect: {
|
|
73
|
+
type: Function as PropType<(labels: any) => void>,
|
|
74
|
+
default: () => { }
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
emits: [
|
|
78
|
+
'update:open'
|
|
79
|
+
],
|
|
80
|
+
setup(props, { emit }) {
|
|
81
|
+
const state = inject("dropdown", null);
|
|
82
|
+
|
|
83
|
+
const isNested = !!state;
|
|
84
|
+
const label = toRef(props, 'label')
|
|
85
|
+
const isOpen = ref(props.open);
|
|
86
|
+
const placement = ref(props.placement);
|
|
87
|
+
const transfer = toRef(props, 'transfer');
|
|
88
|
+
const wrapper = ref(null);
|
|
89
|
+
const referenceRef = ref(null);
|
|
90
|
+
|
|
91
|
+
const reference = computed(() => {
|
|
92
|
+
if (props.virtual !== null) {
|
|
93
|
+
const virtual = (props.virtual as any).$el ?? props.virtual;
|
|
94
|
+
if (virtual) {
|
|
95
|
+
if ('getBoundingClientRect' in virtual) {
|
|
96
|
+
return virtual as VirtualElement;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if ('x' in virtual && 'y' in virtual) {
|
|
100
|
+
return {
|
|
101
|
+
getBoundingClientRect: () => ({
|
|
102
|
+
x: virtual.x,
|
|
103
|
+
y: virtual.y,
|
|
104
|
+
left: virtual.x,
|
|
105
|
+
top: virtual.y,
|
|
106
|
+
width: 0,
|
|
107
|
+
height: 0
|
|
108
|
+
})
|
|
109
|
+
} as VirtualElement
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return referenceRef.value;
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const { popper, transferTo, updatePopper } = usePopper({
|
|
118
|
+
reference: reference,
|
|
119
|
+
placement,
|
|
120
|
+
transfer,
|
|
121
|
+
wrapper,
|
|
122
|
+
isDrop: true,
|
|
123
|
+
offset: isNested ? [-2, 2] : undefined
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const currentLabel = useLabel(label, referenceRef)
|
|
127
|
+
|
|
128
|
+
provide("dropdown-select", null);
|
|
129
|
+
provide("dropdown", {
|
|
130
|
+
handleSelect,
|
|
131
|
+
isOpen: isOpen,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
watch(() => props.open, (value) => {
|
|
135
|
+
isOpen.value = value;
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
watch(() => props.placement, (value) => {
|
|
139
|
+
setPlacement(value);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
watch(isOpen, (value) => {
|
|
143
|
+
if (value) {
|
|
144
|
+
updatePopper();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
emit('update:open', value);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
onMounted(() => {
|
|
151
|
+
nextTick(() => {
|
|
152
|
+
setPlacement(props.placement)
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
useEventListener('resize', () => {
|
|
157
|
+
updatePopper();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
onClickOutside(wrapper, (e) => {
|
|
161
|
+
let parent = e.target as HTMLElement;
|
|
162
|
+
|
|
163
|
+
// fail safe of 10
|
|
164
|
+
let i = 0;
|
|
165
|
+
while (parent) {
|
|
166
|
+
if (parent.classList.contains('m-dropdown-menu')) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
parent = parent.parentElement as HTMLElement;
|
|
170
|
+
|
|
171
|
+
if (i > 10) {
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
i++;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
isOpen.value = false;
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
function setPlacement(value: Placement) {
|
|
181
|
+
const [xPlacement] = value.split('-');
|
|
182
|
+
|
|
183
|
+
if (isNested && xPlacement !== 'right' && xPlacement !== 'left') {
|
|
184
|
+
placement.value = 'right-start';
|
|
185
|
+
} else {
|
|
186
|
+
placement.value = value;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function toggleDropdown() {
|
|
191
|
+
isOpen.value = !isOpen.value;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function handleSelect(labels: string[]) {
|
|
195
|
+
isOpen.value = false;
|
|
196
|
+
props.onSelect(labels);
|
|
197
|
+
// @ts-ignore
|
|
198
|
+
if (typeof state?.handleSelect === 'function') {
|
|
199
|
+
// @ts-ignore
|
|
200
|
+
state.handleSelect([currentLabel.value!, ...labels]);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const computedWrapperClasses = computed(() => {
|
|
205
|
+
return [
|
|
206
|
+
'm-dropdown',
|
|
207
|
+
{
|
|
208
|
+
'm-dropdown--open': isOpen.value,
|
|
209
|
+
'm-dropdown--nested': isNested
|
|
210
|
+
}
|
|
211
|
+
]
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
const computedReferenceClasses = computed(() => {
|
|
215
|
+
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
const transitionName = computed(() => {
|
|
219
|
+
return `m-transition__${props.transitionName}`;
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
return {
|
|
223
|
+
wrapper,
|
|
224
|
+
referenceRef,
|
|
225
|
+
popper,
|
|
226
|
+
transferTo,
|
|
227
|
+
isOpen,
|
|
228
|
+
isNested,
|
|
229
|
+
placement,
|
|
230
|
+
computedWrapperClasses,
|
|
231
|
+
computedReferenceClasses,
|
|
232
|
+
transitionName,
|
|
233
|
+
toggleDropdown
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
})
|
|
237
|
+
</script>
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<li ref="wrapper" :class="computedWrapperClasses" role="menuitem" tabindex="0" @click="handleSelect">
|
|
3
|
+
<div v-if="hasIconLeft" class="m-dropdown__icon-left">
|
|
4
|
+
<slot name="icon-left" />
|
|
5
|
+
</div>
|
|
6
|
+
<div class="m-dropdown__text">
|
|
7
|
+
<slot />
|
|
8
|
+
</div>
|
|
9
|
+
<!-- <div v-if="hotkey" class="m-dropdown__hotkeys">
|
|
10
|
+
<template v-for="key in hotkey.split('+')">
|
|
11
|
+
<kbd>{{ key }}</kbd>
|
|
12
|
+
</template>
|
|
13
|
+
</div> -->
|
|
14
|
+
<div v-if="hasIconRight" class="m-dropdown__icon-right">
|
|
15
|
+
<slot name="icon-right" />
|
|
16
|
+
</div>
|
|
17
|
+
</li>
|
|
18
|
+
</template>
|
|
19
|
+
|
|
20
|
+
<script lang="ts">
|
|
21
|
+
import { defineComponent, inject, ref, type PropType, computed, toRef, onMounted } from 'vue';
|
|
22
|
+
import { useMagicKeys, whenever } from '@vueuse/core';
|
|
23
|
+
import { useLabel } from './hooks';
|
|
24
|
+
|
|
25
|
+
export default defineComponent({
|
|
26
|
+
name: "DropdownItem",
|
|
27
|
+
props: {
|
|
28
|
+
label: {
|
|
29
|
+
type: [String, Number],
|
|
30
|
+
default: null
|
|
31
|
+
},
|
|
32
|
+
disabled: {
|
|
33
|
+
type: Boolean,
|
|
34
|
+
default: false
|
|
35
|
+
},
|
|
36
|
+
reference: {
|
|
37
|
+
type: Boolean,
|
|
38
|
+
default: false
|
|
39
|
+
},
|
|
40
|
+
onSelect: {
|
|
41
|
+
type: Function as PropType<(label: string | number) => void>,
|
|
42
|
+
default: () => { }
|
|
43
|
+
},
|
|
44
|
+
hotkey: {
|
|
45
|
+
type: String,
|
|
46
|
+
default: null
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
emits: [],
|
|
50
|
+
setup(props, { slots }) {
|
|
51
|
+
const parentSelect = inject('dropdown-select', null);
|
|
52
|
+
const state = inject("dropdown", null);
|
|
53
|
+
// const keys = useMagicKeys({
|
|
54
|
+
// passive: false,
|
|
55
|
+
// onEventFired: (event) => {
|
|
56
|
+
|
|
57
|
+
// // only fire when the dropdown is open
|
|
58
|
+
// if (state?.isOpen.value) {
|
|
59
|
+
// event.preventDefault();
|
|
60
|
+
// }
|
|
61
|
+
// }
|
|
62
|
+
// });
|
|
63
|
+
|
|
64
|
+
const hasIconLeft = computed(() => !!(slots['icon-left']));
|
|
65
|
+
const hasIconRight = computed(() => !!(slots['icon-right']));
|
|
66
|
+
|
|
67
|
+
const wrapper = ref(null);
|
|
68
|
+
const label = toRef(props, 'label')
|
|
69
|
+
const isReference = ref(props.reference)
|
|
70
|
+
const currentLabel = useLabel(label, wrapper)
|
|
71
|
+
function handleSelect() {
|
|
72
|
+
if (props.disabled || isReference.value) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (typeof parentSelect === 'function') {
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
parentSelect([currentLabel.value!]);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
props.onSelect(currentLabel.value!);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// const isOpen = computed(() => {
|
|
85
|
+
// return state?.isOpen.value;
|
|
86
|
+
// });
|
|
87
|
+
|
|
88
|
+
const computedWrapperClasses = computed(() => {
|
|
89
|
+
return {
|
|
90
|
+
'm-dropdown-item': true,
|
|
91
|
+
'm-dropdown-item--disabled': props.disabled,
|
|
92
|
+
'm-dropdown-item--reference': props.reference
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// onMounted(() => {
|
|
97
|
+
// if (props.hotkey) {
|
|
98
|
+
// const combination = keys[props.hotkey];
|
|
99
|
+
|
|
100
|
+
// whenever(combination, (v) => {
|
|
101
|
+
// if (v && isOpen.value) {
|
|
102
|
+
// handleSelect();
|
|
103
|
+
// }
|
|
104
|
+
// })
|
|
105
|
+
// }
|
|
106
|
+
// })
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
wrapper,
|
|
111
|
+
hasIconLeft,
|
|
112
|
+
hasIconRight,
|
|
113
|
+
handleSelect,
|
|
114
|
+
computedWrapperClasses
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
</script>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<ul>
|
|
3
|
+
<slot />
|
|
4
|
+
</ul>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script lang="ts">
|
|
8
|
+
import { defineComponent } from 'vue';
|
|
9
|
+
|
|
10
|
+
export default defineComponent({
|
|
11
|
+
name: "DropdownList",
|
|
12
|
+
setup() {
|
|
13
|
+
|
|
14
|
+
// computed classes
|
|
15
|
+
return {
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
</script>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<slot />
|
|
3
|
+
</template>
|
|
4
|
+
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
import { defineComponent, inject, provide } from 'vue';
|
|
7
|
+
|
|
8
|
+
export default defineComponent({
|
|
9
|
+
name: 'DropdownWrapper',
|
|
10
|
+
setup() {
|
|
11
|
+
const state = inject("dropdown", null);
|
|
12
|
+
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
provide('dropdown-select', state?.handleSelect);
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
</script>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ref, watch, onMounted, nextTick } from 'vue'
|
|
2
|
+
|
|
3
|
+
import type { Ref } from 'vue'
|
|
4
|
+
|
|
5
|
+
export function useLabel(
|
|
6
|
+
rawLabel: Ref<string | number | null>,
|
|
7
|
+
element: Ref<HTMLElement | null | undefined>
|
|
8
|
+
) {
|
|
9
|
+
const label = ref(rawLabel.value)
|
|
10
|
+
|
|
11
|
+
function setLabel(value: string | number | null) {
|
|
12
|
+
if (element.value) {
|
|
13
|
+
label.value = value ?? element.value.textContent?.trim() ?? null
|
|
14
|
+
} else {
|
|
15
|
+
label.value = value
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
watch(rawLabel, value => {
|
|
20
|
+
setLabel(value)
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
onMounted(() => {
|
|
24
|
+
nextTick(() => {
|
|
25
|
+
setLabel(rawLabel.value)
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
return label
|
|
30
|
+
}
|