Skip to content

Commit

Permalink
Merge branch 'development' into feature/multi-select
Browse files Browse the repository at this point in the history
  • Loading branch information
vassbence authored Nov 12, 2024
2 parents fb13e2c + 587beb8 commit eea08ca
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
28 changes: 28 additions & 0 deletions src/components/Calendar/CalendarItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ type CalendarItemProps = {
position?: 'start' | 'middle' | 'end'
repeating?: boolean
onClick?: () => void
forceHover?: boolean
onHoverChange?: (hover: boolean) => void
}

function CalendarItem({
Expand All @@ -21,9 +23,12 @@ function CalendarItem({
position,
repeating,
onClick,
forceHover,
onHoverChange,
}: CalendarItemProps) {
return (
<styled.div
data-forcehover={forceHover ? forceHover : undefined}
style={{
flexShrink: 0,
display: 'flex',
Expand Down Expand Up @@ -83,8 +88,31 @@ function CalendarItem({
}),
},
}),
'&[data-forcehover]': {
...(color === 'neutral' && {
background: colors.neutral10,
}),
...(color === 'red' && {
background: colors.red20,
}),
...(color === 'green' && {
background: colors.green20,
}),
...(color === 'blue' && {
background: colors.blue20,
}),
...(color === 'orange' && {
background: colors.orange20,
}),
},
}}
onClick={onClick}
onPointerEnter={() => {
onHoverChange?.(true)
}}
onPointerLeave={() => {
onHoverChange?.(false)
}}
>
{(!position || position === 'start') && repeating && (
<Icon variant="repeat" size="small" />
Expand Down
6 changes: 5 additions & 1 deletion src/components/Calendar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function Calendar({
const maxItemsPerCell = Math.floor(
(cellHeight + 4) / ((variant === 'monthly' ? 24 : 40) + 4),
)
const [forceHover, setForceHover] = useState<string>()

const days = useMemo(() => {
const count =
Expand All @@ -61,7 +62,6 @@ function Calendar({
for (let i = 0; i < count; i++) {
const day = addDays(new Date(visiblePeriodStart), i)

// TODO is structClone needed? it was a fix for the __hidden attribute sticking around but now it might not be necessary
const dayItems = structuredClone(data).filter((e) =>
endField
? isSameDay(day, new Date(e[startField])) ||
Expand Down Expand Up @@ -416,6 +416,10 @@ function Calendar({
onClick={() => {
onItemClick?.(e)
}}
forceHover={forceHover === e.id}
onHoverChange={(hover) => {
setForceHover(hover ? e.id : undefined)
}}
/>
</div>
),
Expand Down
10 changes: 0 additions & 10 deletions src/components/DateInput/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,12 @@ import {
useClick,
useDismiss,
useFloating,
useHover,
useInteractions,
useTransitionStyles,
} from '@floating-ui/react'
import {
cloneElement,
createContext,
Dispatch,
ReactElement,
ReactNode,
SetStateAction,
useCallback,
useContext,
useEffect,
useMemo,
useRef,
Expand All @@ -36,15 +29,12 @@ import {
addYears,
compareAsc,
endOfMonth,
endOfWeek,
format,
getHours,
getMinutes,
getMonth,
getYear,
isSameDay,
isSameHour,
isSameMinute,
isSameMonth,
isSameYear,
isToday,
Expand Down

0 comments on commit eea08ca

Please sign in to comment.