ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

feat: datetime, expose calendar grid buttons for styling

Open phyr0s opened this issue 1 year ago • 7 comments

Prerequisites

Describe the Feature Request

This issue #24963 is closed but ion-datetime hasn't got properties to edit css https://github.com/ionic-team/ionic-framework/issues/24963

In that issue there is one code pen -> https://codepen.io/liamdebeasi/pen/YzYWBgV but it's not possible to change all colors.

For example if i want this style with the text in one color (white) and background selected (green) it's not possible to customize

Captura de Pantalla 2022-05-24 a las 12 46 44

Font size, bold, or change disabled styles (for one days or more days) it's not possible

Captura de Pantalla 2022-05-24 a las 12 42 37

Describe the Use Case

Should allow to customize color, background color, font size, font weight, for all items (selected, unselected, disabled, selection arrows)

Describe Preferred Solution

No response

Describe Alternatives

No response

Related Code

No response

Additional Information

No response

phyr0s avatar May 24 '22 10:05 phyr0s

I have the same problem... It's important for me to cutomize the component.

GusLAN avatar May 24 '22 10:05 GusLAN

Thanks for the issue. Can you help me understand the use case for each of the customizations you need as well as what you have tried already? Most of the customizations listed here can be achieved by modifying the Ionic theme. Here is an example: https://ionic-docs-okx99ne93-ionic1.vercel.app/docs/api/datetime#theming

Datetime is a tricky component to open up for customization given how complex it is. As a result, we are trying to prioritize a consistent user experience. However, there are certainly areas that we should open up for more customization.

liamdebeasi avatar May 24 '22 12:05 liamdebeasi

@liamdebeasi try to change font size of the numbers or create day selector with custom color. Only can change the background-color but not the color of the number

phyr0s avatar May 24 '22 13:05 phyr0s

Thanks! It sounds like a majority of the styling needs here revolve around the buttons in the calendar grid. I think it makes sense to expose these buttons with potentially ways of styling based on state (selected, today, disabled, etc).

One idea is to expose one or more CSS Shadow Parts. This will give developers the flexibility to apply any style to the individual buttons without disrupting the overall layout of the calendar grid.

liamdebeasi avatar May 25 '22 15:05 liamdebeasi

@liamdebeasi css shadow parts will be perfect solution.

phyr0s avatar May 27 '22 10:05 phyr0s

@liamdebeasi any updates on this feature request?

balaji-sasikumar avatar Jul 20 '22 05:07 balaji-sasikumar

I came here to request this exact feature! I need to display multiple date ranges each with it's own color and styling (for example, I style the first/last dates of the range differently from the dates in the middle).

I currently use the Angular material datepicker for this feature (https://material.angular.io/components/datepicker/overview#datepicker-date-class). They utilize a "dateClass" method which runs for each individual date and applies a custom class based on whatever logic you want. The downside to their feature is that since it applies a class, I need to hard code the classes (unless there is a way to dynamically load css that I don't know about, which is very possible). It would be nicer if there were a way to apply either classes or styles to each date based on some logic.

ntorrey avatar Aug 02 '22 12:08 ntorrey

Somewhat unrelated but hoping someone can point me in the right direction. I somehow messed up the css for the datetimepicker, but can't find where to restore it. I see that the class for the day button is calendar-day but in which file is this normally stored? afbeelding

Joep-DDQ avatar Nov 02 '22 15:11 Joep-DDQ

Also somewhat related, being able to change the size of the selector would be beneficial, and i can't find documentation on that ability. Example of what I'm running into:

image

Where my selector is covering up adjacent dates because im using the calendar in a narrow area.

ZachLHelms avatar Dec 19 '22 03:12 ZachLHelms

Thanks! It sounds like a majority of the styling needs here revolve around the buttons in the calendar grid. I think it makes sense to expose these buttons with potentially ways of styling based on state (selected, today, disabled, etc).

One idea is to expose one or more CSS Shadow Parts. This will give developers the flexibility to apply any style to the individual buttons without disrupting the overall layout of the calendar grid.

@liamdebeasi How do envision setting the CSS for a specific button's shadow parts? Adding a cssClass property to DatetimeHighlightStyle?

aparajita avatar Apr 21 '23 21:04 aparajita

I'm having this issue, too. My specific use case is changing the border-radius of the circular highlight on the selected date(s) so that it's a rounded rectangle rather than a circle. Having shadow parts for this would work nicely.

loyaj avatar Apr 26 '23 18:04 loyaj

After working further with the datetime component, I too am needing to specify the font properties for the numbers in the grid (like font-size and font-weight). Again, shadow parts for the individual date buttons would work nicely for this.

Also, could we have a shadow part or css property for changing the size of the chevrons we use to navigate to the next/previous month (in the upper-right corner)? Compared to the other buttons in my interface, these buttons are huge and I need a way to make them smaller.

loyaj avatar May 16 '23 01:05 loyaj

@liamdebeasi I think the simplest solution would be to add a style property to DatetimeHighlightStyle. That would give us complete control.

aparajita avatar May 16 '23 08:05 aparajita

Thank you for the issue! This has been resolved by https://github.com/ionic-team/ionic-framework/commit/79b005da704c2ce481e1e3bc4d24cdba06a36d04. It will be in the 7.4 release. Example usage will be available in the datetime docs after the release is published.

brandyscarney avatar Sep 06 '23 16:09 brandyscarney

@brandyscarney Unless I'm missing something, this solution is global to the entire calendar, and does not allow us to style different days in different ways.

aparajita avatar Sep 06 '23 19:09 aparajita

The original request was to expose a way to style the days in the calendar grid. We also added a way to style the selected days as well as today's date. If you want to customize specific days (regardless of today/selected state) then the highlightedDates API should be used.

liamdebeasi avatar Sep 06 '23 19:09 liamdebeasi

Unfortunately highlightedDates is extremely limited. Here's the interface:

export type DatetimeHighlightStyle = {
  textColor: string;
  backgroundColor?: string;
} | {
  textColor?: string;
  backgroundColor: string;
};

No control over any other css properties!

aparajita avatar Sep 06 '23 19:09 aparajita

That's intentional. highlightedDates allows developers to call out notable dates in the calendar not change the shape of specific calendar days. Our focus is on providing tools so developers can customize datetime in a consistent way.

liamdebeasi avatar Sep 06 '23 19:09 liamdebeasi

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

ionitron-bot[bot] avatar Oct 06 '23 19:10 ionitron-bot[bot]