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

feat: Slot group prop getter (#1471) #1510

Merged
merged 2 commits into from
Feb 13, 2020
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
22 changes: 11 additions & 11 deletions .size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"./dist/react-big-calendar.js": {
"bundled": 501317,
"minified": 146786,
"gzipped": 44762
"bundled": 507436,
"minified": 149016,
"gzipped": 45496
},
"./dist/react-big-calendar.min.js": {
"bundled": 439004,
"minified": 127972,
"gzipped": 40409
"bundled": 444328,
"minified": 130089,
"gzipped": 41174
},
"dist/react-big-calendar.esm.js": {
"bundled": 168678,
"minified": 80552,
"gzipped": 19913,
"bundled": 174497,
"minified": 83179,
"gzipped": 20739,
"treeshaked": {
"rollup": {
"code": 58283,
"code": 60400,
"import_statements": 1578
},
"webpack": {
"code": 62787
"code": 64923
}
}
}
Expand Down
20 changes: 16 additions & 4 deletions src/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,14 +487,23 @@ class Calendar extends React.Component {

/**
* Optionally provide a function that returns an object of className or style props
* to be applied to the the time-slot node. Caution! Styles that change layout or
* to be applied to the time-slot node. Caution! Styles that change layout or
* position may break the calendar in unexpected ways.
*
* ```js
* (date: Date, resourceId: (number|string)) => { className?: string, style?: Object }
* ```
*/
slotPropGetter: PropTypes.func,
slotPropGetter: PropTypes.func,

/**
* Optionally provide a function that returns an object of props to be applied
* to the time-slot group node. Useful to dynamically change the sizing of time nodes.
* ```js
* () => { style?: Object }
* ```
*/
slotGroupPropGetter: PropTypes.func,

/**
* Optionally provide a function that returns an object of className or style props
Expand Down Expand Up @@ -776,7 +785,8 @@ class Calendar extends React.Component {
resourceIdAccessor,
resourceTitleAccessor,
eventPropGetter,
slotPropGetter,
slotPropGetter,
slotGroupPropGetter,
dayPropGetter,
view,
views,
Expand All @@ -795,7 +805,9 @@ class Calendar extends React.Component {
eventProp: (...args) =>
(eventPropGetter && eventPropGetter(...args)) || {},
slotProp: (...args) =>
(slotPropGetter && slotPropGetter(...args)) || {},
(slotPropGetter && slotPropGetter(...args)) || {},
slotGroupProp: (...args) =>
(slotGroupPropGetter && slotGroupPropGetter(...args)) || {},
dayProp: (...args) => (dayPropGetter && dayPropGetter(...args)) || {},
},
components: defaults(components[view] || {}, omit(components, names), {
Expand Down
1 change: 1 addition & 0 deletions src/TimeGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export default class TimeGrid extends Component {
timeslots={this.props.timeslots}
components={components}
className="rbc-time-gutter"
getters={getters}
/>
{this.renderEvents(range, rangeEvents, getNow())}
</div>
Expand Down
4 changes: 3 additions & 1 deletion src/TimeGutter.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class TimeGutter extends Component {
}

render() {
const { resource, components } = this.props
const { resource, components, getters } = this.props

return (
<div className="rbc-time-gutter rbc-time-column">
Expand All @@ -48,6 +48,7 @@ export default class TimeGutter extends Component {
resource={resource}
components={components}
renderSlot={this.renderSlot}
getters={getters}
/>
)
})}
Expand All @@ -63,6 +64,7 @@ TimeGutter.propTypes = {
step: PropTypes.number.isRequired,
getNow: PropTypes.func.isRequired,
components: PropTypes.object.isRequired,
getters: PropTypes.object,

localizer: PropTypes.object.isRequired,
resource: PropTypes.string,
Expand Down
3 changes: 2 additions & 1 deletion src/TimeSlotGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ export default class TimeSlotGroup extends Component {
components: { timeSlotWrapper: Wrapper = BackgroundWrapper } = {},
} = this.props

const groupProps = getters ? getters.slotGroupProp() : {}
return (
<div className="rbc-timeslot-group">
<div className="rbc-timeslot-group" {...groupProps}>
{group.map((value, idx) => {
const slotProps = getters ? getters.slotProp(value, resource) : {}
return (
Expand Down