mirror of
https://github.com/acid-info/lsd.git
synced 2025-01-27 01:09:59 +00:00
fix: implements some fixes from the PR comments and design review
This commit is contained in:
parent
d572aefe0a
commit
dcaeb22efe
@ -30,4 +30,7 @@ export const calendarClasses = {
|
|||||||
todayIndicator: 'lsd-calendar-day__today_indicator',
|
todayIndicator: 'lsd-calendar-day__today_indicator',
|
||||||
|
|
||||||
monthTable: 'lsd-calendar__month-table',
|
monthTable: 'lsd-calendar__month-table',
|
||||||
|
|
||||||
|
nextMonthButton: 'lsd-calendar__next-month-button',
|
||||||
|
previousMonthButton: 'lsd-calendar__previous-month-button',
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,6 @@ export type CalendarContextType = {
|
|||||||
goToNextMonths: () => void
|
goToNextMonths: () => void
|
||||||
goToNextYear: () => void
|
goToNextYear: () => void
|
||||||
goToPreviousYear: () => void
|
goToPreviousYear: () => void
|
||||||
changeYearMode: boolean
|
|
||||||
setChangeYearMode: (value: boolean) => void
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CalendarContext = React.createContext<CalendarContextType>(
|
export const CalendarContext = React.createContext<CalendarContextType>(
|
||||||
|
@ -14,12 +14,14 @@ export const CalendarStyles = css`
|
|||||||
padding: 0;
|
padding: 0;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
background: rgb(var(--lsd-surface-primary));
|
background: rgb(var(--lsd-surface-primary));
|
||||||
|
|
||||||
|
user-select: none;
|
||||||
|
padding: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.${calendarClasses.container} {
|
.${calendarClasses.container} {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
margin: 8px 2px 2px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.${calendarClasses.open} {
|
.${calendarClasses.open} {
|
||||||
@ -29,10 +31,10 @@ export const CalendarStyles = css`
|
|||||||
|
|
||||||
.${calendarClasses.header} {
|
.${calendarClasses.header} {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding-inline: 10px;
|
height: 32px;
|
||||||
padding-bottom: 10px;
|
margin-bottom: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.${calendarClasses.weekDay} {
|
.${calendarClasses.weekDay} {
|
||||||
@ -40,6 +42,7 @@ export const CalendarStyles = css`
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
aspect-ratio: 1 / 1;
|
aspect-ratio: 1 / 1;
|
||||||
|
margin-bottom: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.${calendarClasses.row} {
|
.${calendarClasses.row} {
|
||||||
@ -72,12 +75,6 @@ export const CalendarStyles = css`
|
|||||||
margin-right: 8px;
|
margin-right: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.${calendarClasses.year}:hover {
|
|
||||||
cursor: pointer;
|
|
||||||
text-decoration: underline;
|
|
||||||
text-decoration-color: rgb(var(--lsd-border-primary));
|
|
||||||
}
|
|
||||||
|
|
||||||
.${calendarClasses.dayContainer} {
|
.${calendarClasses.dayContainer} {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
@ -145,6 +142,18 @@ export const CalendarStyles = css`
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: 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, */
|
/* Using style double instead of solid. When collapsing borders, */
|
||||||
|
@ -67,7 +67,6 @@ export const Calendar: React.FC<CalendarProps> & {
|
|||||||
const [endDate, setEndDate] = useState<Date | null>(
|
const [endDate, setEndDate] = useState<Date | null>(
|
||||||
endDateProp ? safeConvertDate(endDateProp, minDate, maxDate).date : null,
|
endDateProp ? safeConvertDate(endDateProp, minDate, maxDate).date : null,
|
||||||
)
|
)
|
||||||
const [changeYearMode, setChangeYearMode] = useState(false)
|
|
||||||
|
|
||||||
useClickAway(ref, (event) => {
|
useClickAway(ref, (event) => {
|
||||||
if (!open) return
|
if (!open) return
|
||||||
@ -183,8 +182,6 @@ export const Calendar: React.FC<CalendarProps> & {
|
|||||||
goToNextMonths,
|
goToNextMonths,
|
||||||
goToNextYear,
|
goToNextYear,
|
||||||
goToPreviousYear,
|
goToPreviousYear,
|
||||||
changeYearMode,
|
|
||||||
setChangeYearMode,
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
|
@ -18,16 +18,18 @@ import { useCalendarContext } from './Calendar.context'
|
|||||||
type CalendarNavigationButtonProps = {
|
type CalendarNavigationButtonProps = {
|
||||||
direction: 'previous' | 'next'
|
direction: 'previous' | 'next'
|
||||||
onClick: () => void
|
onClick: () => void
|
||||||
|
className?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CalendarNavigationButton: FC<CalendarNavigationButtonProps> = ({
|
export const CalendarNavigationButton: FC<CalendarNavigationButtonProps> = ({
|
||||||
direction,
|
direction,
|
||||||
onClick,
|
onClick,
|
||||||
|
className,
|
||||||
}) => {
|
}) => {
|
||||||
const Icon = direction === 'previous' ? NavigateBeforeIcon : NavigateNextIcon
|
const Icon = direction === 'previous' ? NavigateBeforeIcon : NavigateNextIcon
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
className={clsx(calendarClasses.button)}
|
className={clsx(calendarClasses.button, className)}
|
||||||
type="button"
|
type="button"
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
>
|
>
|
||||||
@ -39,21 +41,12 @@ export const CalendarNavigationButton: FC<CalendarNavigationButtonProps> = ({
|
|||||||
type YearControlProps = {
|
type YearControlProps = {
|
||||||
year: string
|
year: string
|
||||||
size: 'large' | 'medium' | 'small'
|
size: 'large' | 'medium' | 'small'
|
||||||
onClickAway: () => void
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const YearControl: FC<YearControlProps> = ({
|
export const YearControl: FC<YearControlProps> = ({ year, size }) => {
|
||||||
year,
|
|
||||||
size,
|
|
||||||
onClickAway,
|
|
||||||
}) => {
|
|
||||||
const ref = useRef<HTMLDivElement>(null)
|
const ref = useRef<HTMLDivElement>(null)
|
||||||
const { goToNextYear, goToPreviousYear } = useCalendarContext()
|
const { goToNextYear, goToPreviousYear } = useCalendarContext()
|
||||||
|
|
||||||
useClickAway(ref, () => {
|
|
||||||
onClickAway()
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={ref} className={calendarClasses.changeYear}>
|
<div ref={ref} className={calendarClasses.changeYear}>
|
||||||
<Typography
|
<Typography
|
||||||
@ -91,12 +84,7 @@ type MonthHeaderProps = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const MonthHeader: FC<MonthHeaderProps> = ({ monthLabel, size }) => {
|
export const MonthHeader: FC<MonthHeaderProps> = ({ monthLabel, size }) => {
|
||||||
const {
|
const { goToPreviousMonths, goToNextMonths } = useCalendarContext()
|
||||||
goToPreviousMonths,
|
|
||||||
goToNextMonths,
|
|
||||||
changeYearMode,
|
|
||||||
setChangeYearMode,
|
|
||||||
} = useCalendarContext()
|
|
||||||
const [month, year] = monthLabel.split(' ')
|
const [month, year] = monthLabel.split(' ')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -104,6 +92,7 @@ export const MonthHeader: FC<MonthHeaderProps> = ({ monthLabel, size }) => {
|
|||||||
<CalendarNavigationButton
|
<CalendarNavigationButton
|
||||||
direction="previous"
|
direction="previous"
|
||||||
onClick={goToPreviousMonths}
|
onClick={goToPreviousMonths}
|
||||||
|
className={calendarClasses.previousMonthButton}
|
||||||
/>
|
/>
|
||||||
<div className={calendarClasses.row}>
|
<div className={calendarClasses.row}>
|
||||||
<Typography
|
<Typography
|
||||||
@ -113,25 +102,14 @@ export const MonthHeader: FC<MonthHeaderProps> = ({ monthLabel, size }) => {
|
|||||||
>
|
>
|
||||||
{month}
|
{month}
|
||||||
</Typography>
|
</Typography>
|
||||||
{changeYearMode ? (
|
|
||||||
<YearControl
|
<YearControl year={year} size={size} />
|
||||||
year={year}
|
|
||||||
size={size}
|
|
||||||
onClickAway={() => {
|
|
||||||
setChangeYearMode(false)
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<Typography
|
|
||||||
onClick={() => setChangeYearMode(true)}
|
|
||||||
variant={size === 'large' ? 'label1' : 'label2'}
|
|
||||||
className={calendarClasses.year}
|
|
||||||
>
|
|
||||||
{year}
|
|
||||||
</Typography>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
<CalendarNavigationButton direction="next" onClick={goToNextMonths} />
|
<CalendarNavigationButton
|
||||||
|
direction="next"
|
||||||
|
onClick={goToNextMonths}
|
||||||
|
className={calendarClasses.nextMonthButton}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user