@veritree/ui 0.5.2 → 0.7.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 CHANGED
@@ -1,56 +1,95 @@
1
- import VTAlert from './src/Alerts/VTAlert.vue';
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";
2
20
 
3
- // import VTSpinner from './src/Spinner/VTSpinner.vue';
21
+ import VTAlert from "./src/Alerts/VTAlert.vue";
4
22
 
5
- import VTButton from './src/Button/VTButton.vue';
23
+ import VTSpinner from "./src/Spinner/VTSpinner.vue";
24
+
25
+ import VTButton from "./src/Button/VTButton.vue";
6
26
  // import VTButtonSave from './src/Button/VTButtonSave.vue';
7
27
 
8
- import VTInput from './src/Input/VTInput.vue';
9
- import VTInputDate from './src/Input/VTInputDate.vue';
10
- import VTInputFile from './src/Input/VTInputFile.vue';
11
- import VTInputUpload from './src/Input/VTInputUpload.vue';
28
+ import VTInput from "./src/Input/VTInput.vue";
29
+ import VTInputDate from "./src/Input/VTInputDate.vue";
30
+ import VTInputFile from "./src/Input/VTInputFile.vue";
31
+ import VTInputUpload from "./src/Input/VTInputUpload.vue";
12
32
 
13
- import VTTextarea from './src/Textarea/VTTextarea.vue';
33
+ import VTTextarea from "./src/Textarea/VTTextarea.vue";
14
34
 
15
- import VTListbox from './src/Listbox/VTListbox.vue';
16
- import VTListboxButton from './src/Listbox/VTListboxButton.vue';
17
- import VTListboxOption from './src/Listbox/VTListboxOption.vue';
18
- import VTListboxOptions from './src/Listbox/VTListboxOptions.vue';
35
+ import VTListbox from "./src/Listbox/VTListbox.vue";
36
+ import VTListboxButton from "./src/Listbox/VTListboxButton.vue";
37
+ import VTListboxOption from "./src/Listbox/VTListboxOption.vue";
38
+ import VTListboxOptions from "./src/Listbox/VTListboxOptions.vue";
19
39
 
20
- import VTModal from './src/Modal/VTModal.vue';
40
+ import VTModal from "./src/Modal/VTModal.vue";
21
41
 
22
- import VTAccordion from './src/Accordion/VTAccordion.vue';
23
- import VTAccordionButton from './src/Accordion/VTAccordionButton.vue';
24
- import VTAccordionGroup from './src/Accordion/VTAccordionGroup.vue';
25
- import VTAccordionPanel from './src/Accordion/VTAccordionPanel.vue';
42
+ import VTAccordion from "./src/Accordion/VTAccordion.vue";
43
+ import VTAccordionButton from "./src/Accordion/VTAccordionButton.vue";
44
+ import VTAccordionGroup from "./src/Accordion/VTAccordionGroup.vue";
45
+ import VTAccordionPanel from "./src/Accordion/VTAccordionPanel.vue";
26
46
 
27
- import VTTab from './src/Tabs/VTTab.vue';
28
- import VTTabGroup from './src/Tabs/VTTabGroup.vue';
29
- import VTTabList from './src/Tabs/VTTabList.vue';
30
- import VTTabPanel from './src/Tabs/VTTabPanel.vue';
31
- import VTTabPanels from './src/Tabs/VTTabPanels.vue';
47
+ import VTTab from "./src/Tabs/VTTab.vue";
48
+ import VTTabGroup from "./src/Tabs/VTTabGroup.vue";
49
+ import VTTabList from "./src/Tabs/VTTabList.vue";
50
+ import VTTabPanel from "./src/Tabs/VTTabPanel.vue";
51
+ import VTTabPanels from "./src/Tabs/VTTabPanels.vue";
32
52
 
33
- import VTDialog from './src/Dialog/VTDialog.vue';
34
- import VTDialogClose from './src/Dialog/VTDialogClose.vue';
35
- import VTDialogContent from './src/Dialog/VTDialogContent.vue';
36
- import VTDialogFooter from './src/Dialog/VTDialogFooter.vue';
37
- import VTDialogHeader from './src/Dialog/VTDialogHeader.vue';
38
- import VTDialogMain from './src/Dialog/VTDialogMain.vue';
39
- import VTDialogOverlay from './src/Dialog/VTDialogOverlay.vue';
40
- import VTDialogTitle from './src/Dialog/VTDialogTitle.vue';
53
+ import VTDialog from "./src/Dialog/VTDialog.vue";
54
+ import VTDialogClose from "./src/Dialog/VTDialogClose.vue";
55
+ import VTDialogContent from "./src/Dialog/VTDialogContent.vue";
56
+ import VTDialogFooter from "./src/Dialog/VTDialogFooter.vue";
57
+ import VTDialogHeader from "./src/Dialog/VTDialogHeader.vue";
58
+ import VTDialogMain from "./src/Dialog/VTDialogMain.vue";
59
+ import VTDialogOverlay from "./src/Dialog/VTDialogOverlay.vue";
60
+ import VTDialogTitle from "./src/Dialog/VTDialogTitle.vue";
41
61
 
42
- import VTDrawer from './src/Drawer/VTDrawer.vue';
43
- import VTDrawerClose from './src/Drawer/VTDrawerClose.vue';
44
- import VTDrawerContent from './src/Drawer/VTDrawerContent.vue';
45
- import VTDrawerFooter from './src/Drawer/VTDrawerFooter.vue';
46
- import VTDrawerHeader from './src/Drawer/VTDrawerHeader.vue';
47
- import VTDrawerTitle from './src/Drawer/VTDrawerTitle.vue';
48
- import VTDrawerMain from './src/Drawer/VTDrawerMain.vue';
49
- import VTDrawerOverlay from './src/Drawer/VTDrawerOverlay.vue';
62
+ import VTDrawer from "./src/Drawer/VTDrawer.vue";
63
+ import VTDrawerClose from "./src/Drawer/VTDrawerClose.vue";
64
+ import VTDrawerContent from "./src/Drawer/VTDrawerContent.vue";
65
+ import VTDrawerFooter from "./src/Drawer/VTDrawerFooter.vue";
66
+ import VTDrawerHeader from "./src/Drawer/VTDrawerHeader.vue";
67
+ import VTDrawerTitle from "./src/Drawer/VTDrawerTitle.vue";
68
+ import VTDrawerMain from "./src/Drawer/VTDrawerMain.vue";
69
+ import VTDrawerOverlay from "./src/Drawer/VTDrawerOverlay.vue";
50
70
 
51
71
  export {
72
+ VTAvatar,
73
+ VTAvatarImage,
74
+ VTAvatarText,
75
+ VTImage,
76
+ VTImageCounter,
77
+ VTImageHover,
52
78
  VTAlert,
53
- // VTSpinner,
79
+ VTSpinner,
80
+ VTDropdownMenu,
81
+ VTDropdownMenuContent,
82
+ VTDropdownMenuDivider,
83
+ VTDropdownMenuGroup,
84
+ VTDropdownMenuItem,
85
+ VTDropdownMenuLabel,
86
+ VTDropdownMenuTrigger,
87
+ VTPopover,
88
+ VTPopoverContent,
89
+ VTPopoverDivider,
90
+ VTPopoverGroup,
91
+ VTPopoverItem,
92
+ VTPopoverTrigger,
54
93
  VTButton,
55
94
  // VTButtonSave,
56
95
  VTInput,
@@ -88,5 +127,4 @@ export {
88
127
  VTDialogMain,
89
128
  VTDialogOverlay,
90
129
  VTDialogTitle,
91
- }
92
-
130
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veritree/ui",
3
- "version": "0.5.2",
3
+ "version": "0.7.0",
4
4
  "description": "veritree ui library",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -0,0 +1,50 @@
1
+ <template>
2
+ <div
3
+ :class="{
4
+ Avatar: headless,
5
+ 'flex items-center justify-center overflow-hidden rounded-full':
6
+ !headless,
7
+ 'h-10 w-10': !small,
8
+ 'h-8 w-8': small,
9
+ 'border border-solid': !dark,
10
+ 'bg-white text-fd-500': dark,
11
+ }"
12
+ >
13
+ <slot></slot>
14
+ </div>
15
+ </template>
16
+
17
+ <script>
18
+ export default {
19
+ name: 'VTAvatar',
20
+
21
+ provide() {
22
+ return {
23
+ api: () => {
24
+ const { dark: isDark, headless: isHeadless, light: isLight } = this;
25
+
26
+ return {
27
+ isDark,
28
+ isHeadless,
29
+ isLight,
30
+ };
31
+ },
32
+ };
33
+ },
34
+
35
+ props: {
36
+ headless: {
37
+ type: Boolean,
38
+ default: false,
39
+ },
40
+ dark: {
41
+ type: Boolean,
42
+ default: false,
43
+ },
44
+ small: {
45
+ type: Boolean,
46
+ default: false,
47
+ },
48
+ },
49
+ };
50
+ </script>
@@ -0,0 +1,38 @@
1
+ <template>
2
+ <VTImage v-if="src" :src="src" v-bind="attrs" width="40" />
3
+ <VTImage v-else-if="cdnSrc" :cdn-src="cdnSrc" v-bind="attrs" width="40" />
4
+ </template>
5
+
6
+ <script>
7
+ import VTImage from "../Image/VTImage.vue";
8
+
9
+ export default {
10
+ name: "VTAvatarImage",
11
+
12
+ components: { VTImage },
13
+
14
+ props: {
15
+ alt: {
16
+ type: String,
17
+ required: true,
18
+ },
19
+ src: {
20
+ type: String,
21
+ default: "",
22
+ },
23
+ cdnSrc: {
24
+ type: [String, Object],
25
+ default: null,
26
+ },
27
+ },
28
+
29
+ computed: {
30
+ attrs() {
31
+ return {
32
+ alt: this.alt,
33
+ class: "h-auto w-full",
34
+ };
35
+ },
36
+ },
37
+ };
38
+ </script>
@@ -0,0 +1,9 @@
1
+ <template>
2
+ <span class="font-semibold"><slot></slot></span>
3
+ </template>
4
+
5
+ <script>
6
+ export default {
7
+ name: 'VTAvatarText',
8
+ };
9
+ </script>
@@ -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,9 @@
1
+ <template>
2
+ <div role="group"><slot></slot></div>
3
+ </template>
4
+
5
+ <script>
6
+ export default {
7
+ name: 'VTDropdownMenuGroup',
8
+ };
9
+ </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,74 @@
1
+ <template>
2
+ <img
3
+ :src="srcComputed"
4
+ :class="{ 'animate-pulse': !isLoaded }"
5
+ v-bind="$attrs"
6
+ @load="onLoad"
7
+ @error="onError"
8
+ />
9
+ </template>
10
+
11
+ <script>
12
+ import { specifyImageWidth } from "~/utils/images";
13
+
14
+ export default {
15
+ name: "VTImage",
16
+
17
+ props: {
18
+ src: {
19
+ type: String,
20
+ default: "",
21
+ },
22
+ cdnSrc: {
23
+ type: [String, Object],
24
+ default: null,
25
+ },
26
+ placeholder: {
27
+ type: String,
28
+ default: `data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22600%22%20height%3D%22400%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20%25%7Bw%7D%20%25%7Bh%7D%22%20preserveAspectRatio%3D%22none%22%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20style%3D%22fill%3A%23bbb%3B%22%3E%3C%2Frect%3E%3C%2Fsvg%3E`,
29
+ },
30
+ },
31
+
32
+ data() {
33
+ return {
34
+ canLoad: true,
35
+ isLoaded: false,
36
+ };
37
+ },
38
+
39
+ computed: {
40
+ srcComputed() {
41
+ if (!this.isLoaded) {
42
+ return this.placeholder;
43
+ } else {
44
+ if (!this.canLoad) {
45
+ return this.placeholder;
46
+ }
47
+
48
+ if (this.cdnSrc) {
49
+ return this.specifyImageWidth(this.cdnSrc, this.$attrs.width);
50
+ }
51
+
52
+ if (this.src) {
53
+ return this.src;
54
+ }
55
+ }
56
+
57
+ return null;
58
+ },
59
+ },
60
+
61
+ methods: {
62
+ specifyImageWidth,
63
+
64
+ onLoad() {
65
+ this.isLoaded = true;
66
+ },
67
+
68
+ onError() {
69
+ this.canLoad = false;
70
+ this.$emit("error");
71
+ },
72
+ },
73
+ };
74
+ </script>
@@ -0,0 +1,6 @@
1
+ <template>
2
+ <span
3
+ class="absolute inset-0 grid place-content-center bg-gray-500/75 font-semibold text-white no-underline transition-all hover:bg-gray-600/50"
4
+ >+ <slot></slot> images</span
5
+ >
6
+ </template>
@@ -0,0 +1,5 @@
1
+ <template>
2
+ <span
3
+ class="before:absolute before:inset-0 before:bg-transparent before:transition-all before:content-[''] before:hover:bg-gray-600/50"
4
+ ></span>
5
+ </template>
@@ -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,5 @@
1
+ <template>
2
+ <div class="grid">
3
+ <slot></slot>
4
+ </div>
5
+ </template>
@@ -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>
@@ -8,7 +8,7 @@
8
8
  >
9
9
  <path
10
10
  d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
11
- fill="currentFill"
11
+ fill="currentColor"
12
12
  />
13
13
  </svg>
14
14
  </template>