-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
231 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/components/Calendar/helpers/__test__/isEmptyRange.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import isEmptyRange from '../isEmptyRange'; | ||
|
||
describe('isEmptyRange', () => { | ||
it('should return true', () => { | ||
const ranges = [null, undefined, [], {}, 0, [undefined], [undefined, undefined]]; | ||
ranges.forEach(range => { | ||
expect(isEmptyRange(range)).toBe(true); | ||
}); | ||
}); | ||
it('should return false', () => { | ||
const ranges = [[1], [1, 2]]; | ||
ranges.forEach(range => { | ||
expect(isEmptyRange(range)).toBe(false); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default function isEmptyRange(range) { | ||
if ([null, undefined, [], {}].includes(range)) return true; | ||
if (!Array.isArray(range) || range.length === 0) return true; | ||
const nullFilteredRange = range.filter(item => !!item); | ||
return nullFilteredRange.length === 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as useCurrentDateFromValue } from './useCurrentDateFromValue'; | ||
export { default as useRangeFromValue } from './useRangeFromValue'; | ||
export { default as useDaysBuilder } from './useDaysBuilder'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React, { useMemo } from 'react'; | ||
import { addDays, shouldDateBeSelected, isDateWithinRange, isSameDay } from '../helpers'; | ||
|
||
export default function useDaysBuilder(Component, props) { | ||
const { | ||
startDate, | ||
endDate, | ||
firstDayMonth, | ||
lastDayMonth, | ||
minDate, | ||
maxDate, | ||
selectionType, | ||
value, | ||
selectedRange, | ||
currentRange, | ||
onChange, | ||
} = props; | ||
return useMemo(() => { | ||
let date = new Date(startDate); | ||
const days = []; | ||
|
||
let index = 0; | ||
while (date <= endDate) { | ||
days.push( | ||
<Component | ||
date={date} | ||
firstDayMonth={firstDayMonth} | ||
key={date.getTime()} | ||
minDate={minDate} | ||
maxDate={maxDate} | ||
onChange={onChange} | ||
isSelected={shouldDateBeSelected(date, value, selectionType, selectedRange)} | ||
isWithinRange={isDateWithinRange(date, currentRange)} | ||
isFirstDayOfWeek={index === 0 || isSameDay(date, firstDayMonth)} | ||
isLastDayOfWeek={index === 6 || isSameDay(date, lastDayMonth)} | ||
/>, | ||
); | ||
date = addDays(date, 1); | ||
index += 1; | ||
} | ||
return days; | ||
}, [ | ||
currentRange, | ||
endDate, | ||
firstDayMonth, | ||
lastDayMonth, | ||
maxDate, | ||
minDate, | ||
onChange, | ||
selectedRange, | ||
selectionType, | ||
startDate, | ||
value, | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import styled from 'styled-components'; | ||
import attachThemeAttrs from '../../../styles/helpers/attachThemeAttrs'; | ||
|
||
const StyledRangeHighlight = attachThemeAttrs(styled.div).attrs(props => { | ||
const gradientStart = props.palette.brand.light; | ||
const gradientEnd = props.palette.background.main; | ||
|
||
return { | ||
gradientStart, | ||
gradientEnd, | ||
}; | ||
})` | ||
height: 38px; | ||
line-height: 38px; | ||
margin: 5px auto; | ||
@media (max-width: 600px) { | ||
margin: 3px auto; | ||
} | ||
${props => | ||
props.isVisible && | ||
` | ||
background: ${props.gradientStart}; | ||
`}; | ||
${props => | ||
props.isVisible && | ||
props.isFirstDayOfWeek && | ||
` | ||
background: linear-gradient( | ||
to left, | ||
${props.gradientStart}, | ||
${props.gradientEnd} | ||
); | ||
`}; | ||
${props => | ||
props.isVisible && | ||
props.isLastDayOfWeek && | ||
` | ||
background: linear-gradient( | ||
to right, | ||
${props.gradientStart}, | ||
${props.gradientEnd} | ||
); | ||
`}; | ||
${props => | ||
props.isVisible && | ||
props.isFirstInRange && | ||
` | ||
background: linear-gradient( | ||
to left, | ||
${props.gradientStart}, | ||
${props.gradientEnd} 60%, | ||
${props.gradientEnd} | ||
); | ||
`}; | ||
${props => | ||
props.isVisible && | ||
props.isLastInRange && | ||
` | ||
background: linear-gradient( | ||
to right, | ||
${props.gradientStart}, | ||
${props.gradientEnd} 60%, | ||
${props.gradientEnd} | ||
); | ||
`}; | ||
`; | ||
|
||
export default StyledRangeHighlight; |
Oops, something went wrong.