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/hide hours column week view #754

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
27 changes: 16 additions & 11 deletions src/components/CalendarBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ interface CalendarBodyProps<T extends ICalendarEventBase> {
headerComponent?: React.ReactElement | null
headerComponentStyle?: ViewStyle
hourStyle?: TextStyle
hideHours?: Boolean
}

function _CalendarBody<T extends ICalendarEventBase>({
Expand All @@ -76,6 +77,7 @@ function _CalendarBody<T extends ICalendarEventBase>({
headerComponent = null,
headerComponentStyle = {},
hourStyle = {},
hideHours = false,
}: CalendarBodyProps<T>) {
const scrollView = React.useRef<ScrollView>(null)
const { now } = useNow(!hideNowIndicator)
Expand Down Expand Up @@ -158,17 +160,20 @@ function _CalendarBody<T extends ICalendarEventBase>({
style={[u['flex-1'], theme.isRTL ? u['flex-row-reverse'] : u['flex-row']]}
{...(Platform.OS === 'web' ? panResponder.panHandlers : {})}
>
<View style={[u['z-20'], u['w-50']]}>
{hours.map((hour) => (
<HourGuideColumn
key={hour}
cellHeight={cellHeight}
hour={hour}
ampm={ampm}
hourStyle={hourStyle}
/>
))}
</View>
{!hideHours && (
<View style={[u['z-20'], u['w-50']]}>
{hours.map((hour) => (
<HourGuideColumn
key={hour}
cellHeight={cellHeight}
hour={hour}
ampm={ampm}
hourStyle={hourStyle}
/>
))}
</View>
)}

{dateRange.map((date) => (
<View style={[u['flex-1'], u['overflow-hidden']]} key={date.toString()}>
{hours.map((hour, index) => (
Expand Down
6 changes: 6 additions & 0 deletions src/components/CalendarContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import { CalendarHeader } from './CalendarHeader'
import { CalendarHeaderForMonthView } from './CalendarHeaderForMonthView'

export interface CalendarContainerProps<T extends ICalendarEventBase> {
/**
* To remove Hours Column from week View.
*/
hideHours?: Boolean
/**
* Events to be rendered. This is a required prop.
*/
Expand Down Expand Up @@ -138,6 +142,7 @@ function _CalendarContainer<T extends ICalendarEventBase>({
moreLabel = '{moreCount} More',
showAdjacentMonths = true,
sortedMonthView = true,
hideHours = false,
}: CalendarContainerProps<T>) {
const [targetDate, setTargetDate] = React.useState(dayjs(date))

Expand Down Expand Up @@ -212,6 +217,7 @@ function _CalendarContainer<T extends ICalendarEventBase>({
dateRange,
mode,
onPressEvent,
hideHours,
}

if (mode === 'month') {
Expand Down
4 changes: 3 additions & 1 deletion src/components/CalendarHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface CalendarHeaderProps<T extends ICalendarEventBase> {
dayHeaderHighlightColor?: string
weekDayHeaderHighlightColor?: string
showAllDayEventCell?: boolean
hideHours?: Boolean
}

function _CalendarHeader<T extends ICalendarEventBase>({
Expand All @@ -35,6 +36,7 @@ function _CalendarHeader<T extends ICalendarEventBase>({
dayHeaderHighlightColor = '',
weekDayHeaderHighlightColor = '',
showAllDayEventCell = true,
hideHours = false,
}: CalendarHeaderProps<T>) {
const _onPressHeader = React.useCallback(
(date: Date) => {
Expand Down Expand Up @@ -64,7 +66,7 @@ function _CalendarHeader<T extends ICalendarEventBase>({
style,
]}
>
<View style={[u['z-10'], u['w-50'], borderColor]} />
{!hideHours && <View style={[u['z-10'], u['w-50'], borderColor]} />}
{dateRange.map((date) => {
const shouldHighlight = activeDate ? date.isSame(activeDate, 'date') : isToday(date)

Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface ICalendarEventBase {
end: Date
title: string
children?: ReactElement | null
hideHours?: boolean
}

export type CalendarTouchableOpacityProps = {
Expand Down
2 changes: 1 addition & 1 deletion stories/mobile.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ storiesOf('showcase - Mobile', module)
))
.add('week mode', () => (
<View style={styles.mobile}>
<Calendar height={MOBILE_HEIGHT} events={events} />
<Calendar hideHours height={MOBILE_HEIGHT} events={events} />
</View>
))
.add('Month mode', () => {
Expand Down