mui-x icon indicating copy to clipboard operation
mui-x copied to clipboard

[pickers] Add `viewRenderers` documentation

Open Semigradsky opened this issue 3 years ago • 20 comments

Edit

The new purpose of the issue is mentioned here.

Duplicates

  • [X] I have searched the existing issues

Latest version

  • [X] I have tested the latest version

Summary 💡

There is the solution for customizing days - https://mui.com/x/react-date-pickers/date-picker/#customized-day-rendering

Need to have a solution for customizing months and years.

Examples 🌈

renderMonth and renderYear properties?

Motivation 🔦

No response

Order ID 💳 (optional)

No response

Semigradsky avatar Apr 26 '22 12:04 Semigradsky

I would indeed be nice to be able to customize the year / month

@alexfauquette for day / month / year custom rendering, should be also use component slots ? (so replace props.renderDay by a props.components.Day)

flaviendelangle avatar Apr 26 '22 13:04 flaviendelangle

Yes, the slot seems to work well on datagrid, so we could reuse it here.

@Semigradsky What do you want to perform with custom month/year? Most of the modifications can be done with CSS class names

alexfauquette avatar Apr 26 '22 16:04 alexfauquette

@alexfauquette My current need - specially display 'today' month/year. For example, today (2022-04-26) 'today month' is April and 'today year' is 2022.

Semigradsky avatar Apr 26 '22 18:04 Semigradsky

Showing today does not feel like an isolated use-case. We could add a .MuiPickersYear-today and .MuiPickersMonth-today like we already have .MuiPickersDay-today

alexfauquette avatar Sep 26 '22 09:09 alexfauquette

We could add a .MuiPickersYear-today and .MuiPickersMonth-today like we already have .MuiPickersDay-today

And renderMonth/renderYear?

Semigradsky avatar Oct 13 '22 07:10 Semigradsky

We plan to create those two :+1:

flaviendelangle avatar Oct 13 '22 07:10 flaviendelangle

The ability to override views has been added via viewRenderers in v6. The issue is that it has not yet been documented well and the only single example of its usage is given in the migration guide.

If you do have the time and need, could you please investigate if this option covers your use case?

As for the issue. I'm renaming it to cover the implementation of the viewRenderers documentation with examples.

LukasTy avatar May 02 '23 19:05 LukasTy

I'm trying to highlight specific days on the date picker, it sounds like viewRenderers is the new way to do that? Does anyone have any examples of how to use them yet?

sarink avatar May 30 '23 18:05 sarink

@sarink viewRenderers are for providing a totally custom view. If you need to highlight specific days, there are definitely better ways to do it. Consider using slotProps.day. Try checking this example, maybe it will help steer you in the right direction. 🤔

LukasTy avatar May 30 '23 18:05 LukasTy

The ability to override views has been added via viewRenderers in v6. The issue is that it has not yet been documented well and the only single example of its usage is given in the migration guide.

If you do have the time and need, could you please investigate if this option covers your use case?

As for the issue. I'm renaming it to cover the implementation of the viewRenderers documentation with examples.

Well, I need a "quarter" view, which I thought would be an easy job, basically taking month view and going from 12 to 4 items.

If I understood correctly, I would now need to copy-paste renderDateViewCalendar, <DateCalendar/>, and ~every /internals/ import from there, to be able to do this?

MonstraG avatar Jul 25 '23 12:07 MonstraG

Well, I need a "quarter" view, which I thought would be an easy job, basically taking month view and going from 12 to 4 items.

Oh, such a change would be hardly trivial, because it's technically a separate view and would be easier to implement if we had this view in the options. You could technically consider hacking such view in and think of a trigger on how to open it, be it the toolbar or somewhere else, but I can't guarantee that it would work without major problems.

Another option, as you've said, would be to create your own DateCalendar having the toggle inside of it, but that's also somewhat tedious. https://github.com/mui/mui-x/pull/7784 should technically allow changing the very place, where such view changing triggers would make the most sense. Without it, I would hardly imagine a sustainable way to introduce such a view. 🤔

LukasTy avatar Jul 25 '23 12:07 LukasTy

Well, I need a "quarter" view, which I thought would be an easy job, basically taking month view and going from 12 to 4 items.

Oh, such a change would be hardly trivial, because it's technically a separate view and would be easier to implement if we had this view in the options. You could technically consider hacking such view in and think of a trigger on how to open it, be it the toolbar or somewhere else, but I can't guarantee that it would work without major problems.

Another option, as you've said, would be to create your own DateCalendar having the toggle inside of it, but that's also somewhat tedious. #7784 should technically allow changing the very place, where such view changing triggers would make the most sense. Without it, I would hardly imagine a sustainable way to introduce such a view. 🤔

Yea, I tried that, and the easies way is copy those two files, change imports of internals, from relative to project, (+ add the package into transpilePackages in next.config.js because they are ESM), and finally replace the picker for months for a quarters one, but too complex, and I decided to just make one from scratch instead.

MonstraG avatar Jul 31 '23 14:07 MonstraG

Looks like viewRenderers not available for DateCalendar 🤔

Semigradsky avatar Oct 25 '23 12:10 Semigradsky

The views are the UIs rendered inside the Modal/Popupe of the pickers. The DatePicker uses a view for the date that renders DateCalendar.

This is a tool that is only built for the pickers.

flaviendelangle avatar Oct 25 '23 12:10 flaviendelangle

DateCalendar has views property too.

Semigradsky avatar Oct 25 '23 13:10 Semigradsky

Yes it does Those are not the same concept, even though I do agree it's confusing and we should clean it at some point. I wrote some of my thoughts in #8989 a few months ago.

Basically, the views prop defines which parts of the date you want to edit and the viewRenderers define how to edit them on the pickers.

flaviendelangle avatar Oct 25 '23 13:10 flaviendelangle

Ok, are there any plans to adding viewRenderers to DateCalendar or slots month/year (in the same way as we have day slot)?

Semigradsky avatar Oct 25 '23 14:10 Semigradsky

are there any plans to adding viewRenderers to DateCalendar

No, it's not something we are considering for now. But if there is enough traction, we can of course do it at some point.

or slots month/year (in the same way as we have day slot)?

If what you are trying is to override a single month / year button, then sure we can add those slots. It's a topic mentionned in https://github.com/mui/mui-x/issues/6488 but made it a duplicate of this one which is wrong :thinking:

flaviendelangle avatar Oct 25 '23 14:10 flaviendelangle

to override a single month / year button

Yeah, that is what I need 🙏

Semigradsky avatar Oct 25 '23 17:10 Semigradsky

Ok, are there any plans to adding viewRenderers to DateCalendar or slots month/year (in the same way as we have day slot)?

i would also appreciate this feature.

carlosgl93 avatar May 01 '24 11:05 carlosgl93