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

Improve pickers composition #1833

Closed
Pajn opened this issue May 27, 2020 · 10 comments
Closed

Improve pickers composition #1833

Pajn opened this issue May 27, 2020 · 10 comments
Labels
enhancement New feature or request

Comments

@Pajn
Copy link

Pajn commented May 27, 2020

Is your feature request related to a problem? Please describe.
It's very hard to impossible to customize the components in any way making them unusable if the default behavior does not exactly match the requirements.

Describe the solution you'd like
Like core, add *Component props to allow overriding any inner components and also export the inner components used in this library so that one can make use of them when implementing overrides.

Describe alternatives you've considered
There aren't really any. I could make separate feature requests for the behavior I need right now but even if all of them gets implemented I would feel a bit uneasy to use this library as any future requirement might require the whole solution to be rewritten in something else.

Additional context
See how the mui Dialog component allows overriding the Backdrop, Paper and Transition components

@oliviertassinari oliviertassinari added the enhancement New feature or request label May 27, 2020
@oliviertassinari
Copy link
Member

@Pajn Could you share more details on your use case? What do you wish to accomplish? Which component do you need to customize?

@Pajn
Copy link
Author

Pajn commented May 27, 2020

Right now I would need to add extra controls inside the popup for DesktopDateRangePicker.
makeRangePicker is exported so if DesktopPopperWrapper also was exported I think I could create a custom wrapper to archive what I want by wrapping DesktopPopperWrapper but being familiar with core I would have expected props like DateRangePickerViewComponent, DateRangePickerViewProps (which in turn has DateRangePickerViewDesktopComponent), ToolbarComponent, CalendarComponent etc. Core also provides all files in the npm package instead of a big bundle so I have never experienced not being able to import an inner component before, even though it might not be exported from the top level module.

Now, according to the types, ToolbarComponent does exists but it does not seem to do anything and https://github.com/mui-org/material-ui-pickers/blob/6cde0eaf11531d10667d9f4d78bbcb9b3d51763f/lib/src/DateRangePicker/DateRangePickerView.tsx#L195 directly renders the imported component which would explain that.

@oliviertassinari
Copy link
Member

@Pajn If you could share a visual preview of what you are going after, it will help

@oliviertassinari
Copy link
Member

oliviertassinari commented May 27, 2020

Regarding the consistency with the core, you can follow mui/material-ui#19706 and #1631 which can help.

@Pajn
Copy link
Author

Pajn commented May 27, 2020

Right now it was this:
Annotation 2020-05-27 153230

I have solved my immediate problem with overriding the transition component and doing some hacky things with inspecting and cloning children:

const TransitionOverride = forwardRef(
  (transitionProps: TransitionProps & { children?: any }, ref) => (
    <Grow {...transitionProps} ref={ref}>
      {cloneElement(transitionProps.children, {
        children: (
          <div style={{ display: 'flex' }}>
            <CommonlyUsed />
            {transitionProps.children?.props.children}
          </div>
        ),
      })}
    </Grow>
  ),
);

It's more the general case I am concerned about. This was harder than it should have been and can easily imagine requirements that might come that I yet does not now how to solve. For example, week numbers or date/time range picking. If I could override and import the Calender component I could easily wrap it and add extra controls around each calendar.

@dmtrKovalenko
Copy link
Member

For the custom wrapper components, we specifically expose the Static version of components.

So if you want to build custom wrapper, you can do the following

<Popper>
    <StaticDateRangePicker />
   <DialogActions>
       ...your controls
   </DialogActions>
</Popper>

Moreover pickers properly expose the components
image

And also you can pass any props down to the MuiComponents using PopperProps or PopoverProps or DialogProps. So I think we can close this issue

@oliviertassinari
Copy link
Member

oliviertassinari commented May 27, 2020

@Pajn Ok thanks, we track this shortcut feature in #1659. Also, be careful with your use case for the component, please mind #364 (comment).

@oliviertassinari
Copy link
Member

oliviertassinari commented May 27, 2020

So if you want to build custom wrapper, you can do the following

@dmtrKovalenko Would this be enough? I believe the integration with an input is not obvious. Maybe we would need a new demo or abstraction?

@oliviertassinari oliviertassinari changed the title Export and allow overriding inner components Improve pickers composition May 27, 2020
@aamirafridi
Copy link
Contributor

@oliviertassinari I think this issue should be reopened as well.
ToolbarComponent prop is still not working with the latest alpha.12 https://codesandbox.io/s/material-ui-date-range-xy8yx

@oliviertassinari
Copy link
Member

Closing as too ambitious compared to our bandwidth and the other problems we need to fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants