@mellow.io/ds 0.1.1 → 0.2.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/README.md +5 -4
- package/dist/components/datepicker/datepicker-utils.d.ts +37 -0
- package/dist/components/datepicker/datepicker-utils.d.ts.map +1 -0
- package/dist/components/datepicker/datepicker-utils.js +157 -0
- package/dist/components/datepicker/datepicker-utils.js.map +1 -0
- package/dist/components/datepicker/datepicker.d.ts +62 -0
- package/dist/components/datepicker/datepicker.d.ts.map +1 -0
- package/dist/components/datepicker/datepicker.js +380 -0
- package/dist/components/datepicker/datepicker.js.map +1 -0
- package/dist/components/datepicker/datepicker.styles.d.ts +2 -0
- package/dist/components/datepicker/datepicker.styles.d.ts.map +1 -0
- package/dist/components/datepicker/datepicker.styles.js +384 -0
- package/dist/components/datepicker/datepicker.styles.js.map +1 -0
- package/dist/components/datepicker/index.d.ts +4 -0
- package/dist/components/datepicker/index.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +67 -65
- package/dist/index.js.map +1 -1
- package/dist/react/index.d.ts +9 -0
- package/dist/react/index.d.ts.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @mellow.io/ds
|
|
2
2
|
|
|
3
|
-
Mellow Design System — a library of
|
|
3
|
+
Mellow Design System — a library of 32 UI components built with [Lit 3](https://lit.dev/) Web Components. Works with any framework or no framework at all.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -50,7 +50,7 @@ function App() {
|
|
|
50
50
|
### Import Strategies
|
|
51
51
|
|
|
52
52
|
```ts
|
|
53
|
-
// Full bundle — registers all
|
|
53
|
+
// Full bundle — registers all 32 components at once
|
|
54
54
|
import '@mellow.io/ds'
|
|
55
55
|
|
|
56
56
|
// Per-component (tree-shakeable, recommended)
|
|
@@ -81,6 +81,7 @@ import '@mellow.io/ds/tokens'
|
|
|
81
81
|
| [Switch](docs/components.md#switch) | `<mellow-switch>` | Toggle switch |
|
|
82
82
|
| [Select](docs/components.md#select) | `<mellow-select>` | Dropdown select with searchable option |
|
|
83
83
|
| [Form Field](docs/components.md#form-field) | `<mellow-form-field>` | Wrapper providing label, error, hint for any input |
|
|
84
|
+
| [Datepicker](docs/components.md#datepicker) | `<mellow-datepicker>` | Calendar with single/range selection, presets, min/max |
|
|
84
85
|
|
|
85
86
|
### Primitives
|
|
86
87
|
|
|
@@ -190,9 +191,9 @@ document.querySelector('mellow-input')
|
|
|
190
191
|
|
|
191
192
|
| Event | Components | Detail |
|
|
192
193
|
|---|---|---|
|
|
193
|
-
| `mellow-change` | input, textarea, checkbox, radio-group, select, switch | `{ value }` or `{ checked }` |
|
|
194
|
+
| `mellow-change` | input, textarea, checkbox, radio-group, select, switch, datepicker | `{ value }` or `{ checked }` |
|
|
194
195
|
| `mellow-input` | input, textarea | `{ value }` |
|
|
195
|
-
| `mellow-select` | dropdown, tag | `{ value }` or `{ selected }` |
|
|
196
|
+
| `mellow-select` | dropdown, tag, datepicker | `{ value }` or `{ selected }` |
|
|
196
197
|
| `mellow-dismiss` | alert, toast | — |
|
|
197
198
|
| `mellow-close` | dialog | — |
|
|
198
199
|
| `mellow-toggle` | accordion-item, popover | `{ open }` |
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface CalendarDay {
|
|
2
|
+
date: Date;
|
|
3
|
+
day: number;
|
|
4
|
+
currentMonth: boolean;
|
|
5
|
+
today: boolean;
|
|
6
|
+
disabled: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface DatepickerPreset {
|
|
9
|
+
label: string;
|
|
10
|
+
getValue: () => {
|
|
11
|
+
start: string;
|
|
12
|
+
end: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export declare function parseISO(value: string): Date | null;
|
|
16
|
+
export declare function formatISO(date: Date): string;
|
|
17
|
+
export declare function isSameDay(a: Date, b: Date): boolean;
|
|
18
|
+
export declare function isBefore(a: Date, b: Date): boolean;
|
|
19
|
+
export declare function isAfter(a: Date, b: Date): boolean;
|
|
20
|
+
export declare function isBetween(date: Date, start: Date, end: Date): boolean;
|
|
21
|
+
export declare function stripTime(date: Date): Date;
|
|
22
|
+
export declare function addMonths(date: Date, months: number): Date;
|
|
23
|
+
export declare function addYears(date: Date, years: number): Date;
|
|
24
|
+
export declare function startOfMonth(date: Date): Date;
|
|
25
|
+
export declare function endOfMonth(date: Date): Date;
|
|
26
|
+
export declare function getCalendarGrid(viewDate: Date, weekStart: 0 | 1, minDate: Date | null, maxDate: Date | null): CalendarDay[];
|
|
27
|
+
export declare function getWeekdayNames(locale: string, weekStart: 0 | 1): string[];
|
|
28
|
+
export declare function getMonthNames(locale: string): string[];
|
|
29
|
+
export declare function getMonthName(locale: string, month: number): string;
|
|
30
|
+
export declare function getYearsGrid(centerYear: number): number[];
|
|
31
|
+
export declare function getDefaultPresets(locale: string): DatepickerPreset[];
|
|
32
|
+
export declare function parseRangeValue(value: string): {
|
|
33
|
+
start: Date | null;
|
|
34
|
+
end: Date | null;
|
|
35
|
+
};
|
|
36
|
+
export declare function orderDates(a: Date, b: Date): [Date, Date];
|
|
37
|
+
//# sourceMappingURL=datepicker-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datepicker-utils.d.ts","sourceRoot":"","sources":["../../../src/components/datepicker/datepicker-utils.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,IAAI,CAAA;IACV,GAAG,EAAE,MAAM,CAAA;IACX,YAAY,EAAE,OAAO,CAAA;IACrB,KAAK,EAAE,OAAO,CAAA;IACd,QAAQ,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM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AAM,EAAE,CAMtD;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAElE;AAED,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CAOzD;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAmEpE;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,IAAI,GAAG,IAAI,CAAC;IAAC,GAAG,EAAE,IAAI,GAAG,IAAI,CAAA;CAAE,CAMvF;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAEzD"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
function h(t) {
|
|
2
|
+
if (!t) return null;
|
|
3
|
+
const n = t.match(/^(\d{4})-(\d{2})-(\d{2})$/);
|
|
4
|
+
if (!n) return null;
|
|
5
|
+
const [, a, o, l] = n, e = new Date(Number(a), Number(o) - 1, Number(l));
|
|
6
|
+
return isNaN(e.getTime()) ? null : e;
|
|
7
|
+
}
|
|
8
|
+
function u(t) {
|
|
9
|
+
const n = t.getFullYear(), a = String(t.getMonth() + 1).padStart(2, "0"), o = String(t.getDate()).padStart(2, "0");
|
|
10
|
+
return `${n}-${a}-${o}`;
|
|
11
|
+
}
|
|
12
|
+
function S(t, n) {
|
|
13
|
+
return t.getFullYear() === n.getFullYear() && t.getMonth() === n.getMonth() && t.getDate() === n.getDate();
|
|
14
|
+
}
|
|
15
|
+
function Y(t, n) {
|
|
16
|
+
return s(t).getTime() < s(n).getTime();
|
|
17
|
+
}
|
|
18
|
+
function T(t, n) {
|
|
19
|
+
return s(t).getTime() > s(n).getTime();
|
|
20
|
+
}
|
|
21
|
+
function b(t, n, a) {
|
|
22
|
+
const o = s(t).getTime(), l = s(n).getTime(), e = s(a).getTime(), r = Math.min(l, e), c = Math.max(l, e);
|
|
23
|
+
return o >= r && o <= c;
|
|
24
|
+
}
|
|
25
|
+
function s(t) {
|
|
26
|
+
return new Date(t.getFullYear(), t.getMonth(), t.getDate());
|
|
27
|
+
}
|
|
28
|
+
function M(t, n) {
|
|
29
|
+
return new Date(t.getFullYear(), t.getMonth() + n, 1);
|
|
30
|
+
}
|
|
31
|
+
function N(t, n) {
|
|
32
|
+
return new Date(t.getFullYear() + n, t.getMonth(), 1);
|
|
33
|
+
}
|
|
34
|
+
function m(t) {
|
|
35
|
+
return new Date(t.getFullYear(), t.getMonth(), 1);
|
|
36
|
+
}
|
|
37
|
+
function w(t) {
|
|
38
|
+
return new Date(t.getFullYear(), t.getMonth() + 1, 0);
|
|
39
|
+
}
|
|
40
|
+
function V(t, n, a, o) {
|
|
41
|
+
const l = s(/* @__PURE__ */ new Date()), e = t.getFullYear(), r = t.getMonth();
|
|
42
|
+
let i = new Date(e, r, 1).getDay() - n;
|
|
43
|
+
i < 0 && (i += 7);
|
|
44
|
+
const D = new Date(e, r, 1 - i), f = [];
|
|
45
|
+
for (let d = 0; d < 42; d++) {
|
|
46
|
+
const g = new Date(D.getFullYear(), D.getMonth(), D.getDate() + d), F = g.getMonth() === r, p = a !== null && Y(g, a) || o !== null && T(g, o);
|
|
47
|
+
f.push({
|
|
48
|
+
date: g,
|
|
49
|
+
day: g.getDate(),
|
|
50
|
+
currentMonth: F,
|
|
51
|
+
today: S(g, l),
|
|
52
|
+
disabled: p
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return f;
|
|
56
|
+
}
|
|
57
|
+
function L(t, n) {
|
|
58
|
+
const a = new Date(2024, 0, n === 0 ? 7 : 1), o = [];
|
|
59
|
+
for (let l = 0; l < 7; l++) {
|
|
60
|
+
const e = new Date(a.getFullYear(), a.getMonth(), a.getDate() + l);
|
|
61
|
+
o.push(e.toLocaleDateString(t, { weekday: "short" }).slice(0, 2));
|
|
62
|
+
}
|
|
63
|
+
return o;
|
|
64
|
+
}
|
|
65
|
+
function y(t, n) {
|
|
66
|
+
return new Date(2024, n, 1).toLocaleDateString(t, { month: "long" });
|
|
67
|
+
}
|
|
68
|
+
function O(t) {
|
|
69
|
+
const n = t - 7, a = [];
|
|
70
|
+
for (let o = 0; o < 15; o++)
|
|
71
|
+
a.push(n + o);
|
|
72
|
+
return a;
|
|
73
|
+
}
|
|
74
|
+
function $(t) {
|
|
75
|
+
const n = s(/* @__PURE__ */ new Date()), a = y(t, n.getMonth()), o = M(n, -1), l = y(t, o.getMonth());
|
|
76
|
+
return [
|
|
77
|
+
{
|
|
78
|
+
label: "Today",
|
|
79
|
+
getValue: () => {
|
|
80
|
+
const e = s(/* @__PURE__ */ new Date()), r = u(e);
|
|
81
|
+
return { start: r, end: r };
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
label: "Last 7 days",
|
|
86
|
+
getValue: () => {
|
|
87
|
+
const e = s(/* @__PURE__ */ new Date()), r = new Date(e.getFullYear(), e.getMonth(), e.getDate() - 6);
|
|
88
|
+
return { start: u(r), end: u(e) };
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
label: "Last 30 days",
|
|
93
|
+
getValue: () => {
|
|
94
|
+
const e = s(/* @__PURE__ */ new Date()), r = new Date(e.getFullYear(), e.getMonth(), e.getDate() - 29);
|
|
95
|
+
return { start: u(r), end: u(e) };
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
label: "Last 60 days",
|
|
100
|
+
getValue: () => {
|
|
101
|
+
const e = s(/* @__PURE__ */ new Date()), r = new Date(e.getFullYear(), e.getMonth(), e.getDate() - 59);
|
|
102
|
+
return { start: u(r), end: u(e) };
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
label: "Last 90 days",
|
|
107
|
+
getValue: () => {
|
|
108
|
+
const e = s(/* @__PURE__ */ new Date()), r = new Date(e.getFullYear(), e.getMonth(), e.getDate() - 89);
|
|
109
|
+
return { start: u(r), end: u(e) };
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
label: a,
|
|
114
|
+
getValue: () => {
|
|
115
|
+
const e = s(/* @__PURE__ */ new Date()), r = m(e), c = w(e);
|
|
116
|
+
return { start: u(r), end: u(c) };
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
label: l,
|
|
121
|
+
getValue: () => {
|
|
122
|
+
const e = s(/* @__PURE__ */ new Date()), r = M(e, -1), c = m(r), i = w(r);
|
|
123
|
+
return { start: u(c), end: u(i) };
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
];
|
|
127
|
+
}
|
|
128
|
+
function k(t) {
|
|
129
|
+
if (!t.includes("/"))
|
|
130
|
+
return { start: h(t), end: null };
|
|
131
|
+
const [n, a] = t.split("/");
|
|
132
|
+
return { start: h(n), end: h(a) };
|
|
133
|
+
}
|
|
134
|
+
function x(t, n) {
|
|
135
|
+
return Y(t, n) ? [t, n] : [n, t];
|
|
136
|
+
}
|
|
137
|
+
export {
|
|
138
|
+
M as addMonths,
|
|
139
|
+
N as addYears,
|
|
140
|
+
w as endOfMonth,
|
|
141
|
+
u as formatISO,
|
|
142
|
+
V as getCalendarGrid,
|
|
143
|
+
$ as getDefaultPresets,
|
|
144
|
+
y as getMonthName,
|
|
145
|
+
L as getWeekdayNames,
|
|
146
|
+
O as getYearsGrid,
|
|
147
|
+
T as isAfter,
|
|
148
|
+
Y as isBefore,
|
|
149
|
+
b as isBetween,
|
|
150
|
+
S as isSameDay,
|
|
151
|
+
x as orderDates,
|
|
152
|
+
h as parseISO,
|
|
153
|
+
k as parseRangeValue,
|
|
154
|
+
m as startOfMonth,
|
|
155
|
+
s as stripTime
|
|
156
|
+
};
|
|
157
|
+
//# sourceMappingURL=datepicker-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datepicker-utils.js","sources":["../../../src/components/datepicker/datepicker-utils.ts"],"sourcesContent":["export interface CalendarDay {\n date: Date\n day: number\n currentMonth: boolean\n today: boolean\n disabled: boolean\n}\n\nexport interface DatepickerPreset {\n label: string\n getValue: () => { start: string; end: string }\n}\n\nexport function parseISO(value: string): Date | null {\n if (!value) return null\n const match = value.match(/^(\\d{4})-(\\d{2})-(\\d{2})$/)\n if (!match) return null\n const [, y, m, d] = match\n const date = new Date(Number(y), Number(m) - 1, Number(d))\n if (isNaN(date.getTime())) return null\n return date\n}\n\nexport function formatISO(date: Date): string {\n const y = date.getFullYear()\n const m = String(date.getMonth() + 1).padStart(2, '0')\n const d = String(date.getDate()).padStart(2, '0')\n return `${y}-${m}-${d}`\n}\n\nexport function isSameDay(a: Date, b: Date): boolean {\n return (\n a.getFullYear() === b.getFullYear() &&\n a.getMonth() === b.getMonth() &&\n a.getDate() === b.getDate()\n )\n}\n\nexport function isBefore(a: Date, b: Date): boolean {\n return stripTime(a).getTime() < stripTime(b).getTime()\n}\n\nexport function isAfter(a: Date, b: Date): boolean {\n return stripTime(a).getTime() > stripTime(b).getTime()\n}\n\nexport function isBetween(date: Date, start: Date, end: Date): boolean {\n const t = stripTime(date).getTime()\n const s = stripTime(start).getTime()\n const e = stripTime(end).getTime()\n const min = Math.min(s, e)\n const max = Math.max(s, e)\n return t >= min && t <= max\n}\n\nexport function stripTime(date: Date): Date {\n return new Date(date.getFullYear(), date.getMonth(), date.getDate())\n}\n\nexport function addMonths(date: Date, months: number): Date {\n const result = new Date(date.getFullYear(), date.getMonth() + months, 1)\n return result\n}\n\nexport function addYears(date: Date, years: number): Date {\n return new Date(date.getFullYear() + years, date.getMonth(), 1)\n}\n\nexport function startOfMonth(date: Date): Date {\n return new Date(date.getFullYear(), date.getMonth(), 1)\n}\n\nexport function endOfMonth(date: Date): Date {\n return new Date(date.getFullYear(), date.getMonth() + 1, 0)\n}\n\nexport function getCalendarGrid(\n viewDate: Date,\n weekStart: 0 | 1,\n minDate: Date | null,\n maxDate: Date | null,\n): CalendarDay[] {\n const today = stripTime(new Date())\n const year = viewDate.getFullYear()\n const month = viewDate.getMonth()\n\n const firstDay = new Date(year, month, 1)\n let dayOfWeek = firstDay.getDay() - weekStart\n if (dayOfWeek < 0) dayOfWeek += 7\n\n const gridStart = new Date(year, month, 1 - dayOfWeek)\n const days: CalendarDay[] = []\n\n for (let i = 0; i < 42; i++) {\n const date = new Date(gridStart.getFullYear(), gridStart.getMonth(), gridStart.getDate() + i)\n const isCurrentMonth = date.getMonth() === month\n const isDisabled =\n (minDate !== null && isBefore(date, minDate)) ||\n (maxDate !== null && isAfter(date, maxDate))\n\n days.push({\n date,\n day: date.getDate(),\n currentMonth: isCurrentMonth,\n today: isSameDay(date, today),\n disabled: isDisabled,\n })\n }\n\n return days\n}\n\nexport function getWeekdayNames(locale: string, weekStart: 0 | 1): string[] {\n const base = new Date(2024, 0, weekStart === 0 ? 7 : 1) // Sun Jan 7 or Mon Jan 1\n const names: string[] = []\n for (let i = 0; i < 7; i++) {\n const d = new Date(base.getFullYear(), base.getMonth(), base.getDate() + i)\n names.push(d.toLocaleDateString(locale, { weekday: 'short' }).slice(0, 2))\n }\n return names\n}\n\nexport function getMonthNames(locale: string): string[] {\n const names: string[] = []\n for (let i = 0; i < 12; i++) {\n names.push(new Date(2024, i, 1).toLocaleDateString(locale, { month: 'long' }))\n }\n return names\n}\n\nexport function getMonthName(locale: string, month: number): string {\n return new Date(2024, month, 1).toLocaleDateString(locale, { month: 'long' })\n}\n\nexport function getYearsGrid(centerYear: number): number[] {\n const start = centerYear - 7\n const years: number[] = []\n for (let i = 0; i < 15; i++) {\n years.push(start + i)\n }\n return years\n}\n\nexport function getDefaultPresets(locale: string): DatepickerPreset[] {\n const today = stripTime(new Date())\n const currentMonthName = getMonthName(locale, today.getMonth())\n const prevMonthDate = addMonths(today, -1)\n const prevMonthName = getMonthName(locale, prevMonthDate.getMonth())\n\n return [\n {\n label: 'Today',\n getValue: () => {\n const t = stripTime(new Date())\n const iso = formatISO(t)\n return { start: iso, end: iso }\n },\n },\n {\n label: 'Last 7 days',\n getValue: () => {\n const t = stripTime(new Date())\n const start = new Date(t.getFullYear(), t.getMonth(), t.getDate() - 6)\n return { start: formatISO(start), end: formatISO(t) }\n },\n },\n {\n label: 'Last 30 days',\n getValue: () => {\n const t = stripTime(new Date())\n const start = new Date(t.getFullYear(), t.getMonth(), t.getDate() - 29)\n return { start: formatISO(start), end: formatISO(t) }\n },\n },\n {\n label: 'Last 60 days',\n getValue: () => {\n const t = stripTime(new Date())\n const start = new Date(t.getFullYear(), t.getMonth(), t.getDate() - 59)\n return { start: formatISO(start), end: formatISO(t) }\n },\n },\n {\n label: 'Last 90 days',\n getValue: () => {\n const t = stripTime(new Date())\n const start = new Date(t.getFullYear(), t.getMonth(), t.getDate() - 89)\n return { start: formatISO(start), end: formatISO(t) }\n },\n },\n {\n label: currentMonthName,\n getValue: () => {\n const t = stripTime(new Date())\n const s = startOfMonth(t)\n const e = endOfMonth(t)\n return { start: formatISO(s), end: formatISO(e) }\n },\n },\n {\n label: prevMonthName,\n getValue: () => {\n const t = stripTime(new Date())\n const pm = addMonths(t, -1)\n const s = startOfMonth(pm)\n const e = endOfMonth(pm)\n return { start: formatISO(s), end: formatISO(e) }\n },\n },\n ]\n}\n\nexport function parseRangeValue(value: string): { start: Date | null; end: Date | null } {\n if (!value.includes('/')) {\n return { start: parseISO(value), end: null }\n }\n const [startStr, endStr] = value.split('/')\n return { start: parseISO(startStr), end: parseISO(endStr) }\n}\n\nexport function orderDates(a: Date, b: Date): [Date, Date] {\n return isBefore(a, b) ? [a, b] : [b, a]\n}\n"],"names":["parseISO","value","match","y","m","d","date","formatISO","isSameDay","a","b","isBefore","stripTime","isAfter","isBetween","start","end","t","s","min","max","addMonths","months","addYears","years","startOfMonth","endOfMonth","getCalendarGrid","viewDate","weekStart","minDate","maxDate","today","year","month","dayOfWeek","gridStart","days","i","isCurrentMonth","isDisabled","getWeekdayNames","locale","base","names","getMonthName","getYearsGrid","centerYear","getDefaultPresets","currentMonthName","prevMonthDate","prevMonthName","iso","e","pm","parseRangeValue","startStr","endStr","orderDates"],"mappings":"AAaO,SAASA,EAASC,GAA4B;AACnD,MAAI,CAACA,EAAO,QAAO;AACnB,QAAMC,IAAQD,EAAM,MAAM,2BAA2B;AACrD,MAAI,CAACC,EAAO,QAAO;AACnB,QAAM,GAAGC,GAAGC,GAAGC,CAAC,IAAIH,GACdI,IAAO,IAAI,KAAK,OAAOH,CAAC,GAAG,OAAOC,CAAC,IAAI,GAAG,OAAOC,CAAC,CAAC;AACzD,SAAI,MAAMC,EAAK,QAAA,CAAS,IAAU,OAC3BA;AACT;AAEO,SAASC,EAAUD,GAAoB;AAC5C,QAAMH,IAAIG,EAAK,YAAA,GACTF,IAAI,OAAOE,EAAK,SAAA,IAAa,CAAC,EAAE,SAAS,GAAG,GAAG,GAC/CD,IAAI,OAAOC,EAAK,QAAA,CAAS,EAAE,SAAS,GAAG,GAAG;AAChD,SAAO,GAAGH,CAAC,IAAIC,CAAC,IAAIC,CAAC;AACvB;AAEO,SAASG,EAAUC,GAASC,GAAkB;AACnD,SACED,EAAE,YAAA,MAAkBC,EAAE,YAAA,KACtBD,EAAE,SAAA,MAAeC,EAAE,cACnBD,EAAE,QAAA,MAAcC,EAAE,QAAA;AAEtB;AAEO,SAASC,EAASF,GAASC,GAAkB;AAClD,SAAOE,EAAUH,CAAC,EAAE,QAAA,IAAYG,EAAUF,CAAC,EAAE,QAAA;AAC/C;AAEO,SAASG,EAAQJ,GAASC,GAAkB;AACjD,SAAOE,EAAUH,CAAC,EAAE,QAAA,IAAYG,EAAUF,CAAC,EAAE,QAAA;AAC/C;AAEO,SAASI,EAAUR,GAAYS,GAAaC,GAAoB;AACrE,QAAMC,IAAIL,EAAUN,CAAI,EAAE,QAAA,GACpBY,IAAIN,EAAUG,CAAK,EAAE,QAAA,GACrB,IAAIH,EAAUI,CAAG,EAAE,QAAA,GACnBG,IAAM,KAAK,I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;AACd,cAAMhC,IAAIL,EAAU,oBAAI,MAAM,GACxBM,IAAIO,EAAaR,CAAC,GAClBoC,IAAI3B,EAAWT,CAAC;AACtB,eAAO,EAAE,OAAOV,EAAUW,CAAC,GAAG,KAAKX,EAAU8C,CAAC,EAAA;AAAA,MAChD;AAAA,IAAA;AAAA,IAEF;AAAA,MACE,OAAOF;AAAA,MACP,UAAU,MAAM;AACd,cAAMlC,IAAIL,EAAU,oBAAI,MAAM,GACxB0C,IAAKjC,EAAUJ,GAAG,EAAE,GACpBC,IAAIO,EAAa6B,CAAE,GACnBD,IAAI3B,EAAW4B,CAAE;AACvB,eAAO,EAAE,OAAO/C,EAAUW,CAAC,GAAG,KAAKX,EAAU8C,CAAC,EAAA;AAAA,MAChD;AAAA,IAAA;AAAA,EACF;AAEJ;AAEO,SAASE,EAAgBtD,GAAyD;AACvF,MAAI,CAACA,EAAM,SAAS,GAAG;AACrB,WAAO,EAAE,OAAOD,EAASC,CAAK,GAAG,KAAK,KAAA;AAExC,QAAM,CAACuD,GAAUC,CAAM,IAAIxD,EAAM,MAAM,GAAG;AAC1C,SAAO,EAAE,OAAOD,EAASwD,CAAQ,GAAG,KAAKxD,EAASyD,CAAM,EAAA;AAC1D;AAEO,SAASC,EAAWjD,GAASC,GAAuB;AACzD,SAAOC,EAASF,GAAGC,CAAC,IAAI,CAACD,GAAGC,CAAC,IAAI,CAACA,GAAGD,CAAC;AACxC;"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import { type DatepickerPreset } from './datepicker-utils.js';
|
|
3
|
+
export type DatepickerMode = 'single' | 'range';
|
|
4
|
+
export declare class MellowDatepicker extends LitElement {
|
|
5
|
+
static styles: import("lit").CSSResult[];
|
|
6
|
+
mode: DatepickerMode;
|
|
7
|
+
value: string;
|
|
8
|
+
minDate: string;
|
|
9
|
+
maxDate: string;
|
|
10
|
+
presets: boolean;
|
|
11
|
+
presetItems: DatepickerPreset[];
|
|
12
|
+
weekStart: 0 | 1;
|
|
13
|
+
disabled: boolean;
|
|
14
|
+
locale: string;
|
|
15
|
+
private _view;
|
|
16
|
+
private _viewDate;
|
|
17
|
+
private _hoveredDate;
|
|
18
|
+
private _rangeStart;
|
|
19
|
+
private _pendingValue;
|
|
20
|
+
connectedCallback(): void;
|
|
21
|
+
willUpdate(changed: Map<string, unknown>): void;
|
|
22
|
+
private _syncFromValue;
|
|
23
|
+
private get _minDateParsed();
|
|
24
|
+
private get _maxDateParsed();
|
|
25
|
+
private get _effectivePresets();
|
|
26
|
+
private _prevMonth;
|
|
27
|
+
private _nextMonth;
|
|
28
|
+
private _prevYear;
|
|
29
|
+
private _nextYear;
|
|
30
|
+
private _prevYearRange;
|
|
31
|
+
private _nextYearRange;
|
|
32
|
+
private _showMonths;
|
|
33
|
+
private _showYears;
|
|
34
|
+
private _selectDay;
|
|
35
|
+
private _selectMonth;
|
|
36
|
+
private _selectYear;
|
|
37
|
+
private _handleDayHover;
|
|
38
|
+
private _handleDayMouseLeave;
|
|
39
|
+
private _goToToday;
|
|
40
|
+
private _selectPreset;
|
|
41
|
+
private _save;
|
|
42
|
+
private _fireSelect;
|
|
43
|
+
private _isDaySelected;
|
|
44
|
+
private _isDayInRange;
|
|
45
|
+
private _isRangeStart;
|
|
46
|
+
private _isRangeEnd;
|
|
47
|
+
private _isPresetActive;
|
|
48
|
+
private _handleKeydown;
|
|
49
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
50
|
+
private _renderPresets;
|
|
51
|
+
private _renderHeader;
|
|
52
|
+
private _renderDays;
|
|
53
|
+
private _renderMonths;
|
|
54
|
+
private _renderYears;
|
|
55
|
+
private _renderFooter;
|
|
56
|
+
}
|
|
57
|
+
declare global {
|
|
58
|
+
interface HTMLElementTagNameMap {
|
|
59
|
+
'mellow-datepicker': MellowDatepicker;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=datepicker.d.ts.map
|
|
@@ -0,0 +1 @@
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