@xsolla/xui-date-picker 0.148.0 → 0.148.1
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 +170 -0
- package/package.json +5 -5
package/README.md
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# Date Picker
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @xsolla/xui-date-picker
|
|
9
|
+
# or
|
|
10
|
+
yarn add @xsolla/xui-date-picker
|
|
11
|
+
```
|
|
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
|
+
|
|
15
|
+
## Demo
|
|
16
|
+
|
|
17
|
+
### Single Date Selection
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import * as React from 'react';
|
|
21
|
+
import { DatePicker } from '@xsolla/xui-date-picker';
|
|
22
|
+
|
|
23
|
+
export default function SingleDate() {
|
|
24
|
+
const [date, setDate] = React.useState<Date | null>(null);
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<DatePicker
|
|
28
|
+
selectedDate={date}
|
|
29
|
+
onChange={(newDate) => setDate(newDate as Date)}
|
|
30
|
+
placeholder="Select a date"
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Date Range Selection
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
import * as React from 'react';
|
|
40
|
+
import { DatePicker } from '@xsolla/xui-date-picker';
|
|
41
|
+
|
|
42
|
+
export default function DateRange() {
|
|
43
|
+
const [startDate, setStartDate] = React.useState<Date | null>(null);
|
|
44
|
+
const [endDate, setEndDate] = React.useState<Date | null>(null);
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<DatePicker
|
|
48
|
+
selectsRange
|
|
49
|
+
startDate={startDate}
|
|
50
|
+
endDate={endDate}
|
|
51
|
+
onChange={(range) => {
|
|
52
|
+
const [start, end] = range as [Date | null, Date | null];
|
|
53
|
+
setStartDate(start);
|
|
54
|
+
setEndDate(end);
|
|
55
|
+
}}
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### With Preset Chips
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
import * as React from 'react';
|
|
65
|
+
import { DatePicker } from '@xsolla/xui-date-picker';
|
|
66
|
+
|
|
67
|
+
const chips = [
|
|
68
|
+
{ label: 'Today', value: 'today' },
|
|
69
|
+
{ label: 'Last 7 days', value: 'last7' },
|
|
70
|
+
{ label: 'Last 30 days', value: 'last30' },
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
export default function WithChips() {
|
|
74
|
+
const [date, setDate] = React.useState<Date | null>(null);
|
|
75
|
+
const [activeChip, setActiveChip] = React.useState<string | null>('last30');
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<DatePicker
|
|
79
|
+
selectedDate={date}
|
|
80
|
+
onChange={(newDate) => setDate(newDate as Date)}
|
|
81
|
+
chips={chips}
|
|
82
|
+
activeChip={activeChip}
|
|
83
|
+
onChipSelect={setActiveChip}
|
|
84
|
+
/>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Different Sizes
|
|
90
|
+
|
|
91
|
+
```tsx
|
|
92
|
+
import * as React from 'react';
|
|
93
|
+
import { DatePicker } from '@xsolla/xui-date-picker';
|
|
94
|
+
|
|
95
|
+
export default function Sizes() {
|
|
96
|
+
return (
|
|
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" />
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Standalone Calendar
|
|
107
|
+
|
|
108
|
+
For standalone calendar usage, import from `@xsolla/xui-calendar`:
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
import { Calendar, DualCalendar } from '@xsolla/xui-calendar';
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## API Reference
|
|
115
|
+
|
|
116
|
+
### DatePicker
|
|
117
|
+
|
|
118
|
+
**DatePickerProps:**
|
|
119
|
+
|
|
120
|
+
| Prop | Type | Default | Description |
|
|
121
|
+
| :--- | :--- | :------ | :---------- |
|
|
122
|
+
| selectedDate | `Date` | - | Selected date for single mode. |
|
|
123
|
+
| startDate | `Date` | - | Start date for range mode. |
|
|
124
|
+
| endDate | `Date` | - | End date for range mode. |
|
|
125
|
+
| selectsRange | `boolean` | `false` | Enable date range selection. |
|
|
126
|
+
| onChange | `(date: Date \| [Date, Date]) => void` | - | Date change callback. |
|
|
127
|
+
| size | `"xs" \| "sm" \| "md" \| "lg" \| "xl"` | `"md"` | Input size variant. |
|
|
128
|
+
| locale | `string` | `"enUS"` | Date-fns locale identifier. |
|
|
129
|
+
| placeholder | `string` | `"MM/DD/YYYY"` | Input placeholder text. |
|
|
130
|
+
| minDate | `Date` | - | Minimum selectable date. |
|
|
131
|
+
| maxDate | `Date` | - | Maximum selectable date. |
|
|
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. |
|
|
136
|
+
| testID | `string` | - | Test identifier. |
|
|
137
|
+
|
|
138
|
+
## Date Format
|
|
139
|
+
|
|
140
|
+
The component displays dates in `MM/DD/YYYY` format:
|
|
141
|
+
|
|
142
|
+
| Mode | Display Format |
|
|
143
|
+
| :--- | :------------- |
|
|
144
|
+
| Single | `01/15/2024` |
|
|
145
|
+
| Range | `01/15/2024 - 01/20/2024` |
|
|
146
|
+
|
|
147
|
+
## Calendar Features
|
|
148
|
+
|
|
149
|
+
- **Month navigation**: Previous/next month buttons
|
|
150
|
+
- **Year navigation**: Year selection dropdown
|
|
151
|
+
- **Today indicator**: Current date is highlighted
|
|
152
|
+
- **Selected state**: Selected date(s) have distinct styling
|
|
153
|
+
- **Range highlighting**: Dates between start and end are highlighted
|
|
154
|
+
- **Disabled dates**: Dates outside min/max range are disabled
|
|
155
|
+
- **Preset chips**: Quick-select date ranges (Today, Last 7 days, etc.)
|
|
156
|
+
|
|
157
|
+
## Behavior
|
|
158
|
+
|
|
159
|
+
- Calendar opens on input focus
|
|
160
|
+
- Calendar closes when a date is selected (single mode)
|
|
161
|
+
- Calendar closes when both dates are selected (range mode)
|
|
162
|
+
- Clicking outside closes the calendar
|
|
163
|
+
- Input value updates immediately on selection
|
|
164
|
+
|
|
165
|
+
## Accessibility
|
|
166
|
+
|
|
167
|
+
- Input is keyboard accessible
|
|
168
|
+
- Calendar dates are navigable via keyboard
|
|
169
|
+
- Selected dates are announced to screen readers
|
|
170
|
+
- 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.148.
|
|
3
|
+
"version": "0.148.1",
|
|
4
4
|
"main": "./web/index.js",
|
|
5
5
|
"module": "./web/index.mjs",
|
|
6
6
|
"types": "./web/index.d.ts",
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"test:coverage": "vitest run --coverage"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@xsolla/xui-calendar": "0.148.
|
|
17
|
-
"@xsolla/xui-core": "0.148.
|
|
18
|
-
"@xsolla/xui-input": "0.148.
|
|
19
|
-
"@xsolla/xui-primitives-core": "0.148.
|
|
16
|
+
"@xsolla/xui-calendar": "0.148.1",
|
|
17
|
+
"@xsolla/xui-core": "0.148.1",
|
|
18
|
+
"@xsolla/xui-input": "0.148.1",
|
|
19
|
+
"@xsolla/xui-primitives-core": "0.148.1",
|
|
20
20
|
"date-fns": "^3.0.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|