Skip to content

Commit

Permalink
feat: add disabled dates UI
Browse files Browse the repository at this point in the history
  • Loading branch information
xlecunff-pass committed Nov 28, 2024
1 parent 33e2dfe commit 4cf892c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/features/offer/components/MovieCalendar/MovieCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Props = {
selectedDate: Date | undefined
onTabChange: (date: Date) => void
flatListRef: React.MutableRefObject<FlatList | null>
disabledDates?: Date[]
flatListWidth?: number
onFlatListLayout?: (event: LayoutChangeEvent) => void
itemWidth?: number
Expand All @@ -33,6 +34,7 @@ export const MovieCalendar: React.FC<Props> = ({
onFlatListLayout,
itemWidth,
onItemLayout,
disabledDates,
}) => {
const { isDesktopViewport } = useTheme()
const {
Expand Down Expand Up @@ -94,6 +96,7 @@ export const MovieCalendar: React.FC<Props> = ({
date={date}
selectedDate={selectedDate}
onTabChange={onInternalTabChange}
disabled={disabledDates?.includes(date)}
/>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useMemo } from 'react'
import { View, ViewProps } from 'react-native'
import styled from 'styled-components/native'

Expand All @@ -13,22 +13,37 @@ type Props = {
onTabChange: (date: Date) => void
selectedDate?: Date
onLayout?: ViewProps['onLayout']
disabled?: boolean
}

export const MovieCalendarDay: React.FC<Props> = ({
date,
selectedDate,
onTabChange,
onLayout,
disabled,
}) => {
const { weekDay, dayDate, month, accessibilityLabel, isSelected } = useMovieCalendarDay(
date,
selectedDate
)
const { CalendarText } = StatusPattern[isSelected ? 'selected' : 'default']

const CalendarText = useMemo(() => {
if (disabled) {
return DisabledCalendarText
}
if (selectedDate) {
return SelectedCalendarText
}
return DefaultCalendarText
}, [disabled, selectedDate])

return (
<CalendarCell onLayout={onLayout} testID="movie-calendar-day" onPress={() => onTabChange(date)}>
<CalendarCell
disabled={disabled}
onLayout={onLayout}
testID="movie-calendar-day"
onPress={() => onTabChange(date)}>
<CalendarTextView accessibilityLabel={accessibilityLabel}>
<CalendarText numberOfLines={1}>{weekDay}</CalendarText>
<CalendarText numberOfLines={1}>{dayDate}</CalendarText>
Expand Down Expand Up @@ -65,11 +80,6 @@ const SelectedCalendarText = styled(DefaultCalendarText)(({ theme }) => ({
color: theme.colors.primary,
}))

const StatusPattern = {
default: {
CalendarText: DefaultCalendarText,
},
selected: {
CalendarText: SelectedCalendarText,
},
}
const DisabledCalendarText = styled(DefaultCalendarText)(({ theme }) => ({
color: theme.colors.greyMedium,
}))
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export const MovieCalendarProvider: React.FC<{
<MovieCalendar
dates={dates}
selectedDate={selectedDate}
disabledDates={[]}
onTabChange={setSelectedDate}
flatListRef={flatListRef}
flatListWidth={flatListWidth}
Expand Down

0 comments on commit 4cf892c

Please sign in to comment.