Skip to content

Commit e8221b7

Browse files
fix: remove hardcoded values in excludeInRange + improve looks
1 parent fc1c667 commit e8221b7

File tree

3 files changed

+38
-21
lines changed

3 files changed

+38
-21
lines changed

example/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ function App({
301301
onConfirm={onChangeExcludeRange}
302302
// sunday, saturday
303303
disableWeekDays={disabledWeekDays}
304+
// emptyLabel="Altijd"
305+
// label="Ik kan niet op"
304306
// animationType="slide" // optional, default is slide on ios/android and none on web
305307
/>
306308
<DatePickerModal

src/Date/DatePickerModalContent.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export function DatePickerModalContent(
150150
collapsed={collapsed}
151151
onToggle={onToggleCollapse}
152152
headerSeparator={props.headerSeparator}
153+
emptyLabel={props.emptyLabel}
153154
label={props.label}
154155
startLabel={props.startLabel}
155156
endLabel={props.endLabel}

src/Date/DatePickerModalContentHeader.tsx

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Color from 'color'
88

99
export interface HeaderPickProps {
1010
label?: string
11-
excludeLabel?: string
11+
emptyLabel?: string
1212
saveLabel?: string
1313
headerSeparator?: string
1414
startLabel?: string
@@ -33,7 +33,7 @@ function getLabel(mode: ModeType, configuredLabel?: string) {
3333
return 'Select date'
3434
}
3535
if (mode === 'excludeInRange') {
36-
return 'Select exclude dates'
36+
return 'Select excluded dates'
3737
}
3838
return '...?'
3939
}
@@ -76,6 +76,7 @@ export default function DatePickerModalHeader(props: HeaderContentProps) {
7676

7777
export function HeaderContentSingle({
7878
state,
79+
emptyLabel = ' ',
7980
color,
8081
}: HeaderContentProps & { color: string }) {
8182
const lighterColor = Color(color).fade(0.5).rgb().toString()
@@ -90,44 +91,57 @@ export function HeaderContentSingle({
9091

9192
return (
9293
<Text style={[styles.singleHeaderText, { color: dateColor }]}>
93-
{state.date ? formatter.format(state.date) : ' '}
94+
{state.date ? formatter.format(state.date) : emptyLabel}
9495
</Text>
9596
)
9697
}
9798

9899
export function HeaderContentExcludeInRange({
99100
state,
100-
headerSeparator = '-',
101-
excludeLabel = 'Without',
101+
emptyLabel = ' ',
102102
color,
103103
}: HeaderContentProps & { color: string }) {
104-
const lighterColor = Color(color).fade(0.3).rgb().toString()
104+
const lighterColor = Color(color).fade(0.5).rgb().toString()
105105

106-
const formatter = React.useMemo(() => {
106+
const dayFormatter = React.useMemo(() => {
107107
return new Intl.DateTimeFormat(undefined, {
108-
month: 'short',
109108
day: 'numeric',
110109
})
111110
}, [])
111+
const monthFormatter = React.useMemo(() => {
112+
return new Intl.DateTimeFormat(undefined, {
113+
month: 'short',
114+
})
115+
}, [])
116+
117+
const excludedDaysPerMonth = React.useMemo(() => {
118+
// TODO: fix years :O
119+
let months: { [monthIndex: number]: Date[] } = {}
120+
state.excludedDates.forEach((ed) => {
121+
const existing = months[ed.getMonth()]
122+
months[ed.getMonth()] = existing ? [...existing, ed] : [ed]
123+
})
124+
return months
125+
}, [state.excludedDates])
126+
const dateColor =
127+
state.excludedDates && state.excludedDates.length > 0 ? color : lighterColor
112128

113129
return (
114130
<View style={styles.column}>
115131
<View style={styles.row}>
116-
<Text style={[styles.excludeInRangeHeaderText, { color }]}>
117-
{state.startDate ? formatter.format(state.startDate) : ''}
118-
</Text>
119-
<Text style={[styles.headerSeparator, { color }]}>
120-
{headerSeparator}
121-
</Text>
122-
<Text style={[styles.excludeInRangeHeaderText, { color }]}>
123-
{state.endDate ? formatter.format(state.endDate) : ''}
132+
<Text style={[styles.excludeInRangeHeaderText, { color: dateColor }]}>
133+
{Object.keys(excludedDaysPerMonth)
134+
.map(
135+
(monthIndex: any) =>
136+
excludedDaysPerMonth[monthIndex]
137+
.map((date) => dayFormatter.format(date))
138+
.join(', ') +
139+
' ' +
140+
monthFormatter.format(excludedDaysPerMonth[monthIndex][0]!)
141+
)
142+
.join(', ') || emptyLabel}
124143
</Text>
125144
</View>
126-
<Text
127-
style={[styles.excludeInRangeHeaderTextSmall, { color: lighterColor }]}
128-
>
129-
{excludeLabel} 16 dec, 17 dec
130-
</Text>
131145
</View>
132146
)
133147
}

0 commit comments

Comments
 (0)