Is there any way to change the styling of this component? And not only some basic stuff like colour and size but the entire style, buttons, etc.
https://ionicframework.com/docs/api/components/datetime/DateTime/
<ion-item>
<ion-label>Date</ion-label>
<ion-datetime displayFormat="MM/DD/YYYY" [(ngModel)]="myDate"></ion-datetime>
</ion-item>
[(ngModel)] keeps track of a variable that can be set by yourself inside your controller. displayFormat is a comman formatting schema for your date. If you want to display for example in German format, then you will have to write DD.MM.YYYY.
https://ionicframework.com/docs/api/components/datetime/DateTime/#sass-variables. There are five ariables for each device type (iOS, Android and deprecated Windows Phone):
$datetime-ios-padding-top$datetime-ios-padding-end $datetime-ios-padding-bottom $datetime-ios-padding-start$datetime-ios-placeholder-colorhttps://github.com/ionic-team/ionic-docs/blob/master/src/demos/api/datetime/index.html
I know it's an old question, but if anyone still needs a method on customizing the look of the component here is my method.
I use Renderer2 from Angular to apply a part attribute to (in my case) calendar days so I can style them to my needs.
@ViewChild('calendar', { read: ElementRef, static: false }) calendar?: ElementRef;
ngAfterViewInit(): void {
timer(200).subscribe(() => { //async issues I couldn't resolve
const shadow: DocumentFragment = this.calendar?.nativeElement.shadowRoot;
const days = shadow.querySelectorAll('.calendar-day');
days.forEach(day => {
this.renderer.setAttribute(day, 'part', 'day');
});
});
}
Then I used regular scss to format.
ion-datetime {
&::part(day) {
border: 1px solid black;
border-radius: 50%;
width: 34px;
height: 34px;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With