aryan-date-picker 0.1.0 → 0.1.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.
Files changed (2) hide show
  1. package/README.md +190 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,190 @@
1
+ # Aryan Date Picker
2
+
3
+ A lightweight React date picker component library with calendar-aware localization adapters.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ pnpm add aryan-date-picker
9
+ ```
10
+
11
+ ## Basic usage
12
+
13
+ ```tsx
14
+ import { useState } from 'react';
15
+ import { DatePicker } from 'aryan-date-picker';
16
+ import 'aryan-date-picker/styles.css';
17
+
18
+ export function App() {
19
+ const [selectedDate, setSelectedDate] = useState<Date | null>(null);
20
+
21
+ return <DatePicker value={selectedDate} onChange={setSelectedDate} />;
22
+ }
23
+ ```
24
+
25
+
26
+ ## Controlled and uncontrolled values
27
+
28
+ `DatePicker` and `DateRangePicker` support the standard React controlled component pattern. Pass `value` and `onChange` when the selected value should be owned by your application state.
29
+
30
+ ```tsx
31
+ import { useState } from 'react';
32
+ import { DatePicker, DateRangePicker, type DateRangeValue } from 'aryan-date-picker';
33
+
34
+ export function ControlledExample() {
35
+ const [selectedDate, setSelectedDate] = useState<Date | null>(null);
36
+ const [selectedRange, setSelectedRange] = useState<DateRangeValue | null>(null);
37
+
38
+ return (
39
+ <>
40
+ <DatePicker value={selectedDate} onChange={setSelectedDate} />
41
+ <DateRangePicker value={selectedRange} onChange={setSelectedRange} />
42
+ </>
43
+ );
44
+ }
45
+ ```
46
+
47
+ For lightweight usage, omit `value` and optionally provide `defaultValue` to let the component manage its own selected value.
48
+
49
+ ```tsx
50
+ <DatePicker defaultValue={new Date()} />
51
+ <DateRangePicker defaultValue={{ startDate: new Date(), endDate: null }} />
52
+ ```
53
+
54
+ ## Why the localization layer exists
55
+
56
+ Date pickers need more than translated labels. Different calendars can have different years, month boundaries, month lengths, leap-year rules, weekday ordering, formatting, navigation behavior, and layout direction. Aryan Date Picker keeps those responsibilities behind a `CalendarAdapter` so `DatePicker`, `DateRangePicker`, and `Calendar` can stay calendar-agnostic.
57
+
58
+ The public value model remains standard JavaScript `Date`. Adapters interpret and render those `Date` instances in a calendar system, but consumers continue passing and receiving `Date` objects without a breaking API change.
59
+
60
+ ## LocalizationProvider
61
+
62
+ `LocalizationProvider` places a calendar adapter in React context. Components below the provider use that adapter for formatting, month grids, navigation, comparisons, and direction.
63
+
64
+ ```tsx
65
+ import {
66
+ DatePicker,
67
+ LocalizationProvider,
68
+ createGregorianCalendarAdapter,
69
+ } from 'aryan-date-picker';
70
+
71
+ const gregorianAdapter = createGregorianCalendarAdapter({ locale: 'en-US' });
72
+
73
+ export function GregorianExample() {
74
+ return (
75
+ <LocalizationProvider adapter={gregorianAdapter}>
76
+ <DatePicker />
77
+ </LocalizationProvider>
78
+ );
79
+ }
80
+ ```
81
+
82
+ If no adapter is provided, the library uses the default Gregorian adapter.
83
+
84
+ ## Switching calendars
85
+
86
+ Switch calendars by swapping the adapter; the picker values remain JavaScript `Date` instances.
87
+
88
+ ```tsx
89
+ import {
90
+ DatePicker,
91
+ DateRangePicker,
92
+ LocalizationProvider,
93
+ createGregorianCalendarAdapter,
94
+ jalaliCalendarAdapter,
95
+ } from 'aryan-date-picker';
96
+
97
+ const gregorianAdapter = createGregorianCalendarAdapter({ locale: 'en-US' });
98
+
99
+ export function CalendarSwitchingExample() {
100
+ return (
101
+ <>
102
+ <LocalizationProvider adapter={gregorianAdapter}>
103
+ <DatePicker />
104
+ <DateRangePicker />
105
+ </LocalizationProvider>
106
+
107
+ <LocalizationProvider adapter={jalaliCalendarAdapter}>
108
+ <DatePicker />
109
+ <DateRangePicker />
110
+ </LocalizationProvider>
111
+ </>
112
+ );
113
+ }
114
+ ```
115
+
116
+ ## Jalali calendar
117
+
118
+ The Jalali adapter renders actual Jalali calendar structure: Persian month names, weekday labels, Jalali month grids, Jalali month arithmetic, start/end of month, formatting, and leap-year-aware Esfand length. It exposes `direction: 'rtl'`, so existing direction support is applied automatically.
119
+
120
+ ```tsx
121
+ import { DatePicker, LocalizationProvider, createJalaliCalendarAdapter } from 'aryan-date-picker';
122
+
123
+ const jalaliAdapter = createJalaliCalendarAdapter();
124
+
125
+ export function JalaliExample() {
126
+ return (
127
+ <LocalizationProvider adapter={jalaliAdapter}>
128
+ <DatePicker />
129
+ </LocalizationProvider>
130
+ );
131
+ }
132
+ ```
133
+
134
+ Parsing and labels use Jalali dates, but selected values are still JavaScript `Date` objects:
135
+
136
+ ```tsx
137
+ const adapter = createJalaliCalendarAdapter();
138
+ const date: Date | null = adapter.parseDate('1403-12-30');
139
+ ```
140
+
141
+ ## Building custom adapters
142
+
143
+ Implement the `CalendarAdapter` interface and pass it to `LocalizationProvider`.
144
+
145
+ A custom adapter owns:
146
+
147
+ - calendar interpretation of JavaScript `Date` values
148
+ - month names and weekday labels
149
+ - month grid generation
150
+ - `startOfMonth`, `endOfMonth`, and `addMonths`
151
+ - day/month comparisons
152
+ - date formatting and parsing
153
+ - layout direction (`'ltr'` or `'rtl'`)
154
+
155
+ ```tsx
156
+ import type { CalendarAdapter } from 'aryan-date-picker';
157
+ import { LocalizationProvider, DatePicker } from 'aryan-date-picker';
158
+
159
+ const customAdapter: CalendarAdapter = {
160
+ // Implement the full adapter contract for your calendar system.
161
+ };
162
+
163
+ export function CustomCalendarExample() {
164
+ return (
165
+ <LocalizationProvider adapter={customAdapter}>
166
+ <DatePicker />
167
+ </LocalizationProvider>
168
+ );
169
+ }
170
+ ```
171
+
172
+ ## Workspace
173
+
174
+ This repository is a minimal pnpm workspace:
175
+
176
+ - `packages/date-picker` contains the publishable library.
177
+ - `playground` contains a local Vite + React + TypeScript development app.
178
+
179
+ ## Development
180
+
181
+ ```sh
182
+ pnpm install
183
+ pnpm dev
184
+ ```
185
+
186
+ ## Build
187
+
188
+ ```sh
189
+ pnpm build
190
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aryan-date-picker",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "A lightweight React date picker component library.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",