@volverjs/ui-vue 0.0.10-beta.54 → 0.0.10-beta.56
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/auto-imports.d.ts +3 -0
- package/dist/components/VvCombobox/VvCombobox.es.js +357 -357
- package/dist/components/VvCombobox/VvCombobox.umd.js +1 -1
- package/dist/components/VvInputText/VvInputText.es.js +150 -44
- package/dist/components/VvInputText/VvInputText.umd.js +1 -1
- package/dist/components/VvInputText/VvInputText.vue.d.ts +6 -6
- package/dist/components/VvInputText/index.d.ts +1 -1
- package/dist/components/VvTextarea/VvTextarea.es.js +966 -67
- package/dist/components/VvTextarea/VvTextarea.umd.js +1 -1
- package/dist/components/VvTextarea/VvTextarea.vue.d.ts +52 -0
- package/dist/components/VvTextarea/index.d.ts +37 -1
- package/dist/components/index.es.js +542 -284
- package/dist/components/index.umd.js +1 -1
- package/dist/icons.es.js +3 -3
- package/dist/icons.umd.js +1 -1
- package/dist/stories/InputText/InputText.test.d.ts +1 -0
- package/dist/stories/InputText/InputTextIso.stories.d.ts +10 -0
- package/dist/utils/DateUtilities.d.ts +22 -0
- package/package.json +22 -22
- package/src/assets/icons/detailed.json +1 -1
- package/src/assets/icons/normal.json +1 -1
- package/src/assets/icons/simple.json +1 -1
- package/src/components/VvCombobox/VvCombobox.vue +3 -3
- package/src/components/VvInputText/VvInputText.vue +103 -63
- package/src/components/VvInputText/index.ts +1 -1
- package/src/components/VvTextarea/VvTextarea.vue +108 -5
- package/src/components/VvTextarea/index.ts +32 -1
- package/src/stories/InputText/InputText.test.ts +25 -0
- package/src/stories/InputText/InputTextIso.stories.ts +69 -0
- package/src/utils/DateUtilities.ts +98 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a string is a valid ISO date string
|
|
3
|
+
* @param dateString
|
|
4
|
+
* @returns True if valid ISO date string
|
|
5
|
+
*/
|
|
6
|
+
export function isDateIsoString(dateString: unknown) {
|
|
7
|
+
if (typeof dateString !== 'string') {
|
|
8
|
+
return false
|
|
9
|
+
}
|
|
10
|
+
// Support both with/without milliseconds and timezone variations
|
|
11
|
+
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?(?:Z|[+-]\d{2}:?\d{2})?$/.test(dateString)) {
|
|
12
|
+
return false
|
|
13
|
+
}
|
|
14
|
+
const d = new Date(dateString)
|
|
15
|
+
return !Number.isNaN(d.getTime()) && d.toISOString() === dateString
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Converts a Date object to a string value for input element
|
|
20
|
+
* @param date - Date object or string
|
|
21
|
+
* @param typeOfInput - Type of HTML input element
|
|
22
|
+
* @param withSeconds - Include seconds in time value
|
|
23
|
+
* @returns String value for input element
|
|
24
|
+
*/
|
|
25
|
+
export function getInputValueFromDate(date: Date | string, typeOfInput: 'date' | 'time' | 'month' | 'datetime-local' = 'date', withSeconds?: boolean) {
|
|
26
|
+
if (typeof date === 'string') {
|
|
27
|
+
if (!isDateIsoString(date)) {
|
|
28
|
+
return ''
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const currentDate = new Date(date)
|
|
32
|
+
if (Number.isNaN(currentDate.getTime())) {
|
|
33
|
+
return ''
|
|
34
|
+
}
|
|
35
|
+
const span = (num: number) => num.toString().padStart(2, '0')
|
|
36
|
+
let toReturn = `${currentDate.getFullYear()}-${span(currentDate.getMonth() + 1)}`
|
|
37
|
+
if (typeOfInput === 'month') {
|
|
38
|
+
return toReturn
|
|
39
|
+
}
|
|
40
|
+
toReturn += `-${span(currentDate.getDate())}`
|
|
41
|
+
if (typeOfInput === 'date') {
|
|
42
|
+
return toReturn
|
|
43
|
+
}
|
|
44
|
+
const time = withSeconds
|
|
45
|
+
? `${span(currentDate.getHours())}:${span(currentDate.getMinutes())}:${span(currentDate.getSeconds())}`
|
|
46
|
+
: `${span(currentDate.getHours())}:${span(currentDate.getMinutes())}`
|
|
47
|
+
if (typeOfInput === 'time') {
|
|
48
|
+
return time
|
|
49
|
+
}
|
|
50
|
+
return `${toReturn}T${time}`
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Converts an input string to a Date object based on input type
|
|
55
|
+
* @param value - String value from input element
|
|
56
|
+
* @param typeOfInput - Type of HTML input element
|
|
57
|
+
* @returns Date object or null if invalid
|
|
58
|
+
* @throws Error for invalid input format
|
|
59
|
+
*/
|
|
60
|
+
export function getDateFromInputValue(value: string, typeOfInput: 'date' | 'time' | 'month' | 'datetime-local' = 'date') {
|
|
61
|
+
if (!value?.trim()) {
|
|
62
|
+
return null
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const today = new Date()
|
|
66
|
+
const currentYear = today.getFullYear()
|
|
67
|
+
const currentMonth = today.getMonth()
|
|
68
|
+
const currentDate = today.getDate()
|
|
69
|
+
|
|
70
|
+
if (typeOfInput === 'date') {
|
|
71
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(value)) {
|
|
72
|
+
throw new Error('Invalid date format. Expected: YYYY-MM-DD')
|
|
73
|
+
}
|
|
74
|
+
return new Date(`${value}T00:00:00`)
|
|
75
|
+
}
|
|
76
|
+
if (typeOfInput === 'month') {
|
|
77
|
+
if (!/^\d{4}-\d{2}$/.test(value)) {
|
|
78
|
+
throw new Error('Invalid month format. Expected: YYYY-MM')
|
|
79
|
+
}
|
|
80
|
+
return new Date(`${value}-01T00:00:00`)
|
|
81
|
+
}
|
|
82
|
+
if (typeOfInput === 'time') {
|
|
83
|
+
if (!/^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?$/.test(value)) {
|
|
84
|
+
throw new Error('Invalid time format. Expected: HH:mm or HH:mm:ss')
|
|
85
|
+
}
|
|
86
|
+
if (value.length === 8) {
|
|
87
|
+
return new Date(`${currentYear}-${currentMonth + 1}-${currentDate}T${value}`)
|
|
88
|
+
}
|
|
89
|
+
return new Date(`${currentYear}-${currentMonth + 1}-${currentDate}T${value}:00`)
|
|
90
|
+
}
|
|
91
|
+
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2})?$/.test(value)) {
|
|
92
|
+
throw new Error('Invalid datetime format. Expected: YYYY-MM-DDThh:mm or YYYY-MM-DDThh:mm:ss')
|
|
93
|
+
}
|
|
94
|
+
if (value.length === 16) {
|
|
95
|
+
return new Date(`${value}:00`)
|
|
96
|
+
}
|
|
97
|
+
return new Date(`${value}`)
|
|
98
|
+
}
|