forked from t0gre/react-datepicker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateRangeInputModern.stories.tsx
More file actions
136 lines (130 loc) · 4.12 KB
/
DateRangeInputModern.stories.tsx
File metadata and controls
136 lines (130 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import React, {useReducer} from 'react'
import {storiesOf} from '@storybook/react'
import {action} from '@storybook/addon-actions'
import {text, boolean} from '@storybook/addon-knobs'
import {
dayLabelFormat as dayLabelFormatFn,
weekdayLabelFormat as weekdayLabelFormatFn,
monthLabelFormat as monthLabelFormatFn,
} from '@datepicker-react/hooks'
import {
DateRangeInputModern,
OnDatesChangeProps,
FirstDayOfWeek,
DateRangeInputPhrases,
dateRangeInputPhrases,
} from '../../index'
const initialState: OnDatesChangeProps = {
startDate: null,
endDate: null,
focusedInput: null,
}
function reducer(state: OnDatesChangeProps, action: Record<string, unknown>) {
switch (action.type) {
case 'focusChange':
return {...state, focusedInput: action.payload}
case 'dateChange':
return action.payload
default:
throw new Error()
}
}
interface AppProps {
displayFormat?: string
vertical?: boolean
rtl?: boolean
showResetDates?: boolean
showClose?: boolean
showSelectedDates?: boolean
exactMinBookingDays?: boolean
minBookingDays?: number
numberOfMonths?: number
firstDayOfWeek?: FirstDayOfWeek
phrasesProp?: DateRangeInputPhrases
isDateBlocked?(date: Date): boolean
minBookingDate?: Date
maxBookingDate?: Date
dayLabelFormat?(date: Date): string
weekdayLabelFormat?(date: Date): string
monthLabelFormat?(date: Date): string
onDayRender?(date: Date): React.ReactNode
unavailableDates?: Date[]
initialVisibleMonth?: Date
datepickerCloseWrapperRightCustom?: string | null
datepickerPaddingCustom?: string | null
}
function App({
displayFormat = 'MM/DD/YYYY',
showClose = true,
showSelectedDates = true,
showResetDates = false,
vertical = false,
rtl = false,
exactMinBookingDays = false,
minBookingDays = 1,
numberOfMonths = 2,
firstDayOfWeek = 1,
phrasesProp = dateRangeInputPhrases,
isDateBlocked = () => false,
minBookingDate,
maxBookingDate,
initialVisibleMonth,
dayLabelFormat = dayLabelFormatFn,
weekdayLabelFormat = weekdayLabelFormatFn,
monthLabelFormat = monthLabelFormatFn,
onDayRender = undefined,
unavailableDates = [],
datepickerCloseWrapperRightCustom = null,
datepickerPaddingCustom = null,
}: AppProps) {
const [state, dispatch] = useReducer(reducer, initialState)
return (
<DateRangeInputModern
minBookingDate={minBookingDate}
maxBookingDate={maxBookingDate}
// @ts-ignore
onDatesChange={data => dispatch({type: 'dateChange', payload: data})}
onFocusChange={focusedInput => dispatch({type: 'focusChange', payload: focusedInput})}
// @ts-ignore
startDate={state.startDate}
// @ts-ignore
endDate={state.endDate}
// @ts-ignore
focusedInput={state.focusedInput}
onClose={action('onClose')}
displayFormat={displayFormat}
vertical={vertical}
rtl={rtl}
showClose={showClose}
showResetDates={showResetDates}
showSelectedDates={showSelectedDates}
exactMinBookingDays={exactMinBookingDays}
minBookingDays={minBookingDays}
numberOfMonths={numberOfMonths}
firstDayOfWeek={firstDayOfWeek}
phrases={phrasesProp}
isDateBlocked={isDateBlocked}
dayLabelFormat={dayLabelFormat}
weekdayLabelFormat={weekdayLabelFormat}
monthLabelFormat={monthLabelFormat}
onDayRender={onDayRender}
unavailableDates={unavailableDates}
initialVisibleMonth={initialVisibleMonth}
datepickerCloseWrapperRightCustom={datepickerCloseWrapperRightCustom}
datepickerPaddingCustom={datepickerPaddingCustom}
/>
)
}
storiesOf('DateRangeInputModern', module).add('Simple demo', () => (
<App
rtl={boolean('rtl', false)}
vertical={boolean('vertical', false)}
exactMinBookingDays={boolean('exactMinBookingDays', false)}
showResetDates={boolean('showResetDates', true)}
showClose={boolean('showClose', true)}
showSelectedDates={boolean('showSelectedDates', true)}
displayFormat={text('displayFormat', 'MM/dd/yyyy')}
datepickerCloseWrapperRightCustom={text('datepickerCloseWrapperRightCustom', '10px')}
datepickerPaddingCustom={text('datepickerPaddingCustom', '10px')}
/>
))