Skip to content

Commit

Permalink
feat: pass resource prop to DayColumnWrapper; Updated docs and storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyredd committed Jun 10, 2024
1 parent 621b8f1 commit 05c6c09
Show file tree
Hide file tree
Showing 8 changed files with 41,638 additions and 2,418 deletions.
38,476 changes: 38,476 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

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
31 changes: 30 additions & 1 deletion stories/Calendar.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ import React from 'react'
import { action } from '@storybook/addon-actions'

import demoEvents from './resources/events'
// import demoResourceEvents from './resources/resourceEvents'
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 +108,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
5 changes: 5 additions & 0 deletions stories/resources/resourceEvents.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
export default {
events: [
{
id: 1,
title: 'Rencontre',
resourceId: 'a',
start: new Date(2015, 3, 2, 5, 30, 0, 0),
end: new Date(2015, 3, 2, 10, 30, 0, 0),
},
{
id: 2,
title: 'Another Meeting',
resourceId: 'b',
start: new Date(2015, 3, 1, 2, 30, 0, 0),
end: new Date(2015, 3, 1, 4, 30, 0, 0),
},
{
id: 3,
title: 'A',
resourceId: 'a',
start: new Date(2015, 3, 4, 5, 30, 0, 0),
end: new Date(2015, 3, 4, 10, 30, 0, 0),
},
{
id: 4,
title: 'B',
resourceId: 'b',
start: new Date(2015, 3, 4, 5, 30, 0, 0),
end: new Date(2015, 3, 4, 10, 30, 0, 0),
},
{
id: 5,
title: 'C',
resourceId: 'c',
start: new Date(2015, 3, 4, 5, 30, 0, 0),
Expand Down
5,518 changes: 3,101 additions & 2,417 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit 05c6c09

Please sign in to comment.