Skip to content

Commit ba72ad0

Browse files
author
Jiri Kolarik
authored
Merge pull request #14 from OzoTek/uix-enhancements
UIX enhancements on disable/available dates
2 parents 0876f58 + cf3bad5 commit ba72ad0

1 file changed

Lines changed: 24 additions & 16 deletions

File tree

src/index.js

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ type DatesType = {
1515
endDate: ?moment,
1616
focusedInput: 'startDate' | 'endDate',
1717
onDatesChange: (date: { date?: ?moment, startDate?: ?moment, endDate?: ?moment }) => void,
18-
isDateBlocked: (date: moment) => boolean
18+
isDateBlocked: (date: moment) => boolean,
19+
onDisableClicked: (date: moment) => void
1920
}
2021

2122
type MonthType = {
@@ -27,7 +28,8 @@ type MonthType = {
2728
currentDate: moment,
2829
focusedMonth: moment,
2930
onDatesChange: (date: { date?: ?moment, startDate?: ?moment, endDate?: ?moment }) => void,
30-
isDateBlocked: (date: moment) => boolean
31+
isDateBlocked: (date: moment) => boolean,
32+
onDisableClicked: (date: moment) => void
3133
}
3234

3335
type WeekType = {
@@ -36,10 +38,10 @@ type WeekType = {
3638
startDate: ?moment,
3739
endDate: ?moment,
3840
focusedInput: 'startDate' | 'endDate',
39-
focusedMonth: moment,
4041
startOfWeek: moment,
4142
onDatesChange: (date: { date?: ?moment, startDate?: ?moment, endDate?: ?moment }) => void,
42-
isDateBlocked: (date: moment) => boolean
43+
isDateBlocked: (date: moment) => boolean,
44+
onDisableClicked: (date: moment) => void
4345
}
4446

4547
const styles = StyleSheet.create({
@@ -63,7 +65,7 @@ const styles = StyleSheet.create({
6365
flexGrow: 1,
6466
flexBasis: 1,
6567
alignItems: 'center',
66-
backgroundColor: 'rgb(248, 248, 248)',
68+
backgroundColor: 'rgb(245, 245, 245)',
6769
margin: 1,
6870
padding: 10
6971
},
@@ -74,10 +76,13 @@ const styles = StyleSheet.create({
7476
backgroundColor: 'rgb(52,120,246)'
7577
},
7678
dayText: {
77-
color: 'rgb(0, 0, 0)'
79+
color: 'rgb(0, 0, 0)',
80+
fontWeight: '600'
7881
},
7982
dayDisabledText: {
80-
color: 'gray'
83+
color: 'gray',
84+
opacity: 0.5,
85+
fontWeight: '400'
8186
},
8287
daySelectedText: {
8388
color: 'rgb(252, 252, 252)'
@@ -109,18 +114,20 @@ export const Week = (props: WeekType) => {
109114
startDate,
110115
endDate,
111116
focusedInput,
112-
focusedMonth,
113117
startOfWeek,
114118
onDatesChange,
115-
isDateBlocked
119+
isDateBlocked,
120+
onDisableClicked
116121
} = props;
117122

118123
const days = [];
119124
const endOfWeek = startOfWeek.clone().endOf('isoweek');
120125

121126
moment.range(startOfWeek, endOfWeek).by('days', (day: moment) => {
122127
const onPress = () => {
123-
if (range) {
128+
if (isDateBlocked(day)) {
129+
onDisableClicked(day);
130+
} else if (range) {
124131
let isPeriodBlocked = false;
125132
const start = focusedInput === 'startDate' ? day : startDate;
126133
const end = focusedInput === 'endDate' ? day : endDate;
@@ -147,20 +154,18 @@ export const Week = (props: WeekType) => {
147154
return date && day.isSame(date);
148155
};
149156

150-
const isCurrentMonth = day.month() === focusedMonth.month();
151157
const isBlocked = isDateBlocked(day);
152158
const isSelected = isDateSelected();
153-
const isDisabled = !isCurrentMonth || isBlocked;
154159

155160
const style = [
156161
styles.day,
157-
isDisabled && styles.dayBlocked,
162+
isBlocked && styles.dayBlocked,
158163
isSelected && styles.daySelected
159164
];
160165

161166
const styleText = [
162167
styles.dayText,
163-
isDisabled && styles.dayDisabledText,
168+
isBlocked && styles.dayDisabledText,
164169
isSelected && styles.daySelectedText
165170
];
166171

@@ -169,7 +174,7 @@ export const Week = (props: WeekType) => {
169174
key={day.date()}
170175
style={style}
171176
onPress={onPress}
172-
disabled={isDisabled}
177+
disabled={isBlocked && !onDisableClicked}
173178
>
174179
<Text style={styleText}>{day.date()}</Text>
175180
</TouchableOpacity>
@@ -191,7 +196,8 @@ export const Month = (props: MonthType) => {
191196
currentDate,
192197
focusedMonth,
193198
onDatesChange,
194-
isDateBlocked
199+
isDateBlocked,
200+
onDisableClicked
195201
} = props;
196202

197203
const dayNames = [];
@@ -222,6 +228,7 @@ export const Month = (props: MonthType) => {
222228
startOfWeek={week}
223229
onDatesChange={onDatesChange}
224230
isDateBlocked={isDateBlocked}
231+
onDisableClicked={onDisableClicked}
225232
/>
226233
);
227234
});
@@ -273,6 +280,7 @@ export default class Dates extends Component {
273280
focusedMonth={this.state.focusedMonth}
274281
onDatesChange={this.props.onDatesChange}
275282
isDateBlocked={this.props.isDateBlocked}
283+
onDisableClicked={this.props.onDisableClicked}
276284
/>
277285
</View>
278286
);

0 commit comments

Comments
 (0)