Skip to content

Commit 06e5efa

Browse files
committed
Introduce start and end year props.
1 parent 0c9546d commit 06e5efa

File tree

8 files changed

+33
-4
lines changed

8 files changed

+33
-4
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ export default function ReadMeExampleSingle() {
151151
// uppercase={false} // optional, default is true
152152
// label="Select date" // optional
153153
// animationType="slide" // optional, default is 'slide' on ios/android and 'none' on web
154+
// startYear={2000} // optional, default is 1800
155+
// endYear={2100} // optional, default is 2200
154156
/>
155157
</>
156158
);
@@ -209,6 +211,8 @@ export default function ReadMeExampleRange() {
209211
// startLabel="From" // optional
210212
// endLabel="To" // optional
211213
// animationType="slide" // optional, default is slide on ios/android and none on web
214+
// startYear={2000} // optional, default is 1800
215+
// endYear={2100} // optional, default is 2200
212216
/>
213217
</>
214218
);
@@ -263,6 +267,8 @@ export default function ReadMeExampleMultiple() {
263267
// startLabel="From" // optional
264268
// endLabel="To" // optional
265269
// animationType="slide" // optional, default is slide on ios/android and none on web
270+
// startYear={2000} // optional, default is 1800
271+
// endYear={2100} // optional, default is 2200
266272
/>
267273
</>
268274
);

example/src/App.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ function App() {
318318
// startLabel="From" // optional
319319
// endLabel="To" // optional
320320
// animationType="slide" // optional, default is slide on ios/android and none on web
321+
// startYear={2000} // optional, default is 1800
322+
// endYear={2100} // optional, default is 2200
321323
/>
322324

323325
<DatePickerModal
@@ -337,6 +339,8 @@ function App() {
337339
// uppercase={false} // optional, default is true
338340
// label="Select date" // optional
339341
// animationType="slide" // optional, default is 'slide' on ios/android and 'none' on web
342+
// startYear={2000} // optional, default is 1800
343+
// endYear={2100} // optional, default is 2200
340344
/>
341345

342346
<DatePickerModal
@@ -355,6 +359,8 @@ function App() {
355359
// uppercase={false} // optional, default is true
356360
// label="Select date" // optional
357361
// animationType="slide" // optional, default is 'slide' on ios/android and 'none' on web
362+
// startYear={2000} // optional, default is 1800
363+
// endYear={2100} // optional, default is 2200
358364
/>
359365

360366
<TimePickerModal

example/src/ReadMeExampleMultiple.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export default function ReadMeExampleMultiple() {
4242
// startLabel="From" // optional
4343
// endLabel="To" // optional
4444
// animationType="slide" // optional, default is slide on ios/android and none on web
45+
// startYear={2000} // optional, default is 1800
46+
// endYear={2100} // optional, default is 2200
4547
/>
4648
</>
4749
)

example/src/ReadMeExampleRange.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export default function ReadMeExampleRange() {
4949
// startLabel="From" // optional
5050
// endLabel="To" // optional
5151
// animationType="slide" // optional, default is slide on ios/android and none on web
52+
// startYear={2000} // optional, default is 1800
53+
// endYear={2100} // optional, default is 2200
5254
/>
5355
</>
5456
)

example/src/ReadMeExampleSingle.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export default function ReadMeExampleSingle() {
4040
// uppercase={false} // optional, default is true
4141
// label="Select date" // optional
4242
// animationType="slide" // optional, default is 'slide' on ios/android and 'none' on web
43+
// startYear={2000} // optional, default is 1800
44+
// endYear={2100} // optional, default is 2200
4345
/>
4446
</>
4547
)

src/Date/Calendar.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export type BaseCalendarProps = {
3131
locale: string
3232
disableWeekDays?: DisableWeekDaysType
3333
validRange?: ValidRangeType
34+
startYear?: number
35+
endYear?: number
3436

3537
// here they are optional but in final implemenation they are required
3638
date?: CalendarDate
@@ -88,6 +90,8 @@ function Calendar(
8890
endDate,
8991
date,
9092
disableWeekDays,
93+
startYear,
94+
endYear,
9195
dates,
9296
validRange,
9397
dateMode,
@@ -206,6 +210,8 @@ function Calendar(
206210
selectedYear={selectedYear}
207211
selectingYear={selectingYear}
208212
onPressYear={onPressYear}
213+
startYear={startYear ?? 1800}
214+
endYear={endYear ?? 2200}
209215
/>
210216
) : null}
211217
</View>

src/Date/DatePickerModalContent.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ export function DatePickerModalContent(
8181
locale,
8282
validRange,
8383
dateMode,
84+
startYear,
85+
endYear
8486
} = props
8587

8688
const anyProps = props as any
@@ -175,6 +177,8 @@ export function DatePickerModalContent(
175177
dates={state.dates}
176178
validRange={validRange}
177179
dateMode={dateMode}
180+
startYear={startYear}
181+
endYear={endYear}
178182
/>
179183
}
180184
calendarEdit={

src/Date/YearPicker.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,22 @@ import { range } from '../utils'
55

66
const ITEM_HEIGHT = 62
77

8-
const startYear = 1800
9-
const endYear = 2200
10-
const years = range(startYear, endYear)
11-
128
export default function YearPicker({
139
selectedYear,
1410
selectingYear,
1511
onPressYear,
12+
startYear,
13+
endYear,
1614
}: {
1715
selectedYear: number | undefined
1816
selectingYear: boolean
1917
onPressYear: (year: number) => any
18+
startYear: number
19+
endYear: number
2020
}) {
2121
const theme = useTheme()
2222
const flatList = React.useRef<FlatList<number> | null>(null)
23+
const years = range(isNaN(startYear) ? 1800 : startYear, isNaN(endYear) ? 2200 : endYear)
2324

2425
// scroll to selected year
2526
React.useEffect(() => {

0 commit comments

Comments
 (0)