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

Feature/timeslots #1092

Merged
merged 3 commits into from
Sep 9, 2024
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export interface CalendarProps<T extends ICalendarEventBase> {
showAdjacentMonths?: boolean
sortedMonthView?: boolean
showVerticalScrollIndicator?: boolean
timeslots?: number
}
```

Expand Down Expand Up @@ -204,6 +205,7 @@ export interface CalendarProps<T extends ICalendarEventBase> {
| `showWeekNumber` | no | `boolean` | Show week number. Week number will be shown at top left corner for week/day mode and at start of each row for month mode |
| `weekNumberPrefix` | no | `string` | Prefix for week number. For month mode, the prefix will be shown in header row. |
| `maxVisibleEventCount` | no | `number` | Maximum number of events to show in a cell in month view. If the number of events exceeds this value, the cell will show the `moreLabel`. Defaults to 3. |
| `timeslots` | no | `number` | Number of timeslots to render per Hour. Default to 0 |
| `hourComponent` | no | `HourRenderer` | Custom hour renderer |

## EventRenderer
Expand Down
3 changes: 3 additions & 0 deletions src/components/CalendarBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ interface CalendarBodyProps<T extends ICalendarEventBase> {
enrichedEventsByDate?: Record<string, T[]>
enableEnrichedEvents?: boolean
eventsAreSorted?: boolean
timeslots?: number
hourComponent?: HourRenderer
}

Expand Down Expand Up @@ -114,6 +115,7 @@ function _CalendarBody<T extends ICalendarEventBase>({
enrichedEventsByDate,
enableEnrichedEvents = false,
eventsAreSorted = false,
timeslots = 0,
hourComponent,
}: CalendarBodyProps<T>) {
const scrollView = React.useRef<ScrollView>(null)
Expand Down Expand Up @@ -327,6 +329,7 @@ function _CalendarBody<T extends ICalendarEventBase>({
index={index}
calendarCellStyle={calendarCellStyle}
calendarCellAccessibilityProps={calendarCellAccessibilityProps}
timeslots={timeslots}
/>
))}
{_renderEvents(date)}
Expand Down
3 changes: 3 additions & 0 deletions src/components/CalendarContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export interface CalendarContainerProps<T extends ICalendarEventBase> {
* Default value is `false`.
*/
eventsAreSorted?: boolean
timeslots?: number
hourComponent?: HourRenderer
}

Expand Down Expand Up @@ -216,6 +217,7 @@ function _CalendarContainer<T extends ICalendarEventBase>({
enableEnrichedEvents = false,
eventsAreSorted = false,
onSwipeEnd,
timeslots = 0,
hourComponent,
}: CalendarContainerProps<T>) {
// To ensure we have proper effect callback, use string to date comparision.
Expand Down Expand Up @@ -451,6 +453,7 @@ function _CalendarContainer<T extends ICalendarEventBase>({
enrichedEventsByDate={enrichedEventsByDate}
enableEnrichedEvents={enableEnrichedEvents}
eventsAreSorted={eventsAreSorted}
timeslots={timeslots}
hourComponent={hourComponent}
/>
</React.Fragment>
Expand Down
25 changes: 22 additions & 3 deletions src/components/HourGuideCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface HourGuideCellProps {
index: number
calendarCellStyle?: CalendarCellStyle
calendarCellAccessibilityProps?: AccessibilityProps
timeslots: number
}

const _HourGuideCell = ({
Expand All @@ -26,6 +27,7 @@ const _HourGuideCell = ({
index,
calendarCellStyle,
calendarCellAccessibilityProps,
timeslots,
}: HourGuideCellProps) => {
const theme = useTheme()

Expand All @@ -44,11 +46,28 @@ const _HourGuideCell = ({
style={[
u['border-l'],
u['border-b'],
{ borderColor: theme.palette.gray['200'] },
{ height: cellHeight },
{
borderColor: theme.palette.gray['200'],
height: cellHeight,
justifyContent: 'space-evenly',
},
{ ...getCalendarCellStyle(date.toDate(), index) },
]}
/>
>
{Array.from({ length: timeslots }, (_, index) => (
<View
key={index}
style={[
u['border-l'],
u['border-b'],
{
borderColor: theme.palette.gray['100'],
height: 1,
},
]}
/>
))}
</View>
</TouchableWithoutFeedback>
)
}
Expand Down
5 changes: 5 additions & 0 deletions stories/desktop.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ storiesOf('showcase - Desktop', module)
<Calendar height={SCREEN_HEIGHT} events={events} overlapOffset={70} />
</View>
))
.add('With timeslots', () => (
<View style={styles.desktop}>
<Calendar height={SCREEN_HEIGHT} events={events} overlapOffset={70} timeslots={1} />
</View>
))
.add('RTL', () => {
React.useEffect(() => {
require('dayjs/locale/he')
Expand Down
Loading