@teammodlr/ui-kit 1.0.2 → 1.0.4
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 +1 -4
- package/src/__storybook__/argTypes.ts +0 -42
- package/src/__storybook__/createStory.ts +0 -15
- package/src/__storybook__/index.ts +0 -2
- package/src/components/avatar/Avatar.css +0 -69
- package/src/components/avatar/Avatar.vue +0 -102
- package/src/components/avatargroup/AvatarGroup.css +0 -8
- package/src/components/avatargroup/AvatarGroup.vue +0 -32
- package/src/components/breadcrumb/Breadcrumb.css +0 -46
- package/src/components/breadcrumb/Breadcrumb.vue +0 -51
- package/src/components/breadcrumbitem/BreadcrumbItem.vue +0 -66
- package/src/components/breadcrumbitem/index.ts +0 -1
- package/src/components/button/Button.css +0 -378
- package/src/components/button/Button.vue +0 -108
- package/src/components/buttongroup/ButtonGroup.vue +0 -47
- package/src/components/checkbox/Checkbox.css +0 -185
- package/src/components/checkbox/Checkbox.vue +0 -140
- package/src/components/dropdown/Dropdown.css +0 -68
- package/src/components/dropdown/Dropdown.vue +0 -237
- package/src/components/dropdown/DropdownItem.vue +0 -118
- package/src/components/dropdown/DropdownList.vue +0 -20
- package/src/components/dropdown/DropdownWrapper.vue +0 -17
- package/src/components/dropdown/hooks.ts +0 -30
- package/src/components/form/Form.vue +0 -141
- package/src/components/image/Image.vue +0 -71
- package/src/components/index.ts +0 -27
- package/src/components/input/Input.css +0 -173
- package/src/components/input/Input.vue +0 -176
- package/src/components/link/Link.css +0 -147
- package/src/components/link/Link.vue +0 -54
- package/src/components/messageprovider/Message.vue +0 -76
- package/src/components/messageprovider/MessageProvider.css +0 -36
- package/src/components/messageprovider/MessageProvider.vue +0 -142
- package/src/components/messageprovider/types.ts +0 -39
- package/src/components/messageprovider/useMessage.ts +0 -12
- package/src/components/select/Select.css +0 -226
- package/src/components/select/Select.vue +0 -474
- package/src/components/skeleton/Skeleton.css +0 -73
- package/src/components/skeleton/Skeleton.vue +0 -47
- package/src/components/tab/Tab.css +0 -113
- package/src/components/tab/Tab.vue +0 -98
- package/src/components/tab/TabGroup.vue +0 -90
- package/src/components/table/Table.css +0 -45
- package/src/components/table/Table.vue +0 -108
- package/src/components/table/TableBody.vue +0 -13
- package/src/components/table/TableCell.vue +0 -13
- package/src/components/table/TableHead.vue +0 -22
- package/src/components/table/TableHeadRow.vue +0 -15
- package/src/components/table/TableRow.vue +0 -13
- package/src/components/table/types/index.ts +0 -5
- package/src/components/tooltip/Tooltip.css +0 -49
- package/src/components/tooltip/Tooltip.vue +0 -85
- package/src/components/virtualscroll/VirtualScroll.css +0 -13
- package/src/components/virtualscroll/VirtualScroll.vue +0 -61
- package/src/composables/element.ts +0 -13
- package/src/composables/useCachedUid.ts +0 -48
- package/src/composables/useEventListener.ts +0 -14
- package/src/composables/useInput.ts +0 -134
- package/src/composables/useIsServer.ts +0 -7
- package/src/composables/useMount.ts +0 -43
- package/src/composables/usePopper.ts +0 -194
- package/src/create.ts +0 -34
- package/src/css/components.css +0 -14
- package/src/css/index.css +0 -4
- package/src/css/normalize.css +0 -379
- package/src/css/transitions.css +0 -40
- package/src/css/variables.css +0 -80
- package/src/exports/nuxt.js +0 -33
- package/src/exports/nuxt.plugin.js +0 -8
- package/src/index.ts +0 -5
- package/src/install.ts +0 -8
- package/src/shims-vue.d.ts +0 -6
- package/src/types/props.ts +0 -3
|
@@ -1,140 +0,0 @@
|
|
|
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>
|
|
@@ -1,68 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,237 +0,0 @@
|
|
|
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>
|
|
@@ -1,118 +0,0 @@
|
|
|
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>
|
|
@@ -1,20 +0,0 @@
|
|
|
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>
|
|
@@ -1,17 +0,0 @@
|
|
|
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>
|
|
@@ -1,30 +0,0 @@
|
|
|
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
|
-
}
|