@refraktor/dates 0.0.3 → 0.0.5
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/build/components/date-range-picker/date-range-picker.d.ts +4 -0
- package/build/components/date-range-picker/date-range-picker.d.ts.map +1 -0
- package/build/components/date-range-picker/date-range-picker.js +379 -0
- package/build/components/date-range-picker/date-range-picker.types.d.ts +100 -0
- package/build/components/date-range-picker/date-range-picker.types.d.ts.map +1 -0
- package/build/components/date-range-picker/date-range-picker.types.js +1 -0
- package/build/components/date-range-picker/index.d.ts +3 -0
- package/build/components/date-range-picker/index.d.ts.map +1 -0
- package/build/components/date-range-picker/index.js +1 -0
- package/build/components/time-input/index.d.ts +1 -1
- package/build/components/time-input/index.d.ts.map +1 -1
- package/build/components/time-input/time-input.d.ts.map +1 -1
- package/build/components/time-input/time-input.js +7 -196
- package/build/components/time-input/time-input.types.d.ts +5 -83
- package/build/components/time-input/time-input.types.d.ts.map +1 -1
- package/build/components/time-picker/index.d.ts +1 -1
- package/build/components/time-picker/index.d.ts.map +1 -1
- package/build/components/time-picker/time-picker.d.ts.map +1 -1
- package/build/components/time-picker/time-picker.js +498 -350
- package/build/components/time-picker/time-picker.types.d.ts +96 -61
- package/build/components/time-picker/time-picker.types.d.ts.map +1 -1
- package/build/style.css +2 -2
- package/package.json +33 -4
- package/.turbo/turbo-build.log +0 -4
- package/refraktor-dates-0.0.1-alpha.0.tgz +0 -0
- package/src/components/date-input/date-input.tsx +0 -379
- package/src/components/date-input/date-input.types.ts +0 -161
- package/src/components/date-input/index.ts +0 -13
- package/src/components/date-picker/date-picker.tsx +0 -649
- package/src/components/date-picker/date-picker.types.ts +0 -145
- package/src/components/date-picker/index.ts +0 -15
- package/src/components/dates-provider/context.ts +0 -18
- package/src/components/dates-provider/dates-provider.tsx +0 -136
- package/src/components/dates-provider/index.ts +0 -10
- package/src/components/dates-provider/types.ts +0 -33
- package/src/components/dates-provider/use-dates.ts +0 -5
- package/src/components/index.ts +0 -9
- package/src/components/month-input/index.ts +0 -13
- package/src/components/month-input/month-input.tsx +0 -366
- package/src/components/month-input/month-input.types.ts +0 -139
- package/src/components/month-picker/index.ts +0 -14
- package/src/components/month-picker/month-picker.tsx +0 -458
- package/src/components/month-picker/month-picker.types.ts +0 -117
- package/src/components/picker-shared/index.ts +0 -7
- package/src/components/picker-shared/picker-header.tsx +0 -178
- package/src/components/picker-shared/picker-header.types.ts +0 -49
- package/src/components/picker-shared/picker.styles.ts +0 -69
- package/src/components/picker-shared/picker.types.ts +0 -4
- package/src/components/time-input/index.ts +0 -23
- package/src/components/time-input/time-input.tsx +0 -453
- package/src/components/time-input/time-input.types.ts +0 -163
- package/src/components/time-picker/index.ts +0 -19
- package/src/components/time-picker/time-picker.tsx +0 -737
- package/src/components/time-picker/time-picker.types.ts +0 -135
- package/src/components/year-input/index.ts +0 -13
- package/src/components/year-input/year-input.tsx +0 -350
- package/src/components/year-input/year-input.types.ts +0 -118
- package/src/components/year-picker/index.ts +0 -15
- package/src/components/year-picker/year-picker.tsx +0 -504
- package/src/components/year-picker/year-picker.types.ts +0 -108
- package/src/index.ts +0 -3
- package/src/style.css +0 -1
- package/tsconfig.json +0 -13
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { ComponentPropsWithoutRef, ReactNode } from "react";
|
|
2
|
-
import {
|
|
3
|
-
RefraktorRadius,
|
|
4
|
-
RefraktorSize,
|
|
5
|
-
createClassNamesConfig,
|
|
6
|
-
createComponentConfig,
|
|
7
|
-
FactoryPayload
|
|
8
|
-
} from "@refraktor/core";
|
|
9
|
-
import type {
|
|
10
|
-
MonthPickerGetHeaderLabel,
|
|
11
|
-
MonthPickerGetMonthAriaLabel,
|
|
12
|
-
MonthPickerGetMonthLabel,
|
|
13
|
-
MonthPickerGetNavigationAriaLabel
|
|
14
|
-
} from "../month-picker";
|
|
15
|
-
|
|
16
|
-
export type DatePickerValue = Date;
|
|
17
|
-
export type DatePickerSize = RefraktorSize;
|
|
18
|
-
export type DatePickerRadius = RefraktorRadius;
|
|
19
|
-
|
|
20
|
-
export type DatePickerNavigationDirection = "previous" | "next";
|
|
21
|
-
|
|
22
|
-
export type DatePickerOnChange = (value: DatePickerValue) => void;
|
|
23
|
-
|
|
24
|
-
export type DatePickerGetDayLabel = (value: Date) => ReactNode;
|
|
25
|
-
|
|
26
|
-
export type DatePickerGetDayAriaLabel = (
|
|
27
|
-
value: Date,
|
|
28
|
-
selected: boolean
|
|
29
|
-
) => string;
|
|
30
|
-
|
|
31
|
-
export type DatePickerGetWeekdayLabel = (
|
|
32
|
-
dayOfWeek: number,
|
|
33
|
-
label: string
|
|
34
|
-
) => ReactNode;
|
|
35
|
-
|
|
36
|
-
export type DatePickerGetHeaderLabel = (
|
|
37
|
-
month: number,
|
|
38
|
-
year: number,
|
|
39
|
-
value: Date
|
|
40
|
-
) => ReactNode;
|
|
41
|
-
|
|
42
|
-
export type DatePickerGetNavigationAriaLabel = (
|
|
43
|
-
direction: DatePickerNavigationDirection,
|
|
44
|
-
value: Date
|
|
45
|
-
) => string;
|
|
46
|
-
|
|
47
|
-
export type DatePickerClassNames = {
|
|
48
|
-
root?: string;
|
|
49
|
-
header?: string;
|
|
50
|
-
headerControls?: string;
|
|
51
|
-
headerControl?: string;
|
|
52
|
-
headerPreviousControl?: string;
|
|
53
|
-
headerNextControl?: string;
|
|
54
|
-
headerLabel?: string;
|
|
55
|
-
weekdays?: string;
|
|
56
|
-
weekday?: string;
|
|
57
|
-
grid?: string;
|
|
58
|
-
day?: string;
|
|
59
|
-
dayOutside?: string;
|
|
60
|
-
dayToday?: string;
|
|
61
|
-
daySelected?: string;
|
|
62
|
-
dayDisabled?: string;
|
|
63
|
-
monthPicker?: string;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export interface DatePickerProps
|
|
67
|
-
extends Omit<
|
|
68
|
-
ComponentPropsWithoutRef<"div">,
|
|
69
|
-
"onChange" | "value" | "defaultValue"
|
|
70
|
-
> {
|
|
71
|
-
/** Active date (controlled). */
|
|
72
|
-
value?: DatePickerValue;
|
|
73
|
-
|
|
74
|
-
/** Initial active date (uncontrolled). */
|
|
75
|
-
defaultValue?: DatePickerValue;
|
|
76
|
-
|
|
77
|
-
/** Callback called when active date changes. */
|
|
78
|
-
onChange?: DatePickerOnChange;
|
|
79
|
-
|
|
80
|
-
/** Minimum selectable date. */
|
|
81
|
-
minDate?: Date;
|
|
82
|
-
|
|
83
|
-
/** Maximum selectable date. */
|
|
84
|
-
maxDate?: Date;
|
|
85
|
-
|
|
86
|
-
/** Month picker columns @default `3` */
|
|
87
|
-
monthPickerColumns?: number;
|
|
88
|
-
|
|
89
|
-
/** Year picker years rendered in one page @default `9` */
|
|
90
|
-
yearPickerYearsPerPage?: number;
|
|
91
|
-
|
|
92
|
-
/** Year picker columns @default `3` */
|
|
93
|
-
yearPickerColumns?: number;
|
|
94
|
-
|
|
95
|
-
/** Whether all controls are disabled @default `false` */
|
|
96
|
-
disabled?: boolean;
|
|
97
|
-
|
|
98
|
-
/** Component size @default `md` */
|
|
99
|
-
size?: DatePickerSize;
|
|
100
|
-
|
|
101
|
-
/** Border radius @default `default` */
|
|
102
|
-
radius?: DatePickerRadius;
|
|
103
|
-
|
|
104
|
-
/** Custom weekday label renderer. */
|
|
105
|
-
getWeekdayLabel?: DatePickerGetWeekdayLabel;
|
|
106
|
-
|
|
107
|
-
/** Custom day label renderer. */
|
|
108
|
-
getDayLabel?: DatePickerGetDayLabel;
|
|
109
|
-
|
|
110
|
-
/** Custom aria-label generator for day buttons. */
|
|
111
|
-
getDayAriaLabel?: DatePickerGetDayAriaLabel;
|
|
112
|
-
|
|
113
|
-
/** Custom header label renderer for visible month. */
|
|
114
|
-
getHeaderLabel?: DatePickerGetHeaderLabel;
|
|
115
|
-
|
|
116
|
-
/** Custom aria-label generator for previous/next controls. */
|
|
117
|
-
getNavigationAriaLabel?: DatePickerGetNavigationAriaLabel;
|
|
118
|
-
|
|
119
|
-
/** Custom month label renderer in month view. */
|
|
120
|
-
getMonthLabel?: MonthPickerGetMonthLabel;
|
|
121
|
-
|
|
122
|
-
/** Custom aria-label generator for month buttons in month view. */
|
|
123
|
-
getMonthAriaLabel?: MonthPickerGetMonthAriaLabel;
|
|
124
|
-
|
|
125
|
-
/** Custom header label renderer in month view. */
|
|
126
|
-
getMonthHeaderLabel?: MonthPickerGetHeaderLabel;
|
|
127
|
-
|
|
128
|
-
/** Custom aria-label generator for month view navigation controls. */
|
|
129
|
-
getMonthNavigationAriaLabel?: MonthPickerGetNavigationAriaLabel;
|
|
130
|
-
|
|
131
|
-
/** Used for editing root class name. */
|
|
132
|
-
className?: string;
|
|
133
|
-
|
|
134
|
-
/** Used for styling different parts of the component. */
|
|
135
|
-
classNames?: DatePickerClassNames;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export interface DatePickerFactoryPayload extends FactoryPayload {
|
|
139
|
-
props: DatePickerProps;
|
|
140
|
-
ref: HTMLDivElement;
|
|
141
|
-
compound: {
|
|
142
|
-
configure: ReturnType<typeof createComponentConfig<DatePickerProps>>;
|
|
143
|
-
classNames: ReturnType<typeof createClassNamesConfig<DatePickerClassNames>>;
|
|
144
|
-
};
|
|
145
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export { default as DatePicker } from "./date-picker";
|
|
2
|
-
export type {
|
|
3
|
-
DatePickerClassNames,
|
|
4
|
-
DatePickerGetDayAriaLabel,
|
|
5
|
-
DatePickerGetDayLabel,
|
|
6
|
-
DatePickerGetHeaderLabel,
|
|
7
|
-
DatePickerGetNavigationAriaLabel,
|
|
8
|
-
DatePickerGetWeekdayLabel,
|
|
9
|
-
DatePickerNavigationDirection,
|
|
10
|
-
DatePickerOnChange,
|
|
11
|
-
DatePickerProps,
|
|
12
|
-
DatePickerRadius,
|
|
13
|
-
DatePickerSize,
|
|
14
|
-
DatePickerValue
|
|
15
|
-
} from "./date-picker.types";
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { createContext, useContext } from "react";
|
|
2
|
-
import type { DatesContextValue } from "./types";
|
|
3
|
-
|
|
4
|
-
const DatesContext = createContext<DatesContextValue | null>(null);
|
|
5
|
-
|
|
6
|
-
export const DatesContextProvider = DatesContext.Provider;
|
|
7
|
-
|
|
8
|
-
export const useDatesContext = () => {
|
|
9
|
-
const context = useContext(DatesContext);
|
|
10
|
-
|
|
11
|
-
if (context === null) {
|
|
12
|
-
throw new Error(
|
|
13
|
-
"[@refraktor/dates] DatesProvider was not found in the tree"
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return context;
|
|
18
|
-
};
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import dayjs from "dayjs";
|
|
2
|
-
import localeData from "dayjs/plugin/localeData";
|
|
3
|
-
import type { ConfigType } from "dayjs";
|
|
4
|
-
import { useCallback, useMemo } from "react";
|
|
5
|
-
import { DatesContextProvider } from "./context";
|
|
6
|
-
import type {
|
|
7
|
-
DatesContextValue,
|
|
8
|
-
DatesProviderProps,
|
|
9
|
-
DayOfWeek,
|
|
10
|
-
WeekdayFormat
|
|
11
|
-
} from "./types";
|
|
12
|
-
|
|
13
|
-
dayjs.extend(localeData);
|
|
14
|
-
|
|
15
|
-
const DEFAULT_FIRST_DAY_OF_WEEK: DayOfWeek = 1;
|
|
16
|
-
const DEFAULT_WEEKDAY_FORMAT: WeekdayFormat = "short";
|
|
17
|
-
const DEFAULT_CONSISTENT_WEEKS = true;
|
|
18
|
-
const DEFAULT_LOCALE = "en";
|
|
19
|
-
|
|
20
|
-
type DayjsWithLocales = typeof dayjs & {
|
|
21
|
-
Ls?: Record<string, unknown>;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const normalizeLocale = (locale: string) => {
|
|
25
|
-
const normalizedLocale = locale.trim().toLowerCase().replace(/_/g, "-");
|
|
26
|
-
|
|
27
|
-
if (!normalizedLocale) {
|
|
28
|
-
throw new Error(
|
|
29
|
-
"[@refraktor/dates] Invalid locale. Provide a non-empty locale string."
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return normalizedLocale;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const assertLocaleIsRegistered = (locale: string) => {
|
|
37
|
-
const locales = (dayjs as DayjsWithLocales).Ls ?? {};
|
|
38
|
-
|
|
39
|
-
if (locales[locale]) return;
|
|
40
|
-
|
|
41
|
-
throw new Error(
|
|
42
|
-
`[@refraktor/dates] Locale "${locale}" is not registered in dayjs. Import it before rendering DatesProvider (example: import "dayjs/locale/${locale}").`
|
|
43
|
-
);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const isDayOfWeek = (value: number): value is DayOfWeek =>
|
|
47
|
-
Number.isInteger(value) && value >= 0 && value <= 6;
|
|
48
|
-
|
|
49
|
-
const normalizeFirstDayOfWeek = (value: number): DayOfWeek => {
|
|
50
|
-
if (!isDayOfWeek(value)) {
|
|
51
|
-
throw new Error(
|
|
52
|
-
`[@refraktor/dates] Invalid firstDayOfWeek "${value}". Expected a number between 0 and 6.`
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return value;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const rotateWeekdays = (
|
|
60
|
-
weekdays: readonly string[],
|
|
61
|
-
firstDayOfWeek: DayOfWeek
|
|
62
|
-
) => [...weekdays.slice(firstDayOfWeek), ...weekdays.slice(0, firstDayOfWeek)];
|
|
63
|
-
|
|
64
|
-
const getWeekdaysByFormat = (
|
|
65
|
-
locale: string,
|
|
66
|
-
format: WeekdayFormat,
|
|
67
|
-
firstDayOfWeek: DayOfWeek
|
|
68
|
-
) => {
|
|
69
|
-
const localeData = dayjs().locale(locale).localeData();
|
|
70
|
-
|
|
71
|
-
const weekdays =
|
|
72
|
-
format === "long"
|
|
73
|
-
? localeData.weekdays()
|
|
74
|
-
: format === "narrow"
|
|
75
|
-
? localeData.weekdaysMin()
|
|
76
|
-
: localeData.weekdaysShort();
|
|
77
|
-
|
|
78
|
-
return rotateWeekdays(weekdays, firstDayOfWeek);
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export const DatesProvider = ({
|
|
82
|
-
children,
|
|
83
|
-
locale = DEFAULT_LOCALE,
|
|
84
|
-
firstDayOfWeek = DEFAULT_FIRST_DAY_OF_WEEK,
|
|
85
|
-
weekdayFormat = DEFAULT_WEEKDAY_FORMAT,
|
|
86
|
-
consistentWeeks = DEFAULT_CONSISTENT_WEEKS
|
|
87
|
-
}: DatesProviderProps) => {
|
|
88
|
-
const normalizedLocale = normalizeLocale(locale);
|
|
89
|
-
const normalizedFirstDayOfWeek = normalizeFirstDayOfWeek(firstDayOfWeek);
|
|
90
|
-
|
|
91
|
-
assertLocaleIsRegistered(normalizedLocale);
|
|
92
|
-
|
|
93
|
-
const createDate = useCallback(
|
|
94
|
-
(value?: ConfigType) => dayjs(value).locale(normalizedLocale),
|
|
95
|
-
[normalizedLocale]
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
const weekdays = useMemo(
|
|
99
|
-
() =>
|
|
100
|
-
getWeekdaysByFormat(
|
|
101
|
-
normalizedLocale,
|
|
102
|
-
weekdayFormat,
|
|
103
|
-
normalizedFirstDayOfWeek
|
|
104
|
-
),
|
|
105
|
-
[normalizedFirstDayOfWeek, normalizedLocale, weekdayFormat]
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
const contextValue = useMemo<DatesContextValue>(
|
|
109
|
-
() => ({
|
|
110
|
-
locale: normalizedLocale,
|
|
111
|
-
firstDayOfWeek: normalizedFirstDayOfWeek,
|
|
112
|
-
weekdayFormat,
|
|
113
|
-
consistentWeeks,
|
|
114
|
-
weekdays,
|
|
115
|
-
createDate
|
|
116
|
-
}),
|
|
117
|
-
[
|
|
118
|
-
normalizedLocale,
|
|
119
|
-
normalizedFirstDayOfWeek,
|
|
120
|
-
weekdayFormat,
|
|
121
|
-
consistentWeeks,
|
|
122
|
-
weekdays,
|
|
123
|
-
createDate
|
|
124
|
-
]
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
return (
|
|
128
|
-
<DatesContextProvider value={contextValue}>
|
|
129
|
-
{children}
|
|
130
|
-
</DatesContextProvider>
|
|
131
|
-
);
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
DatesProvider.displayName = "@refraktor/dates/DatesProvider";
|
|
135
|
-
|
|
136
|
-
export default DatesProvider;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { default as DatesProvider } from "./dates-provider";
|
|
2
|
-
export { useDatesContext } from "./context";
|
|
3
|
-
export { useDates } from "./use-dates";
|
|
4
|
-
export type {
|
|
5
|
-
CreateDate,
|
|
6
|
-
DatesContextValue,
|
|
7
|
-
DatesProviderProps,
|
|
8
|
-
DayOfWeek,
|
|
9
|
-
WeekdayFormat
|
|
10
|
-
} from "./types";
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { ConfigType, Dayjs } from "dayjs";
|
|
2
|
-
import type { ReactNode } from "react";
|
|
3
|
-
|
|
4
|
-
export type WeekdayFormat = "narrow" | "short" | "long";
|
|
5
|
-
export type DayOfWeek = 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
6
|
-
|
|
7
|
-
export type CreateDate = (value?: ConfigType) => Dayjs;
|
|
8
|
-
|
|
9
|
-
export type DatesProviderProps = {
|
|
10
|
-
/** Content wrapped by the dates provider. */
|
|
11
|
-
children: ReactNode;
|
|
12
|
-
|
|
13
|
-
/** Locale key imported by the user in dayjs. @default `en` */
|
|
14
|
-
locale?: string;
|
|
15
|
-
|
|
16
|
-
/** First day shown in week headers/grid. @default `1` (Monday) */
|
|
17
|
-
firstDayOfWeek?: DayOfWeek;
|
|
18
|
-
|
|
19
|
-
/** Weekday label style. @default `short` */
|
|
20
|
-
weekdayFormat?: WeekdayFormat;
|
|
21
|
-
|
|
22
|
-
/** Keep calendar grid at six rows. @default `true` */
|
|
23
|
-
consistentWeeks?: boolean;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export type DatesContextValue = {
|
|
27
|
-
locale: string;
|
|
28
|
-
firstDayOfWeek: DayOfWeek;
|
|
29
|
-
weekdayFormat: WeekdayFormat;
|
|
30
|
-
consistentWeeks: boolean;
|
|
31
|
-
weekdays: string[];
|
|
32
|
-
createDate: CreateDate;
|
|
33
|
-
};
|
package/src/components/index.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from "./dates-provider";
|
|
2
|
-
export * from "./date-picker";
|
|
3
|
-
export * from "./date-input";
|
|
4
|
-
export * from "./month-picker";
|
|
5
|
-
export * from "./month-input";
|
|
6
|
-
export * from "./year-picker";
|
|
7
|
-
export * from "./year-input";
|
|
8
|
-
export * from "./time-picker";
|
|
9
|
-
export * from "./time-input";
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export { default as MonthInput } from "./month-input";
|
|
2
|
-
export type {
|
|
3
|
-
MonthInputClassNames,
|
|
4
|
-
MonthInputFactoryPayload,
|
|
5
|
-
MonthInputMiddlewares,
|
|
6
|
-
MonthInputOnChange,
|
|
7
|
-
MonthInputPositioning,
|
|
8
|
-
MonthInputProps,
|
|
9
|
-
MonthInputRadius,
|
|
10
|
-
MonthInputSize,
|
|
11
|
-
MonthInputValue,
|
|
12
|
-
MonthInputValueFormat
|
|
13
|
-
} from "./month-input.types";
|