Skip to content

Commit

Permalink
fix: implements some fixes from the PR comments and design review
Browse files Browse the repository at this point in the history
  • Loading branch information
jongomez committed Oct 16, 2023
1 parent d5581c8 commit d2b8ba7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ export const calendarClasses = {
todayIndicator: 'lsd-calendar-day__today_indicator',

monthTable: 'lsd-calendar__month-table',

nextMonthButton: 'lsd-calendar__next-month-button',
previousMonthButton: 'lsd-calendar__previous-month-button',
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ export type CalendarContextType = {
goToNextMonths: () => void
goToNextYear: () => void
goToPreviousYear: () => void
changeYearMode: boolean
setChangeYearMode: (value: boolean) => void
}

export const CalendarContext = React.createContext<CalendarContextType>(
Expand Down
29 changes: 19 additions & 10 deletions packages/lsd-react/src/components/Calendar/Calendar.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ export const CalendarStyles = css`
padding: 0;
box-sizing: border-box;
background: rgb(var(--lsd-surface-primary));
user-select: none;
padding: 8px;
}
.${calendarClasses.container} {
display: flex;
flex-direction: column;
margin: 8px 2px 2px;
}
.${calendarClasses.open} {
Expand All @@ -29,17 +31,18 @@ export const CalendarStyles = css`
.${calendarClasses.header} {
display: flex;
justify-content: space-between;
justify-content: center;
align-items: center;
padding-inline: 10px;
padding-bottom: 10px;
height: 32px;
margin-bottom: 8px;
}
.${calendarClasses.weekDay} {
display: flex;
justify-content: center;
align-items: center;
aspect-ratio: 1 / 1;
margin-bottom: 4px;
}
.${calendarClasses.row} {
Expand Down Expand Up @@ -72,12 +75,6 @@ export const CalendarStyles = css`
margin-right: 8px;
}
.${calendarClasses.year}:hover {
cursor: pointer;
text-decoration: underline;
text-decoration-color: rgb(var(--lsd-border-primary));
}
.${calendarClasses.dayContainer} {
cursor: pointer;
background: transparent;
Expand Down Expand Up @@ -145,6 +142,18 @@ export const CalendarStyles = css`
display: flex;
align-items: center;
justify-content: center;
position: absolute;
}
.${calendarClasses.nextMonthButton} {
top: 8px;
right: 8px;
}
.${calendarClasses.previousMonthButton} {
top: 8px;
left: 8px;
}
/* Using style double instead of solid. When collapsing borders, */
Expand Down
3 changes: 0 additions & 3 deletions packages/lsd-react/src/components/Calendar/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export const Calendar: React.FC<CalendarProps> & {
const [endDate, setEndDate] = useState<Date | null>(
endDateProp ? safeConvertDate(endDateProp, minDate, maxDate).date : null,
)
const [changeYearMode, setChangeYearMode] = useState(false)

useClickAway(ref, (event) => {
if (!open) return
Expand Down Expand Up @@ -183,8 +182,6 @@ export const Calendar: React.FC<CalendarProps> & {
goToNextMonths,
goToNextYear,
goToPreviousYear,
changeYearMode,
setChangeYearMode,
}}
>
<div
Expand Down
48 changes: 13 additions & 35 deletions packages/lsd-react/src/components/Calendar/MonthHelpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ import { useCalendarContext } from './Calendar.context'
type CalendarNavigationButtonProps = {
direction: 'previous' | 'next'
onClick: () => void
className?: string
}

export const CalendarNavigationButton: FC<CalendarNavigationButtonProps> = ({
direction,
onClick,
className,
}) => {
const Icon = direction === 'previous' ? NavigateBeforeIcon : NavigateNextIcon
return (
<button
className={clsx(calendarClasses.button)}
className={clsx(calendarClasses.button, className)}
type="button"
onClick={onClick}
>
Expand All @@ -39,21 +41,12 @@ export const CalendarNavigationButton: FC<CalendarNavigationButtonProps> = ({
type YearControlProps = {
year: string
size: 'large' | 'medium' | 'small'
onClickAway: () => void
}

export const YearControl: FC<YearControlProps> = ({
year,
size,
onClickAway,
}) => {
export const YearControl: FC<YearControlProps> = ({ year, size }) => {
const ref = useRef<HTMLDivElement>(null)
const { goToNextYear, goToPreviousYear } = useCalendarContext()

useClickAway(ref, () => {
onClickAway()
})

return (
<div ref={ref} className={calendarClasses.changeYear}>
<Typography
Expand Down Expand Up @@ -91,19 +84,15 @@ type MonthHeaderProps = {
}

export const MonthHeader: FC<MonthHeaderProps> = ({ monthLabel, size }) => {
const {
goToPreviousMonths,
goToNextMonths,
changeYearMode,
setChangeYearMode,
} = useCalendarContext()
const { goToPreviousMonths, goToNextMonths } = useCalendarContext()
const [month, year] = monthLabel.split(' ')

return (
<div className={calendarClasses.header}>
<CalendarNavigationButton
direction="previous"
onClick={goToPreviousMonths}
className={calendarClasses.previousMonthButton}
/>
<div className={calendarClasses.row}>
<Typography
Expand All @@ -113,25 +102,14 @@ export const MonthHeader: FC<MonthHeaderProps> = ({ monthLabel, size }) => {
>
{month}
</Typography>
{changeYearMode ? (
<YearControl
year={year}
size={size}
onClickAway={() => {
setChangeYearMode(false)
}}
/>
) : (
<Typography
onClick={() => setChangeYearMode(true)}
variant={size === 'large' ? 'label1' : 'label2'}
className={calendarClasses.year}
>
{year}
</Typography>
)}

<YearControl year={year} size={size} />
</div>
<CalendarNavigationButton direction="next" onClick={goToNextMonths} />
<CalendarNavigationButton
direction="next"
onClick={goToNextMonths}
className={calendarClasses.nextMonthButton}
/>
</div>
)
}
Expand Down

0 comments on commit d2b8ba7

Please sign in to comment.