@veritree/ui 0.21.1-8 → 0.22.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/.prettierrc CHANGED
@@ -1,4 +1,5 @@
1
1
  {
2
2
  "semi": true,
3
- "singleQuote": true
3
+ "singleQuote": true,
4
+ "quoteProps": "preserve"
4
5
  }
package/index.js CHANGED
@@ -21,6 +21,9 @@ import VTPopoverItem from "./src/components/Popover/VTPopoverItem.vue";
21
21
  import VTPopoverTrigger from "./src/components/Popover/VTPopoverTrigger.vue";
22
22
  import VTFormFeedback from "./src/components/Form/VTFormFeedback.vue";
23
23
  import VTFormGroup from "./src/components/Form/VTFormGroup.vue";
24
+ import VTInput from "./src/components/Form/VTInput.vue";
25
+ import VTInputIcon from "./src/components/Form/VTInputIcon.vue";
26
+ import VTInputPassword from "./src/components/Form/VTInputPassword.vue";
24
27
  import VTListbox from "./src/components/Listbox/VTListbox.vue";
25
28
  import VTListboxContent from "./src/components/Listbox/VTListboxContent.vue";
26
29
  import VTListboxItem from "./src/components/Listbox/VTListboxItem.vue";
@@ -29,7 +32,6 @@ import VTListboxList from "./src/components/Listbox/VTListboxList.vue";
29
32
  import VTListboxSearch from "./src/components/Listbox/VTListboxSearch.vue";
30
33
  import VTListboxTrigger from "./src/components/Listbox/VTListboxTrigger.vue";
31
34
  import VTSpinner from "./src/components/Spinner/VTSpinner.vue";
32
- import VTInput from "./src/components/Input/VTInput.vue";
33
35
  import VTInputDate from "./src/components/Input/VTInputDate.vue";
34
36
  import VTInputFile from "./src/components/Input/VTInputFile.vue";
35
37
  import VTInputUpload from "./src/components/Input/VTInputUpload.vue";
@@ -96,6 +98,8 @@ export {
96
98
  VTListboxTrigger,
97
99
  VTButton,
98
100
  VTInput,
101
+ VTInputIcon,
102
+ VTInputPassword,
99
103
  VTInputDate,
100
104
  VTInputFile,
101
105
  VTInputUpload,
@@ -18,8 +18,9 @@ export const floatingUiContentMixin = {
18
18
 
19
19
  data() {
20
20
  return {
21
- visible: false,
22
21
  el: null,
22
+ isMousemove: false,
23
+ visible: false,
23
24
  };
24
25
  },
25
26
 
@@ -77,5 +78,25 @@ export const floatingUiContentMixin = {
77
78
  this.componentTrigger.cancel();
78
79
  }
79
80
  },
81
+
82
+ // Mousemove instead of mouseover to support keyboard navigation.
83
+ // The problem with mouseover is that when scrolling (scrollIntoView),
84
+ // mouseover event gets triggered.
85
+ setMousemove() {
86
+ this.isMousemove = true;
87
+ },
88
+
89
+ unsetMousemove() {
90
+ this.isMousemove = false;
91
+ },
92
+
93
+ getMousemove() {
94
+ return this.isMousemove;
95
+ },
96
+
97
+ //
98
+ setActiveDescedant(id) {
99
+ this.activeDescedant = id;
100
+ },
80
101
  },
81
102
  }
@@ -0,0 +1,216 @@
1
+ export const floatingUiItemMixin = {
2
+ props: {
3
+ headless: {
4
+ type: Boolean,
5
+ default: false,
6
+ },
7
+ disabled: {
8
+ type: Boolean,
9
+ default: false,
10
+ },
11
+ },
12
+
13
+ computed: {
14
+ id() {
15
+ return `${this.componentName}-${this.apiInjected().id}-${this.index}`;
16
+ },
17
+
18
+ items() {
19
+ return this.apiInjected().items;
20
+ },
21
+
22
+ el() {
23
+ return this.$el;
24
+ },
25
+
26
+ componentContent() {
27
+ return this.apiInjected().componentContent;
28
+ },
29
+
30
+ componentTrigger() {
31
+ return this.apiInjected().componentTrigger;
32
+ },
33
+
34
+ classComputed() {
35
+ return [
36
+ // default styles
37
+ this.headless
38
+ ? `${this.componentName}`
39
+ : 'relative z-10 flex items-center gap-2 px-3 py-2 text-inherit no-underline',
40
+ // disabled state styles
41
+ this.headless
42
+ ? this.disabled
43
+ ? `${this.componentName}--disabled`
44
+ : null
45
+ : this.disabled
46
+ ? 'pointer-events-none opacity-75'
47
+ : null,
48
+ // selected state styles
49
+ this.headless
50
+ ? this.selected
51
+ ? `${this.componentName}--selected`
52
+ : null
53
+ : this.selected
54
+ ? 'bg-secondary-200/10'
55
+ : null,
56
+ ];
57
+ },
58
+ },
59
+
60
+ data() {
61
+ return {
62
+ index: null,
63
+ selected: false,
64
+ tabIndex: 0,
65
+ };
66
+ },
67
+
68
+ watch: {
69
+ selected(newValue) {
70
+ if (!newValue || !this.componentContent) return;
71
+
72
+ this.componentContent.setActiveDescedant(this.id);
73
+
74
+ const isMousemove = this.componentContent.getMousemove();
75
+
76
+ if (!isMousemove) {
77
+ this.el.scrollIntoView({ block: 'nearest' });
78
+ }
79
+ },
80
+ },
81
+
82
+ mounted() {
83
+ this.init();
84
+ this.addMouseEventListeners();
85
+ },
86
+
87
+ beforeDestroy() {
88
+ this.apiInjected().unregisterItem(this.id);
89
+ this.removeMouseEventListeners();
90
+ },
91
+
92
+ methods: {
93
+ init() {
94
+ const item = {
95
+ id: this.id,
96
+ select: this.select,
97
+ unselect: this.unselect,
98
+ focus: this.focus,
99
+ onClick: this.onClick,
100
+ };
101
+
102
+ this.apiInjected().registerItem(item);
103
+
104
+ this.index = this.items.length - 1;
105
+ },
106
+
107
+ addMouseEventListeners() {
108
+ this.el.addEventListener('mousemove', this.onMousemove);
109
+ this.el.addEventListener('mouseleave', this.onMouseleave);
110
+ },
111
+
112
+ removeMouseEventListeners() {
113
+ this.el.removeEventListener('mousemove', this.onMousemove);
114
+ this.el.removeEventListener('mouseleave', this.onMouseleave);
115
+ },
116
+
117
+ select() {
118
+ this.selected = true;
119
+ },
120
+
121
+ unselect() {
122
+ this.selected = false;
123
+ },
124
+
125
+ focus() {
126
+ if (!this.el) return;
127
+
128
+ this.tabIndex = -1;
129
+ this.selected = true;
130
+ this.el.focus();
131
+ },
132
+
133
+ focusFirstItem() {
134
+ this.setFocusToItem(0);
135
+ },
136
+
137
+ focusLastItem() {
138
+ this.setFocusToItem(this.items.length - 1);
139
+ },
140
+
141
+ /**
142
+ * Focus the previous item in the menu.
143
+ * If is the first item, jump to the last item.
144
+ */
145
+ focusPreviousItem() {
146
+ const isLast = this.index === this.items.length - 1;
147
+ const goToIndex = isLast ? 0 : this.index + 1;
148
+
149
+ this.setFocusToItem(goToIndex);
150
+ },
151
+
152
+ /**
153
+ * Focus the next item in the menu.
154
+ * If is the last item, jump to the first item.
155
+ */
156
+ focusNextItem() {
157
+ const isFirst = this.index === 0;
158
+ const goToIndex = isFirst ? this.items.length - 1 : this.index - 1;
159
+
160
+ this.setFocusToItem(goToIndex);
161
+ },
162
+
163
+ /**
164
+ * Focus item by remove its tabindex and calling
165
+ * focus to the element.
166
+ *
167
+ * @param {Number, String} goToIndex
168
+ */
169
+ setFocusToItem(goToIndex) {
170
+ this.tabIndex = 0;
171
+ this.selected = false;
172
+
173
+ // set all selected to false
174
+ this.items.forEach((item) => item.unselect());
175
+
176
+ // focus item
177
+ this.items[goToIndex].focus();
178
+ },
179
+
180
+ leaveMenu() {
181
+ if (this.componentTrigger) {
182
+ this.componentTrigger.cancel();
183
+ this.componentTrigger.focus();
184
+ }
185
+ },
186
+
187
+ onClick() {
188
+ if (this.disabled) {
189
+ return;
190
+ }
191
+
192
+ this.value ? this.apiInjected().emit(this.value) : this.$emit('click');
193
+ this.$nextTick(() => this.leaveMenu());
194
+ },
195
+
196
+ onKeyEsc() {
197
+ this.leaveMenu();
198
+ },
199
+
200
+ onMousemove() {
201
+ if (this.selected) {
202
+ return;
203
+ }
204
+
205
+ this.items.forEach((item) => item.unselect());
206
+
207
+ this.select();
208
+ this.componentContent.setMousemove();
209
+ },
210
+
211
+ onMouseleave() {
212
+ this.unselect();
213
+ this.componentContent.unsetMousemove();
214
+ },
215
+ },
216
+ };
@@ -4,8 +4,8 @@ export const floatingUiMixin = {
4
4
  props: {
5
5
  placement: {
6
6
  type: String,
7
- default: 'bottom-start'
8
- }
7
+ default: 'bottom-start',
8
+ },
9
9
  },
10
10
 
11
11
  data() {
@@ -14,7 +14,7 @@ export const floatingUiMixin = {
14
14
  componentTrigger: null,
15
15
  componentContent: null,
16
16
  active: false,
17
- }
17
+ };
18
18
  },
19
19
 
20
20
  watch: {
@@ -40,11 +40,11 @@ export const floatingUiMixin = {
40
40
  },
41
41
 
42
42
  positionContentToTrigger() {
43
+ // console.log(window.innerWidth)
44
+
43
45
  const trigger = document.getElementById(this.componentTrigger.id);
44
46
  const content = document.getElementById(this.componentContent.id);
45
47
 
46
- // console.log(this.placement);
47
-
48
48
  computePosition(trigger, content, {
49
49
  placement: this.placement,
50
50
  middleware: [
@@ -53,8 +53,14 @@ export const floatingUiMixin = {
53
53
  shift({ padding: 5 }),
54
54
  size({
55
55
  apply({ rects }) {
56
+ // the min width to floating uis should be 200
57
+ // since less than that can look not as nice
58
+ const minWidthLimit = 200;
59
+ const width = rects.reference.width;
60
+ const minWidth = width < minWidthLimit ? minWidthLimit : width;
61
+
56
62
  Object.assign(content.style, {
57
- minWidth: `${rects.reference.width}px`,
63
+ minWidth: `${minWidth}px`,
58
64
  });
59
65
  },
60
66
  }),
@@ -66,5 +72,5 @@ export const floatingUiMixin = {
66
72
  });
67
73
  });
68
74
  },
69
- }
70
- }
75
+ },
76
+ };
@@ -0,0 +1,53 @@
1
+ import { formControlMixin } from '../mixins/form-control';
2
+
3
+ export const formControlIconMixin = {
4
+ inheritAttrs: false,
5
+
6
+ mixins: [formControlMixin],
7
+
8
+ data() {
9
+ return {
10
+ name: 'input',
11
+ };
12
+ },
13
+
14
+ computed: {
15
+ isLeft() {
16
+ return this.iconPlacement === 'left';
17
+ },
18
+
19
+ isRight() {
20
+ return this.iconPlacement === 'right';
21
+ },
22
+
23
+ classComputedWrapper() {
24
+ return [
25
+ this.headless ? 'form-control-wrapper' : 'relative',
26
+ // placement styles
27
+ this.headless
28
+ ? `form-control-icon--${this.placement}`
29
+ : this.isLeft
30
+ ? '[&_input]:pl-9'
31
+ : this.isRight
32
+ ? '[&_input]:pr-9'
33
+ : null,
34
+ ];
35
+ },
36
+
37
+ classComputedWrapperIcon() {
38
+ return [
39
+ this.headless
40
+ ? 'form-control-wrapper__icon'
41
+ : `absolute top-0 bottom-0 flex w-9 justify-center items-center text-gray-400`,
42
+ // placement styles
43
+ this.headless
44
+ ? null
45
+ : this.isLeft
46
+ ? 'left-0'
47
+ : this.isRight
48
+ ? 'right-0'
49
+ : null,
50
+ ];
51
+ },
52
+ },
53
+ };
@@ -0,0 +1,72 @@
1
+ export const formControlMixin = {
2
+ model: {
3
+ prop: 'value',
4
+ event: 'input',
5
+ },
6
+
7
+ props: {
8
+ disabled: {
9
+ type: Boolean,
10
+ default: false,
11
+ },
12
+ headless: {
13
+ type: Boolean,
14
+ default: false,
15
+ },
16
+ value: {
17
+ type: [String, Number, Object, Array],
18
+ default: null,
19
+ },
20
+ variant: {
21
+ type: [String, Object, Function],
22
+ default: '',
23
+ },
24
+ },
25
+
26
+ computed: {
27
+ listeners() {
28
+ // `Object.assign` merges objects together to form a new object
29
+ return Object.assign(
30
+ {},
31
+ // We add all the listeners from the parent
32
+ this.$listeners,
33
+ // Then we can add custom listeners or override the
34
+ // behavior of some listeners.
35
+ {
36
+ // This ensures that the component works with v-model
37
+ input: (event) => {
38
+ // if (this.lazy) return;
39
+ this.$emit('input', event.target.value);
40
+ },
41
+ blur: (event) => {
42
+ this.$emit('blur', event);
43
+ },
44
+ }
45
+ );
46
+ },
47
+
48
+ classComputed() {
49
+ return [
50
+ this.headless
51
+ ? `${this.name}`
52
+ : 'leading-0 flex w-full max-w-full appearance-none items-center justify-between gap-3 rounded border border-solid px-3 py-2 font-inherit text-base text-inherit file:hidden focus:border-secondary-200',
53
+ // variant styles
54
+ this.headless
55
+ ? `${this.name}--${this.variant}`
56
+ : this.isError
57
+ ? 'border-error-300'
58
+ : 'border-gray-300',
59
+ // height styles
60
+ this.headless
61
+ ? null
62
+ : this.name === 'textarea'
63
+ ? 'min-h-10' // limit it because input type number height can be different from other input types
64
+ : 'h-10',
65
+ ];
66
+ },
67
+
68
+ isError() {
69
+ return this.variant === 'error';
70
+ },
71
+ },
72
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veritree/ui",
3
- "version": "0.21.1-8",
3
+ "version": "0.22.0",
4
4
  "description": "veritree ui library",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -15,5 +15,9 @@
15
15
  "@linusborg/vue-simple-portal": "^0.1.5",
16
16
  "@veritree/icons": "^0.39.0"
17
17
  },
18
- "devDependencies": {}
18
+ "devDependencies": {
19
+ "prettier": "^2.7.1",
20
+ "prettier-plugin-tailwindcss": "^0.1.13",
21
+ "tailwindcss": "^3.2.4"
22
+ }
19
23
  }
@@ -16,8 +16,6 @@ export default {
16
16
  provide() {
17
17
  return {
18
18
  apiDropdownMenu: () => {
19
- const { dark: isDark, headless: isHeadless } = this;
20
-
21
19
  const registerTrigger = (trigger) => {
22
20
  if (!trigger) return;
23
21
  this.componentTrigger = trigger;
@@ -33,8 +31,9 @@ export default {
33
31
  this.items.push(item);
34
32
  };
35
33
 
36
- const unregisterItems = () => {
37
- this.items = [];
34
+ const unregisterItem = (id) => {
35
+ const index = this.items.findIndex((item) => item.id === id);
36
+ this.items.splice(index, 1);
38
37
  };
39
38
 
40
39
  return {
@@ -46,7 +45,7 @@ export default {
46
45
  registerTrigger,
47
46
  registerContent,
48
47
  registerItem,
49
- unregisterItems,
48
+ unregisterItem,
50
49
  };
51
50
  },
52
51
  };
@@ -39,6 +39,10 @@ export default {
39
39
  id: this.id,
40
40
  hide: this.hide,
41
41
  show: this.show,
42
+ getMousemove: this.getMousemove,
43
+ setMousemove: this.setMousemove,
44
+ unsetMousemove: this.unsetMousemove,
45
+ setActiveDescedant: this.setActiveDescedant,
42
46
  };
43
47
 
44
48
  this.apiDropdownMenu().registerContent(content);