React-big-calendar: Custom props for toolbar

Created on 11 Sep 2019  路  2Comments  路  Source: jquense/react-big-calendar

Before creating PR for a new I'd like to ask about your opinion first - maybe there is a better solution :-)

I'm trying to create custom toolbar with additional buttons:

const newToolbar = (props) => {
   return (
      <div className="rbc-toolbar">
          <span className="rbc-btn-group">
             ... code handling standard buttons ...
          </span>
          <span className="rbc-btn-group">
             <button type="button"  onClick={()=>myButton1Handler()} > {'1'} </button>
             <button type="button"  onClick={()=>myButton2Handler()} > {'2'} </button>
          </span>
    </div>
   )
}

Then in rendering Calendar component I'm looking for a way of sending additional props, e.g. handlers to my new buttons, to customized toolbar as current implementation does not seem to support anything like that.

    <Calendar
          components={ toolbar: newToolbar }
     />

Maybe something like this?

    <Calendar
          components={ 
             toolbar:newToolbar, 
             toolbarProps: {onclick1:myButton1Handler, onclick2:myButton2Handler }
          }
     />

Such toolbar props would be merged with props currently sent to toolbar component.

Right now I'm doing it by defining custom toolbar component within the scope of HOC encapsulating Calendar component, but it is not very nice solution.

Any idea?

Most helpful comment

try it like this
components = { toolbar: props => ( <ToolBarView {...props} timesheetDate={timesheetDate} /> ) }

All 2 comments

try it like this
components = { toolbar: props => ( <ToolBarView {...props} timesheetDate={timesheetDate} /> ) }

Yes, this works and is much nicer solution.
Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mathieusanchez picture mathieusanchez  路  4Comments

tiaaaa123 picture tiaaaa123  路  4Comments

bionicvapourboy picture bionicvapourboy  路  3Comments

jgautsch picture jgautsch  路  3Comments

dogC76 picture dogC76  路  4Comments