@veritree/ui 0.0.1 → 0.1.3
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 +54 -8
- package/package.json +1 -1
- package/src/{vtAccordion/vtAccordion.vue → Accordion/VTAccordion.vue} +1 -1
- package/src/{vtAccordion/vtAccordionButton.vue → Accordion/VTAccordionButton.vue} +1 -1
- package/src/{vtAccordion/vtAccordionGroup.vue → Accordion/VTAccordionGroup.vue} +1 -1
- package/src/{vtAccordion/vtAccordionPanel.vue → Accordion/VTAccordionPanel.vue} +1 -3
- package/src/Alerts/VTAlert.vue +72 -0
- package/src/Button/VTButton.vue +86 -0
- package/src/Button/VTButtonSave.vue +27 -0
- package/src/Input/VTInput.vue +82 -0
- package/src/Input/VTInputDate.vue +36 -0
- package/src/Input/VTInputFile.vue +60 -0
- package/src/Input/VTInputUpload.vue +54 -0
- package/src/Listbox/VTListbox.vue +168 -0
- package/src/Listbox/VTListboxButton.vue +82 -0
- package/src/Listbox/VTListboxOption.vue +121 -0
- package/src/Listbox/VTListboxOptions.vue +120 -0
- package/src/Modal/VTModal.vue +69 -0
- package/src/Spinner/VTSpinner.vue +14 -0
- package/src/Tabs/VTTab.vue +126 -0
- package/src/Tabs/VTTabGroup.vue +100 -0
- package/src/Tabs/VTTabList.vue +11 -0
- package/src/Tabs/VTTabPanel.vue +51 -0
- package/src/Tabs/VTTabPanels.vue +11 -0
- package/src/Textarea/VTTextarea.vue +77 -0
- package/src/utils/ids.js +34 -0
- package/src/utils/objects.js +139 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<textarea
|
|
3
|
+
:class="classes"
|
|
4
|
+
class="form-control"
|
|
5
|
+
:data-theme="theme"
|
|
6
|
+
:value="value"
|
|
7
|
+
v-on="listeners"
|
|
8
|
+
></textarea>
|
|
9
|
+
</template>
|
|
10
|
+
|
|
11
|
+
<script>
|
|
12
|
+
export default {
|
|
13
|
+
name: 'VTTextarea',
|
|
14
|
+
|
|
15
|
+
props: {
|
|
16
|
+
lazy: {
|
|
17
|
+
type: Boolean,
|
|
18
|
+
default: false,
|
|
19
|
+
},
|
|
20
|
+
theme: {
|
|
21
|
+
type: String,
|
|
22
|
+
default: null,
|
|
23
|
+
validator(value) {
|
|
24
|
+
return ['dark'].includes(value);
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
variant: {
|
|
28
|
+
type: [String, Object],
|
|
29
|
+
default: '',
|
|
30
|
+
validator(value) {
|
|
31
|
+
if (value === '' || typeof value === 'object') {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return ['success', 'warning', 'error'].includes(value);
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
value: {
|
|
39
|
+
type: [String, Number, Object],
|
|
40
|
+
default: null,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
computed: {
|
|
45
|
+
classes() {
|
|
46
|
+
const classes = {};
|
|
47
|
+
|
|
48
|
+
if (this.variant) {
|
|
49
|
+
classes[`form-control--${this.variant}`] = true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return classes;
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
listeners() {
|
|
56
|
+
// `Object.assign` merges objects together to form a new object
|
|
57
|
+
return Object.assign(
|
|
58
|
+
{},
|
|
59
|
+
// We add all the listeners from the parent
|
|
60
|
+
this.$listeners,
|
|
61
|
+
// Then we can add custom listeners or override the
|
|
62
|
+
// behavior of some listeners.
|
|
63
|
+
{
|
|
64
|
+
// This ensures that the component works with v-model
|
|
65
|
+
input: (event) => {
|
|
66
|
+
if (this.lazy) return;
|
|
67
|
+
this.$emit('input', event.target.value);
|
|
68
|
+
},
|
|
69
|
+
blur: (event) => {
|
|
70
|
+
this.$emit('blur', event);
|
|
71
|
+
},
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
</script>
|
package/src/utils/ids.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Generate id
|
|
2
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*
|
|
3
|
+
let gen = null;
|
|
4
|
+
|
|
5
|
+
function* idMaker() {
|
|
6
|
+
let index = 0;
|
|
7
|
+
while (true) yield index++;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const genId = () => {
|
|
11
|
+
if (!gen) gen = idMaker();
|
|
12
|
+
return gen.next().value;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// Add leading zeros
|
|
16
|
+
// export const pad = (num, size) => {
|
|
17
|
+
// let s = num + '';
|
|
18
|
+
|
|
19
|
+
// while (s.length < size) {
|
|
20
|
+
// s = '0' + s;
|
|
21
|
+
// }
|
|
22
|
+
|
|
23
|
+
// return s;
|
|
24
|
+
// };
|
|
25
|
+
|
|
26
|
+
export const addZerosToId = (id) => {
|
|
27
|
+
let formattedId = null;
|
|
28
|
+
|
|
29
|
+
if (id < 10) formattedId = '000' + id;
|
|
30
|
+
else if (id < 100) formattedId = '00' + id;
|
|
31
|
+
else if (id < 1000) formattedId = '0' + id;
|
|
32
|
+
|
|
33
|
+
return '#' + formattedId;
|
|
34
|
+
};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {*} obj
|
|
3
|
+
* @returns boolean
|
|
4
|
+
*/
|
|
5
|
+
export const isObj = (obj) => {
|
|
6
|
+
return obj !== null && typeof obj === 'object';
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {*} obj
|
|
11
|
+
* @returns {boolean}
|
|
12
|
+
*/
|
|
13
|
+
export const isAnEmptyObj = (obj) => {
|
|
14
|
+
if (!isObj(obj)) return false;
|
|
15
|
+
|
|
16
|
+
return Object.keys(obj).length === 0;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {string} key
|
|
21
|
+
* @param {obj} obj
|
|
22
|
+
* @returns {boolean}
|
|
23
|
+
*/
|
|
24
|
+
export const isKeyInObj = (key, obj) => {
|
|
25
|
+
if (!isObj(obj) || !key) return false;
|
|
26
|
+
|
|
27
|
+
return Object.keys(obj).includes(key);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Compare objects deeply
|
|
32
|
+
* @source https://dmitripavlutin.com/how-to-compare-objects-in-javascript/
|
|
33
|
+
*
|
|
34
|
+
* @param {obj} obj1
|
|
35
|
+
* @param {obj} obj2
|
|
36
|
+
* @returns {boolean}
|
|
37
|
+
*/
|
|
38
|
+
export const areObjsEqual = (obj1, obj2) => {
|
|
39
|
+
const keys1 = Object.keys(obj1);
|
|
40
|
+
const keys2 = Object.keys(obj2);
|
|
41
|
+
|
|
42
|
+
if (keys1.length !== keys2.length) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
for (const key of keys1) {
|
|
47
|
+
const val1 = obj1[key];
|
|
48
|
+
const val2 = obj2[key];
|
|
49
|
+
const areObjects = isObj(val1) && isObj(val2);
|
|
50
|
+
|
|
51
|
+
if (
|
|
52
|
+
(areObjects && !areObjsEqual(val1, val2)) ||
|
|
53
|
+
(!areObjects && val1 !== val2)
|
|
54
|
+
) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return true;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Compare two array of objects and returns an array with the differences
|
|
64
|
+
*
|
|
65
|
+
* @param {array} oldArr
|
|
66
|
+
* @param {array} newArr
|
|
67
|
+
* @returns {array}
|
|
68
|
+
*/
|
|
69
|
+
export const diffArrOfObjs = (oldArr, newArr) => {
|
|
70
|
+
const result = [];
|
|
71
|
+
|
|
72
|
+
// compare all elements of oldArr with all elements of newArr
|
|
73
|
+
// and if there is any difference, push it to result
|
|
74
|
+
oldArr.forEach((obj, i) => {
|
|
75
|
+
if (!newArr[i]) return;
|
|
76
|
+
|
|
77
|
+
const obj2 = newArr[i];
|
|
78
|
+
|
|
79
|
+
if (!areObjsEqual(obj, obj2)) {
|
|
80
|
+
result.push(newArr[i]);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// compare size and if newArr has more elements,
|
|
85
|
+
// push them to result because they are new
|
|
86
|
+
if (oldArr.length < newArr.length) {
|
|
87
|
+
newArr.slice(oldArr.length).forEach((obj) => {
|
|
88
|
+
result.push(obj);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return result;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Compare two objects and returns an object with the differences
|
|
97
|
+
*
|
|
98
|
+
* @param {obj} oldObj
|
|
99
|
+
* @param {ojb} newObj
|
|
100
|
+
* @returns {obj}
|
|
101
|
+
*/
|
|
102
|
+
export const diffObjs = (oldObj, newObj) => {
|
|
103
|
+
const result = {};
|
|
104
|
+
const oldKeys = Object.keys(oldObj);
|
|
105
|
+
const newKeys = Object.keys(newObj);
|
|
106
|
+
|
|
107
|
+
for (const oldKey of oldKeys) {
|
|
108
|
+
const val1 = oldObj[oldKey];
|
|
109
|
+
const val2 = newObj[oldKey];
|
|
110
|
+
|
|
111
|
+
if (!newObj[oldKey]) return;
|
|
112
|
+
|
|
113
|
+
if (typeof val1 === 'object') {
|
|
114
|
+
if (!areObjsEqual(val1, val2)) {
|
|
115
|
+
result[oldKey] = val2;
|
|
116
|
+
}
|
|
117
|
+
} else if (val1 !== val2) {
|
|
118
|
+
result[oldKey] = newObj[oldKey];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// compare size and if newKyes has more elements,
|
|
123
|
+
// push them to result because they are new
|
|
124
|
+
if (oldKeys.length < newKeys.length) {
|
|
125
|
+
for (const key of newKeys) {
|
|
126
|
+
if (!oldKeys.includes(key)) result[key] = newObj[key];
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return result;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @param {obj} obj
|
|
135
|
+
* @returns {obj}
|
|
136
|
+
*/
|
|
137
|
+
export const cloneObj = (obj) => {
|
|
138
|
+
return JSON.parse(JSON.stringify(obj));
|
|
139
|
+
};
|