Skip to content

Commit

Permalink
feat: Slot group prop getter (jquense#1471) (jquense#1510)
Browse files Browse the repository at this point in the history
* feat: Added slotGroupPropGetter (jquense#1471)

* fix: Pass getters to time gutter
  • Loading branch information
emilienh authored Feb 13, 2020
1 parent 7b5a6a7 commit fcb9b9a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 17 deletions.
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 @@ -486,14 +486,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 @@ -775,7 +784,8 @@ class Calendar extends React.Component {
resourceIdAccessor,
resourceTitleAccessor,
eventPropGetter,
slotPropGetter,
slotPropGetter,
slotGroupPropGetter,
dayPropGetter,
view,
views,
Expand All @@ -794,7 +804,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

0 comments on commit fcb9b9a

Please sign in to comment.