@veritree/ui 0.19.2-2 → 0.19.2-21

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.
Files changed (62) hide show
  1. package/mixins/floating-ui-content.js +81 -0
  2. package/mixins/floating-ui-item.js +266 -0
  3. package/mixins/floating-ui.js +67 -0
  4. package/mixins/form-control-icon.js +53 -0
  5. package/mixins/form-control.js +73 -0
  6. package/package.json +7 -3
  7. package/src/components/Avatar/VTAvatar.vue +32 -29
  8. package/src/components/Button/VTButton.vue +9 -5
  9. package/src/components/Dialog/VTDialog.vue +6 -11
  10. package/src/components/Dialog/VTDialogClose.vue +9 -9
  11. package/src/components/Dialog/VTDialogContent.vue +9 -9
  12. package/src/components/Dialog/VTDialogFooter.vue +5 -5
  13. package/src/components/Dialog/VTDialogHeader.vue +8 -8
  14. package/src/components/Dialog/VTDialogMain.vue +8 -8
  15. package/src/components/Dialog/VTDialogOverlay.vue +8 -8
  16. package/src/components/Dialog/VTDialogTitle.vue +4 -4
  17. package/src/components/Disclosure/VTDisclosureContent.vue +1 -1
  18. package/src/components/Disclosure/VTDisclosureDetails.vue +2 -2
  19. package/src/components/Disclosure/VTDisclosureHeader.vue +1 -1
  20. package/src/components/Disclosure/VTDisclosureIcon.vue +1 -1
  21. package/src/components/Drawer/VTDrawer.vue +14 -16
  22. package/src/components/Drawer/VTDrawerClose.vue +9 -9
  23. package/src/components/Drawer/VTDrawerContent.vue +8 -8
  24. package/src/components/Drawer/VTDrawerFooter.vue +3 -3
  25. package/src/components/Drawer/VTDrawerHeader.vue +4 -4
  26. package/src/components/Drawer/VTDrawerMain.vue +5 -5
  27. package/src/components/Drawer/VTDrawerOverlay.vue +6 -6
  28. package/src/components/Drawer/VTDrawerTitle.vue +5 -5
  29. package/src/components/DropdownMenu/VTDropdownMenu.vue +27 -29
  30. package/src/components/DropdownMenu/VTDropdownMenuContent.vue +27 -70
  31. package/src/components/DropdownMenu/VTDropdownMenuDivider.vue +8 -5
  32. package/src/components/DropdownMenu/VTDropdownMenuItem.vue +14 -123
  33. package/src/components/DropdownMenu/VTDropdownMenuLabel.vue +3 -3
  34. package/src/components/DropdownMenu/VTDropdownMenuTrigger.vue +96 -121
  35. package/src/components/Form/VTFormFeedback.vue +33 -22
  36. package/src/components/Form/VTFormGroup.vue +5 -7
  37. package/src/components/Form/VTFormLabel.vue +22 -0
  38. package/src/components/Form/VTFormRow.vue +5 -0
  39. package/src/components/Form/VTInput.vue +40 -0
  40. package/src/components/Form/VTInputIcon.vue +35 -0
  41. package/src/components/Form/VTInputPassword.vue +55 -0
  42. package/src/components/Form/VTTextarea.vue +22 -0
  43. package/src/components/Listbox/VTListbox.vue +122 -50
  44. package/src/components/Listbox/VTListboxContent.vue +20 -116
  45. package/src/components/Listbox/VTListboxItem.vue +116 -166
  46. package/src/components/Listbox/VTListboxLabel.vue +3 -14
  47. package/src/components/Listbox/VTListboxList.vue +10 -40
  48. package/src/components/Listbox/VTListboxSearch.vue +76 -68
  49. package/src/components/Listbox/VTListboxTrigger.vue +75 -86
  50. package/src/components/Popover/VTPopover.vue +24 -30
  51. package/src/components/Popover/VTPopoverContent.vue +24 -59
  52. package/src/components/Popover/VTPopoverDivider.vue +4 -11
  53. package/src/components/Popover/VTPopoverItem.vue +21 -14
  54. package/src/components/Popover/VTPopoverTrigger.vue +126 -21
  55. package/src/components/Tabs/VTTab.vue +10 -11
  56. package/src/components/Tabs/VTTabGroup.vue +9 -7
  57. package/src/components/Tabs/VTTabPanel.vue +4 -5
  58. package/src/components/Transitions/FadeInOut.vue +2 -2
  59. package/src/components/Utils/FloatingUi.vue +87 -0
  60. package/package-lock.json +0 -13
  61. package/src/components/Modal/VTModal.vue +0 -69
  62. package/src/utils/genId.js +0 -13
@@ -12,14 +12,14 @@
12
12
  </template>
13
13
 
14
14
  <script>
15
- import FadeInOut from "../Transitions/FadeInOut.vue";
15
+ import FadeInOut from '../Transitions/FadeInOut.vue';
16
16
 
17
17
  export default {
18
18
  components: {
19
19
  FadeInOut,
20
20
  },
21
21
 
22
- inject: ["api"],
22
+ inject: ['apiDrawer'],
23
23
 
24
24
  data() {
25
25
  return {
@@ -29,21 +29,21 @@ export default {
29
29
 
30
30
  computed: {
31
31
  dark() {
32
- return this.api().isDark;
32
+ return this.apiDrawer().isDark;
33
33
  },
34
34
 
35
35
  headless() {
36
- return this.api().isHeadless;
36
+ return this.apiDrawer().isHeadless;
37
37
  },
38
38
 
39
39
  id() {
40
- return `${this.api().id}-overlay`;
40
+ return `${this.apiDrawer().id}-overlay`;
41
41
  },
42
42
  },
43
43
 
44
44
  mounted() {
45
45
  this.visible = true;
46
- this.api().registerOverlay(this);
46
+ this.apiDrawer().registerOverlay(this);
47
47
  },
48
48
 
49
49
  methods: {
@@ -15,7 +15,7 @@
15
15
  export default {
16
16
  name: 'VTDrawerTitle',
17
17
 
18
- inject: ['api'],
18
+ inject: ['apiDrawer'],
19
19
 
20
20
  props: {
21
21
  as: {
@@ -26,15 +26,15 @@ export default {
26
26
 
27
27
  computed: {
28
28
  dark() {
29
- return this.api().isDark;
29
+ return this.apiDrawer().isDark;
30
30
  },
31
31
 
32
32
  headless() {
33
- return this.api().isHeadless;
33
+ return this.apiDrawer().isHeadless;
34
34
  },
35
35
 
36
36
  id() {
37
- return `${this.api().id}-title`;
37
+ return `${this.apiDrawer().id}-title`;
38
38
  },
39
39
  },
40
40
 
@@ -45,7 +45,7 @@ export default {
45
45
  methods: {
46
46
  // In here because if there is no header, the dialog will not be labelled by
47
47
  setDialogLabelledby() {
48
- const dialog = document.getElementById(this.api().id);
48
+ const dialog = document.getElementById(this.apiDrawer().id);
49
49
 
50
50
  if (dialog) {
51
51
  dialog.setAttribute('aria-labelledby', this.id);
@@ -5,45 +5,47 @@
5
5
  </template>
6
6
 
7
7
  <script>
8
- import { genId } from "../../utils/ids";
8
+ import { floatingUiMixin } from '../../../mixins/floating-ui';
9
+ import { genId } from '../../utils/ids';
9
10
 
10
11
  export default {
11
- name: "VTDropdownMenu",
12
+ name: 'VTDropdownMenu',
13
+
14
+ mixins: [floatingUiMixin],
12
15
 
13
16
  provide() {
14
17
  return {
15
- api: () => {
16
- const { dark: isDark, headless: isHeadless, right: isRight } = this;
17
- const { id, trigger, content, items } = this;
18
-
18
+ apiDropdownMenu: () => {
19
19
  const registerTrigger = (trigger) => {
20
- this.trigger = trigger;
20
+ if (!trigger) return;
21
+ this.componentTrigger = trigger;
21
22
  };
22
23
 
23
24
  const registerContent = (content) => {
24
- this.content = content;
25
+ if (!content) return;
26
+ this.componentContent = content;
25
27
  };
26
28
 
27
29
  const registerItem = (item) => {
30
+ if (!item) return;
28
31
  this.items.push(item);
29
32
  };
30
33
 
31
- const unregisterItems = () => {
32
- this.items = [];
34
+ const unregisterItem = (id) => {
35
+ const index = this.items.findIndex((item) => item.id === id);
36
+ this.items.splice(index, 1);
33
37
  };
34
38
 
35
39
  return {
36
- id,
37
- isDark,
38
- isHeadless,
39
- isRight,
40
- trigger,
41
- content,
42
- items,
40
+ id: this.componentId,
41
+ component: this.component,
42
+ componentTrigger: this.componentTrigger,
43
+ componentContent: this.componentContent,
44
+ items: this.items,
43
45
  registerTrigger,
44
46
  registerContent,
45
47
  registerItem,
46
- unregisterItems,
48
+ unregisterItem,
47
49
  };
48
50
  },
49
51
  };
@@ -54,23 +56,19 @@ export default {
54
56
  type: Boolean,
55
57
  default: false,
56
58
  },
57
- dark: {
58
- type: Boolean,
59
- default: false,
60
- },
61
- right: {
62
- type: Boolean,
63
- default: false,
64
- },
65
59
  },
66
60
 
67
61
  data() {
68
62
  return {
69
- id: `menu-${genId()}`,
70
- trigger: null,
71
- content: null,
63
+ componentId: genId(),
72
64
  items: [],
73
65
  };
74
66
  },
67
+
68
+ computed: {
69
+ id() {
70
+ return `dropdown-menu-${this.componentId}`;
71
+ },
72
+ },
75
73
  };
76
74
  </script>
@@ -1,94 +1,51 @@
1
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"
2
+ <FloatingUi
3
+ :visible="visible"
4
+ :id="id"
5
+ :headless="headless"
6
+ :class="{ 'dropdown-menu-content': headless }"
7
+ :floating-ui-class="floatingUiClass"
10
8
  >
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>
9
+ <slot></slot>
10
+ </FloatingUi>
27
11
  </template>
28
12
 
29
13
  <script>
30
- import { genId } from '../../utils/ids';
14
+ import { floatingUiContentMixin } from '../../../mixins/floating-ui-content';
31
15
 
32
16
  export default {
33
17
  name: 'VTDropdownMenuContent',
34
18
 
35
- inject: ['api'],
19
+ mixins: [floatingUiContentMixin],
36
20
 
37
- data() {
38
- return {
39
- id: `menucontent-${genId()}`,
40
- visible: false,
41
- };
42
- },
21
+ inject: ['apiDropdownMenu'],
43
22
 
44
23
  computed: {
45
- dark() {
46
- return this.api().isDark;
47
- },
48
-
49
- headless() {
50
- return this.api().isHeadless;
24
+ id() {
25
+ return `dropdown-menu-content-${this.apiDropdownMenu().id}`;
51
26
  },
52
27
 
53
- right() {
54
- return this.api().isRight;
28
+ component() {
29
+ return this.apiDropdownMenu().component;
55
30
  },
56
31
 
57
- trigger() {
58
- return this.api().trigger;
32
+ componentTrigger() {
33
+ return this.apiDropdownMenu().componentTrigger;
59
34
  },
60
35
  },
61
36
 
62
37
  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
- this.$emit('shown');
85
- },
38
+ const content = {
39
+ id: this.id,
40
+ hide: this.hide,
41
+ show: this.show,
42
+ getMousemove: this.getMousemove,
43
+ setMousemove: this.setMousemove,
44
+ unsetMousemove: this.unsetMousemove,
45
+ setActiveDescedant: this.setActiveDescedant,
46
+ };
86
47
 
87
- hide() {
88
- this.visible = false;
89
- this.$emit('hidden');
90
- this.api().unregisterItems();
91
- },
48
+ this.apiDropdownMenu().registerContent(content);
92
49
  },
93
50
  };
94
51
  </script>
@@ -3,8 +3,6 @@
3
3
  :class="{
4
4
  PopoverDivider: headless,
5
5
  '-mx-3 my-2 h-[1px]': !headless,
6
- 'bg-gray-200': !dark,
7
- 'bg-fd-500': dark,
8
6
  }"
9
7
  ></div>
10
8
  </template>
@@ -13,15 +11,20 @@
13
11
  export default {
14
12
  name: 'VTDropdownMenuDivider',
15
13
 
16
- inject: ['api'],
14
+ inject: ['apiDropdownMenu'],
15
+
16
+ headless: {
17
+ type: Boolean,
18
+ default: false,
19
+ },
17
20
 
18
21
  computed: {
19
22
  dark() {
20
- return this.api().isDark;
23
+ return this.apiDropdownMenu().isDark;
21
24
  },
22
25
 
23
26
  headless() {
24
- return this.api().isHeadless;
27
+ return this.apiDropdownMenu().isHeadless;
25
28
  },
26
29
  },
27
30
  };
@@ -3,16 +3,10 @@
3
3
  :is="as"
4
4
  :id="id"
5
5
  :to="to"
6
- :class="{
7
- MenuItem: headless,
8
- '-mx-3 flex min-w-max items-center gap-3 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"
6
+ :class="classComputed"
15
7
  :aria-disabled="disabled"
8
+ :tabindex="tabIndex"
9
+ class="-mx-3"
16
10
  role="menuitem"
17
11
  @click.stop.prevent="onClick"
18
12
  @keydown.down.prevent="focusPreviousItem"
@@ -28,12 +22,14 @@
28
22
  </template>
29
23
 
30
24
  <script>
31
- import { genId } from '../../utils/ids';
25
+ import { floatingUiItemMixin } from '../../../mixins/floating-ui-item';
32
26
 
33
27
  export default {
34
28
  name: 'VTDropdownMenuItem',
35
29
 
36
- inject: ['api'],
30
+ mixins: [floatingUiItemMixin],
31
+
32
+ inject: ['apiDropdownMenu'],
37
33
 
38
34
  props: {
39
35
  to: {
@@ -44,127 +40,22 @@ export default {
44
40
  type: String,
45
41
  default: null,
46
42
  },
47
- disabled: {
48
- type: Boolean,
49
- default: false,
50
- },
51
43
  },
52
44
 
53
45
  data() {
54
46
  return {
55
- id: `menuitem-${genId()}`,
56
- index: null,
57
- tabIndex: 0,
47
+ apiInjected: this.apiDropdownMenu,
48
+ componentName: 'dropdown-menu-item',
58
49
  };
59
50
  },
60
51
 
61
52
  computed: {
62
- dark() {
63
- return this.api().isDark;
64
- },
65
-
66
- headless() {
67
- return this.api().isHeadless;
68
- },
69
-
70
53
  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());
54
+ return this.href
55
+ ? 'a'
56
+ : this.to
57
+ ? resolveComponent('NuxtLink')
58
+ : 'button';
168
59
  },
169
60
  },
170
61
  };
@@ -15,15 +15,15 @@
15
15
  export default {
16
16
  name: 'VTDropdownMenuLabel',
17
17
 
18
- inject: ['api'],
18
+ inject: ['apiDropdownMenu'],
19
19
 
20
20
  computed: {
21
21
  dark() {
22
- return this.api().isDark;
22
+ return this.apiDropdownMenu().isDark;
23
23
  },
24
24
 
25
25
  headless() {
26
- return this.api().isHeadless;
26
+ return this.apiDropdownMenu().isHeadless;
27
27
  },
28
28
  },
29
29
  };