Skip to content

Commit

Permalink
feat: pass resource prop to DayColumnWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyredd authored Jun 11, 2024
1 parent 621b8f1 commit 77760aa
Show file tree
Hide file tree
Showing 6 changed files with 1,747 additions and 1,544 deletions.
1 change: 1 addition & 0 deletions src/DayColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class DayColumn extends React.Component {
selecting && 'rbc-slot-selecting'
)}
slotMetrics={slotMetrics}
resource={resource}
>
{slotMetrics.groups.map((grp, idx) => (
<TimeSlotGroup
Expand Down
30 changes: 29 additions & 1 deletion stories/Calendar.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { action } from '@storybook/addon-actions'
import demoEvents from './resources/events'
import { Calendar } from '../src'

import { events, Calendar as BaseCalendar, Views } from './helpers'
import {
events,
Calendar as BaseCalendar,
Views,
resourceEvents,
resources,
} from './helpers'

import createEvents from './helpers/createEvents'
import customComponents from './resources/customComponents'
Expand Down Expand Up @@ -101,3 +107,25 @@ CustomNoAgendaEventsLabel.args = {
noEventsInRange: 'There are no special events in this range [test message]',
},
}

export const CustomDayColumnWrapper = Template.bind({})
CustomDayColumnWrapper.storyName = 'add custom dayColumnWrapper'
CustomDayColumnWrapper.args = {
defaultView: Views.DAY,
events: resourceEvents,
resources: resources,
resourceAccessor: 'resourceId',
resourceIdAccessor: 'id',
resourceTitleAccessor: 'name',
components: {
dayColumnWrapper: customComponents.dayColumnWrapper,
},
}
CustomDayColumnWrapper.parameters = {
docs: {
description: {
story:
'The custom DayColumnWrapper allows you to add your own custom logic when rendering a Day Column.',
},
},
}
1 change: 1 addition & 0 deletions stories/props/components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const components = useMemo(() => ({
eventWrapper: MyEventWrapper,
eventContainerWrapper: MyEventContainerWrapper,
dateCellWrapper: MyDateCellWrapper,
dayColumnWrapper: MyDayColumnWrapper,
timeSlotWrapper: MyTimeSlotWrapper,
timeGutterHeader: MyTimeGutterWrapper,
resourceHeader: MyResourceHeader,
Expand Down
22 changes: 22 additions & 0 deletions stories/resources/CustomDayColumnWrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react'

const DayColumnWrapper = ({ children, className, style, innerRef }) => {
return (
<div className={className} style={style} ref={innerRef}>
{children}
</div>
)
}

export default React.forwardRef((dayColumnWrapperProps, ref) => {
const redBorder = dayColumnWrapperProps.resource % 2 === 0
const style = {
borderColor: redBorder ? 'red' : '#fff',
borderStyle: 'solid',
borderWidth: '1px',
}

return (
<DayColumnWrapper {...dayColumnWrapperProps} style={style} innerRef={ref} />
)
})
2 changes: 2 additions & 0 deletions stories/resources/customComponents.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import { action } from '@storybook/addon-actions'
import CustomDayColumnWrapper from './CustomDayColumnWrapper'

const customComponents = {
dateCellWrapper: (dateCellWrapperProps) => {
Expand Down Expand Up @@ -27,6 +28,7 @@ const customComponents = {
</div>
)
},
dayColumnWrapper: CustomDayColumnWrapper,
timeSlotWrapper: (timeSlotWrapperProps) => {
// Show different styles at arbitrary time
const hasCustomInfo = timeSlotWrapperProps.value
Expand Down
Loading

0 comments on commit 77760aa

Please sign in to comment.