vueless 0.0.482 → 0.0.484
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/adatper.locale/vueless.ts +3 -3
- package/composables/useUI.ts +2 -1
- package/package.json +1 -1
- package/types.ts +10 -3
- package/ui.button/storybook/stories.js +100 -40
- package/ui.button-link/storybook/stories.js +109 -35
- package/ui.form-calendar/UCalendar.vue +310 -370
- package/ui.form-calendar/UCalendarDayView.vue +211 -257
- package/ui.form-calendar/UCalendarMonthView.vue +120 -164
- package/ui.form-calendar/UCalendarYearView.vue +118 -164
- package/ui.form-calendar/{config.js → config.ts} +0 -2
- package/ui.form-calendar/{constants.js → constants.ts} +35 -16
- package/ui.form-calendar/storybook/Docs.mdx +2 -3
- package/ui.form-calendar/storybook/{stories.js → stories.ts} +12 -4
- package/ui.form-calendar/types.ts +91 -0
- package/ui.form-calendar/{useAttrs.js → useAttrs.ts} +5 -2
- package/ui.form-calendar/{utilCalendar.js → utilCalendar.ts} +50 -53
- package/ui.form-calendar/{utilDate.js → utilDate.ts} +44 -37
- package/ui.form-calendar/utilFormatting.ts +178 -0
- package/ui.text-badge/useAttrs.ts +2 -2
- package/ui.text-block/useAttrs.ts +1 -3
- package/web-types.json +177 -50
- package/ui.form-calendar/utilFormatting.js +0 -180
- package/ui.form-date-picker/storybook/Docs.mdx +0 -53
- package/ui.form-date-picker/storybook/stories.js +0 -185
- package/ui.form-date-picker-range/storybook/Docs.mdx +0 -16
- package/ui.form-date-picker-range/storybook/stories.js +0 -216
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
export interface DateLocale {
|
|
2
|
+
weekdays: {
|
|
3
|
+
shorthand: string[];
|
|
4
|
+
longhand: string[];
|
|
5
|
+
userFormat?: unknown;
|
|
6
|
+
};
|
|
7
|
+
months: {
|
|
8
|
+
shorthand: string[];
|
|
9
|
+
longhand: string[];
|
|
10
|
+
userFormat?: unknown;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const pad = (number: number, length = 2) => `000${number}`.slice(length * -1);
|
|
15
|
+
|
|
16
|
+
const doNothing = () => undefined;
|
|
17
|
+
|
|
18
|
+
export const monthToStr = (monthNumber: number, shorthand: boolean, locale: DateLocale) => {
|
|
19
|
+
return locale.months[shorthand ? "shorthand" : "longhand"][monthNumber];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const revFormat = {
|
|
23
|
+
D: doNothing,
|
|
24
|
+
F(dateObj: Date, monthName: string, locale: DateLocale) {
|
|
25
|
+
dateObj.setMonth(locale.months.longhand.indexOf(monthName));
|
|
26
|
+
},
|
|
27
|
+
G: (dateObj: Date, hour: number | string) => {
|
|
28
|
+
dateObj.setHours(parseFloat(String(hour)));
|
|
29
|
+
},
|
|
30
|
+
H: (dateObj: Date, hour: number | string) => {
|
|
31
|
+
dateObj.setHours(parseFloat(String(hour)));
|
|
32
|
+
},
|
|
33
|
+
J: (dateObj: Date, day: number | string) => {
|
|
34
|
+
dateObj.setDate(parseFloat(String(day)));
|
|
35
|
+
},
|
|
36
|
+
M(dateObj: Date, shortMonth: string, locale: DateLocale) {
|
|
37
|
+
dateObj.setMonth(locale.months.shorthand.indexOf(shortMonth));
|
|
38
|
+
},
|
|
39
|
+
S: (dateObj: Date, seconds: number | string) => {
|
|
40
|
+
dateObj.setSeconds(parseFloat(String(seconds)));
|
|
41
|
+
},
|
|
42
|
+
U: (_: unknown, unixSeconds: string | number) => new Date(parseFloat(String(unixSeconds)) * 1000),
|
|
43
|
+
|
|
44
|
+
W(dateObj: Date, weekNum: number | string) {
|
|
45
|
+
const weekNumber = parseInt(String(weekNum), 10);
|
|
46
|
+
const date = new Date(dateObj.getFullYear(), 0, 2 + (weekNumber - 1) * 7, 0, 0, 0, 0);
|
|
47
|
+
|
|
48
|
+
date.setDate(date.getDate() - date.getDay());
|
|
49
|
+
|
|
50
|
+
return date;
|
|
51
|
+
},
|
|
52
|
+
Y: (dateObj: Date, year: number | string) => {
|
|
53
|
+
dateObj.setFullYear(parseFloat(String(year)));
|
|
54
|
+
},
|
|
55
|
+
Z: (_: unknown, ISODate: string) => new Date(ISODate),
|
|
56
|
+
|
|
57
|
+
d: (dateObj: Date, day: number | string) => {
|
|
58
|
+
dateObj.setDate(parseFloat(String(day)));
|
|
59
|
+
},
|
|
60
|
+
h: (dateObj: Date, hour: number | string) => {
|
|
61
|
+
dateObj.setHours(parseFloat(String(hour)));
|
|
62
|
+
},
|
|
63
|
+
i: (dateObj: Date, minutes: number | string) => {
|
|
64
|
+
dateObj.setMinutes(parseFloat(String(minutes)));
|
|
65
|
+
},
|
|
66
|
+
j: (dateObj: Date, day: number | string) => {
|
|
67
|
+
dateObj.setDate(parseFloat(String(day)));
|
|
68
|
+
},
|
|
69
|
+
l: doNothing,
|
|
70
|
+
m: (dateObj: Date, month: number | string) => {
|
|
71
|
+
dateObj.setMonth(parseFloat(String(month)) - 1);
|
|
72
|
+
},
|
|
73
|
+
n: (dateObj: Date, month: number | string) => {
|
|
74
|
+
dateObj.setMonth(parseFloat(String(month)) - 1);
|
|
75
|
+
},
|
|
76
|
+
s: (dateObj: Date, seconds: number | string) => {
|
|
77
|
+
dateObj.setSeconds(parseFloat(String(seconds)));
|
|
78
|
+
},
|
|
79
|
+
u: (_: unknown, unixMillSeconds: number | string) =>
|
|
80
|
+
new Date(parseFloat(String(unixMillSeconds))),
|
|
81
|
+
w: doNothing,
|
|
82
|
+
y: (dateObj: Date, year: number | string) => {
|
|
83
|
+
dateObj.setFullYear(2000 + parseFloat(String(year)));
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export const formats = {
|
|
88
|
+
// get the date in UTC
|
|
89
|
+
Z: (date: Date) => date.toISOString(),
|
|
90
|
+
|
|
91
|
+
// weekday name, short, e.g. Thu
|
|
92
|
+
D(date: Date, locale: DateLocale) {
|
|
93
|
+
return locale.weekdays.shorthand[formats.w(date)];
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
// full month name e.g. January
|
|
97
|
+
F(date: Date, locale: DateLocale) {
|
|
98
|
+
return monthToStr(formats.n(date) - 1, false, locale);
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
// padded hour 1-12
|
|
102
|
+
G(date: Date) {
|
|
103
|
+
return pad(formats.h(date));
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
// hours with leading zero e.g. 03
|
|
107
|
+
H: (date: Date) => pad(date.getHours()),
|
|
108
|
+
|
|
109
|
+
// shorthand month e.g. Jan, Sep, Oct, etc
|
|
110
|
+
M(date: Date, locale: DateLocale) {
|
|
111
|
+
return monthToStr(date.getMonth(), true, locale);
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
// seconds 00-59
|
|
115
|
+
S: (date: Date) => pad(date.getSeconds()),
|
|
116
|
+
|
|
117
|
+
// unix timestamp
|
|
118
|
+
U: (date: Date) => date.getTime() / 1000,
|
|
119
|
+
|
|
120
|
+
W(date: Date) {
|
|
121
|
+
// return options.getWeek(date);
|
|
122
|
+
const localDate = new Date(date.getTime());
|
|
123
|
+
|
|
124
|
+
localDate.setHours(0, 0, 0, 0);
|
|
125
|
+
|
|
126
|
+
// Thursday in current week decides the year.
|
|
127
|
+
localDate.setDate(localDate.getDate() + 3 - ((localDate.getDay() + 6) % 7));
|
|
128
|
+
|
|
129
|
+
// January 4 is always in week 1.
|
|
130
|
+
const week1 = new Date(localDate.getFullYear(), 0, 4);
|
|
131
|
+
|
|
132
|
+
// Adjust to Thursday in week 1 and count number of weeks from date to week1.
|
|
133
|
+
return (
|
|
134
|
+
1 +
|
|
135
|
+
Math.round(
|
|
136
|
+
((localDate.getTime() - week1.getTime()) / 86400000 - 3 + ((week1.getDay() + 6) % 7)) / 7,
|
|
137
|
+
)
|
|
138
|
+
);
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
// full year e.g. 2016, padded (0001-9999)
|
|
142
|
+
Y: (date: Date) => pad(date.getFullYear(), 4),
|
|
143
|
+
|
|
144
|
+
// day in month, padded (01-30)
|
|
145
|
+
d: (date: Date) => pad(date.getDate()),
|
|
146
|
+
|
|
147
|
+
// hour from 1-12 (am/pm)
|
|
148
|
+
h: (date: Date) => (date.getHours() % 12 ? date.getHours() % 12 : 12),
|
|
149
|
+
|
|
150
|
+
// minutes, padded with leading zero e.g. 09
|
|
151
|
+
i: (date: Date) => pad(date.getMinutes()),
|
|
152
|
+
|
|
153
|
+
// day in month (1-30)
|
|
154
|
+
j: (date: Date) => date.getDate(),
|
|
155
|
+
|
|
156
|
+
// weekday name, full, e.g. Thursday
|
|
157
|
+
l(date: Date, locale: DateLocale) {
|
|
158
|
+
return locale.weekdays.longhand[date.getDay()];
|
|
159
|
+
},
|
|
160
|
+
|
|
161
|
+
// padded month number (01-12)
|
|
162
|
+
m: (date: Date) => pad(date.getMonth() + 1),
|
|
163
|
+
|
|
164
|
+
// the month number (1-12)
|
|
165
|
+
n: (date: Date) => date.getMonth() + 1,
|
|
166
|
+
|
|
167
|
+
// seconds 0-59
|
|
168
|
+
s: (date: Date) => date.getSeconds(),
|
|
169
|
+
|
|
170
|
+
// Unix Milliseconds
|
|
171
|
+
u: (date: Date) => date.getTime(),
|
|
172
|
+
|
|
173
|
+
// number of the day of the week
|
|
174
|
+
w: (date: Date) => date.getDay(),
|
|
175
|
+
|
|
176
|
+
// last two digits of year e.g. 16 for 2016
|
|
177
|
+
y: (date: Date) => String(date.getFullYear()).substring(2),
|
|
178
|
+
};
|
|
@@ -8,7 +8,7 @@ import type { UBadgeProps } from "./types.ts";
|
|
|
8
8
|
|
|
9
9
|
type Config = Partial<typeof defaultConfig>;
|
|
10
10
|
|
|
11
|
-
export default function useAttrs(props: UBadgeProps) {
|
|
11
|
+
export default function useAttrs(props: UBadgeProps): UseAttrs<Config> {
|
|
12
12
|
const { config, getKeysAttrs, hasSlotContent } = useUI<Config>(defaultConfig, () => props.config);
|
|
13
13
|
const slots = useSlots();
|
|
14
14
|
|
|
@@ -24,5 +24,5 @@ export default function useAttrs(props: UBadgeProps) {
|
|
|
24
24
|
config,
|
|
25
25
|
...keysAttrs,
|
|
26
26
|
hasSlotContent,
|
|
27
|
-
}
|
|
27
|
+
};
|
|
28
28
|
}
|
|
@@ -5,9 +5,7 @@ import defaultConfig from "./config.ts";
|
|
|
5
5
|
import type { UseAttrs } from "../types.ts";
|
|
6
6
|
import type { UTextProps } from "./types.ts";
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export default function useAttrs(props: UTextProps): UseAttrs {
|
|
8
|
+
export default function useAttrs(props: UTextProps): UseAttrs<Config> {
|
|
11
9
|
const { config, getKeysAttrs, hasSlotContent } = useUI<Config>(defaultConfig, () => props.config);
|
|
12
10
|
|
|
13
11
|
const keysAttrs = getKeysAttrs();
|