@bloomreach/react-banana-ui 1.31.2 → 1.32.0
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/bloomreach-react-banana-ui.es.js +7413 -15720
- package/dist/bloomreach-react-banana-ui.es.js.map +1 -1
- package/dist/bloomreach-react-banana-ui.umd.js +22 -28
- package/dist/bloomreach-react-banana-ui.umd.js.map +1 -1
- package/dist/components/{inputs → date}/calendar-grid/calendar-grid.types.d.ts +7 -0
- package/dist/components/date/date-time-picker/date-time-picker.d.ts +74 -0
- package/dist/components/date/date-time-picker/date-time-picker.stories.d.ts +19 -0
- package/dist/components/date/date-time-picker/date-time-picker.types.d.ts +245 -0
- package/dist/components/date/date-time-picker/index.d.ts +3 -0
- package/dist/components/date/date-time-picker/use-date-time-picker.d.ts +35 -0
- package/dist/components/date/date-time-range-picker/date-time-range-picker.d.ts +94 -0
- package/dist/components/date/date-time-range-picker/date-time-range-picker.stories.d.ts +19 -0
- package/dist/components/date/date-time-range-picker/date-time-range-picker.types.d.ts +268 -0
- package/dist/components/date/date-time-range-picker/index.d.ts +2 -0
- package/dist/components/date/date-time-range-picker/use-date-time-range-picker.d.ts +19 -0
- package/dist/components/date/index.d.ts +2 -0
- package/dist/components/date/internal.d.ts +5 -0
- package/dist/components/date/time-selector/index.d.ts +2 -0
- package/dist/components/date/time-selector/time-selector.d.ts +24 -0
- package/dist/components/date/time-selector/time-selector.types.d.ts +52 -0
- package/dist/components/deprecated/date-time-input/date-time-input.d.ts +89 -0
- package/dist/components/deprecated/date-time-input/date-time-input.stories.d.ts +26 -0
- package/dist/components/deprecated/date-time-input/date-time-input.types.d.ts +142 -0
- package/dist/components/deprecated/date-time-input/index.d.ts +3 -0
- package/dist/components/deprecated/date-time-input/use-date-time-input.d.ts +23 -0
- package/dist/components/deprecated/index.d.ts +6 -0
- package/dist/components/feedback/toast/toast-function/toast.d.ts +1 -1
- package/dist/components/inputs/base-input/base-input.types.d.ts +5 -1
- package/dist/components/inputs/index.d.ts +0 -4
- package/dist/react-banana-ui.css +1 -1
- package/dist/utils/date/aria-date-conversion.d.ts +11 -0
- package/dist/utils/date/date-utils.d.ts +34 -0
- package/dist/utils/date/index.d.ts +1 -0
- package/dist/utils/extract-data-aria-attributes.d.ts +59 -0
- package/dist/utils/index.d.ts +1 -0
- package/package.json +56 -53
- /package/dist/components/{inputs → date}/calendar-cell/calendar-cell.d.ts +0 -0
- /package/dist/components/{inputs → date}/calendar-cell/calendar-cell.types.d.ts +0 -0
- /package/dist/components/{inputs → date}/calendar-cell/index.d.ts +0 -0
- /package/dist/components/{inputs → date}/calendar-grid/calendar-grid.d.ts +0 -0
- /package/dist/components/{inputs → date}/calendar-grid/index.d.ts +0 -0
- /package/dist/components/{inputs → date}/date-segment/date-segment.d.ts +0 -0
- /package/dist/components/{inputs → date}/date-segment/date-segment.types.d.ts +0 -0
- /package/dist/components/{inputs → date}/date-segment/index.d.ts +0 -0
- /package/dist/components/{inputs → date}/date-segments/date-segments.d.ts +0 -0
- /package/dist/components/{inputs → date}/date-segments/date-segments.types.d.ts +0 -0
- /package/dist/components/{inputs → date}/date-segments/index.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/calendar/calendar-base.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/calendar/calendar.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/calendar/calendar.qa.stories.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/calendar/calendar.stories.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/calendar/calendar.types.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/calendar/index.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/calendar/use-calendar-state.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/calendar/use-calendar.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/date-input/date-input.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/date-input/date-input.qa.stories.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/date-input/date-input.stories.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/date-input/date-input.types.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/date-input/index.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/date-input/use-date-input-state.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/date-input/use-date-input.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/date-picker/date-picker.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/date-picker/date-picker.qa.stories.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/date-picker/date-picker.stories.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/date-picker/date-picker.types.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/date-picker/index.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/date-picker/use-date-picker-state.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/date-picker/use-date-picker.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/date-range-picker/date-range-picker.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/date-range-picker/date-range-picker.qa.stories.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/date-range-picker/date-range-picker.stories.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/date-range-picker/date-range-picker.types.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/date-range-picker/index.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/date-range-picker/use-date-range-picker-state.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/date-range-picker/use-date-range-picker.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/range-calendar/index.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/range-calendar/range-calendar-base.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/range-calendar/range-calendar.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/range-calendar/range-calendar.types.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/range-calendar/use-range-calendar-state.d.ts +0 -0
- /package/dist/components/{inputs → deprecated}/range-calendar/use-range-calendar.d.ts +0 -0
|
@@ -4,6 +4,13 @@ export interface CalendarGridProps {
|
|
|
4
4
|
* Custom class name for the container of the component.
|
|
5
5
|
*/
|
|
6
6
|
className?: string;
|
|
7
|
+
/**
|
|
8
|
+
* The locale for the calendar.
|
|
9
|
+
* Follows BCP 47 language tag format (e.g., 'en-US', 'de-DE', 'ja-JP').
|
|
10
|
+
* When not provided, uses the user's browser locale.
|
|
11
|
+
* @example 'en-US', 'de-DE', 'fr-FR'
|
|
12
|
+
*/
|
|
13
|
+
locale?: string;
|
|
7
14
|
/**
|
|
8
15
|
* The state for the calendar from `useCalendarState` or `useRangeCalendarState` hook.
|
|
9
16
|
*/
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { DateTimePickerProps } from './date-time-picker.types';
|
|
2
|
+
/**
|
|
3
|
+
* DateTimePicker is a composite component that combines date and time selection.
|
|
4
|
+
* It provides a text field for entering date/time values and a popup with both
|
|
5
|
+
* a calendar for date selection and time selectors for hour, minute, and second.
|
|
6
|
+
*
|
|
7
|
+
* Built on top of React Aria's date picker primitives with extended time support.
|
|
8
|
+
* The component automatically handles keyboard navigation, accessibility, and
|
|
9
|
+
* internationalization for both date and time components.
|
|
10
|
+
*
|
|
11
|
+
* ## Features
|
|
12
|
+
*
|
|
13
|
+
* - **Unified Date/Time Selection**: Single component for both date and time
|
|
14
|
+
* - **Calendar Integration**: Full calendar for date selection
|
|
15
|
+
* - **Time Selectors**: Dropdown selectors for hour, minute, and second
|
|
16
|
+
* - **Granularity Control**: Configure precision from day to second level
|
|
17
|
+
* - **Keyboard Navigation**: Full keyboard support with Enter/Space to open
|
|
18
|
+
* - **Accessibility**: Screen reader support and proper focus management
|
|
19
|
+
* - **Internationalization**: Automatic formatting based on locale
|
|
20
|
+
* - **Validation**: Built-in min/max date/time validation
|
|
21
|
+
* - **Form Integration**: Works seamlessly with HTML forms
|
|
22
|
+
*
|
|
23
|
+
* ## Usage
|
|
24
|
+
*
|
|
25
|
+
* ### Basic Usage
|
|
26
|
+
* ```tsx
|
|
27
|
+
* import { DateTimePicker } from '@bloomreach/react-banana-ui';
|
|
28
|
+
*
|
|
29
|
+
* function MyComponent() {
|
|
30
|
+
* const [value, setValue] = useState<Date | null>(new Date());
|
|
31
|
+
*
|
|
32
|
+
* return (
|
|
33
|
+
* <DateTimePicker
|
|
34
|
+
* value={value}
|
|
35
|
+
* onChange={(newValue) => setValue(newValue)}
|
|
36
|
+
* granularity="minute"
|
|
37
|
+
* />
|
|
38
|
+
* );
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* ### With Validation
|
|
43
|
+
* ```tsx
|
|
44
|
+
* <DateTimePicker
|
|
45
|
+
* value={value}
|
|
46
|
+
* onChange={(newValue, context) => {
|
|
47
|
+
* if (context.valid) {
|
|
48
|
+
* setValue(newValue);
|
|
49
|
+
* } else {
|
|
50
|
+
* setError(context.validationMessage.join(' '));
|
|
51
|
+
* }
|
|
52
|
+
* }}
|
|
53
|
+
* minDate={new Date('2024-01-01')}
|
|
54
|
+
* maxDate={new Date('2024-12-31')}
|
|
55
|
+
* granularity="second"
|
|
56
|
+
* required
|
|
57
|
+
* />
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* ## Accessibility
|
|
61
|
+
*
|
|
62
|
+
* The component follows WAI-ARIA guidelines for both date and time selection:
|
|
63
|
+
* - Proper focus management between input, calendar, and time selectors
|
|
64
|
+
* - Screen reader announcements for value changes
|
|
65
|
+
* - Keyboard navigation with arrow keys in calendar
|
|
66
|
+
* - Escape key to close, Enter/Space to open
|
|
67
|
+
* - Support for assistive technologies
|
|
68
|
+
*
|
|
69
|
+
* @param props - The props for the DateTimePicker component
|
|
70
|
+
* @param forwardedRef - Ref to be forwarded to the container element
|
|
71
|
+
* @returns A comprehensive date and time picker component
|
|
72
|
+
*/
|
|
73
|
+
declare const DateTimePicker: import('react').ForwardRefExoticComponent<DateTimePickerProps & import('react').RefAttributes<HTMLDivElement>>;
|
|
74
|
+
export default DateTimePicker;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DateTimePicker } from './index';
|
|
2
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
3
|
+
declare const meta: Meta<typeof DateTimePicker>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof DateTimePicker>;
|
|
6
|
+
export declare const Basic: Story;
|
|
7
|
+
export declare const WithInitialValue: Story;
|
|
8
|
+
export declare const Controlled: Story;
|
|
9
|
+
export declare const GranularityComparison: Story;
|
|
10
|
+
export declare const HourCycleComparison: Story;
|
|
11
|
+
export declare const WithMinMaxDates: Story;
|
|
12
|
+
export declare const ErrorState: Story;
|
|
13
|
+
export declare const Disabled: Story;
|
|
14
|
+
export declare const ReadOnly: Story;
|
|
15
|
+
export declare const LocaleComparison: Story;
|
|
16
|
+
export declare const WithTimezone: Story;
|
|
17
|
+
export declare const EventHandlers: Story;
|
|
18
|
+
export declare const ComplexValidation: Story;
|
|
19
|
+
export declare const FormIntegration: Story;
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { DateFieldAria, DatePickerAria } from '@react-aria/datepicker';
|
|
2
|
+
import { CalendarState } from '@react-stately/calendar';
|
|
3
|
+
import { DateFieldState, DatePickerState } from '@react-stately/datepicker';
|
|
4
|
+
import { DOMAttributes, FocusEventHandler, InputHTMLAttributes, KeyboardEventHandler, MouseEventHandler, RefObject } from 'react';
|
|
5
|
+
import { DateValidationResult } from '../../../utils/date';
|
|
6
|
+
import { ButtonProps } from '../../buttons';
|
|
7
|
+
/**
|
|
8
|
+
* Context object passed to the onChange handler of DateTimePicker.
|
|
9
|
+
* Contains validation information and state for error handling.
|
|
10
|
+
*/
|
|
11
|
+
export interface DateTimePickerChangeHandlerContext extends DateValidationResult {
|
|
12
|
+
/**
|
|
13
|
+
* Whether the current date/time value is valid.
|
|
14
|
+
*/
|
|
15
|
+
valid: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Props for the DateTimePicker component.
|
|
19
|
+
*
|
|
20
|
+
* The DateTimePicker combines date and time selection in a single component.
|
|
21
|
+
* It uses DateTimeInput for the input field and provides a popup with both
|
|
22
|
+
* calendar for date selection and time selectors for hour, minute, and second.
|
|
23
|
+
*/
|
|
24
|
+
export interface DateTimePickerProps {
|
|
25
|
+
/**
|
|
26
|
+
* Custom class name for the container of the dropdown component.
|
|
27
|
+
*/
|
|
28
|
+
className?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The date and time that is selected when the component first mounts (uncontrolled).
|
|
31
|
+
* Should be a JavaScript Date object representing the initial value.
|
|
32
|
+
*/
|
|
33
|
+
defaultValue?: Date;
|
|
34
|
+
/**
|
|
35
|
+
* Whether the date-time picker is disabled.
|
|
36
|
+
* When disabled, the user cannot interact with the picker and it appears grayed out.
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
39
|
+
disabled?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Whether the date-time picker is in an error state.
|
|
42
|
+
* When true, the picker will display error styling to indicate validation issues.
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
error?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* The <form> element to associate the input with.
|
|
48
|
+
* The value of this attribute must be the id of a <form> in the same document.
|
|
49
|
+
*/
|
|
50
|
+
form?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Determines which date and time segments are displayed and editable.
|
|
53
|
+
* - `'day'`: Shows only date segments (year, month, day)
|
|
54
|
+
* - `'hour'`: Shows date and hour segments
|
|
55
|
+
* - `'minute'`: Shows date, hour, and minute segments
|
|
56
|
+
* - `'second'`: Shows date, hour, minute, and second segments
|
|
57
|
+
* @default 'minute'
|
|
58
|
+
*/
|
|
59
|
+
granularity?: 'day' | 'hour' | 'minute' | 'second';
|
|
60
|
+
/**
|
|
61
|
+
* Whether to display time in 12 or 24 hour format.
|
|
62
|
+
* By default, this is determined by the user's locale.
|
|
63
|
+
* - `12`: Shows time in 12-hour format with AM/PM
|
|
64
|
+
* - `24`: Shows time in 24-hour format
|
|
65
|
+
* @default 12
|
|
66
|
+
*/
|
|
67
|
+
hourCycle?: 12 | 24;
|
|
68
|
+
/**
|
|
69
|
+
* The ID of the input element.
|
|
70
|
+
* Used for accessibility and form association.
|
|
71
|
+
*/
|
|
72
|
+
id?: string;
|
|
73
|
+
/**
|
|
74
|
+
* The locale to use for formatting the date and time.
|
|
75
|
+
* Follows BCP 47 language tag format (e.g., 'en-US', 'de-DE', 'ja-JP').
|
|
76
|
+
* When not provided, uses the user's browser locale.
|
|
77
|
+
* @example 'en-US', 'de-DE', 'fr-FR'
|
|
78
|
+
*/
|
|
79
|
+
locale?: string;
|
|
80
|
+
/**
|
|
81
|
+
* The maximum date and time that a user can enter.
|
|
82
|
+
* Dates after this value will be considered invalid.
|
|
83
|
+
* Should be a JavaScript Date object.
|
|
84
|
+
*/
|
|
85
|
+
maxDate?: Date;
|
|
86
|
+
/**
|
|
87
|
+
* The minimum date and time that a user can enter.
|
|
88
|
+
* Dates before this value will be considered invalid.
|
|
89
|
+
* Should be a JavaScript Date object.
|
|
90
|
+
*/
|
|
91
|
+
minDate?: Date;
|
|
92
|
+
/**
|
|
93
|
+
* The name of the input element, used when submitting an HTML form.
|
|
94
|
+
* See @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#name.
|
|
95
|
+
*/
|
|
96
|
+
name?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Handler that is called when the input loses focus.
|
|
99
|
+
* Receives the blur event from the date/time input.
|
|
100
|
+
*/
|
|
101
|
+
onBlur?: FocusEventHandler<Element>;
|
|
102
|
+
/**
|
|
103
|
+
* Handler that is called when the date/time value changes.
|
|
104
|
+
* Receives the new Date object or null if the input is cleared,
|
|
105
|
+
* along with a context object containing validation information.
|
|
106
|
+
*
|
|
107
|
+
* @param value - The new date/time value as a Date object, or null if cleared
|
|
108
|
+
* @param context - Validation context with validity state and messages
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```tsx
|
|
112
|
+
* const handleChange = (value: Date | null, context: DateTimePickerChangeHandlerContext) => {
|
|
113
|
+
* if (context.valid && value) {
|
|
114
|
+
* console.log('Valid date/time selected:', value.toISOString());
|
|
115
|
+
* } else {
|
|
116
|
+
* console.log('Invalid date/time or validation errors:', context.validationMessage);
|
|
117
|
+
* }
|
|
118
|
+
* };
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
onChange?: (value: Date | null, context: DateTimePickerChangeHandlerContext) => void;
|
|
122
|
+
/**
|
|
123
|
+
* Handler that is called when the input is clicked.
|
|
124
|
+
* Can be used to programmatically open the picker.
|
|
125
|
+
*/
|
|
126
|
+
onClick?: MouseEventHandler<Element>;
|
|
127
|
+
/**
|
|
128
|
+
* Handler that is called when the input receives focus.
|
|
129
|
+
* Receives the focus event from the date/time input.
|
|
130
|
+
*/
|
|
131
|
+
onFocus?: FocusEventHandler<Element>;
|
|
132
|
+
/**
|
|
133
|
+
* Handler that is called when a key is pressed within the input.
|
|
134
|
+
* Receives keyboard events from the date/time input.
|
|
135
|
+
*/
|
|
136
|
+
onKeyDown?: KeyboardEventHandler<Element>;
|
|
137
|
+
/**
|
|
138
|
+
* Handler that is called when a key is released within the input.
|
|
139
|
+
* Receives keyboard events from the date/time input.
|
|
140
|
+
*/
|
|
141
|
+
onKeyUp?: KeyboardEventHandler<Element>;
|
|
142
|
+
/**
|
|
143
|
+
* Handler that is called when the popup with calendar and time selectors changes state.
|
|
144
|
+
* Use this to track when the picker is opened or closed.
|
|
145
|
+
*
|
|
146
|
+
* @param open - Whether the popup is currently open
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```tsx
|
|
150
|
+
* const handleOpenChange = (open: boolean) => {
|
|
151
|
+
* console.log(open ? 'Picker opened' : 'Picker closed');
|
|
152
|
+
* };
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
onOpenChange?: (open: boolean) => void;
|
|
156
|
+
/**
|
|
157
|
+
* A placeholder date that influences the format and default values of empty segments.
|
|
158
|
+
* This date is used to determine the format and structure but is not the actual value.
|
|
159
|
+
* Useful for setting the year when only month/day are relevant, or timezone context.
|
|
160
|
+
* Defaults to today's date.
|
|
161
|
+
*
|
|
162
|
+
* @default new Date()
|
|
163
|
+
* @example new Date('2024-12-31T23:59:59') // Shows full format structure
|
|
164
|
+
*/
|
|
165
|
+
placeholderValue?: Date;
|
|
166
|
+
/**
|
|
167
|
+
* Whether the date-time picker is read-only.
|
|
168
|
+
* When true, the user can see the value but cannot edit it.
|
|
169
|
+
* The picker will still be focusable and the popup can be opened to view the calendar.
|
|
170
|
+
* @default false
|
|
171
|
+
*/
|
|
172
|
+
readOnly?: boolean;
|
|
173
|
+
/**
|
|
174
|
+
* Whether the date-time picker is required for form submission.
|
|
175
|
+
* When true, the picker must have a value for the form to be valid.
|
|
176
|
+
* @default false
|
|
177
|
+
*/
|
|
178
|
+
required?: boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Whether to show the timezone in the date and time picker.
|
|
181
|
+
* @default false
|
|
182
|
+
*/
|
|
183
|
+
showTimezone?: boolean;
|
|
184
|
+
/**
|
|
185
|
+
* The current date and time value (controlled).
|
|
186
|
+
* Should be a JavaScript Date object representing the current value,
|
|
187
|
+
* or null if no value is selected.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```tsx
|
|
191
|
+
* const [value, setValue] = useState<Date | null>(new Date());
|
|
192
|
+
* return <DateTimePicker value={value} onChange={(newValue) => setValue(newValue)} />;
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
value?: Date | null;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Return type for the useDateTimePicker hook.
|
|
199
|
+
*/
|
|
200
|
+
export interface UseDateTimePickerReturn {
|
|
201
|
+
/** Calendar-related props and state */
|
|
202
|
+
calendarProps: {
|
|
203
|
+
/** Props for the calendar component */
|
|
204
|
+
calendarProps: DOMAttributes<HTMLElement>;
|
|
205
|
+
/** Ref for the calendar component */
|
|
206
|
+
calendarRef: RefObject<HTMLDivElement>;
|
|
207
|
+
/** Calendar state object for date selection */
|
|
208
|
+
calendarState: CalendarState;
|
|
209
|
+
/** Props for the next month button */
|
|
210
|
+
nextButtonProps: Omit<ButtonProps, 'type'>;
|
|
211
|
+
/** Props for the previous month button */
|
|
212
|
+
prevButtonProps: Omit<ButtonProps, 'type'>;
|
|
213
|
+
/** Calendar title string */
|
|
214
|
+
title: string;
|
|
215
|
+
};
|
|
216
|
+
/** Date field-related props and state */
|
|
217
|
+
dateFieldProps: {
|
|
218
|
+
/** Ref for the date field hidden input component */
|
|
219
|
+
dateFieldInputRef: RefObject<HTMLInputElement>;
|
|
220
|
+
/** Props for the date field component */
|
|
221
|
+
dateFieldProps: DateFieldAria['fieldProps'];
|
|
222
|
+
/** Ref for the date field component */
|
|
223
|
+
dateFieldRef: RefObject<HTMLElement>;
|
|
224
|
+
/** Date field state object */
|
|
225
|
+
dateFieldState: DateFieldState;
|
|
226
|
+
/** Props for the input group container */
|
|
227
|
+
groupProps: DatePickerAria['groupProps'];
|
|
228
|
+
/** Props for the hidden input element */
|
|
229
|
+
hiddenInputProps: InputHTMLAttributes<HTMLInputElement>;
|
|
230
|
+
};
|
|
231
|
+
/** The React Aria date picker state object */
|
|
232
|
+
datePickerState: DatePickerState;
|
|
233
|
+
/** Props for the popup component */
|
|
234
|
+
popupProps: {
|
|
235
|
+
/** Props for the popup dialog container */
|
|
236
|
+
dialogProps: DatePickerAria['dialogProps'];
|
|
237
|
+
};
|
|
238
|
+
/** Time field-related props and handlers */
|
|
239
|
+
timeFieldProps: {
|
|
240
|
+
/** Handler for time value changes */
|
|
241
|
+
onTimeChange: (newTime: Date) => void;
|
|
242
|
+
/** Current time value as a Date object */
|
|
243
|
+
timeValue: Date | null;
|
|
244
|
+
};
|
|
245
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { DateTimePickerProps, UseDateTimePickerReturn } from './date-time-picker.types';
|
|
3
|
+
/**
|
|
4
|
+
* Custom hook for the DateTimePicker component.
|
|
5
|
+
*
|
|
6
|
+
* This hook manages the interaction between the DateTimeInput, Calendar, and TimeSelectorPanel
|
|
7
|
+
* components. It handles state synchronization, focus management, and event coordination
|
|
8
|
+
* between the different parts of the date-time picker.
|
|
9
|
+
*
|
|
10
|
+
* ## Features
|
|
11
|
+
*
|
|
12
|
+
* - **Unified State Management**: Coordinates date and time state across components
|
|
13
|
+
* - **Focus Management**: Handles focus trapping and keyboard navigation
|
|
14
|
+
* - **Event Coordination**: Manages opening/closing and value updates
|
|
15
|
+
* - **Input Integration**: Provides props for DateTimeInput component
|
|
16
|
+
* - **Calendar Integration**: Manages calendar state and interactions
|
|
17
|
+
* - **Time Integration**: Handles time selector state and changes
|
|
18
|
+
*
|
|
19
|
+
* @param props - DateTimePicker component props
|
|
20
|
+
* @param ref - React ref to the container element
|
|
21
|
+
* @returns Object with calendar state, input props, and time handling
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* const state = useDateTimePickerState(props);
|
|
26
|
+
* const {
|
|
27
|
+
* calendarState,
|
|
28
|
+
* dateTimeInputProps,
|
|
29
|
+
* lockFocus,
|
|
30
|
+
* timeValue,
|
|
31
|
+
* onTimeChange
|
|
32
|
+
* } = useDateTimePicker(props, state);
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const useDateTimePicker: (props: DateTimePickerProps, ref: RefObject<Element>) => UseDateTimePickerReturn;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { DateTimeRangePickerProps } from './date-time-range-picker.types';
|
|
2
|
+
/**
|
|
3
|
+
* DateTimeRangePicker is a composite component that allows users to select a range of dates and times.
|
|
4
|
+
* It combines two DateTimeInput components for start and end values with a popup containing
|
|
5
|
+
* a calendar for date selection and time selectors for precise time control.
|
|
6
|
+
*
|
|
7
|
+
* Built on top of React Aria's date range picker primitives with extended time support.
|
|
8
|
+
* The component automatically handles keyboard navigation, accessibility, and
|
|
9
|
+
* internationalization for both date and time components.
|
|
10
|
+
*
|
|
11
|
+
* ## Features
|
|
12
|
+
*
|
|
13
|
+
* - **Unified Date/Time Range Selection**: Single component for both date and time ranges
|
|
14
|
+
* - **Dual Input Fields**: Separate inputs for start and end date/time
|
|
15
|
+
* - **Calendar Integration**: Full calendar for date range selection
|
|
16
|
+
* - **Time Selectors**: Dropdown selectors for hour, minute, and second
|
|
17
|
+
* - **Granularity Control**: Configure precision from day to second level
|
|
18
|
+
* - **Keyboard Navigation**: Full keyboard support with Enter/Space to open
|
|
19
|
+
* - **Accessibility**: Screen reader support and proper focus management
|
|
20
|
+
* - **Internationalization**: Automatic formatting based on locale
|
|
21
|
+
* - **Validation**: Built-in min/max date/time validation
|
|
22
|
+
* - **Form Integration**: Works seamlessly with HTML forms
|
|
23
|
+
*
|
|
24
|
+
* ## Usage
|
|
25
|
+
*
|
|
26
|
+
* ### Basic Usage
|
|
27
|
+
* ```tsx
|
|
28
|
+
* import { DateTimeRangePicker } from '@bloomreach/react-banana-ui';
|
|
29
|
+
*
|
|
30
|
+
* function MyComponent() {
|
|
31
|
+
* const [value, setValue] = useState<DateRangeValue | null>({
|
|
32
|
+
* start: new Date('2024-01-01T09:00:00'),
|
|
33
|
+
* end: new Date('2024-01-01T17:00:00')
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* return (
|
|
37
|
+
* <DateTimeRangePicker
|
|
38
|
+
* value={value}
|
|
39
|
+
* onChange={(newValue) => setValue(newValue)}
|
|
40
|
+
* granularity="minute"
|
|
41
|
+
* />
|
|
42
|
+
* );
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* ### With Validation
|
|
47
|
+
* ```tsx
|
|
48
|
+
* <DateTimeRangePicker
|
|
49
|
+
* value={value}
|
|
50
|
+
* onChange={(newValue, context) => {
|
|
51
|
+
* if (context.valid) {
|
|
52
|
+
* setValue(newValue);
|
|
53
|
+
* } else {
|
|
54
|
+
* setError(context.validationMessage.join(' '));
|
|
55
|
+
* }
|
|
56
|
+
* }}
|
|
57
|
+
* minDate={new Date('2024-01-01')}
|
|
58
|
+
* maxDate={new Date('2024-12-31')}
|
|
59
|
+
* granularity="second"
|
|
60
|
+
* required
|
|
61
|
+
* />
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* ### Different Granularities
|
|
65
|
+
* ```tsx
|
|
66
|
+
* // Date range only
|
|
67
|
+
* <DateTimeRangePicker granularity="day" />
|
|
68
|
+
*
|
|
69
|
+
* // Date and hour range
|
|
70
|
+
* <DateTimeRangePicker granularity="hour" />
|
|
71
|
+
*
|
|
72
|
+
* // Date, hour, and minute range (default)
|
|
73
|
+
* <DateTimeRangePicker granularity="minute" />
|
|
74
|
+
*
|
|
75
|
+
* // Full precision with seconds
|
|
76
|
+
* <DateTimeRangePicker granularity="second" />
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* ## Accessibility
|
|
80
|
+
*
|
|
81
|
+
* The component follows WAI-ARIA guidelines for both date and time selection:
|
|
82
|
+
* - Proper focus management between inputs, calendar, and time selectors
|
|
83
|
+
* - Screen reader announcements for value changes
|
|
84
|
+
* - Keyboard navigation with arrow keys in calendar
|
|
85
|
+
* - Escape key to close, Enter/Space to open
|
|
86
|
+
* - Support for assistive technologies
|
|
87
|
+
* - Proper labeling and role attributes
|
|
88
|
+
*
|
|
89
|
+
* @param props - The props for the DateTimeRangePicker component
|
|
90
|
+
* @param forwardedRef - Ref to be forwarded to the container element
|
|
91
|
+
* @returns A comprehensive date and time range picker component
|
|
92
|
+
*/
|
|
93
|
+
declare const DateTimeRangePicker: import('react').ForwardRefExoticComponent<DateTimeRangePickerProps & import('react').RefAttributes<HTMLDivElement>>;
|
|
94
|
+
export default DateTimeRangePicker;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DateTimeRangePicker } from './index';
|
|
2
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
3
|
+
declare const meta: Meta<typeof DateTimeRangePicker>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof DateTimeRangePicker>;
|
|
6
|
+
export declare const Basic: Story;
|
|
7
|
+
export declare const WithInitialValue: Story;
|
|
8
|
+
export declare const Controlled: Story;
|
|
9
|
+
export declare const GranularityComparison: Story;
|
|
10
|
+
export declare const HourCycleComparison: Story;
|
|
11
|
+
export declare const WithMinMaxDates: Story;
|
|
12
|
+
export declare const ErrorState: Story;
|
|
13
|
+
export declare const Disabled: Story;
|
|
14
|
+
export declare const ReadOnly: Story;
|
|
15
|
+
export declare const LocaleComparison: Story;
|
|
16
|
+
export declare const WithTimezoneDisplay: Story;
|
|
17
|
+
export declare const RangeScenarios: Story;
|
|
18
|
+
export declare const InteractiveDemo: Story;
|
|
19
|
+
export declare const ComplexValidation: Story;
|