This repository has been archived by the owner on Jun 10, 2021. It is now read-only.
/
RangeDatePicker.stories.js
155 lines (139 loc) · 3.86 KB
/
RangeDatePicker.stories.js
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// @flow
import React from 'react';
import { storiesOf } from '@storybook/react-native';
import {
boolean,
text,
withKnobs,
object,
number,
} from '@storybook/addon-knobs';
import { addDays } from 'date-fns';
import { Button } from '../Button';
import { RangeDatePicker } from '.';
type Props = {};
type State = {
dates: ?$ReadOnlyArray<Date>,
tempDates: $ReadOnlyArray<Date>,
nightsInDestination: $ReadOnlyArray<number>,
isNightsInDestinationSelected: boolean,
isVisible: boolean,
};
class RangeDatePickerStory extends React.Component<Props, State> {
constructor(props) {
super(props);
const from = addDays(new Date(), 1);
const to = addDays(new Date(), 3);
this.state = {
dates: [from, to],
tempDates: [from, to],
nightsInDestination: [3, 6],
isNightsInDestinationSelected: false,
isVisible: false,
};
}
onChangeTempDates = tempDates => {
this.setState({
tempDates,
});
};
handleConfirmDate = ({ dates }) => {
this.setState({
dates,
});
this.handleDismiss();
};
onNightsInDestinationChange = nightsInDestination => {
this.setState({
nightsInDestination,
});
};
onNightsInDestinationSelectionChange = isNightsInDestinationSelected => {
this.setState({
isNightsInDestinationSelected,
});
};
handleOpenRangeDatePicker = () => {
this.setState({
isVisible: true,
});
};
handleDismiss = () => {
this.setState({
isVisible: false,
});
};
render() {
const isChoosingPastDatesEnabled = boolean(
'isChoosingPastDatesEnabled',
false,
'config',
);
const isRangePicker = boolean('isRangePicker', true, 'config');
const isNightsInDestinationVisible = boolean(
'isNightsInDestinationVisible',
true,
'config',
);
const dateFormat = text('Date format', 'EEE d MMM');
const isControlContainerVisible = boolean(
'isControlContainerVisible',
true,
'config',
);
const weekStartsOn = number('Week starts on', 1, 'config');
const label = text('Label', 'Selected date', 'labels');
const nightsInDestinationLabel = text(
'nightsInDestinationLabel',
'Nights',
'labels',
);
const buttonLabels = object(
'Button labels',
{
cancel: 'Cancel',
confirm: 'Set date',
},
'labels',
);
const numberOfRenderedMonths = 6;
const renderFirstMonthFrom = new Date();
return (
<>
<Button
onPress={this.handleOpenRangeDatePicker}
label="Open RangeDatePicker"
/>
<RangeDatePicker
renderFirstMonthFrom={renderFirstMonthFrom}
isChoosingPastDatesEnabled={isChoosingPastDatesEnabled}
isVisible={this.state.isVisible}
isControlContainerVisible={isControlContainerVisible}
dates={this.state.tempDates}
onConfirm={this.handleConfirmDate}
onDismiss={this.handleDismiss}
onChangeTempDates={this.onChangeTempDates}
label={label}
numberOfRenderedMonths={numberOfRenderedMonths}
weekStartsOn={weekStartsOn}
dateFormat={dateFormat}
isRangePicker={isRangePicker}
buttonLabels={buttonLabels}
nightsInDestinationLabel={nightsInDestinationLabel}
isNightsInDestinationVisible={isNightsInDestinationVisible}
nightsInDestination={this.state.nightsInDestination}
onNightsInDestinationChange={this.onNightsInDestinationChange}
onNightsInDestinationSelectionChange={
this.onNightsInDestinationSelectionChange
}
isNightsInDestinationSelected={
this.state.isNightsInDestinationSelected
}
/>
</>
);
}
}
storiesOf('RangeDatePicker', module)
.addDecorator(withKnobs)
.add('Playground', () => <RangeDatePickerStory />);