@veritree/ui 0.6.1 → 0.9.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,59 +1,76 @@
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';
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";
22
+ import VTListbox from "./src/Listbox/VTListbox.vue";
23
+ import VTListboxContent from "./src/Listbox/VTListboxContent.vue";
24
+ import VTListboxItem from "./src/Listbox/VTListboxItem.vue";
25
+ import VTListboxLabel from "./src/Listbox/VTListboxLabel.vue";
26
+ import VTListboxList from "./src/Listbox/VTListboxList.vue";
27
+ import VTListboxSearch from "./src/Listbox/VTListboxSearch.vue";
28
+ import VTListboxTrigger from "./src/Listbox/VTListboxTrigger.vue";
7
29
 
8
- import VTAlert from './src/Alerts/VTAlert.vue';
30
+ import VTAlert from "./src/Alerts/VTAlert.vue";
9
31
 
10
- import VTSpinner from './src/Spinner/VTSpinner.vue';
32
+ import VTSpinner from "./src/Spinner/VTSpinner.vue";
11
33
 
12
- import VTButton from './src/Button/VTButton.vue';
34
+ import VTButton from "./src/Button/VTButton.vue";
13
35
  // import VTButtonSave from './src/Button/VTButtonSave.vue';
14
36
 
15
- import VTInput from './src/Input/VTInput.vue';
16
- import VTInputDate from './src/Input/VTInputDate.vue';
17
- import VTInputFile from './src/Input/VTInputFile.vue';
18
- import VTInputUpload from './src/Input/VTInputUpload.vue';
37
+ import VTInput from "./src/Input/VTInput.vue";
38
+ import VTInputDate from "./src/Input/VTInputDate.vue";
39
+ import VTInputFile from "./src/Input/VTInputFile.vue";
40
+ import VTInputUpload from "./src/Input/VTInputUpload.vue";
19
41
 
20
- import VTTextarea from './src/Textarea/VTTextarea.vue';
42
+ import VTTextarea from "./src/Textarea/VTTextarea.vue";
21
43
 
22
- import VTListbox from './src/Listbox/VTListbox.vue';
23
- import VTListboxButton from './src/Listbox/VTListboxButton.vue';
24
- import VTListboxOption from './src/Listbox/VTListboxOption.vue';
25
- import VTListboxOptions from './src/Listbox/VTListboxOptions.vue';
44
+ import VTModal from "./src/Modal/VTModal.vue";
26
45
 
27
- import VTModal from './src/Modal/VTModal.vue';
46
+ import VTAccordion from "./src/Accordion/VTAccordion.vue";
47
+ import VTAccordionButton from "./src/Accordion/VTAccordionButton.vue";
48
+ import VTAccordionGroup from "./src/Accordion/VTAccordionGroup.vue";
49
+ import VTAccordionPanel from "./src/Accordion/VTAccordionPanel.vue";
28
50
 
29
- import VTAccordion from './src/Accordion/VTAccordion.vue';
30
- import VTAccordionButton from './src/Accordion/VTAccordionButton.vue';
31
- import VTAccordionGroup from './src/Accordion/VTAccordionGroup.vue';
32
- import VTAccordionPanel from './src/Accordion/VTAccordionPanel.vue';
51
+ import VTTab from "./src/Tabs/VTTab.vue";
52
+ import VTTabGroup from "./src/Tabs/VTTabGroup.vue";
53
+ import VTTabList from "./src/Tabs/VTTabList.vue";
54
+ import VTTabPanel from "./src/Tabs/VTTabPanel.vue";
55
+ import VTTabPanels from "./src/Tabs/VTTabPanels.vue";
33
56
 
34
- import VTTab from './src/Tabs/VTTab.vue';
35
- import VTTabGroup from './src/Tabs/VTTabGroup.vue';
36
- import VTTabList from './src/Tabs/VTTabList.vue';
37
- import VTTabPanel from './src/Tabs/VTTabPanel.vue';
38
- import VTTabPanels from './src/Tabs/VTTabPanels.vue';
57
+ import VTDialog from "./src/Dialog/VTDialog.vue";
58
+ import VTDialogClose from "./src/Dialog/VTDialogClose.vue";
59
+ import VTDialogContent from "./src/Dialog/VTDialogContent.vue";
60
+ import VTDialogFooter from "./src/Dialog/VTDialogFooter.vue";
61
+ import VTDialogHeader from "./src/Dialog/VTDialogHeader.vue";
62
+ import VTDialogMain from "./src/Dialog/VTDialogMain.vue";
63
+ import VTDialogOverlay from "./src/Dialog/VTDialogOverlay.vue";
64
+ import VTDialogTitle from "./src/Dialog/VTDialogTitle.vue";
39
65
 
40
- import VTDialog from './src/Dialog/VTDialog.vue';
41
- import VTDialogClose from './src/Dialog/VTDialogClose.vue';
42
- import VTDialogContent from './src/Dialog/VTDialogContent.vue';
43
- import VTDialogFooter from './src/Dialog/VTDialogFooter.vue';
44
- import VTDialogHeader from './src/Dialog/VTDialogHeader.vue';
45
- import VTDialogMain from './src/Dialog/VTDialogMain.vue';
46
- import VTDialogOverlay from './src/Dialog/VTDialogOverlay.vue';
47
- import VTDialogTitle from './src/Dialog/VTDialogTitle.vue';
48
-
49
- import VTDrawer from './src/Drawer/VTDrawer.vue';
50
- import VTDrawerClose from './src/Drawer/VTDrawerClose.vue';
51
- import VTDrawerContent from './src/Drawer/VTDrawerContent.vue';
52
- import VTDrawerFooter from './src/Drawer/VTDrawerFooter.vue';
53
- import VTDrawerHeader from './src/Drawer/VTDrawerHeader.vue';
54
- import VTDrawerTitle from './src/Drawer/VTDrawerTitle.vue';
55
- import VTDrawerMain from './src/Drawer/VTDrawerMain.vue';
56
- import VTDrawerOverlay from './src/Drawer/VTDrawerOverlay.vue';
66
+ import VTDrawer from "./src/Drawer/VTDrawer.vue";
67
+ import VTDrawerClose from "./src/Drawer/VTDrawerClose.vue";
68
+ import VTDrawerContent from "./src/Drawer/VTDrawerContent.vue";
69
+ import VTDrawerFooter from "./src/Drawer/VTDrawerFooter.vue";
70
+ import VTDrawerHeader from "./src/Drawer/VTDrawerHeader.vue";
71
+ import VTDrawerTitle from "./src/Drawer/VTDrawerTitle.vue";
72
+ import VTDrawerMain from "./src/Drawer/VTDrawerMain.vue";
73
+ import VTDrawerOverlay from "./src/Drawer/VTDrawerOverlay.vue";
57
74
 
58
75
  export {
59
76
  VTAvatar,
@@ -64,6 +81,28 @@ export {
64
81
  VTImageHover,
65
82
  VTAlert,
66
83
  VTSpinner,
84
+ VTDropdownMenu,
85
+ VTDropdownMenuContent,
86
+ VTDropdownMenuDivider,
87
+ VTDropdownMenuGroup,
88
+ VTDropdownMenuItem,
89
+ VTDropdownMenuLabel,
90
+ VTDropdownMenuTrigger,
91
+ VTPopover,
92
+ VTPopoverContent,
93
+ VTPopoverDivider,
94
+ VTPopoverGroup,
95
+ VTPopoverItem,
96
+ VTPopoverTrigger,
97
+ VTFormFeedback,
98
+ VTFormGroup,
99
+ VTListbox,
100
+ VTListboxContent,
101
+ VTListboxItem,
102
+ VTListboxLabel,
103
+ VTListboxList,
104
+ VTListboxSearch,
105
+ VTListboxTrigger,
67
106
  VTButton,
68
107
  // VTButtonSave,
69
108
  VTInput,
@@ -71,10 +110,6 @@ export {
71
110
  VTInputFile,
72
111
  VTInputUpload,
73
112
  VTTextarea,
74
- VTListbox,
75
- VTListboxButton,
76
- VTListboxOption,
77
- VTListboxOptions,
78
113
  VTModal,
79
114
  VTAccordion,
80
115
  VTAccordionButton,
@@ -101,5 +136,4 @@ export {
101
136
  VTDialogMain,
102
137
  VTDialogOverlay,
103
138
  VTDialogTitle,
104
- }
105
-
139
+ };
package/nuxt.js ADDED
@@ -0,0 +1,21 @@
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/Listbox',
10
+ 'src/Image',
11
+ 'src/Tabs',
12
+ ]
13
+
14
+ export default function () {
15
+ this.nuxt.hook('components:dirs', dirs => {
16
+ // Add ./components dir to the list
17
+ components.forEach((component) => {
18
+ dirs.push(join(__dirname, component))
19
+ });
20
+ })
21
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veritree/ui",
3
- "version": "0.6.1",
3
+ "version": "0.9.0",
4
4
  "description": "veritree ui library",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -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>