@veritree/ui 0.6.0 → 0.8.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/index.js +75 -46
- package/nuxt.js +20 -0
- package/package.json +1 -1
- package/src/Avatar/VTAvatarImage.vue +4 -4
- package/src/DropdownMenu/VTDropdownMenu.vue +76 -0
- package/src/DropdownMenu/VTDropdownMenuContent.vue +92 -0
- package/src/DropdownMenu/VTDropdownMenuDivider.vue +28 -0
- package/src/DropdownMenu/VTDropdownMenuGroup.vue +9 -0
- package/src/DropdownMenu/VTDropdownMenuItem.vue +171 -0
- package/src/DropdownMenu/VTDropdownMenuLabel.vue +30 -0
- package/src/DropdownMenu/VTDropdownMenuTrigger.vue +191 -0
- package/src/Form/VTFormFeedback.vue +64 -0
- package/src/Form/VTFormGroup.vue +22 -0
- package/src/Popover/VTPopover.vue +71 -0
- package/src/Popover/VTPopoverContent.vue +83 -0
- package/src/Popover/VTPopoverDivider.vue +28 -0
- package/src/Popover/VTPopoverGroup.vue +5 -0
- package/src/Popover/VTPopoverItem.vue +55 -0
- package/src/Popover/VTPopoverTrigger.vue +51 -0
package/index.js
CHANGED
|
@@ -1,59 +1,74 @@
|
|
|
1
|
-
import VTAvatar from
|
|
2
|
-
import VTAvatarImage from
|
|
3
|
-
import VTAvatarText from
|
|
4
|
-
import VTImage from
|
|
5
|
-
import VTImageCounter from
|
|
6
|
-
import VTImageHover from
|
|
1
|
+
import VTAvatar from "./src/Avatar/VTAvatar.vue";
|
|
2
|
+
import VTAvatarImage from "./src/Avatar/VTAvatarImage.vue";
|
|
3
|
+
import VTAvatarText from "./src/Avatar/VTAvatarText.vue";
|
|
4
|
+
import VTImage from "./src/Image/VTImage.vue";
|
|
5
|
+
import VTImageCounter from "./src/Image/VTImageCounter.vue";
|
|
6
|
+
import VTImageHover from "./src/Image/VTImageHover.vue";
|
|
7
|
+
import VTDropdownMenu from "./src/DropdownMenu/VTDropdownMenu.vue";
|
|
8
|
+
import VTDropdownMenuContent from "./src/DropdownMenu/VTDropdownMenuContent.vue";
|
|
9
|
+
import VTDropdownMenuDivider from "./src/DropdownMenu/VTDropdownMenuDivider.vue";
|
|
10
|
+
import VTDropdownMenuGroup from "./src/DropdownMenu/VTDropdownMenuGroup.vue";
|
|
11
|
+
import VTDropdownMenuItem from "./src/DropdownMenu/VTDropdownMenuItem.vue";
|
|
12
|
+
import VTDropdownMenuLabel from "./src/DropdownMenu/VTDropdownMenuLabel.vue";
|
|
13
|
+
import VTDropdownMenuTrigger from "./src/DropdownMenu/VTDropdownMenuTrigger.vue";
|
|
14
|
+
import VTPopover from "./src/Popover/VTPopover.vue";
|
|
15
|
+
import VTPopoverContent from "./src/Popover/VTPopoverContent.vue";
|
|
16
|
+
import VTPopoverDivider from "./src/Popover/VTPopoverDivider.vue";
|
|
17
|
+
import VTPopoverGroup from "./src/Popover/VTPopoverGroup.vue";
|
|
18
|
+
import VTPopoverItem from "./src/Popover/VTPopoverItem.vue";
|
|
19
|
+
import VTPopoverTrigger from "./src/Popover/VTPopoverTrigger.vue";
|
|
20
|
+
import VTFormFeedback from "./src/Form/VTFormFeedback.vue";
|
|
21
|
+
import VTFormGroup from "./src/Form/VTFormGroup.vue";
|
|
7
22
|
|
|
8
|
-
import VTAlert from
|
|
23
|
+
import VTAlert from "./src/Alerts/VTAlert.vue";
|
|
9
24
|
|
|
10
|
-
import VTSpinner from
|
|
25
|
+
import VTSpinner from "./src/Spinner/VTSpinner.vue";
|
|
11
26
|
|
|
12
|
-
import VTButton from
|
|
27
|
+
import VTButton from "./src/Button/VTButton.vue";
|
|
13
28
|
// import VTButtonSave from './src/Button/VTButtonSave.vue';
|
|
14
29
|
|
|
15
|
-
import VTInput from
|
|
16
|
-
import VTInputDate from
|
|
17
|
-
import VTInputFile from
|
|
18
|
-
import VTInputUpload from
|
|
30
|
+
import VTInput from "./src/Input/VTInput.vue";
|
|
31
|
+
import VTInputDate from "./src/Input/VTInputDate.vue";
|
|
32
|
+
import VTInputFile from "./src/Input/VTInputFile.vue";
|
|
33
|
+
import VTInputUpload from "./src/Input/VTInputUpload.vue";
|
|
19
34
|
|
|
20
|
-
import VTTextarea from
|
|
35
|
+
import VTTextarea from "./src/Textarea/VTTextarea.vue";
|
|
21
36
|
|
|
22
|
-
import VTListbox from
|
|
23
|
-
import VTListboxButton from
|
|
24
|
-
import VTListboxOption from
|
|
25
|
-
import VTListboxOptions from
|
|
37
|
+
import VTListbox from "./src/Listbox/VTListbox.vue";
|
|
38
|
+
import VTListboxButton from "./src/Listbox/VTListboxButton.vue";
|
|
39
|
+
import VTListboxOption from "./src/Listbox/VTListboxOption.vue";
|
|
40
|
+
import VTListboxOptions from "./src/Listbox/VTListboxOptions.vue";
|
|
26
41
|
|
|
27
|
-
import VTModal from
|
|
42
|
+
import VTModal from "./src/Modal/VTModal.vue";
|
|
28
43
|
|
|
29
|
-
import VTAccordion from
|
|
30
|
-
import VTAccordionButton from
|
|
31
|
-
import VTAccordionGroup from
|
|
32
|
-
import VTAccordionPanel from
|
|
44
|
+
import VTAccordion from "./src/Accordion/VTAccordion.vue";
|
|
45
|
+
import VTAccordionButton from "./src/Accordion/VTAccordionButton.vue";
|
|
46
|
+
import VTAccordionGroup from "./src/Accordion/VTAccordionGroup.vue";
|
|
47
|
+
import VTAccordionPanel from "./src/Accordion/VTAccordionPanel.vue";
|
|
33
48
|
|
|
34
|
-
import VTTab from
|
|
35
|
-
import VTTabGroup from
|
|
36
|
-
import VTTabList from
|
|
37
|
-
import VTTabPanel from
|
|
38
|
-
import VTTabPanels from
|
|
49
|
+
import VTTab from "./src/Tabs/VTTab.vue";
|
|
50
|
+
import VTTabGroup from "./src/Tabs/VTTabGroup.vue";
|
|
51
|
+
import VTTabList from "./src/Tabs/VTTabList.vue";
|
|
52
|
+
import VTTabPanel from "./src/Tabs/VTTabPanel.vue";
|
|
53
|
+
import VTTabPanels from "./src/Tabs/VTTabPanels.vue";
|
|
39
54
|
|
|
40
|
-
import VTDialog from
|
|
41
|
-
import VTDialogClose from
|
|
42
|
-
import VTDialogContent from
|
|
43
|
-
import VTDialogFooter from
|
|
44
|
-
import VTDialogHeader from
|
|
45
|
-
import VTDialogMain from
|
|
46
|
-
import VTDialogOverlay from
|
|
47
|
-
import VTDialogTitle from
|
|
55
|
+
import VTDialog from "./src/Dialog/VTDialog.vue";
|
|
56
|
+
import VTDialogClose from "./src/Dialog/VTDialogClose.vue";
|
|
57
|
+
import VTDialogContent from "./src/Dialog/VTDialogContent.vue";
|
|
58
|
+
import VTDialogFooter from "./src/Dialog/VTDialogFooter.vue";
|
|
59
|
+
import VTDialogHeader from "./src/Dialog/VTDialogHeader.vue";
|
|
60
|
+
import VTDialogMain from "./src/Dialog/VTDialogMain.vue";
|
|
61
|
+
import VTDialogOverlay from "./src/Dialog/VTDialogOverlay.vue";
|
|
62
|
+
import VTDialogTitle from "./src/Dialog/VTDialogTitle.vue";
|
|
48
63
|
|
|
49
|
-
import VTDrawer from
|
|
50
|
-
import VTDrawerClose from
|
|
51
|
-
import VTDrawerContent from
|
|
52
|
-
import VTDrawerFooter from
|
|
53
|
-
import VTDrawerHeader from
|
|
54
|
-
import VTDrawerTitle from
|
|
55
|
-
import VTDrawerMain from
|
|
56
|
-
import VTDrawerOverlay from
|
|
64
|
+
import VTDrawer from "./src/Drawer/VTDrawer.vue";
|
|
65
|
+
import VTDrawerClose from "./src/Drawer/VTDrawerClose.vue";
|
|
66
|
+
import VTDrawerContent from "./src/Drawer/VTDrawerContent.vue";
|
|
67
|
+
import VTDrawerFooter from "./src/Drawer/VTDrawerFooter.vue";
|
|
68
|
+
import VTDrawerHeader from "./src/Drawer/VTDrawerHeader.vue";
|
|
69
|
+
import VTDrawerTitle from "./src/Drawer/VTDrawerTitle.vue";
|
|
70
|
+
import VTDrawerMain from "./src/Drawer/VTDrawerMain.vue";
|
|
71
|
+
import VTDrawerOverlay from "./src/Drawer/VTDrawerOverlay.vue";
|
|
57
72
|
|
|
58
73
|
export {
|
|
59
74
|
VTAvatar,
|
|
@@ -64,6 +79,21 @@ export {
|
|
|
64
79
|
VTImageHover,
|
|
65
80
|
VTAlert,
|
|
66
81
|
VTSpinner,
|
|
82
|
+
VTDropdownMenu,
|
|
83
|
+
VTDropdownMenuContent,
|
|
84
|
+
VTDropdownMenuDivider,
|
|
85
|
+
VTDropdownMenuGroup,
|
|
86
|
+
VTDropdownMenuItem,
|
|
87
|
+
VTDropdownMenuLabel,
|
|
88
|
+
VTDropdownMenuTrigger,
|
|
89
|
+
VTPopover,
|
|
90
|
+
VTPopoverContent,
|
|
91
|
+
VTPopoverDivider,
|
|
92
|
+
VTPopoverGroup,
|
|
93
|
+
VTPopoverItem,
|
|
94
|
+
VTPopoverTrigger,
|
|
95
|
+
VTFormFeedback,
|
|
96
|
+
VTFormGroup,
|
|
67
97
|
VTButton,
|
|
68
98
|
// VTButtonSave,
|
|
69
99
|
VTInput,
|
|
@@ -101,5 +131,4 @@ export {
|
|
|
101
131
|
VTDialogMain,
|
|
102
132
|
VTDialogOverlay,
|
|
103
133
|
VTDialogTitle,
|
|
104
|
-
}
|
|
105
|
-
|
|
134
|
+
};
|
package/nuxt.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { join } from 'path';
|
|
2
|
+
|
|
3
|
+
const components = [
|
|
4
|
+
'src/Avatar',
|
|
5
|
+
'src/Drawer',
|
|
6
|
+
'src/Dialog',
|
|
7
|
+
'src/DropdownMenu',
|
|
8
|
+
'src/Form',
|
|
9
|
+
'src/Image',
|
|
10
|
+
'src/Tabs',
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
export default function () {
|
|
14
|
+
this.nuxt.hook('components:dirs', dirs => {
|
|
15
|
+
// Add ./components dir to the list
|
|
16
|
+
components.forEach((component) => {
|
|
17
|
+
dirs.push(join(__dirname, component))
|
|
18
|
+
});
|
|
19
|
+
})
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
</template>
|
|
5
5
|
|
|
6
6
|
<script>
|
|
7
|
-
import VTImage from
|
|
7
|
+
import VTImage from "../Image/VTImage.vue";
|
|
8
8
|
|
|
9
9
|
export default {
|
|
10
|
-
name:
|
|
10
|
+
name: "VTAvatarImage",
|
|
11
11
|
|
|
12
12
|
components: { VTImage },
|
|
13
13
|
|
|
@@ -18,7 +18,7 @@ export default {
|
|
|
18
18
|
},
|
|
19
19
|
src: {
|
|
20
20
|
type: String,
|
|
21
|
-
default:
|
|
21
|
+
default: "",
|
|
22
22
|
},
|
|
23
23
|
cdnSrc: {
|
|
24
24
|
type: [String, Object],
|
|
@@ -30,7 +30,7 @@ export default {
|
|
|
30
30
|
attrs() {
|
|
31
31
|
return {
|
|
32
32
|
alt: this.alt,
|
|
33
|
-
class:
|
|
33
|
+
class: "h-auto w-full",
|
|
34
34
|
};
|
|
35
35
|
},
|
|
36
36
|
},
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="relative">
|
|
3
|
+
<slot></slot>
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script>
|
|
8
|
+
import { genId } from '~/utils/ids';
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
name: 'VTDropdownMenu',
|
|
12
|
+
|
|
13
|
+
provide() {
|
|
14
|
+
return {
|
|
15
|
+
api: () => {
|
|
16
|
+
const { dark: isDark, headless: isHeadless, right: isRight } = this;
|
|
17
|
+
const { id, trigger, content, items } = this;
|
|
18
|
+
|
|
19
|
+
const registerTrigger = (trigger) => {
|
|
20
|
+
this.trigger = trigger;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const registerContent = (content) => {
|
|
24
|
+
this.content = content;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const registerItem = (item) => {
|
|
28
|
+
this.items.push(item);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const unregisterItems = () => {
|
|
32
|
+
this.items = [];
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
id,
|
|
37
|
+
isDark,
|
|
38
|
+
isHeadless,
|
|
39
|
+
isRight,
|
|
40
|
+
trigger,
|
|
41
|
+
content,
|
|
42
|
+
items,
|
|
43
|
+
registerTrigger,
|
|
44
|
+
registerContent,
|
|
45
|
+
registerItem,
|
|
46
|
+
unregisterItems,
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
props: {
|
|
53
|
+
headless: {
|
|
54
|
+
type: Boolean,
|
|
55
|
+
default: false,
|
|
56
|
+
},
|
|
57
|
+
dark: {
|
|
58
|
+
type: Boolean,
|
|
59
|
+
default: false,
|
|
60
|
+
},
|
|
61
|
+
right: {
|
|
62
|
+
type: Boolean,
|
|
63
|
+
default: false,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
data() {
|
|
68
|
+
return {
|
|
69
|
+
id: `menu-${genId()}`,
|
|
70
|
+
trigger: null,
|
|
71
|
+
content: null,
|
|
72
|
+
items: [],
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
</script>
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<transition
|
|
3
|
+
enter-active-class="duration-200 ease-out"
|
|
4
|
+
enter-class="translate-y-[15px] opacity-0"
|
|
5
|
+
enter-to-class="translate-y-0 opacity-100"
|
|
6
|
+
leave-active-class="duration-200 ease-in"
|
|
7
|
+
leave-class="translate-y-0 opacity-100"
|
|
8
|
+
leave-to-class="translate-y-[15px] opacity-0"
|
|
9
|
+
@after-leave="hide"
|
|
10
|
+
>
|
|
11
|
+
<div
|
|
12
|
+
v-if="visible"
|
|
13
|
+
:id="id"
|
|
14
|
+
:class="{
|
|
15
|
+
MenuList: headless,
|
|
16
|
+
'absolute top-full mt-3 grid min-w-[222px] overflow-hidden rounded border border-solid py-2 px-3 transition-all':
|
|
17
|
+
!headless,
|
|
18
|
+
'border-gray-100 bg-white shadow-300': !dark,
|
|
19
|
+
'bg-forest-default border-gray-700 shadow-gray-700': dark,
|
|
20
|
+
'left-0': !right,
|
|
21
|
+
'right-0': right,
|
|
22
|
+
}"
|
|
23
|
+
>
|
|
24
|
+
<slot></slot>
|
|
25
|
+
</div>
|
|
26
|
+
</transition>
|
|
27
|
+
</template>
|
|
28
|
+
|
|
29
|
+
<script>
|
|
30
|
+
import { genId } from '~/utils/ids';
|
|
31
|
+
|
|
32
|
+
export default {
|
|
33
|
+
name: 'VTDropdownMenuContent',
|
|
34
|
+
|
|
35
|
+
inject: ['api'],
|
|
36
|
+
|
|
37
|
+
data() {
|
|
38
|
+
return {
|
|
39
|
+
id: `menucontent-${genId()}`,
|
|
40
|
+
visible: false,
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
computed: {
|
|
45
|
+
dark() {
|
|
46
|
+
return this.api().isDark;
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
headless() {
|
|
50
|
+
return this.api().isHeadless;
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
right() {
|
|
54
|
+
return this.api().isRight;
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
trigger() {
|
|
58
|
+
return this.api().trigger;
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
mounted() {
|
|
63
|
+
this.api().registerContent(this);
|
|
64
|
+
|
|
65
|
+
this.$nextTick(() => {
|
|
66
|
+
if (this.trigger) this.trigger.toggleHasPopup();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// TODO: Create a directive or mixin for this
|
|
70
|
+
document.addEventListener('click', (e) => {
|
|
71
|
+
e.stopPropagation();
|
|
72
|
+
if (this.visible && !this.$el.contains(e.target)) this.trigger.onClick();
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
destroyed() {
|
|
77
|
+
// TODO: Create a directive or mixin for this
|
|
78
|
+
document.removeEventListener('click', this.trigger.onClick());
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
methods: {
|
|
82
|
+
show() {
|
|
83
|
+
this.visible = true;
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
hide() {
|
|
87
|
+
this.visible = false;
|
|
88
|
+
this.api().unregisterItems();
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
</script>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
:class="{
|
|
4
|
+
PopoverDivider: headless,
|
|
5
|
+
'-mx-3 my-2 h-[1px]': !headless,
|
|
6
|
+
'bg-gray-200': !dark,
|
|
7
|
+
'bg-fd-500': dark,
|
|
8
|
+
}"
|
|
9
|
+
></div>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<script>
|
|
13
|
+
export default {
|
|
14
|
+
name: 'VTDropdownMenuDivider',
|
|
15
|
+
|
|
16
|
+
inject: ['api'],
|
|
17
|
+
|
|
18
|
+
computed: {
|
|
19
|
+
dark() {
|
|
20
|
+
return this.api().isDark;
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
headless() {
|
|
24
|
+
return this.api().isHeadless;
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
</script>
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<component
|
|
3
|
+
:is="as"
|
|
4
|
+
:id="id"
|
|
5
|
+
:to="to"
|
|
6
|
+
:class="{
|
|
7
|
+
MenuItem: headless,
|
|
8
|
+
'-mx-3 flex min-w-max items-center gap-2 px-3 py-2 text-inherit no-underline':
|
|
9
|
+
!headless,
|
|
10
|
+
'hover:bg-secondary-200/10': !dark,
|
|
11
|
+
'text-white hover:bg-fd-450 focus:bg-fd-450': dark,
|
|
12
|
+
'pointer-events-none opacity-75': disabled,
|
|
13
|
+
}"
|
|
14
|
+
:tabindex="tabIndex"
|
|
15
|
+
:aria-disabled="disabled"
|
|
16
|
+
role="menuitem"
|
|
17
|
+
@click.stop="onClick"
|
|
18
|
+
@keydown.down.prevent="focusPreviousItem"
|
|
19
|
+
@keydown.up.prevent="focusNextItem"
|
|
20
|
+
@keydown.home.prevent="focusFirstItem"
|
|
21
|
+
@keydown.end.prevent="focusLastItem"
|
|
22
|
+
@keydown.esc.prevent="onKeyEsc"
|
|
23
|
+
@keydown.enter.prevent="onClick"
|
|
24
|
+
@keydown.tab.prevent
|
|
25
|
+
>
|
|
26
|
+
<slot></slot>
|
|
27
|
+
</component>
|
|
28
|
+
</template>
|
|
29
|
+
|
|
30
|
+
<script>
|
|
31
|
+
import { genId } from '~/utils/ids';
|
|
32
|
+
|
|
33
|
+
export default {
|
|
34
|
+
name: 'VTDropdownMenuItem',
|
|
35
|
+
|
|
36
|
+
inject: ['api'],
|
|
37
|
+
|
|
38
|
+
props: {
|
|
39
|
+
to: {
|
|
40
|
+
type: [String, Object],
|
|
41
|
+
default: null,
|
|
42
|
+
},
|
|
43
|
+
href: {
|
|
44
|
+
type: String,
|
|
45
|
+
default: null,
|
|
46
|
+
},
|
|
47
|
+
disabled: {
|
|
48
|
+
type: Boolean,
|
|
49
|
+
default: false,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
data() {
|
|
54
|
+
return {
|
|
55
|
+
id: `menuitem-${genId()}`,
|
|
56
|
+
index: null,
|
|
57
|
+
tabIndex: 0,
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
computed: {
|
|
62
|
+
dark() {
|
|
63
|
+
return this.api().isDark;
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
headless() {
|
|
67
|
+
return this.api().isHeadless;
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
as() {
|
|
71
|
+
return this.href ? 'a' : this.to ? 'NuxtLink' : 'button';
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
items() {
|
|
75
|
+
return this.api().items;
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
el() {
|
|
79
|
+
return this.$el;
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
trigger() {
|
|
83
|
+
return this.api().trigger;
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
content() {
|
|
87
|
+
return this.api().content;
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
mounted() {
|
|
92
|
+
const item = {
|
|
93
|
+
focus: this.focus,
|
|
94
|
+
el: this.el,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
this.api().registerItem(item);
|
|
98
|
+
|
|
99
|
+
this.index = this.items.length - 1;
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
methods: {
|
|
103
|
+
focus() {
|
|
104
|
+
if (!this.el) return;
|
|
105
|
+
|
|
106
|
+
this.tabIndex = -1;
|
|
107
|
+
this.el.focus();
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
focusFirstItem() {
|
|
111
|
+
this.setFocusToItem(0);
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
focusLastItem() {
|
|
115
|
+
this.setFocusToItem(this.items.length - 1);
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Focus the previous item in the menu.
|
|
120
|
+
* If is the first item, jump to the last item.
|
|
121
|
+
*/
|
|
122
|
+
focusPreviousItem() {
|
|
123
|
+
const isLast = this.index === this.items.length - 1;
|
|
124
|
+
const goToIndex = isLast ? 0 : this.index + 1;
|
|
125
|
+
|
|
126
|
+
this.setFocusToItem(goToIndex);
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Focus the next item in the menu.
|
|
131
|
+
* If is the last item, jump to the first item.
|
|
132
|
+
*/
|
|
133
|
+
focusNextItem() {
|
|
134
|
+
const isFirst = this.index === 0;
|
|
135
|
+
const goToIndex = isFirst ? this.items.length - 1 : this.index - 1;
|
|
136
|
+
|
|
137
|
+
this.setFocusToItem(goToIndex);
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Focus item by remove its tabindex and calling
|
|
142
|
+
* focus to the element.
|
|
143
|
+
*
|
|
144
|
+
* @param {Number, String} goToIndex
|
|
145
|
+
*/
|
|
146
|
+
setFocusToItem(goToIndex) {
|
|
147
|
+
this.tabIndex = 0;
|
|
148
|
+
this.items[goToIndex].focus();
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Hides content/menu and focus on trigger
|
|
153
|
+
*/
|
|
154
|
+
leaveMenu() {
|
|
155
|
+
if (this.content) this.content.hide();
|
|
156
|
+
if (this.trigger) this.trigger.focus();
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
onKeyEsc() {
|
|
160
|
+
this.leaveMenu();
|
|
161
|
+
},
|
|
162
|
+
|
|
163
|
+
onClick() {
|
|
164
|
+
if (this.disabled) return;
|
|
165
|
+
|
|
166
|
+
this.$emit('click');
|
|
167
|
+
this.$nextTick(() => this.leaveMenu());
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
</script>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<span
|
|
3
|
+
:class="{
|
|
4
|
+
MenuLabel: headless,
|
|
5
|
+
'mb-2 block text-xs uppercase': !headless,
|
|
6
|
+
'text-inherit': !dark,
|
|
7
|
+
'text-white': dark,
|
|
8
|
+
}"
|
|
9
|
+
>
|
|
10
|
+
<slot></slot>
|
|
11
|
+
</span>
|
|
12
|
+
</template>
|
|
13
|
+
|
|
14
|
+
<script>
|
|
15
|
+
export default {
|
|
16
|
+
name: 'VTDropdownMenuLabel',
|
|
17
|
+
|
|
18
|
+
inject: ['api'],
|
|
19
|
+
|
|
20
|
+
computed: {
|
|
21
|
+
dark() {
|
|
22
|
+
return this.api().isDark;
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
headless() {
|
|
26
|
+
return this.api().isHeadless;
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
</script>
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
:aria-haspopup="hasPopup"
|
|
4
|
+
:aria-expanded="expanded"
|
|
5
|
+
:aria-controls="controls"
|
|
6
|
+
@keydown.down.prevent="onKeyArrowDown"
|
|
7
|
+
@keydown.up.prevent="onKeyArrowUp"
|
|
8
|
+
@keydown.esc.prevent="onKeyesc"
|
|
9
|
+
>
|
|
10
|
+
<slot></slot>
|
|
11
|
+
</div>
|
|
12
|
+
</template>
|
|
13
|
+
|
|
14
|
+
<script>
|
|
15
|
+
export default {
|
|
16
|
+
name: 'VTDropdownMenuTrigger',
|
|
17
|
+
|
|
18
|
+
inject: ['api'],
|
|
19
|
+
|
|
20
|
+
data() {
|
|
21
|
+
return {
|
|
22
|
+
expanded: false,
|
|
23
|
+
hasPopup: false,
|
|
24
|
+
controls: null,
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
computed: {
|
|
29
|
+
// gets slot element
|
|
30
|
+
slotElm() {
|
|
31
|
+
return this.$slots.default[0].elm;
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
slotLength() {
|
|
35
|
+
return this.$slots.default.length;
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
content() {
|
|
39
|
+
return this.api().content;
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
items() {
|
|
43
|
+
return this.api().items;
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
firstMenuItem() {
|
|
47
|
+
return this.items[0];
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
lastMenuItem() {
|
|
51
|
+
return this.items[this.items.length - 1];
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
mounted() {
|
|
56
|
+
this.api().registerTrigger(this);
|
|
57
|
+
this.addEventListenerToSlotElm();
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
destroyed() {
|
|
61
|
+
this.slotElm.removeEventListener('click', this.onClick());
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
methods: {
|
|
65
|
+
/**
|
|
66
|
+
* Add event listener to slot element
|
|
67
|
+
*
|
|
68
|
+
* The click event has to be added to the slot child element
|
|
69
|
+
* since we are not setting the onclick on the component
|
|
70
|
+
* itself.
|
|
71
|
+
*
|
|
72
|
+
* Slot must have only one child element. It avoids
|
|
73
|
+
* errors related to adding the event listener.
|
|
74
|
+
*/
|
|
75
|
+
addEventListenerToSlotElm() {
|
|
76
|
+
if (!this.slotLength) return;
|
|
77
|
+
|
|
78
|
+
if (this.slotLength > 1) {
|
|
79
|
+
throw new Error('VTPopoverButton only accepts one item in its slot');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
this.slotElm.addEventListener('click', (e) => {
|
|
83
|
+
e.stopImmediatePropagation();
|
|
84
|
+
this.onClick();
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Shows content/menu if not already visible
|
|
90
|
+
*/
|
|
91
|
+
showContent() {
|
|
92
|
+
if (!this.expanded) {
|
|
93
|
+
this.toggleExpanded();
|
|
94
|
+
this.content.show();
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Focus slot element if it exists and toggle expanded
|
|
100
|
+
*/
|
|
101
|
+
focus() {
|
|
102
|
+
if (!this.slotElm) return;
|
|
103
|
+
|
|
104
|
+
this.slotElm.focus();
|
|
105
|
+
this.toggleExpanded();
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Toggles aria expanded attribute/state
|
|
110
|
+
*/
|
|
111
|
+
toggleExpanded() {
|
|
112
|
+
this.expanded = !this.expanded;
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Toggles aria popup/controls attribute/state
|
|
117
|
+
*/
|
|
118
|
+
toggleHasPopup() {
|
|
119
|
+
if (!this.content) return;
|
|
120
|
+
|
|
121
|
+
this.hasPopup = !this.hasPopup;
|
|
122
|
+
|
|
123
|
+
if (!this.hasPopup) {
|
|
124
|
+
this.controls = null;
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
this.controls = this.content.id;
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* On click, do the following:
|
|
133
|
+
*
|
|
134
|
+
* 1. Toggle aria expanded attribute/state
|
|
135
|
+
* 2. Open the menu if it's closed
|
|
136
|
+
* 3. Close the menu if it's open
|
|
137
|
+
*/
|
|
138
|
+
onClick() {
|
|
139
|
+
if (!this.content) return;
|
|
140
|
+
|
|
141
|
+
this.toggleExpanded();
|
|
142
|
+
|
|
143
|
+
this.$nextTick(() => {
|
|
144
|
+
if (this.expanded) this.content.show();
|
|
145
|
+
else this.content.hide();
|
|
146
|
+
});
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* On key arrow down, do the following:
|
|
151
|
+
*
|
|
152
|
+
* 1. if the menu is not expanded, expand it and focus the first menu item
|
|
153
|
+
* 2. if the menu is expanded, focus the first menu item
|
|
154
|
+
*/
|
|
155
|
+
onKeyArrowDown() {
|
|
156
|
+
if (!this.content) return;
|
|
157
|
+
|
|
158
|
+
this.showContent();
|
|
159
|
+
|
|
160
|
+
this.$nextTick(() => {
|
|
161
|
+
this.firstMenuItem.focus();
|
|
162
|
+
});
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* On key arrow up, do the following:
|
|
167
|
+
*
|
|
168
|
+
* 1. if the menu is not expanded, expand it and focus the last menu item
|
|
169
|
+
* 2. if the menu is expanded, focus the last menu item
|
|
170
|
+
*/
|
|
171
|
+
onKeyArrowUp() {
|
|
172
|
+
if (!this.content) return;
|
|
173
|
+
|
|
174
|
+
this.showContent();
|
|
175
|
+
|
|
176
|
+
this.$nextTick(() => {
|
|
177
|
+
this.lastMenuItem.focus();
|
|
178
|
+
});
|
|
179
|
+
},
|
|
180
|
+
|
|
181
|
+
onKeyesc() {
|
|
182
|
+
if (!this.content) return;
|
|
183
|
+
|
|
184
|
+
if (this.expanded) {
|
|
185
|
+
this.toggleExpanded();
|
|
186
|
+
this.content.hide();
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
</script>
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="form-feedback" :class="classes">
|
|
3
|
+
<component :is="icon" v-if="showIcon" />
|
|
4
|
+
<span class="text-gray-500"><slot></slot></span>
|
|
5
|
+
</div>
|
|
6
|
+
</template>
|
|
7
|
+
|
|
8
|
+
<script>
|
|
9
|
+
import { IconCheck, IconWarning } from '@veritree/icons';
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
name: 'VTFormFeedback',
|
|
13
|
+
|
|
14
|
+
components: {
|
|
15
|
+
IconWarning,
|
|
16
|
+
IconCheck,
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
props: {
|
|
20
|
+
variant: {
|
|
21
|
+
type: [String, Object],
|
|
22
|
+
default: '',
|
|
23
|
+
validator(value) {
|
|
24
|
+
if (value === '' || typeof value === 'object') {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return ['success', 'warning', 'error'].includes(value);
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
hideIcon: {
|
|
32
|
+
type: Boolean,
|
|
33
|
+
default: false,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
computed: {
|
|
38
|
+
classes() {
|
|
39
|
+
const classes = {};
|
|
40
|
+
|
|
41
|
+
if (this.variant) {
|
|
42
|
+
classes[`form-feedback--${this.variant}`] = true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return classes;
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
icon() {
|
|
49
|
+
if (this.variant === 'success') return IconCheck;
|
|
50
|
+
return IconWarning;
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
showIcon() {
|
|
54
|
+
return !this.hideIcon;
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
methods: {
|
|
59
|
+
onClick() {
|
|
60
|
+
this.$emit('click');
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
</script>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<component :is="as" :class="classes" class="form-group">
|
|
3
|
+
<slot></slot>
|
|
4
|
+
</component>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script>
|
|
8
|
+
export default {
|
|
9
|
+
props: {
|
|
10
|
+
as: {
|
|
11
|
+
type: String,
|
|
12
|
+
default: 'div',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
data() {
|
|
17
|
+
return {
|
|
18
|
+
classes: {},
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
</script>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
:id="id"
|
|
4
|
+
class="relative"
|
|
5
|
+
:aria-haspopup="content ? 'true' : null"
|
|
6
|
+
:aria-controls="content ? content.id : null"
|
|
7
|
+
>
|
|
8
|
+
<slot></slot>
|
|
9
|
+
</div>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<script>
|
|
13
|
+
import { genId } from '~/utils/ids';
|
|
14
|
+
|
|
15
|
+
export default {
|
|
16
|
+
name: 'VTPopover',
|
|
17
|
+
|
|
18
|
+
provide() {
|
|
19
|
+
return {
|
|
20
|
+
api: () => {
|
|
21
|
+
const { dark: isDark, headless: isHeadless, right: isRight } = this;
|
|
22
|
+
const { id, button, content } = this;
|
|
23
|
+
|
|
24
|
+
const registerButton = (button) => {
|
|
25
|
+
if (!button) return;
|
|
26
|
+
this.button = button;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const registerContent = (content) => {
|
|
30
|
+
if (!content) return;
|
|
31
|
+
this.content = content;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
id,
|
|
36
|
+
isDark,
|
|
37
|
+
isHeadless,
|
|
38
|
+
isRight,
|
|
39
|
+
button,
|
|
40
|
+
content,
|
|
41
|
+
registerButton,
|
|
42
|
+
registerContent,
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
props: {
|
|
49
|
+
headless: {
|
|
50
|
+
type: Boolean,
|
|
51
|
+
default: false,
|
|
52
|
+
},
|
|
53
|
+
dark: {
|
|
54
|
+
type: Boolean,
|
|
55
|
+
default: false,
|
|
56
|
+
},
|
|
57
|
+
right: {
|
|
58
|
+
type: Boolean,
|
|
59
|
+
default: false,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
data() {
|
|
64
|
+
return {
|
|
65
|
+
id: `popover-${genId()}`,
|
|
66
|
+
button: null,
|
|
67
|
+
content: null,
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
</script>
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<transition
|
|
3
|
+
enter-active-class="duration-200 ease-out"
|
|
4
|
+
enter-class="translate-y-[15px] opacity-0"
|
|
5
|
+
enter-to-class="translate-y-0 opacity-100"
|
|
6
|
+
leave-active-class="duration-200 ease-in"
|
|
7
|
+
leave-class="translate-y-0 opacity-100"
|
|
8
|
+
leave-to-class="translate-y-[15px] opacity-0"
|
|
9
|
+
@after-leave="hide"
|
|
10
|
+
>
|
|
11
|
+
<div
|
|
12
|
+
v-show="visible"
|
|
13
|
+
:id="id"
|
|
14
|
+
:class="{
|
|
15
|
+
PopoverPanel: headless,
|
|
16
|
+
'absolute top-full mt-3 rounded-md shadow-300 ':
|
|
17
|
+
!headless,
|
|
18
|
+
'bg-white': !dark,
|
|
19
|
+
'border-gray-700 bg-forest-default shadow-gray-700': dark,
|
|
20
|
+
'left-0': !right,
|
|
21
|
+
'right-0': right,
|
|
22
|
+
}"
|
|
23
|
+
>
|
|
24
|
+
<slot></slot>
|
|
25
|
+
</div>
|
|
26
|
+
</transition>
|
|
27
|
+
</template>
|
|
28
|
+
|
|
29
|
+
<script>
|
|
30
|
+
import { genId } from '~/utils/ids';
|
|
31
|
+
|
|
32
|
+
export default {
|
|
33
|
+
name: 'VTPopoverContent',
|
|
34
|
+
|
|
35
|
+
inject: ['api'],
|
|
36
|
+
|
|
37
|
+
data() {
|
|
38
|
+
return {
|
|
39
|
+
id: `popover-panel-${genId()}`,
|
|
40
|
+
visible: false,
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
computed: {
|
|
45
|
+
dark() {
|
|
46
|
+
return this.api().isDark;
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
headless() {
|
|
50
|
+
return this.api().isHeadless;
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
right() {
|
|
54
|
+
return this.api().isRight;
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
mounted() {
|
|
59
|
+
this.api().registerContent(this);
|
|
60
|
+
|
|
61
|
+
// TODO: Create a directive or mixin for this
|
|
62
|
+
document.addEventListener('click', (e) => {
|
|
63
|
+
e.stopPropagation();
|
|
64
|
+
if (this.visible && !this.$el.contains(e.target)) this.hide();
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
destroyed() {
|
|
69
|
+
// TODO: Create a directive or mixin for this
|
|
70
|
+
document.removeEventListener('click', this.hide());
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
methods: {
|
|
74
|
+
show() {
|
|
75
|
+
this.visible = true;
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
hide() {
|
|
79
|
+
this.visible = false;
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
</script>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
:class="{
|
|
4
|
+
PopoverDivider: headless,
|
|
5
|
+
'h-[1px]': !headless,
|
|
6
|
+
'bg-white': !dark,
|
|
7
|
+
'bg-fd-500': dark,
|
|
8
|
+
}"
|
|
9
|
+
></div>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<script>
|
|
13
|
+
export default {
|
|
14
|
+
name: 'VTPopoverDivider',
|
|
15
|
+
|
|
16
|
+
inject: ['api'],
|
|
17
|
+
|
|
18
|
+
computed: {
|
|
19
|
+
dark() {
|
|
20
|
+
return this.api().isDark;
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
headless() {
|
|
24
|
+
return this.api().isHeadless;
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
</script>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<component
|
|
3
|
+
:is="as"
|
|
4
|
+
:class="{
|
|
5
|
+
PopoverItem: headless,
|
|
6
|
+
'-mx-3 flex min-w-max items-center gap-2 px-3 py-2 no-underline':
|
|
7
|
+
!headless,
|
|
8
|
+
'text-fd-500': !dark,
|
|
9
|
+
'text-white hover:bg-fd-450': dark,
|
|
10
|
+
}"
|
|
11
|
+
@click="onClick"
|
|
12
|
+
>
|
|
13
|
+
<slot></slot>
|
|
14
|
+
</component>
|
|
15
|
+
</template>
|
|
16
|
+
|
|
17
|
+
<script>
|
|
18
|
+
export default {
|
|
19
|
+
name: 'VTPopoverItem',
|
|
20
|
+
|
|
21
|
+
inject: ['api'],
|
|
22
|
+
|
|
23
|
+
props: {
|
|
24
|
+
to: {
|
|
25
|
+
type: [String, Object],
|
|
26
|
+
default: null,
|
|
27
|
+
},
|
|
28
|
+
href: {
|
|
29
|
+
type: String,
|
|
30
|
+
default: null,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
computed: {
|
|
35
|
+
dark() {
|
|
36
|
+
return this.api().isDark;
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
headless() {
|
|
40
|
+
return this.api().isHeadless;
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
as() {
|
|
44
|
+
return this.href ? 'a' : this.to ? 'NuxtLink' : 'button';
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
methods: {
|
|
49
|
+
onClick() {
|
|
50
|
+
if (this.href || this.to) return;
|
|
51
|
+
this.$emit('click');
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
</script>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div @keydown.esc.prevent="onEsc">
|
|
3
|
+
<slot></slot>
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script>
|
|
8
|
+
export default {
|
|
9
|
+
name: 'VTPopoverTrigger',
|
|
10
|
+
|
|
11
|
+
inject: ['api'],
|
|
12
|
+
|
|
13
|
+
computed: {
|
|
14
|
+
content() {
|
|
15
|
+
return this.api().content;
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
mounted() {
|
|
20
|
+
this.api().registerButton(this);
|
|
21
|
+
this.handleSlotTrigger();
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
methods: {
|
|
25
|
+
handleSlotTrigger() {
|
|
26
|
+
const slot = this.$slots.default;
|
|
27
|
+
const trigger = slot[0].elm;
|
|
28
|
+
|
|
29
|
+
if (slot.length > 1) {
|
|
30
|
+
console.error('VTPopoverButton only accepts one item in its slot');
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
trigger.addEventListener('click', (e) => {
|
|
35
|
+
this.onClick();
|
|
36
|
+
e.stopPropagation();
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
onClick() {
|
|
41
|
+
if (this.content.visible) this.content.hide();
|
|
42
|
+
else this.content.show();
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
onEsc() {
|
|
46
|
+
if (!this.content) return;
|
|
47
|
+
this.content.hide();
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
</script>
|