@refraktor/dates 0.0.4 → 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 (42) hide show
  1. package/build/style.css +2 -2
  2. package/package.json +33 -4
  3. package/.turbo/turbo-build.log +0 -4
  4. package/refraktor-dates-0.0.1-alpha.0.tgz +0 -0
  5. package/src/components/date-input/date-input.tsx +0 -379
  6. package/src/components/date-input/date-input.types.ts +0 -161
  7. package/src/components/date-input/index.ts +0 -13
  8. package/src/components/date-picker/date-picker.tsx +0 -649
  9. package/src/components/date-picker/date-picker.types.ts +0 -145
  10. package/src/components/date-picker/index.ts +0 -15
  11. package/src/components/dates-provider/context.ts +0 -18
  12. package/src/components/dates-provider/dates-provider.tsx +0 -136
  13. package/src/components/dates-provider/index.ts +0 -10
  14. package/src/components/dates-provider/types.ts +0 -33
  15. package/src/components/dates-provider/use-dates.ts +0 -5
  16. package/src/components/index.ts +0 -9
  17. package/src/components/month-input/index.ts +0 -13
  18. package/src/components/month-input/month-input.tsx +0 -366
  19. package/src/components/month-input/month-input.types.ts +0 -139
  20. package/src/components/month-picker/index.ts +0 -14
  21. package/src/components/month-picker/month-picker.tsx +0 -458
  22. package/src/components/month-picker/month-picker.types.ts +0 -117
  23. package/src/components/picker-shared/index.ts +0 -7
  24. package/src/components/picker-shared/picker-header.tsx +0 -178
  25. package/src/components/picker-shared/picker-header.types.ts +0 -49
  26. package/src/components/picker-shared/picker.styles.ts +0 -69
  27. package/src/components/picker-shared/picker.types.ts +0 -4
  28. package/src/components/time-input/index.ts +0 -6
  29. package/src/components/time-input/time-input.tsx +0 -48
  30. package/src/components/time-input/time-input.types.ts +0 -30
  31. package/src/components/time-picker/index.ts +0 -10
  32. package/src/components/time-picker/time-picker.tsx +0 -1088
  33. package/src/components/time-picker/time-picker.types.ts +0 -166
  34. package/src/components/year-input/index.ts +0 -13
  35. package/src/components/year-input/year-input.tsx +0 -350
  36. package/src/components/year-input/year-input.types.ts +0 -118
  37. package/src/components/year-picker/index.ts +0 -15
  38. package/src/components/year-picker/year-picker.tsx +0 -504
  39. package/src/components/year-picker/year-picker.types.ts +0 -108
  40. package/src/index.ts +0 -3
  41. package/src/style.css +0 -1
  42. package/tsconfig.json +0 -13
@@ -1,166 +0,0 @@
1
- import type { Placement } from "@floating-ui/react";
2
- import { ComponentPropsWithoutRef, ReactNode, Ref } from "react";
3
- import {
4
- RefraktorRadius,
5
- RefraktorSize,
6
- InputVariant,
7
- createClassNamesConfig,
8
- createComponentConfig,
9
- FactoryPayload
10
- } from "@refraktor/core";
11
-
12
- export type TimePickerValue = string;
13
- export type TimePickerFormat = "12h" | "24h";
14
- export type TimePickerAmPmLabels = { am: string; pm: string };
15
-
16
- export type TimePickerClassNames = {
17
- root?: string;
18
- fieldsWrapper?: string;
19
- field?: string;
20
- separator?: string;
21
- amPmInput?: string;
22
- dropdown?: string;
23
- dropdownColumn?: string;
24
- dropdownColumnLabel?: string;
25
- dropdownOption?: string;
26
- dropdownOptionActive?: string;
27
- };
28
-
29
- export type TimePickerPopoverProps = {
30
- /** Dropdown placement relative to the input @default `bottom-start` */
31
- placement?: Placement;
32
- /** Offset distance from the input in pixels @default `4` */
33
- offset?: number;
34
- };
35
-
36
- interface _TimePickerProps {
37
- /** Controlled time value in 24h format (`HH:mm` or `HH:mm:ss`). Empty string for no value. */
38
- value?: TimePickerValue;
39
-
40
- /** Uncontrolled initial time value in 24h format (`HH:mm` or `HH:mm:ss`). */
41
- defaultValue?: TimePickerValue;
42
-
43
- /** Called when the time value changes. Fires when all visible fields are filled, or all are cleared. */
44
- onChange?: (value: TimePickerValue) => void;
45
-
46
- /** Time display format @default `"24h"` */
47
- format?: TimePickerFormat;
48
-
49
- /** Show seconds field @default `false` */
50
- withSeconds?: boolean;
51
-
52
- /** Show scrollable dropdown with time options @default `false` */
53
- withDropdown?: boolean;
54
-
55
- /** Show clear button in the right section @default `false` */
56
- clearable?: boolean;
57
-
58
- /** Minimum selectable time in 24h format (`HH:mm` or `HH:mm:ss`) */
59
- min?: TimePickerValue;
60
-
61
- /** Maximum selectable time in 24h format (`HH:mm` or `HH:mm:ss`) */
62
- max?: TimePickerValue;
63
-
64
- /** Step for hour increment/decrement and dropdown generation @default `1` */
65
- hoursStep?: number;
66
-
67
- /** Step for minute increment/decrement and dropdown generation @default `1` */
68
- minutesStep?: number;
69
-
70
- /** Step for second increment/decrement and dropdown generation @default `1` */
71
- secondsStep?: number;
72
-
73
- /** Custom AM/PM labels @default `{ am: "AM", pm: "PM" }` */
74
- amPmLabels?: TimePickerAmPmLabels;
75
-
76
- /** Whether the input is disabled @default `false` */
77
- disabled?: boolean;
78
-
79
- /** Whether the input is read-only @default `false` */
80
- readOnly?: boolean;
81
-
82
- /** Input variant @default `"default"` */
83
- variant?: InputVariant;
84
-
85
- /** Component size @default `"md"` */
86
- size?: RefraktorSize;
87
-
88
- /** Border radius @default `"default"` */
89
- radius?: RefraktorRadius;
90
-
91
- /** Label text */
92
- label?: ReactNode;
93
-
94
- /** Description text displayed below the label */
95
- description?: ReactNode;
96
-
97
- /** Error message */
98
- error?: ReactNode;
99
-
100
- /** Whether the field is required */
101
- required?: boolean;
102
-
103
- /** Display an asterisk next to the label */
104
- withAsterisk?: boolean;
105
-
106
- /** Left section content */
107
- leftSection?: ReactNode;
108
-
109
- /** Right section content (overridden by clearable when value is set) */
110
- rightSection?: ReactNode;
111
-
112
- /** Ref for the hours input element */
113
- hoursRef?: Ref<HTMLInputElement>;
114
-
115
- /** Ref for the minutes input element */
116
- minutesRef?: Ref<HTMLInputElement>;
117
-
118
- /** Ref for the seconds input element */
119
- secondsRef?: Ref<HTMLInputElement>;
120
-
121
- /** Ref for the AM/PM select element */
122
- amPmRef?: Ref<HTMLInputElement>;
123
-
124
- /** Aria label for hours input */
125
- hoursInputLabel?: string;
126
-
127
- /** Aria label for minutes input */
128
- minutesInputLabel?: string;
129
-
130
- /** Aria label for seconds input */
131
- secondsInputLabel?: string;
132
-
133
- /** Aria label for AM/PM input */
134
- amPmInputLabel?: string;
135
-
136
- /** Popover props for the dropdown */
137
- popoverProps?: TimePickerPopoverProps;
138
-
139
- /** Called when any field gains focus */
140
- onFocus?: (event: React.FocusEvent<HTMLDivElement>) => void;
141
-
142
- /** Called when all fields lose focus */
143
- onBlur?: (event: React.FocusEvent<HTMLDivElement>) => void;
144
-
145
- /** Used for styling different parts of the component */
146
- classNames?: TimePickerClassNames;
147
- }
148
-
149
- export type TimePickerProps = _TimePickerProps &
150
- Omit<
151
- ComponentPropsWithoutRef<"div">,
152
- | "onChange"
153
- | "value"
154
- | "defaultValue"
155
- | "onFocus"
156
- | "onBlur"
157
- >;
158
-
159
- export interface TimePickerFactoryPayload extends FactoryPayload {
160
- props: TimePickerProps;
161
- ref: HTMLDivElement;
162
- compound: {
163
- configure: ReturnType<typeof createComponentConfig<TimePickerProps>>;
164
- classNames: ReturnType<typeof createClassNamesConfig<TimePickerClassNames>>;
165
- };
166
- }
@@ -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";