@@ -8,7 +8,7 @@ import Color from 'color'
88
99export 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
7777export 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
9899export 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