Skip to content

feat: datetime, expose calendar grid buttons for styling #25340

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

Closed
3 tasks done
phyr0s opened this issue May 24, 2022 · 19 comments · Fixed by #27641
Closed
3 tasks done

feat: datetime, expose calendar grid buttons for styling #25340

phyr0s opened this issue May 24, 2022 · 19 comments · Fixed by #27641
Labels
package: core @ionic/core package type: feature request a new feature, enhancement, or improvement

Comments

@phyr0s
Copy link

phyr0s commented May 24, 2022

Prerequisites

Describe the Feature Request

This issue #24963 is closed but ion-datetime hasn't got properties to edit css #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

@ionitron-bot ionitron-bot bot added the triage label May 24, 2022
@GusLAN
Copy link

GusLAN commented May 24, 2022

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

@liamdebeasi
Copy link
Contributor

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 liamdebeasi added the needs: reply the issue needs a response from the user label May 24, 2022
@ionitron-bot ionitron-bot bot removed the triage label May 24, 2022
@phyr0s
Copy link
Author

phyr0s commented May 24, 2022

@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

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels May 24, 2022
@liamdebeasi
Copy link
Contributor

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 liamdebeasi changed the title feat: ion-datetime component to allow CSS customization feat: datetime, expose calendar grid buttons for styling May 25, 2022
@liamdebeasi liamdebeasi added type: feature request a new feature, enhancement, or improvement package: core @ionic/core package labels May 25, 2022
@ionitron-bot ionitron-bot bot removed the triage label May 25, 2022
@phyr0s
Copy link
Author

phyr0s commented May 27, 2022

@liamdebeasi css shadow parts will be perfect solution.

@balaji-sasikumar
Copy link

@liamdebeasi any updates on this feature request?

@ntorrey
Copy link

ntorrey commented Aug 2, 2022

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.

@Joep-DDQ
Copy link

Joep-DDQ commented Nov 2, 2022

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

@ZachLHelms
Copy link

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.

@aparajita
Copy link

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?

@loyaj
Copy link

loyaj commented Apr 26, 2023

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
Copy link

loyaj commented May 16, 2023

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.

@aparajita
Copy link

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

brandyscarney added a commit that referenced this issue Sep 6, 2023
Issue number: resolves #25340

---------

- Exposes the following parts for a calendar day: `calendar-day`,
`today`, and `active`
- Combines the `calendar-day-highlight` element with the `calendar-day`
element so developers don't have to know to style two different elements
& we don't have to expose them as separate parts
- Improves height parity of the calendar day across browsers
- Updates the `custom` e2e test to include an example of styling days
using the newly exposed CSS parts
- Adds tests for the focus states of the calendar day
@brandyscarney
Copy link
Member

Thank you for the issue! This has been resolved by 79b005d. It will be in the 7.4 release. Example usage will be available in the datetime docs after the release is published.

@aparajita
Copy link

@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.

@liamdebeasi
Copy link
Contributor

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.

@aparajita
Copy link

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!

@liamdebeasi
Copy link
Contributor

liamdebeasi commented Sep 6, 2023

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.

@ionitron-bot
Copy link

ionitron-bot bot commented Oct 6, 2023

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 ionitron-bot bot locked and limited conversation to collaborators Oct 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: core @ionic/core package type: feature request a new feature, enhancement, or improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants