@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.
Files changed (63) hide show
  1. package/build/components/date-range-picker/date-range-picker.d.ts +4 -0
  2. package/build/components/date-range-picker/date-range-picker.d.ts.map +1 -0
  3. package/build/components/date-range-picker/date-range-picker.js +379 -0
  4. package/build/components/date-range-picker/date-range-picker.types.d.ts +100 -0
  5. package/build/components/date-range-picker/date-range-picker.types.d.ts.map +1 -0
  6. package/build/components/date-range-picker/date-range-picker.types.js +1 -0
  7. package/build/components/date-range-picker/index.d.ts +3 -0
  8. package/build/components/date-range-picker/index.d.ts.map +1 -0
  9. package/build/components/date-range-picker/index.js +1 -0
  10. package/build/components/time-input/index.d.ts +1 -1
  11. package/build/components/time-input/index.d.ts.map +1 -1
  12. package/build/components/time-input/time-input.d.ts.map +1 -1
  13. package/build/components/time-input/time-input.js +7 -196
  14. package/build/components/time-input/time-input.types.d.ts +5 -83
  15. package/build/components/time-input/time-input.types.d.ts.map +1 -1
  16. package/build/components/time-picker/index.d.ts +1 -1
  17. package/build/components/time-picker/index.d.ts.map +1 -1
  18. package/build/components/time-picker/time-picker.d.ts.map +1 -1
  19. package/build/components/time-picker/time-picker.js +498 -350
  20. package/build/components/time-picker/time-picker.types.d.ts +96 -61
  21. package/build/components/time-picker/time-picker.types.d.ts.map +1 -1
  22. package/build/style.css +2 -2
  23. package/package.json +33 -4
  24. package/.turbo/turbo-build.log +0 -4
  25. package/refraktor-dates-0.0.1-alpha.0.tgz +0 -0
  26. package/src/components/date-input/date-input.tsx +0 -379
  27. package/src/components/date-input/date-input.types.ts +0 -161
  28. package/src/components/date-input/index.ts +0 -13
  29. package/src/components/date-picker/date-picker.tsx +0 -649
  30. package/src/components/date-picker/date-picker.types.ts +0 -145
  31. package/src/components/date-picker/index.ts +0 -15
  32. package/src/components/dates-provider/context.ts +0 -18
  33. package/src/components/dates-provider/dates-provider.tsx +0 -136
  34. package/src/components/dates-provider/index.ts +0 -10
  35. package/src/components/dates-provider/types.ts +0 -33
  36. package/src/components/dates-provider/use-dates.ts +0 -5
  37. package/src/components/index.ts +0 -9
  38. package/src/components/month-input/index.ts +0 -13
  39. package/src/components/month-input/month-input.tsx +0 -366
  40. package/src/components/month-input/month-input.types.ts +0 -139
  41. package/src/components/month-picker/index.ts +0 -14
  42. package/src/components/month-picker/month-picker.tsx +0 -458
  43. package/src/components/month-picker/month-picker.types.ts +0 -117
  44. package/src/components/picker-shared/index.ts +0 -7
  45. package/src/components/picker-shared/picker-header.tsx +0 -178
  46. package/src/components/picker-shared/picker-header.types.ts +0 -49
  47. package/src/components/picker-shared/picker.styles.ts +0 -69
  48. package/src/components/picker-shared/picker.types.ts +0 -4
  49. package/src/components/time-input/index.ts +0 -23
  50. package/src/components/time-input/time-input.tsx +0 -453
  51. package/src/components/time-input/time-input.types.ts +0 -163
  52. package/src/components/time-picker/index.ts +0 -19
  53. package/src/components/time-picker/time-picker.tsx +0 -737
  54. package/src/components/time-picker/time-picker.types.ts +0 -135
  55. package/src/components/year-input/index.ts +0 -13
  56. package/src/components/year-input/year-input.tsx +0 -350
  57. package/src/components/year-input/year-input.types.ts +0 -118
  58. package/src/components/year-picker/index.ts +0 -15
  59. package/src/components/year-picker/year-picker.tsx +0 -504
  60. package/src/components/year-picker/year-picker.types.ts +0 -108
  61. package/src/index.ts +0 -3
  62. package/src/style.css +0 -1
  63. package/tsconfig.json +0 -13
@@ -1,135 +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
-
10
- export type TimePickerValue = string;
11
- export type TimePickerMode = "12h" | "24h";
12
- export type TimePickerPeriod = "am" | "pm";
13
- export type TimePickerSize = RefraktorSize;
14
- export type TimePickerRadius = RefraktorRadius;
15
-
16
- export type TimePickerOnChange = (value: TimePickerValue) => void;
17
-
18
- export type TimePickerGetHourLabel = (
19
- hour: number,
20
- mode: TimePickerMode
21
- ) => ReactNode;
22
-
23
- export type TimePickerGetMinuteLabel = (minute: number) => ReactNode;
24
-
25
- export type TimePickerGetSecondLabel = (second: number) => ReactNode;
26
-
27
- export type TimePickerGetPeriodLabel = (period: TimePickerPeriod) => ReactNode;
28
-
29
- export type TimePickerGetHourAriaLabel = (
30
- hour: number,
31
- mode: TimePickerMode,
32
- selected: boolean
33
- ) => string;
34
-
35
- export type TimePickerGetMinuteAriaLabel = (
36
- minute: number,
37
- selected: boolean
38
- ) => string;
39
-
40
- export type TimePickerGetSecondAriaLabel = (
41
- second: number,
42
- selected: boolean
43
- ) => string;
44
-
45
- export type TimePickerGetPeriodAriaLabel = (
46
- period: TimePickerPeriod,
47
- selected: boolean
48
- ) => string;
49
-
50
- export type TimePickerClassNames = {
51
- root?: string;
52
- grid?: string;
53
- section?: string;
54
- sectionLabel?: string;
55
- list?: string;
56
- option?: string;
57
- optionActive?: string;
58
- optionDisabled?: string;
59
- hourSection?: string;
60
- minuteSection?: string;
61
- secondSection?: string;
62
- periodSection?: string;
63
- };
64
-
65
- export interface TimePickerProps
66
- extends Omit<
67
- ComponentPropsWithoutRef<"div">,
68
- "onChange" | "value" | "defaultValue"
69
- > {
70
- /** Active time (controlled), accepts `H:mm:ss` or `HH:mm:ss` (24h). */
71
- value?: TimePickerValue;
72
-
73
- /** Initial active time (uncontrolled), accepts `H:mm:ss` or `HH:mm:ss` (24h). */
74
- defaultValue?: TimePickerValue;
75
-
76
- /** Callback called when active time changes in normalized `HH:mm:ss` format (24h). */
77
- onChange?: TimePickerOnChange;
78
-
79
- /** Lower selectable bound for time-of-day, accepts `H:mm:ss` or `HH:mm:ss` (24h). */
80
- minTime?: TimePickerValue;
81
-
82
- /** Upper selectable bound for time-of-day, accepts `H:mm:ss` or `HH:mm:ss` (24h). */
83
- maxTime?: TimePickerValue;
84
-
85
- /** Time display mode @default `24h` */
86
- mode?: TimePickerMode;
87
-
88
- /** Whether all controls are disabled @default `false` */
89
- disabled?: boolean;
90
-
91
- /** Component size @default `md` */
92
- size?: TimePickerSize;
93
-
94
- /** Border radius @default `default` */
95
- radius?: TimePickerRadius;
96
-
97
- /** Custom hour label renderer. */
98
- getHourLabel?: TimePickerGetHourLabel;
99
-
100
- /** Custom minute label renderer. */
101
- getMinuteLabel?: TimePickerGetMinuteLabel;
102
-
103
- /** Custom second label renderer. */
104
- getSecondLabel?: TimePickerGetSecondLabel;
105
-
106
- /** Custom AM/PM label renderer in 12h mode. */
107
- getPeriodLabel?: TimePickerGetPeriodLabel;
108
-
109
- /** Custom aria-label generator for hour options. */
110
- getHourAriaLabel?: TimePickerGetHourAriaLabel;
111
-
112
- /** Custom aria-label generator for minute options. */
113
- getMinuteAriaLabel?: TimePickerGetMinuteAriaLabel;
114
-
115
- /** Custom aria-label generator for second options. */
116
- getSecondAriaLabel?: TimePickerGetSecondAriaLabel;
117
-
118
- /** Custom aria-label generator for period options. */
119
- getPeriodAriaLabel?: TimePickerGetPeriodAriaLabel;
120
-
121
- /** Used for editing root class name. */
122
- className?: string;
123
-
124
- /** Used for styling different parts of the component. */
125
- classNames?: TimePickerClassNames;
126
- }
127
-
128
- export interface TimePickerFactoryPayload extends FactoryPayload {
129
- props: TimePickerProps;
130
- ref: HTMLDivElement;
131
- compound: {
132
- configure: ReturnType<typeof createComponentConfig<TimePickerProps>>;
133
- classNames: ReturnType<typeof createClassNamesConfig<TimePickerClassNames>>;
134
- };
135
- }
@@ -1,13 +0,0 @@
1
- export { default as YearInput } from "./year-input";
2
- export type {
3
- YearInputClassNames,
4
- YearInputFactoryPayload,
5
- YearInputMiddlewares,
6
- YearInputOnChange,
7
- YearInputPositioning,
8
- YearInputProps,
9
- YearInputRadius,
10
- YearInputSize,
11
- YearInputValue,
12
- YearInputValueFormat
13
- } from "./year-input.types";
@@ -1,350 +0,0 @@
1
- import { useId, useUncontrolled } from "@refraktor/utils";
2
- import { useCallback, useMemo } from "react";
3
- import {
4
- createClassNamesConfig,
5
- createComponentConfig,
6
- factory,
7
- Input,
8
- Transition,
9
- useClassNames,
10
- useProps,
11
- useTheme
12
- } from "@refraktor/core";
13
- import {
14
- autoUpdate,
15
- flip,
16
- FloatingFocusManager,
17
- FloatingPortal,
18
- inline,
19
- Middleware,
20
- offset,
21
- shift,
22
- useDismiss,
23
- useFloating,
24
- useFocus,
25
- useInteractions,
26
- useRole
27
- } from "@floating-ui/react";
28
- import { useDates } from "../dates-provider";
29
- import { YearPicker } from "../year-picker";
30
- import {
31
- YearInputClassNames,
32
- YearInputFactoryPayload,
33
- YearInputProps
34
- } from "./year-input.types";
35
-
36
- const DEFAULT_YEARS_PER_PAGE = 9;
37
- const DEFAULT_COLUMNS = 3;
38
- const DEFAULT_VALUE_FORMAT = "YYYY";
39
-
40
- const defaultProps = {
41
- yearsPerPage: DEFAULT_YEARS_PER_PAGE,
42
- columns: DEFAULT_COLUMNS,
43
- valueFormat: DEFAULT_VALUE_FORMAT,
44
- disabled: false,
45
- size: "md",
46
- radius: "default",
47
- positioning: {
48
- placement: "bottom-start",
49
- offset: 4
50
- },
51
- middlewares: {
52
- flip: true,
53
- shift: true
54
- },
55
- withinPortal: true,
56
- closeOnClickOutside: true,
57
- closeOnEscape: true
58
- } satisfies Partial<YearInputProps>;
59
-
60
- const toSafeInteger = (value: number | undefined) => {
61
- if (!Number.isFinite(value)) {
62
- return undefined;
63
- }
64
-
65
- return Math.trunc(value as number);
66
- };
67
-
68
- const YearInput = factory<YearInputFactoryPayload>((_props, ref) => {
69
- const { cx, getRadius } = useTheme();
70
- const { createDate } = useDates();
71
- const {
72
- id,
73
- value,
74
- defaultValue,
75
- onChange,
76
- opened,
77
- defaultOpened,
78
- onOpenedChange,
79
- minYear,
80
- maxYear,
81
- yearsPerPage,
82
- columns,
83
- valueFormat,
84
- disabled,
85
- size,
86
- radius,
87
- positioning,
88
- middlewares,
89
- withinPortal,
90
- closeOnClickOutside,
91
- closeOnEscape,
92
- transitionProps,
93
- inputClassNames,
94
- className,
95
- classNames,
96
- onFocus,
97
- onBlur,
98
- onClick,
99
- onKeyDown,
100
- ...inputProps
101
- } = useProps("YearInput", defaultProps, _props);
102
- const classes = useClassNames("YearInput", classNames);
103
-
104
- const _id = useId(id);
105
- const dropdownId = `${_id}-dropdown`;
106
-
107
- const [selectedYearState, setSelectedYear] = useUncontrolled<
108
- number | undefined
109
- >({
110
- value,
111
- defaultValue,
112
- finalValue: undefined,
113
- onChange: (nextYear) => {
114
- if (nextYear !== undefined) {
115
- onChange?.(nextYear);
116
- }
117
- }
118
- });
119
-
120
- const [isOpenState, setIsOpen] = useUncontrolled<boolean>({
121
- value: opened,
122
- defaultValue: defaultOpened,
123
- finalValue: false,
124
- onChange: onOpenedChange
125
- });
126
-
127
- const isOpen = isOpenState && !disabled;
128
-
129
- const middleware = useMemo(() => {
130
- const middlewareList: Middleware[] = [];
131
-
132
- middlewareList.push(offset(positioning?.offset ?? 4));
133
-
134
- if (middlewares?.flip ?? true) {
135
- middlewareList.push(
136
- flip(
137
- typeof middlewares?.flip === "boolean"
138
- ? undefined
139
- : middlewares.flip
140
- )
141
- );
142
- }
143
-
144
- if (middlewares?.shift ?? true) {
145
- middlewareList.push(
146
- shift(
147
- typeof middlewares?.shift === "boolean"
148
- ? undefined
149
- : middlewares.shift
150
- )
151
- );
152
- }
153
-
154
- if (middlewares?.inline) {
155
- middlewareList.push(
156
- inline(
157
- typeof middlewares.inline === "boolean"
158
- ? undefined
159
- : middlewares.inline
160
- )
161
- );
162
- }
163
-
164
- return middlewareList;
165
- }, [middlewares, positioning?.offset]);
166
-
167
- const handleOpenChange = useCallback(
168
- (nextOpen: boolean) => {
169
- if (disabled && nextOpen) {
170
- return;
171
- }
172
-
173
- setIsOpen(nextOpen);
174
- },
175
- [disabled, setIsOpen]
176
- );
177
-
178
- const floating = useFloating({
179
- placement: positioning?.placement ?? "bottom-start",
180
- open: isOpen,
181
- onOpenChange: handleOpenChange,
182
- middleware,
183
- whileElementsMounted: autoUpdate,
184
- strategy: "fixed"
185
- });
186
-
187
- const focus = useFocus(floating.context, {
188
- enabled: !disabled
189
- });
190
-
191
- const dismiss = useDismiss(floating.context, {
192
- outsidePress: closeOnClickOutside,
193
- escapeKey: closeOnEscape
194
- });
195
-
196
- const role = useRole(floating.context, {
197
- role: "dialog"
198
- });
199
-
200
- const { getReferenceProps, getFloatingProps } = useInteractions([
201
- focus,
202
- dismiss,
203
- role
204
- ]);
205
-
206
- const setInputRef = useCallback(
207
- (node: HTMLInputElement | null) => {
208
- floating.refs.setReference(node);
209
-
210
- if (typeof ref === "function") {
211
- ref(node);
212
- } else if (ref) {
213
- ref.current = node;
214
- }
215
- },
216
- [floating.refs, ref]
217
- );
218
-
219
- const handleInputKeyDown = useCallback(
220
- (event: React.KeyboardEvent<HTMLInputElement>) => {
221
- onKeyDown?.(event);
222
-
223
- if (event.defaultPrevented || disabled) {
224
- return;
225
- }
226
-
227
- if (
228
- event.key === "ArrowDown" ||
229
- event.key === "Enter" ||
230
- event.key === " "
231
- ) {
232
- event.preventDefault();
233
- setIsOpen(true);
234
- return;
235
- }
236
-
237
- if (event.key === "Escape") {
238
- event.preventDefault();
239
- setIsOpen(false);
240
- }
241
- },
242
- [disabled, onKeyDown, setIsOpen]
243
- );
244
-
245
- const handleYearChange = useCallback(
246
- (nextYear: number) => {
247
- setSelectedYear(nextYear);
248
- setIsOpen(false);
249
- },
250
- [setIsOpen, setSelectedYear]
251
- );
252
-
253
- const selectedYear = toSafeInteger(selectedYearState);
254
- const inputValue =
255
- selectedYear === undefined
256
- ? ""
257
- : createDate(new Date(selectedYear, 0, 1)).format(valueFormat);
258
-
259
- const mergedReferenceProps = getReferenceProps({
260
- onFocus,
261
- onBlur,
262
- onClick,
263
- onKeyDown: handleInputKeyDown
264
- });
265
-
266
- const dropdownContent = (
267
- <Transition
268
- transition="fade"
269
- duration={150}
270
- mounted={isOpen}
271
- style={{ position: "relative", zIndex: 1000 }}
272
- {...transitionProps}
273
- >
274
- <div
275
- ref={floating.refs.setFloating}
276
- id={dropdownId}
277
- style={{
278
- ...floating.floatingStyles,
279
- zIndex: 1000
280
- }}
281
- className={cx(
282
- "w-60 z-50 border border-[var(--refraktor-border)] bg-[var(--refraktor-bg)] p-2 text-[var(--refraktor-text)] shadow-md",
283
- getRadius(radius),
284
- classes.dropdown
285
- )}
286
- {...getFloatingProps()}
287
- >
288
- <YearPicker
289
- value={selectedYear}
290
- onChange={handleYearChange}
291
- minYear={minYear}
292
- maxYear={maxYear}
293
- yearsPerPage={yearsPerPage}
294
- columns={columns}
295
- disabled={disabled}
296
- size={size}
297
- radius={radius}
298
- className={cx("bg-transparent p-0", classes.yearPicker)}
299
- />
300
- </div>
301
- </Transition>
302
- );
303
-
304
- const wrappedContent = isOpen ? (
305
- <FloatingFocusManager
306
- context={floating.context}
307
- modal={false}
308
- initialFocus={-1}
309
- returnFocus={false}
310
- >
311
- {dropdownContent}
312
- </FloatingFocusManager>
313
- ) : (
314
- dropdownContent
315
- );
316
-
317
- return (
318
- <>
319
- <Input
320
- ref={setInputRef}
321
- id={_id}
322
- readOnly
323
- value={inputValue}
324
- disabled={disabled}
325
- size={size}
326
- radius={radius}
327
- role="combobox"
328
- aria-haspopup="dialog"
329
- aria-expanded={isOpen}
330
- aria-controls={isOpen ? dropdownId : undefined}
331
- className={cx(classes.input, className)}
332
- classNames={inputClassNames}
333
- {...inputProps}
334
- {...(mergedReferenceProps as any)}
335
- />
336
-
337
- {withinPortal ? (
338
- <FloatingPortal>{wrappedContent}</FloatingPortal>
339
- ) : (
340
- wrappedContent
341
- )}
342
- </>
343
- );
344
- });
345
-
346
- YearInput.displayName = "@refraktor/dates/YearInput";
347
- YearInput.configure = createComponentConfig<YearInputProps>();
348
- YearInput.classNames = createClassNamesConfig<YearInputClassNames>();
349
-
350
- export default YearInput;
@@ -1,118 +0,0 @@
1
- import type {
2
- FlipOptions,
3
- InlineOptions,
4
- Placement,
5
- ShiftOptions
6
- } from "@floating-ui/react";
7
- import {
8
- createClassNamesConfig,
9
- createComponentConfig,
10
- FactoryPayload,
11
- InputFieldClassNames,
12
- InputProps,
13
- RefraktorRadius,
14
- RefraktorSize,
15
- TransitionProps
16
- } from "@refraktor/core";
17
-
18
- export type YearInputValue = number;
19
- export type YearInputSize = RefraktorSize;
20
- export type YearInputRadius = RefraktorRadius;
21
- export type YearInputOnChange = (value: YearInputValue) => void;
22
- export type YearInputValueFormat = string;
23
-
24
- export type YearInputPositioning = {
25
- /** The placement of the dropdown relative to the input @default `bottom-start` */
26
- placement?: Placement;
27
-
28
- /** Offset distance from the input in pixels @default `4` */
29
- offset?: number;
30
- };
31
-
32
- export type YearInputMiddlewares = {
33
- shift?: boolean | ShiftOptions;
34
- flip?: boolean | FlipOptions;
35
- inline?: boolean | InlineOptions;
36
- };
37
-
38
- export type YearInputClassNames = {
39
- input?: string;
40
- dropdown?: string;
41
- yearPicker?: string;
42
- };
43
-
44
- interface _YearInputProps {
45
- /** Selected year (controlled). */
46
- value?: YearInputValue;
47
-
48
- /** Initial selected year (uncontrolled). */
49
- defaultValue?: YearInputValue;
50
-
51
- /** Callback called when selected year changes. */
52
- onChange?: YearInputOnChange;
53
-
54
- /** Dropdown open state (controlled). */
55
- opened?: boolean;
56
-
57
- /** Initial dropdown open state (uncontrolled). */
58
- defaultOpened?: boolean;
59
-
60
- /** Callback called when dropdown open state changes. */
61
- onOpenedChange?: (opened: boolean) => void;
62
-
63
- /** Minimum selectable year. */
64
- minYear?: number;
65
-
66
- /** Maximum selectable year. */
67
- maxYear?: number;
68
-
69
- /** Years rendered in one page @default `9` */
70
- yearsPerPage?: number;
71
-
72
- /** Grid columns used by the year list @default `3` */
73
- columns?: number;
74
-
75
- /** Dayjs format used to render selected year in the input @default `YYYY` */
76
- valueFormat?: YearInputValueFormat;
77
-
78
- /** Positioning settings for the dropdown. */
79
- positioning?: YearInputPositioning;
80
-
81
- /** Floating middleware settings. */
82
- middlewares?: YearInputMiddlewares;
83
-
84
- /** Whether to render dropdown in a portal @default `true` */
85
- withinPortal?: boolean;
86
-
87
- /** Whether to close on click outside @default `true` */
88
- closeOnClickOutside?: boolean;
89
-
90
- /** Whether to close on Escape key @default `true` */
91
- closeOnEscape?: boolean;
92
-
93
- /** Transition props for dropdown, uses Transition internally */
94
- transitionProps?: Omit<TransitionProps, "children" | "mounted">;
95
-
96
- /** Used for styling the core Input field parts. */
97
- inputClassNames?: InputFieldClassNames;
98
-
99
- /** Used for styling YearInput parts. */
100
- classNames?: YearInputClassNames;
101
- }
102
-
103
- export type YearInputProps = _YearInputProps &
104
- Omit<
105
- InputProps,
106
- "value" | "defaultValue" | "onChange" | "readOnly" | "classNames"
107
- >;
108
-
109
- export interface YearInputFactoryPayload extends FactoryPayload {
110
- props: YearInputProps;
111
- ref: HTMLInputElement;
112
- compound: {
113
- configure: ReturnType<typeof createComponentConfig<YearInputProps>>;
114
- classNames: ReturnType<
115
- typeof createClassNamesConfig<YearInputClassNames>
116
- >;
117
- };
118
- }
@@ -1,15 +0,0 @@
1
- export { default as YearPicker } from "./year-picker";
2
- export type {
3
- YearPickerClassNames,
4
- YearPickerGetHeaderLabel,
5
- YearPickerGetNavigationAriaLabel,
6
- YearPickerGetYearAriaLabel,
7
- YearPickerGetYearLabel,
8
- YearPickerNavigationDirection,
9
- YearPickerOnChange,
10
- YearPickerProps,
11
- YearPickerRadius,
12
- YearPickerRange,
13
- YearPickerSize,
14
- YearPickerValue
15
- } from "./year-picker.types";