@xsolla/xui-date-picker 0.117.0 → 0.118.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Date Picker
2
2
 
3
- A cross-platform React date picker component with an input field that opens a calendar dropdown for date selection.
3
+ A cross-platform React date picker component with an input field that opens a calendar dropdown for date selection. The calendar is provided by `@xsolla/xui-calendar`.
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,6 +10,8 @@ npm install @xsolla/xui-date-picker
10
10
  yarn add @xsolla/xui-date-picker
11
11
  ```
12
12
 
13
+ > The `Calendar`, `DualCalendar`, `CalendarChips`, and related components are available from `@xsolla/xui-calendar` and are re-exported from this package for backward compatibility. For standalone calendar usage (without the input), install `@xsolla/xui-calendar` directly.
14
+
13
15
  ## Demo
14
16
 
15
17
  ### Single Date Selection
@@ -56,150 +58,57 @@ export default function DateRange() {
56
58
  }
57
59
  ```
58
60
 
59
- ### Different Sizes
60
-
61
- ```tsx
62
- import * as React from 'react';
63
- import { DatePicker } from '@xsolla/xui-date-picker';
64
-
65
- export default function Sizes() {
66
- return (
67
- <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
68
- <DatePicker size="sm" placeholder="Small" />
69
- <DatePicker size="md" placeholder="Medium" />
70
- <DatePicker size="lg" placeholder="Large" />
71
- </div>
72
- );
73
- }
74
- ```
75
-
76
- ## Anatomy
77
-
78
- ```jsx
79
- import { DatePicker } from '@xsolla/xui-date-picker';
80
-
81
- <DatePicker
82
- selectedDate={date} // Selected date (single mode)
83
- startDate={startDate} // Start date (range mode)
84
- endDate={endDate} // End date (range mode)
85
- selectsRange={false} // Enable range selection
86
- onChange={handleChange} // Change callback
87
- size="md" // Input size
88
- locale="enUS" // Date locale
89
- placeholder="MM/DD/YYYY" // Input placeholder
90
- backgroundColor={color} // Custom background
91
- />
92
- ```
93
-
94
- ## Examples
95
-
96
- ### With Initial Date
61
+ ### With Preset Chips
97
62
 
98
63
  ```tsx
99
64
  import * as React from 'react';
100
65
  import { DatePicker } from '@xsolla/xui-date-picker';
101
66
 
102
- export default function InitialDate() {
103
- const [date, setDate] = React.useState<Date>(new Date(2024, 0, 15));
104
-
105
- return (
106
- <DatePicker
107
- selectedDate={date}
108
- onChange={(newDate) => setDate(newDate as Date)}
109
- />
110
- );
111
- }
112
- ```
113
-
114
- ### With Date Constraints
115
-
116
- ```tsx
117
- import * as React from 'react';
118
- import { DatePicker } from '@xsolla/xui-date-picker';
67
+ const chips = [
68
+ { label: 'Today', value: 'today' },
69
+ { label: 'Last 7 days', value: 'last7' },
70
+ { label: 'Last 30 days', value: 'last30' },
71
+ ];
119
72
 
120
- export default function DateConstraints() {
73
+ export default function WithChips() {
121
74
  const [date, setDate] = React.useState<Date | null>(null);
122
- const today = new Date();
123
- const nextMonth = new Date(today.getFullYear(), today.getMonth() + 1, today.getDate());
75
+ const [activeChip, setActiveChip] = React.useState<string | null>('last30');
124
76
 
125
77
  return (
126
78
  <DatePicker
127
79
  selectedDate={date}
128
80
  onChange={(newDate) => setDate(newDate as Date)}
129
- minDate={today}
130
- maxDate={nextMonth}
131
- placeholder="Select within next 30 days"
81
+ chips={chips}
82
+ activeChip={activeChip}
83
+ onChipSelect={setActiveChip}
132
84
  />
133
85
  );
134
86
  }
135
87
  ```
136
88
 
137
- ### Booking Date Range
89
+ ### Different Sizes
138
90
 
139
91
  ```tsx
140
92
  import * as React from 'react';
141
93
  import { DatePicker } from '@xsolla/xui-date-picker';
142
94
 
143
- export default function BookingRange() {
144
- const [startDate, setStartDate] = React.useState<Date | null>(null);
145
- const [endDate, setEndDate] = React.useState<Date | null>(null);
146
-
147
- const handleChange = (range: [Date | null, Date | null]) => {
148
- const [start, end] = range;
149
- setStartDate(start);
150
- setEndDate(end);
151
-
152
- if (start && end) {
153
- const nights = Math.ceil((end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
154
- console.log(`${nights} night(s) selected`);
155
- }
156
- };
157
-
95
+ export default function Sizes() {
158
96
  return (
159
- <div>
160
- <DatePicker
161
- selectsRange
162
- startDate={startDate}
163
- endDate={endDate}
164
- onChange={handleChange}
165
- placeholder="Check-in - Check-out"
166
- />
167
- {startDate && endDate && (
168
- <p>
169
- {startDate.toLocaleDateString()} to {endDate.toLocaleDateString()}
170
- </p>
171
- )}
97
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
98
+ <DatePicker size="sm" placeholder="Small" />
99
+ <DatePicker size="md" placeholder="Medium" />
100
+ <DatePicker size="lg" placeholder="Large" />
172
101
  </div>
173
102
  );
174
103
  }
175
104
  ```
176
105
 
177
- ### With Locale
106
+ ### Standalone Calendar
178
107
 
179
- ```tsx
180
- import * as React from 'react';
181
- import { DatePicker } from '@xsolla/xui-date-picker';
108
+ For standalone calendar usage, import from `@xsolla/xui-calendar`:
182
109
 
183
- export default function LocalizedPicker() {
184
- const [date, setDate] = React.useState<Date | null>(null);
185
-
186
- return (
187
- <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
188
- <DatePicker
189
- selectedDate={date}
190
- onChange={(d) => setDate(d as Date)}
191
- locale="enUS"
192
- placeholder="English (US)"
193
- />
194
- <DatePicker
195
- selectedDate={date}
196
- onChange={(d) => setDate(d as Date)}
197
- locale="de"
198
- placeholder="German"
199
- />
200
- </div>
201
- );
202
- }
110
+ ```tsx
111
+ import { Calendar, DualCalendar } from '@xsolla/xui-calendar';
203
112
  ```
204
113
 
205
114
  ## API Reference
@@ -221,6 +130,9 @@ export default function LocalizedPicker() {
221
130
  | minDate | `Date` | - | Minimum selectable date. |
222
131
  | maxDate | `Date` | - | Maximum selectable date. |
223
132
  | backgroundColor | `string` | - | Custom background color. |
133
+ | chips | `CalendarChipOption[]` | - | Preset date range chips. |
134
+ | activeChip | `string \| null` | - | Currently active chip value. |
135
+ | onChipSelect | `(value: string) => void` | - | Chip selection callback. |
224
136
  | testID | `string` | - | Test identifier. |
225
137
 
226
138
  ## Date Format
@@ -240,6 +152,7 @@ The component displays dates in `MM/DD/YYYY` format:
240
152
  - **Selected state**: Selected date(s) have distinct styling
241
153
  - **Range highlighting**: Dates between start and end are highlighted
242
154
  - **Disabled dates**: Dates outside min/max range are disabled
155
+ - **Preset chips**: Quick-select date ranges (Today, Last 7 days, etc.)
243
156
 
244
157
  ## Behavior
245
158
 
@@ -1,71 +1,7 @@
1
+ import { CalendarProps, CalendarLocaleType } from '@xsolla/xui-calendar';
2
+ export { Calendar, CalendarChipOption, CalendarChips, CalendarChipsProps, CalendarGrid, CalendarGridProps, CalendarHeader, CalendarHeaderProps, CalendarLocaleType, CalendarProps, DualCalendar, DualCalendarProps } from '@xsolla/xui-calendar';
1
3
  import * as react from 'react';
2
- import { ReactNode } from 'react';
3
- import * as locales from 'date-fns/locale';
4
4
 
5
- type CalendarLocaleType = keyof typeof locales;
6
- interface CalendarProps {
7
- locale?: CalendarLocaleType;
8
- /**
9
- * The day to use as first day of the week, starting from 0 (Sunday) to 6 (Saturday).
10
- */
11
- firstDayOfWeek?: number;
12
- /**
13
- * The month to display in the calendar at first render.
14
- */
15
- initialMonth?: Date;
16
- /**
17
- * The month to display in the calendar.
18
- */
19
- month?: Date;
20
- /**
21
- * Select in range mode for calendar
22
- */
23
- selectsRange?: boolean;
24
- /**
25
- * The minimum selectable date
26
- */
27
- minDate?: Date | null;
28
- /**
29
- * The maximum selectable date
30
- */
31
- maxDate?: Date | null;
32
- /**
33
- * For range mode. Start date in selected period
34
- */
35
- startDate?: Date | null;
36
- /**
37
- * For range mode. End date in selected period
38
- */
39
- endDate?: Date | null;
40
- /**
41
- * The selected date
42
- */
43
- selectedDate?: Date | null;
44
- /**
45
- * Property sets the maximum height of a context menus for selecting month and year.
46
- */
47
- contextMenuMaxHeight?: number;
48
- /**
49
- * Returns custom content to display above the calendar's date picker.
50
- */
51
- topContent?: (datePicker: {
52
- close: () => void;
53
- }) => ReactNode;
54
- /**
55
- * Returns custom content to display beneath the calendar's date picker.
56
- */
57
- bottomContent?: (datePicker: {
58
- close: () => void;
59
- }) => ReactNode;
60
- /**
61
- * Test ID for testing frameworks
62
- */
63
- testID?: string;
64
- /**
65
- * Callback fired when the date changes
66
- */
67
- onChange?: (date: Date | [Date | null, Date | null]) => void;
68
- }
69
5
  type DateRangeType = [Date | null, Date | null];
70
6
  interface DatePickerProps extends Omit<CalendarProps, "onChange"> {
71
7
  /**
@@ -92,9 +28,6 @@ interface DatePickerProps extends Omit<CalendarProps, "onChange"> {
92
28
 
93
29
  declare const DatePicker: react.ForwardRefExoticComponent<DatePickerProps & react.RefAttributes<any>>;
94
30
 
95
- declare const Calendar: react.ForwardRefExoticComponent<CalendarProps & react.RefAttributes<any>>;
96
-
97
31
  declare function formatDate(date: Date, formatStr: string, locale?: CalendarLocaleType): string;
98
- declare function getMonthInLocale(month: number, locale?: CalendarLocaleType): string;
99
32
 
100
- export { Calendar, type CalendarLocaleType, type CalendarProps, DatePicker, type DatePickerProps, type DateRangeType, formatDate, getMonthInLocale };
33
+ export { DatePicker, type DatePickerProps, type DateRangeType, formatDate };
package/native/index.d.ts CHANGED
@@ -1,71 +1,7 @@
1
+ import { CalendarProps, CalendarLocaleType } from '@xsolla/xui-calendar';
2
+ export { Calendar, CalendarChipOption, CalendarChips, CalendarChipsProps, CalendarGrid, CalendarGridProps, CalendarHeader, CalendarHeaderProps, CalendarLocaleType, CalendarProps, DualCalendar, DualCalendarProps } from '@xsolla/xui-calendar';
1
3
  import * as react from 'react';
2
- import { ReactNode } from 'react';
3
- import * as locales from 'date-fns/locale';
4
4
 
5
- type CalendarLocaleType = keyof typeof locales;
6
- interface CalendarProps {
7
- locale?: CalendarLocaleType;
8
- /**
9
- * The day to use as first day of the week, starting from 0 (Sunday) to 6 (Saturday).
10
- */
11
- firstDayOfWeek?: number;
12
- /**
13
- * The month to display in the calendar at first render.
14
- */
15
- initialMonth?: Date;
16
- /**
17
- * The month to display in the calendar.
18
- */
19
- month?: Date;
20
- /**
21
- * Select in range mode for calendar
22
- */
23
- selectsRange?: boolean;
24
- /**
25
- * The minimum selectable date
26
- */
27
- minDate?: Date | null;
28
- /**
29
- * The maximum selectable date
30
- */
31
- maxDate?: Date | null;
32
- /**
33
- * For range mode. Start date in selected period
34
- */
35
- startDate?: Date | null;
36
- /**
37
- * For range mode. End date in selected period
38
- */
39
- endDate?: Date | null;
40
- /**
41
- * The selected date
42
- */
43
- selectedDate?: Date | null;
44
- /**
45
- * Property sets the maximum height of a context menus for selecting month and year.
46
- */
47
- contextMenuMaxHeight?: number;
48
- /**
49
- * Returns custom content to display above the calendar's date picker.
50
- */
51
- topContent?: (datePicker: {
52
- close: () => void;
53
- }) => ReactNode;
54
- /**
55
- * Returns custom content to display beneath the calendar's date picker.
56
- */
57
- bottomContent?: (datePicker: {
58
- close: () => void;
59
- }) => ReactNode;
60
- /**
61
- * Test ID for testing frameworks
62
- */
63
- testID?: string;
64
- /**
65
- * Callback fired when the date changes
66
- */
67
- onChange?: (date: Date | [Date | null, Date | null]) => void;
68
- }
69
5
  type DateRangeType = [Date | null, Date | null];
70
6
  interface DatePickerProps extends Omit<CalendarProps, "onChange"> {
71
7
  /**
@@ -92,9 +28,6 @@ interface DatePickerProps extends Omit<CalendarProps, "onChange"> {
92
28
 
93
29
  declare const DatePicker: react.ForwardRefExoticComponent<DatePickerProps & react.RefAttributes<any>>;
94
30
 
95
- declare const Calendar: react.ForwardRefExoticComponent<CalendarProps & react.RefAttributes<any>>;
96
-
97
31
  declare function formatDate(date: Date, formatStr: string, locale?: CalendarLocaleType): string;
98
- declare function getMonthInLocale(month: number, locale?: CalendarLocaleType): string;
99
32
 
100
- export { Calendar, type CalendarLocaleType, type CalendarProps, DatePicker, type DatePickerProps, type DateRangeType, formatDate, getMonthInLocale };
33
+ export { DatePicker, type DatePickerProps, type DateRangeType, formatDate };