Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: highlight current date (today) in Calendar #2031

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/components/Calendar/day.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function DayComponent(props) {
const buttonRef = useRef();
const isRangeStartDate = useRangeStartDate(date, currentRange);
const isRangeEndDate = useRangeEndDate(date, currentRange);
const isToday = isSameDay(date, new Date());

useEffect(() => {
if (useAutoFocus && buttonRef.current && tabIndex !== -1) {
Expand All @@ -58,6 +59,7 @@ function DayComponent(props) {
isLastInRange={isRangeEndDate}
isFirstDayOfWeek={isFirstDayOfWeek}
isLastDayOfWeek={isLastDayOfWeek}
isToday={isToday}
>
<StyledDayButton
ref={buttonRef}
Expand All @@ -71,6 +73,7 @@ function DayComponent(props) {
onFocus={privateOnFocus}
onBlur={privateOnBlur}
isWithinRange={isWithinRange}
isToday={isToday}
>
{day}
</StyledDayButton>
Expand Down
40 changes: 39 additions & 1 deletion src/components/Calendar/styled/dayButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const StyledDayButton = attachThemeAttrs(styled.button)`
text-transform: none;
appearance: button;
border: 1px solid transparent;

position: relative;

${props =>
!props.isHovered &&
`
Expand All @@ -40,6 +41,43 @@ const StyledDayButton = attachThemeAttrs(styled.button)`
line-height: 36px;
}

${props =>
props.isToday &&
`
font-weight: 900;

&::after {
content: '';
height: 4px;
width: 4px;
position: absolute;
top: 28px;
left: 16px;
border-radius: 50%;
background: ${
props.isSelected || props.isHovered
? props.palette.getContrastText(props.palette.brand.main)
: props.palette.brand.main
};
}


`}

${props =>
props.isSelected &&
props.isToday &&
`
&:hover,
&:focus,
&:active {
&::after {
top: 27px;
left: 16px;
}
}
`};

${props =>
props.isSelected &&
`
Expand Down
6 changes: 6 additions & 0 deletions src/components/Calendar/styled/rangeHighlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ const StyledRangeHighlight = attachThemeAttrs(styled.div).attrs(props => {
margin: 3px auto;
}

${props =>
props.isToday &&
`
color: ${props.palette.brand.main};
`}

${props =>
props.isVisible &&
`
Expand Down