@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,366 +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 { MonthPicker } from "../month-picker";
30
- import {
31
- MonthInputClassNames,
32
- MonthInputFactoryPayload,
33
- MonthInputProps
34
- } from "./month-input.types";
35
-
36
- const DEFAULT_COLUMNS = 3;
37
- const DEFAULT_YEAR_PICKER_YEARS_PER_PAGE = 9;
38
- const DEFAULT_YEAR_PICKER_COLUMNS = 3;
39
- const DEFAULT_VALUE_FORMAT = "MMMM YYYY";
40
-
41
- const defaultProps = {
42
- columns: DEFAULT_COLUMNS,
43
- yearPickerYearsPerPage: DEFAULT_YEAR_PICKER_YEARS_PER_PAGE,
44
- yearPickerColumns: DEFAULT_YEAR_PICKER_COLUMNS,
45
- valueFormat: DEFAULT_VALUE_FORMAT,
46
- disabled: false,
47
- size: "md",
48
- radius: "default",
49
- positioning: {
50
- placement: "bottom-start",
51
- offset: 4
52
- },
53
- middlewares: {
54
- flip: true,
55
- shift: true
56
- },
57
- withinPortal: true,
58
- closeOnClickOutside: true,
59
- closeOnEscape: true
60
- } satisfies Partial<MonthInputProps>;
61
-
62
- const isValidDate = (value: unknown): value is Date =>
63
- value instanceof Date && !Number.isNaN(value.getTime());
64
-
65
- const normalizeMonthValue = (value: Date | undefined) => {
66
- if (!isValidDate(value)) {
67
- return undefined;
68
- }
69
-
70
- const normalizedValue = new Date(value);
71
- normalizedValue.setDate(1);
72
- normalizedValue.setHours(0, 0, 0, 0);
73
- return normalizedValue;
74
- };
75
-
76
- const MonthInput = factory<MonthInputFactoryPayload>((_props, ref) => {
77
- const { cx, getRadius } = useTheme();
78
- const { createDate } = useDates();
79
- const {
80
- id,
81
- value,
82
- defaultValue,
83
- onChange,
84
- opened,
85
- defaultOpened,
86
- onOpenedChange,
87
- minYear,
88
- maxYear,
89
- columns,
90
- yearPickerYearsPerPage,
91
- yearPickerColumns,
92
- getMonthLabel,
93
- getMonthAriaLabel,
94
- getHeaderLabel,
95
- getNavigationAriaLabel,
96
- valueFormat,
97
- disabled,
98
- size,
99
- radius,
100
- positioning,
101
- middlewares,
102
- withinPortal,
103
- closeOnClickOutside,
104
- closeOnEscape,
105
- transitionProps,
106
- inputClassNames,
107
- className,
108
- classNames,
109
- onFocus,
110
- onBlur,
111
- onClick,
112
- onKeyDown,
113
- ...inputProps
114
- } = useProps("MonthInput", defaultProps, _props);
115
- const classes = useClassNames("MonthInput", classNames);
116
-
117
- const _id = useId(id);
118
- const dropdownId = `${_id}-dropdown`;
119
-
120
- const [selectedMonthState, setSelectedMonth] = useUncontrolled<
121
- Date | undefined
122
- >({
123
- value,
124
- defaultValue,
125
- finalValue: undefined,
126
- onChange: (nextMonth) => {
127
- if (nextMonth !== undefined) {
128
- onChange?.(nextMonth);
129
- }
130
- }
131
- });
132
-
133
- const [isOpenState, setIsOpen] = useUncontrolled<boolean>({
134
- value: opened,
135
- defaultValue: defaultOpened,
136
- finalValue: false,
137
- onChange: onOpenedChange
138
- });
139
-
140
- const isOpen = isOpenState && !disabled;
141
-
142
- const middleware = useMemo(() => {
143
- const middlewareList: Middleware[] = [];
144
-
145
- middlewareList.push(offset(positioning?.offset ?? 4));
146
-
147
- if (middlewares?.flip ?? true) {
148
- middlewareList.push(
149
- flip(
150
- typeof middlewares?.flip === "boolean"
151
- ? undefined
152
- : middlewares.flip
153
- )
154
- );
155
- }
156
-
157
- if (middlewares?.shift ?? true) {
158
- middlewareList.push(
159
- shift(
160
- typeof middlewares?.shift === "boolean"
161
- ? undefined
162
- : middlewares.shift
163
- )
164
- );
165
- }
166
-
167
- if (middlewares?.inline) {
168
- middlewareList.push(
169
- inline(
170
- typeof middlewares.inline === "boolean"
171
- ? undefined
172
- : middlewares.inline
173
- )
174
- );
175
- }
176
-
177
- return middlewareList;
178
- }, [middlewares, positioning?.offset]);
179
-
180
- const handleOpenChange = useCallback(
181
- (nextOpen: boolean) => {
182
- if (disabled && nextOpen) {
183
- return;
184
- }
185
-
186
- setIsOpen(nextOpen);
187
- },
188
- [disabled, setIsOpen]
189
- );
190
-
191
- const floating = useFloating({
192
- placement: positioning?.placement ?? "bottom-start",
193
- open: isOpen,
194
- onOpenChange: handleOpenChange,
195
- middleware,
196
- whileElementsMounted: autoUpdate,
197
- strategy: "fixed"
198
- });
199
-
200
- const focus = useFocus(floating.context, {
201
- enabled: !disabled
202
- });
203
-
204
- const dismiss = useDismiss(floating.context, {
205
- outsidePress: closeOnClickOutside,
206
- escapeKey: closeOnEscape
207
- });
208
-
209
- const role = useRole(floating.context, {
210
- role: "dialog"
211
- });
212
-
213
- const { getReferenceProps, getFloatingProps } = useInteractions([
214
- focus,
215
- dismiss,
216
- role
217
- ]);
218
-
219
- const setInputRef = useCallback(
220
- (node: HTMLInputElement | null) => {
221
- floating.refs.setReference(node);
222
-
223
- if (typeof ref === "function") {
224
- ref(node);
225
- } else if (ref) {
226
- ref.current = node;
227
- }
228
- },
229
- [floating.refs, ref]
230
- );
231
-
232
- const handleInputKeyDown = useCallback(
233
- (event: React.KeyboardEvent<HTMLInputElement>) => {
234
- onKeyDown?.(event);
235
-
236
- if (event.defaultPrevented || disabled) {
237
- return;
238
- }
239
-
240
- if (
241
- event.key === "ArrowDown" ||
242
- event.key === "Enter" ||
243
- event.key === " "
244
- ) {
245
- event.preventDefault();
246
- setIsOpen(true);
247
- return;
248
- }
249
-
250
- if (event.key === "Escape") {
251
- event.preventDefault();
252
- setIsOpen(false);
253
- }
254
- },
255
- [disabled, onKeyDown, setIsOpen]
256
- );
257
-
258
- const handleMonthChange = useCallback(
259
- (nextMonth: Date) => {
260
- setSelectedMonth(nextMonth);
261
- setIsOpen(false);
262
- },
263
- [setIsOpen, setSelectedMonth]
264
- );
265
-
266
- const selectedMonth = normalizeMonthValue(selectedMonthState);
267
- const inputValue =
268
- selectedMonth === undefined ? "" : createDate(selectedMonth).format(valueFormat);
269
-
270
- const mergedReferenceProps = getReferenceProps({
271
- onFocus,
272
- onBlur,
273
- onClick,
274
- onKeyDown: handleInputKeyDown
275
- });
276
-
277
- const dropdownContent = (
278
- <Transition
279
- transition="fade"
280
- duration={150}
281
- mounted={isOpen}
282
- style={{ position: "relative", zIndex: 1000 }}
283
- {...transitionProps}
284
- >
285
- <div
286
- ref={floating.refs.setFloating}
287
- id={dropdownId}
288
- style={{
289
- ...floating.floatingStyles,
290
- zIndex: 1000
291
- }}
292
- className={cx(
293
- "w-72 z-50 border border-[var(--refraktor-border)] bg-[var(--refraktor-bg)] p-2 text-[var(--refraktor-text)] shadow-md",
294
- getRadius(radius),
295
- classes.dropdown
296
- )}
297
- {...getFloatingProps()}
298
- >
299
- <MonthPicker
300
- value={selectedMonth}
301
- onChange={handleMonthChange}
302
- minYear={minYear}
303
- maxYear={maxYear}
304
- columns={columns}
305
- yearPickerYearsPerPage={yearPickerYearsPerPage}
306
- yearPickerColumns={yearPickerColumns}
307
- disabled={disabled}
308
- size={size}
309
- radius={radius}
310
- getMonthLabel={getMonthLabel}
311
- getMonthAriaLabel={getMonthAriaLabel}
312
- getHeaderLabel={getHeaderLabel}
313
- getNavigationAriaLabel={getNavigationAriaLabel}
314
- className={cx("bg-transparent p-0", classes.monthPicker)}
315
- />
316
- </div>
317
- </Transition>
318
- );
319
-
320
- const wrappedContent = isOpen ? (
321
- <FloatingFocusManager
322
- context={floating.context}
323
- modal={false}
324
- initialFocus={-1}
325
- returnFocus={false}
326
- >
327
- {dropdownContent}
328
- </FloatingFocusManager>
329
- ) : (
330
- dropdownContent
331
- );
332
-
333
- return (
334
- <>
335
- <Input
336
- ref={setInputRef}
337
- id={_id}
338
- readOnly
339
- value={inputValue}
340
- disabled={disabled}
341
- size={size}
342
- radius={radius}
343
- role="combobox"
344
- aria-haspopup="dialog"
345
- aria-expanded={isOpen}
346
- aria-controls={isOpen ? dropdownId : undefined}
347
- className={cx(classes.input, className)}
348
- classNames={inputClassNames}
349
- {...inputProps}
350
- {...(mergedReferenceProps as any)}
351
- />
352
-
353
- {withinPortal ? (
354
- <FloatingPortal>{wrappedContent}</FloatingPortal>
355
- ) : (
356
- wrappedContent
357
- )}
358
- </>
359
- );
360
- });
361
-
362
- MonthInput.displayName = "@refraktor/dates/MonthInput";
363
- MonthInput.configure = createComponentConfig<MonthInputProps>();
364
- MonthInput.classNames = createClassNamesConfig<MonthInputClassNames>();
365
-
366
- export default MonthInput;
@@ -1,139 +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
- import type {
18
- MonthPickerGetHeaderLabel,
19
- MonthPickerGetMonthAriaLabel,
20
- MonthPickerGetMonthLabel,
21
- MonthPickerGetNavigationAriaLabel
22
- } from "../month-picker";
23
-
24
- export type MonthInputValue = Date;
25
- export type MonthInputSize = RefraktorSize;
26
- export type MonthInputRadius = RefraktorRadius;
27
- export type MonthInputOnChange = (value: MonthInputValue) => void;
28
- export type MonthInputValueFormat = string;
29
-
30
- export type MonthInputPositioning = {
31
- /** The placement of the dropdown relative to the input @default `bottom-start` */
32
- placement?: Placement;
33
-
34
- /** Offset distance from the input in pixels @default `4` */
35
- offset?: number;
36
- };
37
-
38
- export type MonthInputMiddlewares = {
39
- shift?: boolean | ShiftOptions;
40
- flip?: boolean | FlipOptions;
41
- inline?: boolean | InlineOptions;
42
- };
43
-
44
- export type MonthInputClassNames = {
45
- input?: string;
46
- dropdown?: string;
47
- monthPicker?: string;
48
- };
49
-
50
- interface _MonthInputProps {
51
- /** Selected month (controlled). */
52
- value?: MonthInputValue;
53
-
54
- /** Initial selected month (uncontrolled). */
55
- defaultValue?: MonthInputValue;
56
-
57
- /** Callback called when selected month changes. */
58
- onChange?: MonthInputOnChange;
59
-
60
- /** Dropdown open state (controlled). */
61
- opened?: boolean;
62
-
63
- /** Initial dropdown open state (uncontrolled). */
64
- defaultOpened?: boolean;
65
-
66
- /** Callback called when dropdown open state changes. */
67
- onOpenedChange?: (opened: boolean) => void;
68
-
69
- /** Minimum selectable year in month and year views. */
70
- minYear?: number;
71
-
72
- /** Maximum selectable year in month and year views. */
73
- maxYear?: number;
74
-
75
- /** Grid columns used by the month list @default `3` */
76
- columns?: number;
77
-
78
- /** Year picker years rendered in one page @default `9` */
79
- yearPickerYearsPerPage?: number;
80
-
81
- /** Year picker columns @default `3` */
82
- yearPickerColumns?: number;
83
-
84
- /** Custom month label renderer. */
85
- getMonthLabel?: MonthPickerGetMonthLabel;
86
-
87
- /** Custom aria-label generator for month buttons. */
88
- getMonthAriaLabel?: MonthPickerGetMonthAriaLabel;
89
-
90
- /** Custom header label renderer for visible year. */
91
- getHeaderLabel?: MonthPickerGetHeaderLabel;
92
-
93
- /** Custom aria-label generator for previous/next controls. */
94
- getNavigationAriaLabel?: MonthPickerGetNavigationAriaLabel;
95
-
96
- /** Dayjs format used to render selected month in the input @default `MMMM YYYY` */
97
- valueFormat?: MonthInputValueFormat;
98
-
99
- /** Positioning settings for the dropdown. */
100
- positioning?: MonthInputPositioning;
101
-
102
- /** Floating middleware settings. */
103
- middlewares?: MonthInputMiddlewares;
104
-
105
- /** Whether to render dropdown in a portal @default `true` */
106
- withinPortal?: boolean;
107
-
108
- /** Whether to close on click outside @default `true` */
109
- closeOnClickOutside?: boolean;
110
-
111
- /** Whether to close on Escape key @default `true` */
112
- closeOnEscape?: boolean;
113
-
114
- /** Transition props for dropdown, uses Transition internally */
115
- transitionProps?: Omit<TransitionProps, "children" | "mounted">;
116
-
117
- /** Used for styling the core Input field parts. */
118
- inputClassNames?: InputFieldClassNames;
119
-
120
- /** Used for styling MonthInput parts. */
121
- classNames?: MonthInputClassNames;
122
- }
123
-
124
- export type MonthInputProps = _MonthInputProps &
125
- Omit<
126
- InputProps,
127
- "value" | "defaultValue" | "onChange" | "readOnly" | "classNames"
128
- >;
129
-
130
- export interface MonthInputFactoryPayload extends FactoryPayload {
131
- props: MonthInputProps;
132
- ref: HTMLInputElement;
133
- compound: {
134
- configure: ReturnType<typeof createComponentConfig<MonthInputProps>>;
135
- classNames: ReturnType<
136
- typeof createClassNamesConfig<MonthInputClassNames>
137
- >;
138
- };
139
- }
@@ -1,14 +0,0 @@
1
- export { default as MonthPicker } from "./month-picker";
2
- export type {
3
- MonthPickerClassNames,
4
- MonthPickerGetHeaderLabel,
5
- MonthPickerGetMonthAriaLabel,
6
- MonthPickerGetMonthLabel,
7
- MonthPickerGetNavigationAriaLabel,
8
- MonthPickerNavigationDirection,
9
- MonthPickerOnChange,
10
- MonthPickerProps,
11
- MonthPickerRadius,
12
- MonthPickerSize,
13
- MonthPickerValue
14
- } from "./month-picker.types";