@a-type/ui 3.0.32 → 3.0.33
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/dist/cjs/components/datePicker/Calendar.d.ts +11 -0
- package/dist/cjs/components/datePicker/Calendar.js +37 -0
- package/dist/cjs/components/datePicker/Calendar.js.map +1 -0
- package/dist/cjs/components/datePicker/DatePicker.d.ts +42 -13
- package/dist/cjs/components/datePicker/DatePicker.js +31 -71
- package/dist/cjs/components/datePicker/DatePicker.js.map +1 -1
- package/dist/cjs/components/datePicker/DatePicker.stories.d.ts +36 -1
- package/dist/cjs/components/datePicker/DatePicker.stories.js +18 -2
- package/dist/cjs/components/datePicker/DatePicker.stories.js.map +1 -1
- package/dist/cjs/components/datePicker/DateRangePicker.d.ts +55 -0
- package/dist/cjs/components/datePicker/DateRangePicker.js +89 -0
- package/dist/cjs/components/datePicker/DateRangePicker.js.map +1 -0
- package/dist/cjs/components/datePicker/index.d.ts +2 -0
- package/dist/cjs/components/datePicker/index.js +1 -0
- package/dist/cjs/components/datePicker/index.js.map +1 -1
- package/dist/esm/components/datePicker/Calendar.d.ts +11 -0
- package/dist/esm/components/datePicker/Calendar.js +32 -0
- package/dist/esm/components/datePicker/Calendar.js.map +1 -0
- package/dist/esm/components/datePicker/DatePicker.d.ts +42 -13
- package/dist/esm/components/datePicker/DatePicker.js +32 -68
- package/dist/esm/components/datePicker/DatePicker.js.map +1 -1
- package/dist/esm/components/datePicker/DatePicker.stories.d.ts +36 -1
- package/dist/esm/components/datePicker/DatePicker.stories.js +19 -3
- package/dist/esm/components/datePicker/DatePicker.stories.js.map +1 -1
- package/dist/esm/components/datePicker/DateRangePicker.d.ts +55 -0
- package/dist/esm/components/datePicker/DateRangePicker.js +83 -0
- package/dist/esm/components/datePicker/DateRangePicker.js.map +1 -0
- package/dist/esm/components/datePicker/index.d.ts +2 -0
- package/dist/esm/components/datePicker/index.js +1 -0
- package/dist/esm/components/datePicker/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/datePicker/Calendar.tsx +83 -0
- package/src/components/datePicker/DatePicker.stories.tsx +37 -2
- package/src/components/datePicker/DatePicker.tsx +77 -222
- package/src/components/datePicker/DateRangePicker.tsx +161 -0
- package/src/components/datePicker/index.ts +2 -0
|
@@ -1,20 +1,49 @@
|
|
|
1
|
+
import { CalendarDays } from 'calendar-blocks';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
1
3
|
import { PaletteName } from '../../uno/index.js';
|
|
4
|
+
import { CalendarGrid } from './Calendar.js';
|
|
5
|
+
declare function DatePickerMonthControls({}: {}): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
declare function DatePickerRoot({ className, color, value, onChange, children, ...rest }: DatePickerProps & {
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
2
9
|
export interface DatePickerProps {
|
|
3
10
|
value: Date | null;
|
|
4
11
|
onChange: (date: Date | null) => void;
|
|
5
12
|
className?: string;
|
|
6
13
|
color?: PaletteName;
|
|
7
14
|
}
|
|
8
|
-
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
declare function DatePickerDefault(props: DatePickerProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export declare const DatePicker: typeof DatePickerDefault & {
|
|
17
|
+
Root: typeof DatePickerRoot;
|
|
18
|
+
Calendar: import("react").ForwardRefExoticComponent<Omit<import("react").HTMLAttributes<HTMLDivElement>, "onChange" | "value"> & {
|
|
19
|
+
onDisplayChange?: (newValue: {
|
|
20
|
+
month: number;
|
|
21
|
+
year: number;
|
|
22
|
+
}) => any;
|
|
23
|
+
displayYear: number;
|
|
24
|
+
displayMonth: number;
|
|
25
|
+
value?: Date | null;
|
|
26
|
+
onChange?: (value: Date | null) => any;
|
|
27
|
+
rangeValue?: {
|
|
28
|
+
start: Date | null;
|
|
29
|
+
end: Date | null;
|
|
30
|
+
};
|
|
31
|
+
onRangeChange?: (range: {
|
|
32
|
+
start: Date | null;
|
|
33
|
+
end: Date | null;
|
|
34
|
+
}) => any;
|
|
35
|
+
onRangeStartChange?: (range: Date) => any;
|
|
36
|
+
getDateEnabled?: (date: Date) => boolean;
|
|
37
|
+
defaultDate?: Date;
|
|
38
|
+
weekStartsOn?: import("calendar-blocks/dist/constants.js").WeekDay;
|
|
39
|
+
} & import("react").RefAttributes<any>>;
|
|
40
|
+
CalendarDay: import("react").FunctionComponent<import("calendar-blocks").CalendarDayProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
41
|
+
CalendarDays: typeof CalendarDays;
|
|
42
|
+
CalendarGrid: typeof CalendarGrid;
|
|
43
|
+
DayLabels: () => import("react/jsx-runtime").JSX.Element;
|
|
44
|
+
MonthControls: typeof DatePickerMonthControls;
|
|
45
|
+
MonthButton: import("react").FunctionComponent<import("../index.js").ButtonProps>;
|
|
46
|
+
MonthLabel: import("react").FunctionComponent<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>>;
|
|
47
|
+
MonthRow: import("react").FunctionComponent<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>>;
|
|
48
|
+
};
|
|
49
|
+
export {};
|
|
@@ -10,83 +10,47 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
}
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
14
|
-
import {
|
|
15
|
-
import
|
|
16
|
-
import {
|
|
17
|
-
import { withClassName } from '../../hooks.js';
|
|
18
|
-
import { Button } from '../button/index.js';
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
import { Calendar, CalendarDays, useCalendarContext } from 'calendar-blocks';
|
|
15
|
+
import { clsx } from 'clsx';
|
|
16
|
+
import { useState } from 'react';
|
|
19
17
|
import { Icon } from '../icon/index.js';
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
month: new Date().getMonth(),
|
|
24
|
-
year: new Date().getFullYear(),
|
|
25
|
-
}));
|
|
18
|
+
import { CalendarDay, CalendarGrid, DayLabels, MonthButton, MonthLabel, MonthRow, } from './Calendar.js';
|
|
19
|
+
function DatePickerMonthControls({}) {
|
|
20
|
+
const { setDisplayInfo, month, year } = useCalendarContext();
|
|
26
21
|
const monthLabel = new Date(year, month).toLocaleDateString('en-US', {
|
|
27
22
|
month: 'long',
|
|
28
23
|
year: 'numeric',
|
|
29
24
|
});
|
|
30
|
-
return (_jsxs(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
25
|
+
return (_jsxs(MonthRow, { children: [_jsx(MonthButton, { emphasis: "ghost", onClick: () => setDisplayInfo({
|
|
26
|
+
month: month - 1,
|
|
27
|
+
year: year,
|
|
28
|
+
}), children: _jsx(Icon, { name: "arrowLeft" }) }), _jsx(MonthLabel, { children: monthLabel }), _jsx(MonthButton, { emphasis: "ghost", onClick: () => setDisplayInfo({
|
|
29
|
+
month: month + 1,
|
|
30
|
+
year: year,
|
|
31
|
+
}), children: _jsx(Icon, { name: "arrowRight" }) })] }));
|
|
37
32
|
}
|
|
38
|
-
|
|
33
|
+
function DatePickerRoot(_a) {
|
|
34
|
+
var { className, color, value, onChange, children } = _a, rest = __rest(_a, ["className", "color", "value", "onChange", "children"]);
|
|
39
35
|
const [{ month, year }, setDisplay] = useState(() => ({
|
|
40
36
|
month: new Date().getMonth(),
|
|
41
37
|
year: new Date().getFullYear(),
|
|
42
38
|
}));
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
});
|
|
47
|
-
const nextMonth = new Date(year, month + 1);
|
|
48
|
-
const nextMonthLabel = nextMonth.toLocaleDateString('en-US', {
|
|
49
|
-
month: 'long',
|
|
50
|
-
year: 'numeric',
|
|
51
|
-
});
|
|
52
|
-
const onDisplayChange = useCallback(({ month: newMonth, year: newYear }) => {
|
|
53
|
-
/**
|
|
54
|
-
* Important UX consideration:
|
|
55
|
-
*
|
|
56
|
-
* since we are displaying 2 months at once, we don't
|
|
57
|
-
* always want to change our view if the user's cursor
|
|
58
|
-
* date moves from one month to another. Specifically,
|
|
59
|
-
* if they move from the first visible month to the
|
|
60
|
-
* second visible month, we don't need to change the view,
|
|
61
|
-
* since they are still within the visible range.
|
|
62
|
-
* So, we write logic to ignore that case!
|
|
63
|
-
*/
|
|
64
|
-
if (newMonth === month + 1 && newYear === year) {
|
|
65
|
-
return; // ignore movement from the first to the second frame
|
|
66
|
-
}
|
|
67
|
-
setDisplay({
|
|
68
|
-
month: newMonth,
|
|
69
|
-
year: newYear,
|
|
70
|
-
});
|
|
71
|
-
}, [month, year]);
|
|
72
|
-
return (_jsx(Calendar, { displayMonth: month, displayYear: year, rangeValue: value, onRangeChange: (range) => onChange(range), onDisplayChange: onDisplayChange, className: classNames('flex justify-center', className), children: _jsxs(RangeLayout, { children: [_jsx(MonthButton, { emphasis: "ghost", className: "[grid-area:prevMonth]", onClick: () => setDisplay((cur) => ({
|
|
73
|
-
month: cur.month - 1,
|
|
74
|
-
year: cur.year,
|
|
75
|
-
})), children: _jsx(Icon, { name: "arrowLeft" }) }), _jsx(MonthLabel, { className: "[grid-area:leftMonth]", children: monthLabel }), _jsx(MonthLabel, { className: "[grid-area:rightMonth] !hidden !sm:block", children: nextMonthLabel }), _jsx(MonthButton, { emphasis: "ghost", className: "[grid-area:nextMonth]", onClick: () => setDisplay((cur) => ({
|
|
76
|
-
month: cur.month + 1,
|
|
77
|
-
year: cur.year,
|
|
78
|
-
})), children: _jsx(Icon, { name: "arrowRight" }) }), _jsxs(CalendarGrid, { className: "[grid-area:leftGrid]", children: [_jsx(DayLabels, {}), _jsx(CalendarDays, { children: (value) => _jsx(CalendarDay, { value: value }, value.key) })] }), _jsxs(CalendarGrid, { className: "[grid-area:rightGrid] !hidden !sm:grid", children: [_jsx(DayLabels, {}), _jsx(CalendarDays, { monthOffset: 1, children: (value) => _jsx(CalendarDay, { value: value }, value.key) })] })] }) }));
|
|
39
|
+
return (_jsx("div", Object.assign({ className: clsx(color && `palette-${color}`, 'layer-components:flex layer-components:flex-col layer-components:items-center layer-components:justify-center layer-components:w-[calc(var(--day-size,32px)*7)]') }, rest, { children: _jsx(Calendar, { displayMonth: month, displayYear: year, value: value, onChange: onChange, onDisplayChange: setDisplay, children: children }) })));
|
|
40
|
+
}
|
|
41
|
+
function DatePickerDefault(props) {
|
|
42
|
+
return (_jsxs(DatePickerRoot, Object.assign({}, props, { children: [_jsx(DatePickerMonthControls, {}), _jsx(CalendarGrid, { children: (value) => _jsx(CalendarDay, { value: value }, value.key) })] })));
|
|
79
43
|
}
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
44
|
+
export const DatePicker = Object.assign(DatePickerDefault, {
|
|
45
|
+
Root: DatePickerRoot,
|
|
46
|
+
Calendar,
|
|
47
|
+
CalendarDay,
|
|
48
|
+
CalendarDays,
|
|
49
|
+
CalendarGrid,
|
|
50
|
+
DayLabels,
|
|
51
|
+
MonthControls: DatePickerMonthControls,
|
|
52
|
+
MonthButton,
|
|
53
|
+
MonthLabel,
|
|
54
|
+
MonthRow,
|
|
55
|
+
});
|
|
92
56
|
//# sourceMappingURL=DatePicker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatePicker.js","sourceRoot":"","sources":["../../../../src/components/datePicker/DatePicker.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"DatePicker.js","sourceRoot":"","sources":["../../../../src/components/datePicker/D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L,KAAK,EACL,QAAQ,EACR,QAAQ,OAIR,EAHG,IAAI,cANgB,uDAOvB,CADO;IAIP,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;QACrD,KAAK,EAAE,IAAI,IAAI,EAAE,CAAC,QAAQ,EAAE;QAC5B,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KAC9B,CAAC,CAAC,CAAC;IAEJ,OAAO,CACN,4BACC,SAAS,EAAE,IAAI,CACd,KAAK,IAAI,WAAW,KAAK,EAAE,EAC3B,+FAA+F,CAC/F,IACG,IAAI,cAER,KAAC,QAAQ,IACR,YAAY,EAAE,KAAK,EACnB,WAAW,EAAE,IAAI,EACjB,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,QAAQ,EAClB,eAAe,EAAE,UAAU,YAE1B,QAAQ,GACC,IACN,CACN,CAAC;AACH,CAAC;AASD,SAAS,iBAAiB,CAAC,KAAsB;IAChD,OAAO,CACN,MAAC,cAAc,oBAAK,KAAK,eACxB,KAAC,uBAAuB,KAAG,EAC3B,KAAC,YAAY,cACX,CAAC,KAAK,EAAE,EAAE,CAAC,KAAC,WAAW,IAAC,KAAK,EAAE,KAAK,IAAO,KAAK,CAAC,GAAG,CAAI,GAC3C,KACC,CACjB,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE;IAC1D,IAAI,EAAE,cAAc;IACpB,QAAQ;IACR,WAAW;IACX,YAAY;IACZ,YAAY;IACZ,SAAS;IACT,aAAa,EAAE,uBAAuB;IACtC,WAAW;IACX,UAAU;IACV,QAAQ;CACR,CAAC,CAAC"}
|
|
@@ -2,7 +2,41 @@ import type { StoryObj } from '@storybook/react';
|
|
|
2
2
|
import { DatePicker } from './DatePicker.js';
|
|
3
3
|
declare const meta: {
|
|
4
4
|
title: string;
|
|
5
|
-
component:
|
|
5
|
+
component: ((props: import("./DatePicker.js").DatePickerProps) => import("react/jsx-runtime").JSX.Element) & {
|
|
6
|
+
Root: ({ className, color, value, onChange, children, ...rest }: import("./DatePicker.js").DatePickerProps & {
|
|
7
|
+
children?: import("react").ReactNode;
|
|
8
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
Calendar: import("react").ForwardRefExoticComponent<Omit<import("react").HTMLAttributes<HTMLDivElement>, "onChange" | "value"> & {
|
|
10
|
+
onDisplayChange?: (newValue: {
|
|
11
|
+
month: number;
|
|
12
|
+
year: number;
|
|
13
|
+
}) => any;
|
|
14
|
+
displayYear: number;
|
|
15
|
+
displayMonth: number;
|
|
16
|
+
value?: Date | null;
|
|
17
|
+
onChange?: (value: Date | null) => any;
|
|
18
|
+
rangeValue?: {
|
|
19
|
+
start: Date | null;
|
|
20
|
+
end: Date | null;
|
|
21
|
+
};
|
|
22
|
+
onRangeChange?: (range: {
|
|
23
|
+
start: Date | null;
|
|
24
|
+
end: Date | null;
|
|
25
|
+
}) => any;
|
|
26
|
+
onRangeStartChange?: (range: Date) => any;
|
|
27
|
+
getDateEnabled?: (date: Date) => boolean;
|
|
28
|
+
defaultDate?: Date;
|
|
29
|
+
weekStartsOn?: import("calendar-blocks/dist/constants.js").WeekDay;
|
|
30
|
+
} & import("react").RefAttributes<any>>;
|
|
31
|
+
CalendarDay: import("react").FunctionComponent<import("calendar-blocks").CalendarDayProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
32
|
+
CalendarDays: typeof import("calendar-blocks").CalendarDays;
|
|
33
|
+
CalendarGrid: typeof import("./Calendar.js").CalendarGrid;
|
|
34
|
+
DayLabels: () => import("react/jsx-runtime").JSX.Element;
|
|
35
|
+
MonthControls: ({}: {}) => import("react/jsx-runtime").JSX.Element;
|
|
36
|
+
MonthButton: import("react").FunctionComponent<import("../index.js").ButtonProps>;
|
|
37
|
+
MonthLabel: import("react").FunctionComponent<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>>;
|
|
38
|
+
MonthRow: import("react").FunctionComponent<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>>;
|
|
39
|
+
};
|
|
6
40
|
argTypes: {};
|
|
7
41
|
parameters: {
|
|
8
42
|
controls: {
|
|
@@ -14,3 +48,4 @@ export default meta;
|
|
|
14
48
|
type Story = StoryObj<typeof DatePicker>;
|
|
15
49
|
export declare const Default: Story;
|
|
16
50
|
export declare const Range: Story;
|
|
51
|
+
export declare const CustomComposition: Story;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// @unocss-include
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useState } from 'react';
|
|
4
|
-
import {
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
import { Spinner } from '../spinner/Spinner.js';
|
|
5
|
+
import { DatePicker } from './DatePicker.js';
|
|
6
|
+
import { DateRangePicker } from './DateRangePicker.js';
|
|
5
7
|
const meta = {
|
|
6
8
|
title: 'Components/DatePicker',
|
|
7
9
|
component: DatePicker,
|
|
@@ -23,4 +25,18 @@ export const Range = {
|
|
|
23
25
|
return _jsx(DateRangePicker, { value: value, onChange: setValue });
|
|
24
26
|
},
|
|
25
27
|
};
|
|
28
|
+
export const CustomComposition = {
|
|
29
|
+
render() {
|
|
30
|
+
const [value, setValue] = useState(null);
|
|
31
|
+
return (_jsxs(DatePicker.Root, { value: value, onChange: setValue, children: [_jsx(DatePicker.MonthControls, {}), _jsx(DatePicker.CalendarGrid, { children: (value) => _jsx(FakeLoadingDay, { value: value }, value.key) })] }));
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
function FakeLoadingDay({ value }) {
|
|
35
|
+
const [loading, setLoading] = useState(true);
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
const timeout = setTimeout(() => setLoading(false), Math.random() * 2000 + 500);
|
|
38
|
+
return () => clearTimeout(timeout);
|
|
39
|
+
}, []);
|
|
40
|
+
return (_jsx(DatePicker.CalendarDay, { value: value, children: loading ? _jsx(Spinner, { size: 10 }) : value.date.getDate() }));
|
|
41
|
+
}
|
|
26
42
|
//# sourceMappingURL=DatePicker.stories.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatePicker.stories.js","sourceRoot":"","sources":["../../../../src/components/datePicker/DatePicker.stories.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"DatePicker.stories.js","sourceRoot":"","sources":["../../../../src/components/datePicker/DatePicker.stories.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,IAAI,GAAG;IACZ,KAAK,EAAE,uBAAuB;IAC9B,SAAS,EAAE,UAAU;IACrB,QAAQ,EAAE,EAAE;IACZ,UAAU,EAAE;QACX,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;KAC5B;CACiC,CAAC;AAEpC,eAAe,IAAI,CAAC;AAIpB,MAAM,CAAC,MAAM,OAAO,GAAU;IAC7B,MAAM;QACL,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAc,IAAI,CAAC,CAAC;QACtD,OAAO,KAAC,UAAU,IAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,GAAI,CAAC;IACzD,CAAC;CACD,CAAC;AAEF,MAAM,CAAC,MAAM,KAAK,GAAU;IAC3B,MAAM;QACL,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAG/B,EAAE,KAAK,EAAE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1,55 @@
|
|
|
1
|
+
import { CalendarDays } from 'calendar-blocks';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { PaletteName } from '../../uno/index.js';
|
|
4
|
+
import { CalendarGrid } from './Calendar.js';
|
|
5
|
+
declare function DateRangePickerMonthControls(): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
declare function DateRangePickerRoot({ children, color, value, onChange, className, ...rest }: DateRangePickerProps & {
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export interface DateRangePickerProps {
|
|
10
|
+
value: {
|
|
11
|
+
start: Date | null;
|
|
12
|
+
end: Date | null;
|
|
13
|
+
};
|
|
14
|
+
onChange: (value: {
|
|
15
|
+
start: Date | null;
|
|
16
|
+
end: Date | null;
|
|
17
|
+
}) => void;
|
|
18
|
+
className?: string;
|
|
19
|
+
color?: PaletteName;
|
|
20
|
+
}
|
|
21
|
+
declare function DateRangePickerBase(props: DateRangePickerProps): import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
export declare const DateRangePicker: typeof DateRangePickerBase & {
|
|
23
|
+
Root: typeof DateRangePickerRoot;
|
|
24
|
+
RangeLayout: import("react").FunctionComponent<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>>;
|
|
25
|
+
DayLabels: () => import("react/jsx-runtime").JSX.Element;
|
|
26
|
+
CalendarDay: import("react").FunctionComponent<import("calendar-blocks").CalendarDayProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
27
|
+
Calendar: import("react").ForwardRefExoticComponent<Omit<import("react").HTMLAttributes<HTMLDivElement>, "onChange" | "value"> & {
|
|
28
|
+
onDisplayChange?: (newValue: {
|
|
29
|
+
month: number;
|
|
30
|
+
year: number;
|
|
31
|
+
}) => any;
|
|
32
|
+
displayYear: number;
|
|
33
|
+
displayMonth: number;
|
|
34
|
+
value?: Date | null;
|
|
35
|
+
onChange?: (value: Date | null) => any;
|
|
36
|
+
rangeValue?: {
|
|
37
|
+
start: Date | null;
|
|
38
|
+
end: Date | null;
|
|
39
|
+
};
|
|
40
|
+
onRangeChange?: (range: {
|
|
41
|
+
start: Date | null;
|
|
42
|
+
end: Date | null;
|
|
43
|
+
}) => any;
|
|
44
|
+
onRangeStartChange?: (range: Date) => any;
|
|
45
|
+
getDateEnabled?: (date: Date) => boolean;
|
|
46
|
+
defaultDate?: Date;
|
|
47
|
+
weekStartsOn?: import("calendar-blocks/dist/constants.js").WeekDay;
|
|
48
|
+
} & import("react").RefAttributes<any>>;
|
|
49
|
+
CalendarGrid: typeof CalendarGrid;
|
|
50
|
+
CalendarDays: typeof CalendarDays;
|
|
51
|
+
MonthControls: typeof DateRangePickerMonthControls;
|
|
52
|
+
MonthButton: import("react").FunctionComponent<import("../index.js").ButtonProps>;
|
|
53
|
+
MonthLabel: import("react").FunctionComponent<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>>;
|
|
54
|
+
};
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// @unocss-include
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
import { Calendar, CalendarDays, useCalendarContext } from 'calendar-blocks';
|
|
15
|
+
import clsx from 'clsx';
|
|
16
|
+
import { useCallback, useState } from 'react';
|
|
17
|
+
import { withClassName } from '../../hooks.js';
|
|
18
|
+
import { Icon } from '../icon/Icon.js';
|
|
19
|
+
import { CalendarDay, CalendarGrid, DayLabels, MonthButton, MonthLabel, } from './Calendar.js';
|
|
20
|
+
const RangeLayout = withClassName('div', 'grid [grid-template-areas:"prevMonth_leftMonth_nextMonth""leftGrid_leftGrid_leftGrid"] [grid-template-columns:auto_1fr_auto]', '[grid-template-rows:auto_1fr] gap-2', 'sm:grid-areas-[prevMonth_leftMonth_rightMonth_nextMonth]-[leftGrid_leftGrid_rightGrid_rightGrid] sm:[grid-template-columns:auto_1fr_1fr_auto]');
|
|
21
|
+
function DateRangePickerMonthControls() {
|
|
22
|
+
const { setDisplayInfo, month, year } = useCalendarContext();
|
|
23
|
+
const monthLabel = new Date(year, month).toLocaleDateString('en-US', {
|
|
24
|
+
month: 'long',
|
|
25
|
+
year: 'numeric',
|
|
26
|
+
});
|
|
27
|
+
const nextMonth = new Date(year, month + 1);
|
|
28
|
+
const nextMonthLabel = nextMonth.toLocaleDateString('en-US', {
|
|
29
|
+
month: 'long',
|
|
30
|
+
year: 'numeric',
|
|
31
|
+
});
|
|
32
|
+
return (_jsxs(_Fragment, { children: [_jsx(MonthButton, { emphasis: "ghost", className: "[grid-area:prevMonth]", onClick: () => setDisplayInfo({
|
|
33
|
+
month: month - 1,
|
|
34
|
+
year: year,
|
|
35
|
+
}), children: _jsx(Icon, { name: "arrowLeft" }) }), _jsx(MonthLabel, { className: "[grid-area:leftMonth]", children: monthLabel }), _jsx(MonthLabel, { className: "[grid-area:rightMonth] !hidden !sm:block", children: nextMonthLabel }), _jsx(MonthButton, { emphasis: "ghost", className: "[grid-area:nextMonth]", onClick: () => setDisplayInfo({
|
|
36
|
+
month: month + 1,
|
|
37
|
+
year: year,
|
|
38
|
+
}), children: _jsx(Icon, { name: "arrowRight" }) })] }));
|
|
39
|
+
}
|
|
40
|
+
function DateRangePickerRoot(_a) {
|
|
41
|
+
var { children, color, value, onChange, className } = _a, rest = __rest(_a, ["children", "color", "value", "onChange", "className"]);
|
|
42
|
+
const [{ month, year }, setDisplay] = useState(() => ({
|
|
43
|
+
month: new Date().getMonth(),
|
|
44
|
+
year: new Date().getFullYear(),
|
|
45
|
+
}));
|
|
46
|
+
const onDisplayChange = useCallback(({ month: newMonth, year: newYear }) => {
|
|
47
|
+
/**
|
|
48
|
+
* Important UX consideration:
|
|
49
|
+
*
|
|
50
|
+
* since we are displaying 2 months at once, we don't
|
|
51
|
+
* always want to change our view if the user's cursor
|
|
52
|
+
* date moves from one month to another. Specifically,
|
|
53
|
+
* if they move from the first visible month to the
|
|
54
|
+
* second visible month, we don't need to change the view,
|
|
55
|
+
* since they are still within the visible range.
|
|
56
|
+
* So, we write logic to ignore that case!
|
|
57
|
+
*/
|
|
58
|
+
if (newMonth === month + 1 && newYear === year) {
|
|
59
|
+
return; // ignore movement from the first to the second frame
|
|
60
|
+
}
|
|
61
|
+
setDisplay({
|
|
62
|
+
month: newMonth,
|
|
63
|
+
year: newYear,
|
|
64
|
+
});
|
|
65
|
+
}, [month, year]);
|
|
66
|
+
return (_jsx(Calendar, Object.assign({ displayMonth: month, displayYear: year, rangeValue: value, onRangeChange: (range) => onChange(range), onDisplayChange: onDisplayChange, className: clsx('flex justify-center', color && `palette-${color}`, className) }, rest, { children: _jsx(RangeLayout, { children: children }) })));
|
|
67
|
+
}
|
|
68
|
+
function DateRangePickerBase(props) {
|
|
69
|
+
return (_jsxs(DateRangePickerRoot, Object.assign({}, props, { children: [_jsx(DateRangePickerMonthControls, {}), _jsx(CalendarGrid, { className: "[grid-area:leftGrid]", children: (value) => _jsx(CalendarDay, { value: value }, value.key) }), _jsx(CalendarGrid, { className: "[grid-area:rightGrid] !hidden !sm:grid", monthOffset: 1, children: (value) => _jsx(CalendarDay, { value: value }, value.key) })] })));
|
|
70
|
+
}
|
|
71
|
+
export const DateRangePicker = Object.assign(DateRangePickerBase, {
|
|
72
|
+
Root: DateRangePickerRoot,
|
|
73
|
+
RangeLayout,
|
|
74
|
+
DayLabels,
|
|
75
|
+
CalendarDay,
|
|
76
|
+
Calendar,
|
|
77
|
+
CalendarGrid,
|
|
78
|
+
CalendarDays,
|
|
79
|
+
MonthControls: DateRangePickerMonthControls,
|
|
80
|
+
MonthButton,
|
|
81
|
+
MonthLabel,
|
|
82
|
+
});
|
|
83
|
+
//# sourceMappingURL=DateRangePicker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DateRangePicker.js","sourceRoot":"","sources":["../../../../src/components/datePicker/DateRangePicker.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC7E,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAa,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EACN,WAAW,EACX,YAAY,EACZ,SAAS,EACT,WAAW,EACX,UAAU,GACV,MAAM,eAAe,CAAC;AAEvB,MAAM,WAAW,GAAG,aAAa,CAChC,KAAK,EACL,8HAA8H,EAC9H,qCAAqC,EACrC,+IAA+I,CAC/I,CAAC;AAEF,SAAS,4BAA4B;IACpC,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,kBAAkB,EAAE,CAAC;IAC7D,MAAM,UAAU,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,kBAAkB,CAAC,OAAO,EAAE;QACpE,KAAK,EAAE,MAAM;QACb,IAAI,EAAE,SAAS;KACf,CAAC,CAAC;IACH,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;I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AI,EAAE,mBAAmB;IACzB,WAAW;IACX,SAAS;IACT,WAAW;IACX,QAAQ;IACR,YAAY;IACZ,YAAY;IACZ,aAAa,EAAE,4BAA4B;IAC3C,WAAW;IACX,UAAU;CACV,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/datePicker/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/datePicker/index.ts"],"names":[],"mappings":"AACA,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CalendarDay as BaseCalendarDay,
|
|
3
|
+
CalendarDays,
|
|
4
|
+
CalendarDaysProps,
|
|
5
|
+
} from 'calendar-blocks';
|
|
6
|
+
import { withClassName } from '../../hooks.js';
|
|
7
|
+
import { Button } from '../button/index.js';
|
|
8
|
+
|
|
9
|
+
export const MonthRow = withClassName(
|
|
10
|
+
'div',
|
|
11
|
+
'flex flex-row justify-between items-center w-full',
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
export const MonthLabel = withClassName(
|
|
15
|
+
'span',
|
|
16
|
+
'text-sm font-bold min-w-0 overflow-hidden text-center text-ellipsis',
|
|
17
|
+
'self-center',
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export const MonthButton = withClassName(Button, 'self-center');
|
|
21
|
+
|
|
22
|
+
export const CalendarGridRoot = withClassName(
|
|
23
|
+
'div',
|
|
24
|
+
'grid grid-cols-[repeat(7,var(--day-size,32px))] [grid-auto-rows:var(--day-size,32px)]',
|
|
25
|
+
'height-[calc(var(--day-size,32px)*7)] rounded overflow-hidden p-2',
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export const DayLabel = withClassName(
|
|
29
|
+
'div',
|
|
30
|
+
'flex items-center justify-center text-sm color-gray-dark',
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
export const DayLabels = () => (
|
|
34
|
+
<>
|
|
35
|
+
<DayLabel>S</DayLabel>
|
|
36
|
+
<DayLabel>M</DayLabel>
|
|
37
|
+
<DayLabel>T</DayLabel>
|
|
38
|
+
<DayLabel>W</DayLabel>
|
|
39
|
+
<DayLabel>T</DayLabel>
|
|
40
|
+
<DayLabel>F</DayLabel>
|
|
41
|
+
<DayLabel>S</DayLabel>
|
|
42
|
+
</>
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
export function CalendarGrid({
|
|
46
|
+
className,
|
|
47
|
+
...props
|
|
48
|
+
}: CalendarDaysProps & { className?: string }) {
|
|
49
|
+
return (
|
|
50
|
+
<CalendarGridRoot className={className}>
|
|
51
|
+
<DayLabels />
|
|
52
|
+
<CalendarDays {...props} />
|
|
53
|
+
</CalendarGridRoot>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const CalendarDay = withClassName(
|
|
58
|
+
BaseCalendarDay,
|
|
59
|
+
'border border-solid border-transparent bg-white mr--1px mb--1px relative color-black',
|
|
60
|
+
'flex items-center justify-center transition cursor-pointer',
|
|
61
|
+
'[&[data-highlighted]]:(z-1 ring-2 ring-accent)',
|
|
62
|
+
'hover:(z-1 ring-2 ring-accent)',
|
|
63
|
+
'active:(bg-main-light rounded)',
|
|
64
|
+
'[&[data-selected]]:(bg-main z-2 rounded)',
|
|
65
|
+
'[&[data-in-range]]:(bg-main-light rounded-none z-1)',
|
|
66
|
+
'[&[data-range-start]]:(bg-main rounded-l rounded-r-none z-1)',
|
|
67
|
+
'[&[data-range-end]]:(bg-main rounded-r rounded-l-none z-1)',
|
|
68
|
+
'disabled:(opacity-50 cursor-default)',
|
|
69
|
+
// today dot
|
|
70
|
+
"[&[data-today]]:before:(content-[''] absolute left-[1px] top-[1px] w-[6px] h-[6px] rounded-lg bg-attention border-1 border-solid border-black)",
|
|
71
|
+
// calendar edges
|
|
72
|
+
'[&[data-top-edge]]:(border-t-gray)',
|
|
73
|
+
'[&[data-bottom-edge]]:(border-b-gray)',
|
|
74
|
+
'[&[data-first-column]]:(border-l-gray)',
|
|
75
|
+
'[&[data-last-column]]:(border-r-gray)',
|
|
76
|
+
'[&[data-day-first]]:(border-l-gray rounded-tl)',
|
|
77
|
+
'[&[data-day-last]]:(border-r-gray rounded-br)',
|
|
78
|
+
'[&[data-first-column][data-bottom-edge]]:rounded-bl',
|
|
79
|
+
'[&[data-last-column][data-bottom-edge]]:rounded-br',
|
|
80
|
+
'[&[data-first-column][data-top-edge]]:rounded-tl',
|
|
81
|
+
'[&[data-last-column][data-top-edge]]:rounded-tr',
|
|
82
|
+
'[&[data-different-month]]:[visibility:hidden]',
|
|
83
|
+
);
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { CalendarDayValue } from 'calendar-blocks';
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
import { Spinner } from '../spinner/Spinner.js';
|
|
5
|
+
import { DatePicker } from './DatePicker.js';
|
|
6
|
+
import { DateRangePicker } from './DateRangePicker.js';
|
|
4
7
|
|
|
5
8
|
const meta = {
|
|
6
9
|
title: 'Components/DatePicker',
|
|
@@ -31,3 +34,35 @@ export const Range: Story = {
|
|
|
31
34
|
return <DateRangePicker value={value} onChange={setValue} />;
|
|
32
35
|
},
|
|
33
36
|
};
|
|
37
|
+
|
|
38
|
+
export const CustomComposition: Story = {
|
|
39
|
+
render() {
|
|
40
|
+
const [value, setValue] = useState<Date | null>(null);
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<DatePicker.Root value={value} onChange={setValue}>
|
|
44
|
+
<DatePicker.MonthControls />
|
|
45
|
+
<DatePicker.CalendarGrid>
|
|
46
|
+
{(value) => <FakeLoadingDay value={value} key={value.key} />}
|
|
47
|
+
</DatePicker.CalendarGrid>
|
|
48
|
+
</DatePicker.Root>
|
|
49
|
+
);
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
function FakeLoadingDay({ value }: { value: CalendarDayValue }) {
|
|
54
|
+
const [loading, setLoading] = useState(true);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
const timeout = setTimeout(
|
|
57
|
+
() => setLoading(false),
|
|
58
|
+
Math.random() * 2000 + 500,
|
|
59
|
+
);
|
|
60
|
+
return () => clearTimeout(timeout);
|
|
61
|
+
}, []);
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<DatePicker.CalendarDay value={value}>
|
|
65
|
+
{loading ? <Spinner size={10} /> : value.date.getDate()}
|
|
66
|
+
</DatePicker.CalendarDay>
|
|
67
|
+
);
|
|
68
|
+
}
|