@@ -29,6 +29,7 @@ import 'react-day-picker/lib/style.css'
2929import styled from 'styled-components'
3030import has from 'lodash/has'
3131import { mix } from 'polished'
32+ import noop from 'lodash/noop'
3233import { reset } from '@looker/design-tokens'
3334import { LocaleCodes } from '../utils/i18n'
3435import { inputTextFocus } from '../Form/Inputs/InputText'
@@ -49,6 +50,7 @@ interface CalendarProps {
4950 onPrevClick ?: ( date : Date ) => void
5051 onMonthChange ?: ( month : Date ) => void
5152 viewMonth ?: Date
53+ disabled ?: boolean
5254}
5355
5456const NoopComponent : FC = ( ) => null
@@ -66,18 +68,24 @@ const InternalCalendar: FC<CalendarProps> = ({
6668 onPrevClick,
6769 viewMonth,
6870 selectedDates,
71+ disabled,
6972} ) => {
7073 const renderDateRange = selectedDates && has ( selectedDates , 'from' )
7174 const modifiers = renderDateRange ? selectedDates : { }
7275
76+ const disableCallback = ( cb : any ) => {
77+ // allows provided callback to be circumvented by disabled prop
78+ return ( ...args : any [ ] ) => ( disabled ? noop ( ) : cb ( ...args ) ) // eslint-disable-line standard/no-callback-literal
79+ }
80+
7381 return (
7482 < CalendarContext . Provider
7583 value = { {
76- onNextClick,
77- onNowClick,
78- onPrevClick,
79- showNextButton,
80- showPreviousButton,
84+ onNextClick : disableCallback ( onNextClick ) ,
85+ onNowClick : disableCallback ( onNowClick ) ,
86+ onPrevClick : disableCallback ( onPrevClick ) ,
87+ showNextButton : ! disabled && showNextButton ,
88+ showPreviousButton : ! disabled && showPreviousButton ,
8189 size,
8290 } }
8391 >
@@ -87,7 +95,7 @@ const InternalCalendar: FC<CalendarProps> = ({
8795 locale = { locale }
8896 month = { viewMonth }
8997 showOutsideDays = { true }
90- onDayClick = { onDayClick }
98+ onDayClick = { disableCallback ( onDayClick ) }
9199 navbarElement = { CalendarNav }
92100 captionElement = { NoopComponent }
93101 modifiers = { modifiers }
@@ -107,7 +115,7 @@ export const Calendar = styled<FC<CalendarProps>>(InternalCalendar)`
107115 border: 1px solid transparent;
108116 &:focus {
109117 outline: none;
110- ${ inputTextFocus }
118+ ${ ( { disabled } ) => ! disabled && inputTextFocus }
111119 }
112120 }
113121 .DayPicker-Month {
@@ -132,25 +140,35 @@ export const Calendar = styled<FC<CalendarProps>>(InternalCalendar)`
132140 justify-items: center;
133141 border: 1px solid transparent;
134142 transition: background-color 110ms linear;
135- color: ${ ( { theme } ) => theme . colors . palette . charcoal700 } ;
143+ color: ${ ( { theme, disabled } ) =>
144+ disabled
145+ ? theme . colors . palette . charcoal500
146+ : theme . colors . palette . charcoal700 } ;
147+ cursor: ${ ( { disabled } ) => ( disabled ? 'default' : 'pointer' ) } ;
136148 &.DayPicker-Day--outside {
137149 color: ${ ( { theme } ) => theme . colors . palette . charcoal300 } ;
138150 }
139151 &--today {
140- color: ${ ( { theme } ) => theme . colors . semanticColors . primary . main } ;
152+ color: ${ ( { theme, disabled } ) =>
153+ ! disabled && theme . colors . semanticColors . primary . main } ;
141154 }
142155 &--selected:not(.DayPicker-Day--disabled):not(.DayPicker-Day--outside) {
143156 position: static;
144- background-color: ${ ( { theme } ) =>
145- theme . colors . semanticColors . primary . main } ;
157+ background-color: ${ ( { theme, disabled } ) =>
158+ disabled
159+ ? theme . colors . palette . charcoal500
160+ : theme . colors . semanticColors . primary . main } ;
146161 &:hover {
147- background-color: ${ ( { theme } ) =>
148- theme . colors . semanticColors . primary . dark } ;
162+ background-color: ${ ( { theme, disabled } ) =>
163+ disabled
164+ ? theme . colors . palette . charcoal500
165+ : theme . colors . semanticColors . primary . dark } ;
149166 }
150167 }
151168 &:focus {
152169 border-width: 2px;
153- border-color: ${ ( props ) => props . theme . colors . palette . purple300 } ;
170+ border-color: ${ ( { theme : { colors } , disabled } ) =>
171+ disabled ? colors . palette . charcoal200 : colors . palette . purple300 } ;
154172 outline: none;
155173 }
156174 }
@@ -162,8 +180,10 @@ export const Calendar = styled<FC<CalendarProps>>(InternalCalendar)`
162180 .DayPicker-Day--selected {
163181 &.DayPicker-Day--outside,
164182 &:not(.DayPicker-Day--to):not(.DayPicker-Day--from) {
165- background-color: ${ ( { theme } ) =>
166- theme . colors . semanticColors . primary . light } ;
183+ background-color: ${ ( { theme, disabled } ) =>
184+ disabled
185+ ? theme . colors . palette . charcoal200
186+ : theme . colors . semanticColors . primary . light } ;
167187 color: ${ ( { theme } ) =>
168188 mix (
169189 0.65 ,
@@ -207,9 +227,10 @@ export const Calendar = styled<FC<CalendarProps>>(InternalCalendar)`
207227 &:not(.DayPicker--interactionDisabled) {
208228 .DayPicker-Day:not(.DayPicker-Day--disabled):not(.DayPicker-Day--selected):not(.DayPicker-Day--outside):hover {
209229 &:hover {
210- background-color: ${ ( { theme } ) =>
211- theme . colors . semanticColors . primary . light } ;
212- color: ${ ( { theme } ) => theme . colors . semanticColors . primary . main } ;
230+ background-color: ${ ( { theme, disabled } ) =>
231+ disabled ? 'transparent' : theme . colors . semanticColors . primary . light } ;
232+ color: ${ ( { theme, disabled } ) =>
233+ ! disabled && theme . colors . semanticColors . primary . main } ;
213234 }
214235 }
215236 }
0 commit comments