@xsolla/xui-date-picker 0.99.0 → 0.101.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 +236 -25
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,46 +1,257 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Date Picker
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A cross-platform React date picker component with an input field that opens a calendar dropdown for date selection.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
+
npm install @xsolla/xui-date-picker
|
|
9
|
+
# or
|
|
8
10
|
yarn add @xsolla/xui-date-picker
|
|
9
11
|
```
|
|
10
12
|
|
|
11
|
-
##
|
|
13
|
+
## Demo
|
|
14
|
+
|
|
15
|
+
### Single Date Selection
|
|
12
16
|
|
|
13
17
|
```tsx
|
|
18
|
+
import * as React from 'react';
|
|
14
19
|
import { DatePicker } from '@xsolla/xui-date-picker';
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
export default function SingleDate() {
|
|
22
|
+
const [date, setDate] = React.useState<Date | null>(null);
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<DatePicker
|
|
26
|
+
selectedDate={date}
|
|
27
|
+
onChange={(newDate) => setDate(newDate as Date)}
|
|
28
|
+
placeholder="Select a date"
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Date Range Selection
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
import * as React from 'react';
|
|
38
|
+
import { DatePicker } from '@xsolla/xui-date-picker';
|
|
39
|
+
|
|
40
|
+
export default function DateRange() {
|
|
41
|
+
const [startDate, setStartDate] = React.useState<Date | null>(null);
|
|
42
|
+
const [endDate, setEndDate] = React.useState<Date | null>(null);
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<DatePicker
|
|
46
|
+
selectsRange
|
|
47
|
+
startDate={startDate}
|
|
48
|
+
endDate={endDate}
|
|
49
|
+
onChange={(range) => {
|
|
50
|
+
const [start, end] = range as [Date | null, Date | null];
|
|
51
|
+
setStartDate(start);
|
|
52
|
+
setEndDate(end);
|
|
53
|
+
}}
|
|
54
|
+
/>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
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';
|
|
20
80
|
|
|
21
|
-
{/* Range mode */}
|
|
22
81
|
<DatePicker
|
|
23
|
-
|
|
24
|
-
startDate={
|
|
25
|
-
endDate={
|
|
26
|
-
|
|
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
|
|
27
91
|
/>
|
|
28
92
|
```
|
|
29
93
|
|
|
30
|
-
##
|
|
94
|
+
## Examples
|
|
95
|
+
|
|
96
|
+
### With Initial Date
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
import * as React from 'react';
|
|
100
|
+
import { DatePicker } from '@xsolla/xui-date-picker';
|
|
101
|
+
|
|
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';
|
|
119
|
+
|
|
120
|
+
export default function DateConstraints() {
|
|
121
|
+
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());
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<DatePicker
|
|
127
|
+
selectedDate={date}
|
|
128
|
+
onChange={(newDate) => setDate(newDate as Date)}
|
|
129
|
+
minDate={today}
|
|
130
|
+
maxDate={nextMonth}
|
|
131
|
+
placeholder="Select within next 30 days"
|
|
132
|
+
/>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Booking Date Range
|
|
138
|
+
|
|
139
|
+
```tsx
|
|
140
|
+
import * as React from 'react';
|
|
141
|
+
import { DatePicker } from '@xsolla/xui-date-picker';
|
|
142
|
+
|
|
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
|
+
|
|
158
|
+
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
|
+
)}
|
|
172
|
+
</div>
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### With Locale
|
|
178
|
+
|
|
179
|
+
```tsx
|
|
180
|
+
import * as React from 'react';
|
|
181
|
+
import { DatePicker } from '@xsolla/xui-date-picker';
|
|
182
|
+
|
|
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
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## API Reference
|
|
31
206
|
|
|
32
207
|
### DatePicker
|
|
33
208
|
|
|
209
|
+
**DatePickerProps:**
|
|
210
|
+
|
|
34
211
|
| Prop | Type | Default | Description |
|
|
35
|
-
|
|
36
|
-
|
|
|
37
|
-
|
|
|
38
|
-
|
|
|
39
|
-
|
|
|
40
|
-
|
|
|
41
|
-
|
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
|
|
|
45
|
-
|
|
|
46
|
-
|
|
|
212
|
+
| :--- | :--- | :------ | :---------- |
|
|
213
|
+
| selectedDate | `Date` | - | Selected date for single mode. |
|
|
214
|
+
| startDate | `Date` | - | Start date for range mode. |
|
|
215
|
+
| endDate | `Date` | - | End date for range mode. |
|
|
216
|
+
| selectsRange | `boolean` | `false` | Enable date range selection. |
|
|
217
|
+
| onChange | `(date: Date \| [Date, Date]) => void` | - | Date change callback. |
|
|
218
|
+
| size | `"xs" \| "sm" \| "md" \| "lg" \| "xl"` | `"md"` | Input size variant. |
|
|
219
|
+
| locale | `string` | `"enUS"` | Date-fns locale identifier. |
|
|
220
|
+
| placeholder | `string` | `"MM/DD/YYYY"` | Input placeholder text. |
|
|
221
|
+
| minDate | `Date` | - | Minimum selectable date. |
|
|
222
|
+
| maxDate | `Date` | - | Maximum selectable date. |
|
|
223
|
+
| backgroundColor | `string` | - | Custom background color. |
|
|
224
|
+
| testID | `string` | - | Test identifier. |
|
|
225
|
+
|
|
226
|
+
## Date Format
|
|
227
|
+
|
|
228
|
+
The component displays dates in `MM/DD/YYYY` format:
|
|
229
|
+
|
|
230
|
+
| Mode | Display Format |
|
|
231
|
+
| :--- | :------------- |
|
|
232
|
+
| Single | `01/15/2024` |
|
|
233
|
+
| Range | `01/15/2024 - 01/20/2024` |
|
|
234
|
+
|
|
235
|
+
## Calendar Features
|
|
236
|
+
|
|
237
|
+
- **Month navigation**: Previous/next month buttons
|
|
238
|
+
- **Year navigation**: Year selection dropdown
|
|
239
|
+
- **Today indicator**: Current date is highlighted
|
|
240
|
+
- **Selected state**: Selected date(s) have distinct styling
|
|
241
|
+
- **Range highlighting**: Dates between start and end are highlighted
|
|
242
|
+
- **Disabled dates**: Dates outside min/max range are disabled
|
|
243
|
+
|
|
244
|
+
## Behavior
|
|
245
|
+
|
|
246
|
+
- Calendar opens on input focus
|
|
247
|
+
- Calendar closes when a date is selected (single mode)
|
|
248
|
+
- Calendar closes when both dates are selected (range mode)
|
|
249
|
+
- Clicking outside closes the calendar
|
|
250
|
+
- Input value updates immediately on selection
|
|
251
|
+
|
|
252
|
+
## Accessibility
|
|
253
|
+
|
|
254
|
+
- Input is keyboard accessible
|
|
255
|
+
- Calendar dates are navigable via keyboard
|
|
256
|
+
- Selected dates are announced to screen readers
|
|
257
|
+
- Focus is managed when calendar opens/closes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xsolla/xui-date-picker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.101.0",
|
|
4
4
|
"main": "./web/index.js",
|
|
5
5
|
"module": "./web/index.mjs",
|
|
6
6
|
"types": "./web/index.d.ts",
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
"build:native": "PLATFORM=native tsup"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@xsolla/xui-button": "0.
|
|
14
|
-
"@xsolla/xui-core": "0.
|
|
15
|
-
"@xsolla/xui-input": "0.
|
|
16
|
-
"@xsolla/xui-primitives-core": "0.
|
|
17
|
-
"@xsolla/xui-select": "0.
|
|
13
|
+
"@xsolla/xui-button": "0.101.0",
|
|
14
|
+
"@xsolla/xui-core": "0.101.0",
|
|
15
|
+
"@xsolla/xui-input": "0.101.0",
|
|
16
|
+
"@xsolla/xui-primitives-core": "0.101.0",
|
|
17
|
+
"@xsolla/xui-select": "0.101.0",
|
|
18
18
|
"date-fns": "^3.0.0"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|