vueless 0.0.543 → 0.0.545
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
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { computed, useId, useTemplateRef } from "vue";
|
|
2
|
+
import { watch, computed, useId, ref, useTemplateRef, nextTick } from "vue";
|
|
3
3
|
import { merge } from "lodash-es";
|
|
4
4
|
|
|
5
5
|
import UIcon from "../ui.image-icon/UIcon.vue";
|
|
@@ -49,6 +49,10 @@ const emit = defineEmits([
|
|
|
49
49
|
|
|
50
50
|
const wrapperRef = useTemplateRef<HTMLDivElement>("wrapper");
|
|
51
51
|
const optionsRef = useTemplateRef<HTMLLIElement[]>("option");
|
|
52
|
+
const emptyOptionRef = useTemplateRef<HTMLLIElement>("empty-option");
|
|
53
|
+
const addOptionRef = useTemplateRef<HTMLLIElement>("add-option");
|
|
54
|
+
|
|
55
|
+
const wrapperMaxHeight = ref("");
|
|
52
56
|
|
|
53
57
|
const { pointer, pointerDirty, pointerSet, pointerBackward, pointerForward, pointerReset } =
|
|
54
58
|
usePointer(props.options, optionsRef, wrapperRef);
|
|
@@ -80,16 +84,43 @@ const addOptionKeyCombination = computed(() => {
|
|
|
80
84
|
return isMac ? "(⌘ + Enter)" : "(Ctrl + Enter)";
|
|
81
85
|
});
|
|
82
86
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
87
|
+
watch(
|
|
88
|
+
() => [props.options, props.size],
|
|
89
|
+
() => {
|
|
90
|
+
nextTick(() => {
|
|
91
|
+
const options = [
|
|
92
|
+
...(optionsRef.value || []),
|
|
93
|
+
...(addOptionRef.value ? [addOptionRef.value] : []),
|
|
94
|
+
...(emptyOptionRef.value ? [emptyOptionRef.value] : []),
|
|
95
|
+
];
|
|
96
|
+
|
|
97
|
+
if (props.visibleOptions) {
|
|
98
|
+
options.slice(0, props.visibleOptions);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const maxHeight = options
|
|
102
|
+
.slice(0, props.visibleOptions)
|
|
103
|
+
.map((el) => {
|
|
104
|
+
const elHeight = el.getBoundingClientRect().height;
|
|
105
|
+
|
|
106
|
+
const styles = window.getComputedStyle(el);
|
|
107
|
+
const marginTop = parseFloat(styles.marginTop || "0");
|
|
108
|
+
const marginBottom = parseFloat(styles.marginBottom || "0");
|
|
109
|
+
|
|
110
|
+
const [childDiv] = el.getElementsByTagName("div");
|
|
111
|
+
const childStyles = childDiv && window.getComputedStyle(childDiv);
|
|
112
|
+
const childMarginTop = parseFloat(childStyles?.marginTop || "0");
|
|
113
|
+
const childMarginBottom = parseFloat(childStyles?.marginBottom || "0");
|
|
114
|
+
|
|
115
|
+
return elHeight + marginTop + marginBottom + childMarginTop + childMarginBottom;
|
|
116
|
+
})
|
|
117
|
+
.reduce((acc, cur) => acc + cur, 0);
|
|
118
|
+
|
|
119
|
+
wrapperMaxHeight.value = `${maxHeight + 10}px`;
|
|
120
|
+
});
|
|
121
|
+
},
|
|
122
|
+
{ immediate: true },
|
|
123
|
+
);
|
|
93
124
|
|
|
94
125
|
function onClickAddOption() {
|
|
95
126
|
emit("add");
|
|
@@ -116,7 +147,7 @@ function isSelectedOption(option: Option) {
|
|
|
116
147
|
}
|
|
117
148
|
|
|
118
149
|
function getMarginForSubCategory(level: number = 0) {
|
|
119
|
-
const baseMargin =
|
|
150
|
+
const baseMargin = 0.5;
|
|
120
151
|
|
|
121
152
|
if (level > 1) {
|
|
122
153
|
return `margin-left: ${baseMargin * (level - 1)}rem`;
|
|
@@ -269,9 +300,10 @@ defineExpose({
|
|
|
269
300
|
|
|
270
301
|
<li
|
|
271
302
|
v-if="!options.length"
|
|
272
|
-
|
|
303
|
+
:id="`${elementId}-empty`"
|
|
304
|
+
ref="empty-option"
|
|
305
|
+
role="option"
|
|
273
306
|
v-bind="optionAttrs"
|
|
274
|
-
@mouseenter.self="pointerSet(options.length + 1)"
|
|
275
307
|
>
|
|
276
308
|
<!-- @slot Use it to add something instead of empty state. -->
|
|
277
309
|
<slot name="empty">
|
|
@@ -282,6 +314,9 @@ defineExpose({
|
|
|
282
314
|
<!-- Add button -->
|
|
283
315
|
<template v-if="addOption">
|
|
284
316
|
<li
|
|
317
|
+
:id="`${elementId}-addOption`"
|
|
318
|
+
ref="add-option"
|
|
319
|
+
role="option"
|
|
285
320
|
v-bind="addOptionLabelWrapperAttrs"
|
|
286
321
|
@click="onClickAddOption"
|
|
287
322
|
@mouseenter.self="pointerSet(options.length + 1)"
|
|
@@ -5,13 +5,13 @@ export default /*tw*/ {
|
|
|
5
5
|
overflow-auto [-webkit-overflow-scrolling:touch]
|
|
6
6
|
focus:outline-none
|
|
7
7
|
`,
|
|
8
|
-
list: "m-1 inline-block list-none align-top w-full
|
|
8
|
+
list: "m-1 p-0 inline-block list-none align-top w-full",
|
|
9
9
|
listItem: "group/item block",
|
|
10
10
|
option: {
|
|
11
11
|
base: `
|
|
12
12
|
rounded px-2 py-2.5 flex items-center align-middle whitespace-nowrap cursor-pointer
|
|
13
13
|
font-normal !leading-none normal-case text-gray-900
|
|
14
|
-
hover:bg-brand-50
|
|
14
|
+
hover:bg-brand-50 active:bg-brand-100
|
|
15
15
|
overflow-hidden text-ellipsis
|
|
16
16
|
`,
|
|
17
17
|
variants: {
|
|
@@ -28,19 +28,8 @@ export default /*tw*/ {
|
|
|
28
28
|
optionContent: "overflow-visible text-ellipsis",
|
|
29
29
|
optionSelected: "font-bold",
|
|
30
30
|
optionHighlighted: "bg-brand-50",
|
|
31
|
-
|
|
32
|
-
base:
|
|
33
|
-
group-first/item:pt-2`,
|
|
34
|
-
variants: {
|
|
35
|
-
size: {
|
|
36
|
-
sm: "text-2xs",
|
|
37
|
-
md: "text-xs",
|
|
38
|
-
lg: "text-sm",
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
subGroup: {
|
|
43
|
-
base: "pointer-events-none bg-transparent font-medium !leading-none uppercase text-gray-400 pt-2",
|
|
31
|
+
groupBase: {
|
|
32
|
+
base: "px-2 pb-2.5 font-medium !leading-none text-gray-400 overflow-hidden text-ellipsis",
|
|
44
33
|
variants: {
|
|
45
34
|
size: {
|
|
46
35
|
sm: "text-2xs",
|
|
@@ -49,8 +38,14 @@ export default /*tw*/ {
|
|
|
49
38
|
},
|
|
50
39
|
},
|
|
51
40
|
},
|
|
41
|
+
group: `
|
|
42
|
+
border-t border-gray-100 group-first/item:border-none
|
|
43
|
+
mt-1.5 group-first/item:mt-0
|
|
44
|
+
pt-4 group-first/item:pt-2
|
|
45
|
+
`,
|
|
46
|
+
subGroup: "pt-2",
|
|
52
47
|
addOptionLabelWrapper: "-mb-[1.375rem] active:bg-brand-100",
|
|
53
|
-
addOptionLabel: "
|
|
48
|
+
addOptionLabel: "leading-none font-medium",
|
|
54
49
|
addOptionLabelHotkey: "text-gray-500",
|
|
55
50
|
addOptionButton: "{UButton} !leading-none sticky left-[calc(100%-2.15rem)] bottom-2 p-1",
|
|
56
51
|
addOptionIcon: "{UIcon} bg-transparent",
|
|
@@ -91,12 +91,29 @@ VisibleOptions.args = { visibleOptions: 3 };
|
|
|
91
91
|
export const WithoutOptions = DefaultTemplate.bind({});
|
|
92
92
|
WithoutOptions.args = { options: [] };
|
|
93
93
|
|
|
94
|
+
export const GroupedOptions = DefaultTemplate.bind({});
|
|
95
|
+
GroupedOptions.args = {
|
|
96
|
+
labelKey: "name",
|
|
97
|
+
valueKey: "name",
|
|
98
|
+
options: [
|
|
99
|
+
{ groupLabel: "Javascript" },
|
|
100
|
+
{ name: "Vue.js" },
|
|
101
|
+
{ name: "Adonis" },
|
|
102
|
+
{ groupLabel: "Ruby" },
|
|
103
|
+
{ name: "Frameworks", isSubGroup: true, level: 2 },
|
|
104
|
+
{ name: "Rails", level: 2 },
|
|
105
|
+
{ name: "Sinatra", level: 2 },
|
|
106
|
+
{ groupLabel: "Other" },
|
|
107
|
+
{ name: "Laravel" },
|
|
108
|
+
{ name: "Phoenix" },
|
|
109
|
+
],
|
|
110
|
+
};
|
|
111
|
+
|
|
94
112
|
export const OptionSettings = DefaultTemplate.bind({});
|
|
95
113
|
OptionSettings.args = {
|
|
96
114
|
options: [
|
|
97
115
|
{ label: "option 1", id: "1" },
|
|
98
116
|
{ label: "option 2", id: "2", isHidden: true },
|
|
99
|
-
|
|
100
117
|
{
|
|
101
118
|
label: "option 3",
|
|
102
119
|
id: "3",
|
|
@@ -12,7 +12,7 @@ export default function useAttrs(props: UDropdownListProps): UseAttrs<Config> {
|
|
|
12
12
|
() => props.config,
|
|
13
13
|
);
|
|
14
14
|
|
|
15
|
-
const extendingKeys = ["option"];
|
|
15
|
+
const extendingKeys = ["option", "groupBase"];
|
|
16
16
|
const extendingKeysClasses = getExtendingKeysClasses(extendingKeys);
|
|
17
17
|
|
|
18
18
|
const keysAttrs = getKeysAttrs({}, [], {
|
|
@@ -20,10 +20,10 @@ export default function useAttrs(props: UDropdownListProps): UseAttrs<Config> {
|
|
|
20
20
|
base: computed(() => [extendingKeysClasses.option.value]),
|
|
21
21
|
},
|
|
22
22
|
group: {
|
|
23
|
-
base: computed(() => [extendingKeysClasses.
|
|
23
|
+
base: computed(() => [extendingKeysClasses.groupBase.value]),
|
|
24
24
|
},
|
|
25
25
|
subGroup: {
|
|
26
|
-
base: computed(() => [extendingKeysClasses.
|
|
26
|
+
base: computed(() => [extendingKeysClasses.groupBase.value]),
|
|
27
27
|
},
|
|
28
28
|
});
|
|
29
29
|
|