Skip to content

Commit b084a1f

Browse files
authored
feat(ui5-calendar): expose shadow parts for month-picker and year-picker (#11698)
Previously there was no possible way of overstyling the header buttons, the month picker view, and the year picker's buttons of the ui5-calendar web component. With this change we are introducing CSS Shadow Parts, which allows overstyling of those calendar parts.
1 parent 0139932 commit b084a1f

File tree

6 files changed

+50
-2
lines changed

6 files changed

+50
-2
lines changed

packages/main/src/Calendar.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,15 @@ type CalendarYearRangeT = {
188188
* @csspart month-cell - Used to style the month cells.
189189
* @csspart month-cell-selected - Used to style the month cells when selected.
190190
* @csspart month-cell-selected-between - Used to style the day cells in between of selected months in range.
191+
* @csspart month-picker-root - Used to style the month picker root container.
191192
* @csspart year-cell - Used to style the year cells.
192193
* @csspart year-cell-selected - Used to style the year cells when selected.
193194
* @csspart year-cell-selected-between - Used to style the year cells in between of selected years in range.
195+
* @csspart year-picker-root - Used to style the year picker root container.
194196
* @csspart year-range-cell - Used to style the year range cells.
195197
* @csspart year-range-cell-selected - Used to style the year range cells when selected.
196198
* @csspart year-range-cell-selected-between - Used to style the year range cells in between of selected year ranges.
199+
* @csspart calendar-header-middle-button - Used to style the calendar header middle buttons (month/year/year-range buttons).
197200
* @since 1.0.0-rc.11
198201
*/
199202
@customElement({

packages/main/src/CalendarHeaderTemplate.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default function CalendarTemplate(this: Calendar) {
2424
<div
2525
data-ui5-cal-header-btn-month
2626
class="ui5-calheader-arrowbtn ui5-calheader-middlebtn"
27+
part="calendar-header-middle-button"
2728
hidden={this._isHeaderMonthButtonHidden}
2829
tabindex={0}
2930
role="button"
@@ -41,6 +42,7 @@ export default function CalendarTemplate(this: Calendar) {
4142
<div
4243
data-ui5-cal-header-btn-year
4344
class="ui5-calheader-arrowbtn ui5-calheader-middlebtn"
45+
part="calendar-header-middle-button"
4446
hidden={this._isHeaderYearButtonHidden}
4547
tabindex={0}
4648
role="button"
@@ -56,6 +58,7 @@ export default function CalendarTemplate(this: Calendar) {
5658
<div
5759
data-ui5-cal-header-btn-year-range
5860
class="ui5-calheader-arrowbtn ui5-calheader-middlebtn"
61+
part="calendar-header-middle-button"
5962
hidden={this._isHeaderYearRangeButtonHidden}
6063
tabindex={0}
6164
role="button"

packages/main/src/CalendarTemplate.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default function CalendarTemplate(this: Calendar) {
4848
timestamp={this._timestamp}
4949
onChange={this.onSelectedMonthChange}
5050
onNavigate={this.onNavigate}
51-
exportparts="month-cell, month-cell-selected, month-cell-selected-between"
51+
exportparts="month-cell, month-cell-selected, month-cell-selected-between, month-picker-root"
5252
/>
5353

5454
<YearPicker
@@ -66,7 +66,7 @@ export default function CalendarTemplate(this: Calendar) {
6666
_currentYearRange = {this._currentYearRange}
6767
onChange={this.onSelectedYearChange}
6868
onNavigate={this.onNavigate}
69-
exportparts="year-cell, year-cell-selected, year-cell-selected-between"
69+
exportparts="year-cell, year-cell-selected, year-cell-selected-between, year-picker-root"
7070
/>
7171

7272
<YearRangePicker

packages/main/src/MonthPickerTemplate.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export default function MonthPickerTemplate(this: MonthPicker) {
44
return (
55
<div
66
class="ui5-mp-root"
7+
part="month-picker-root"
78
role="grid"
89
aria-roledescription={this.roleDescription}
910
aria-readonly="false"

packages/main/src/YearPickerTemplate.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export default function YearPickerTemplate(this: YearPicker) {
44
return (
55
<div
66
class="ui5-yp-root"
7+
part="year-picker-root"
78
role="grid"
89
aria-roledescription={this.roleDescription}
910
aria-readonly="false"

packages/main/test/pages/Calendar.html

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,35 @@
2020

2121

2222
<link rel="stylesheet" type="text/css" href="./styles/Calendar.css">
23+
24+
<style>
25+
/* Shadow Parts Demo Styles */
26+
.shadow-parts-demo::part(month-picker-root) {
27+
background: linear-gradient(135deg, #e3f2fd, #bbdefb);
28+
border: 2px solid #2196f3;
29+
border-radius: 8px;
30+
}
31+
32+
.shadow-parts-demo::part(year-picker-root) {
33+
background: linear-gradient(135deg, #fff3e0, #ffcc02);
34+
border: 2px solid #ff9800;
35+
border-radius: 8px;
36+
}
37+
38+
.shadow-parts-demo::part(calendar-header-middle-button) {
39+
background: #9c27b0;
40+
color: white;
41+
border-radius: 6px;
42+
border: 2px solid #7b1fa2;
43+
}
44+
45+
.header-parts-demo::part(calendar-header-middle-button) {
46+
background: #673ab7;
47+
color: white;
48+
border: 2px solid #512da8;
49+
transform: scale(1.1);
50+
}
51+
</style>
2352
</head>
2453
<body class="calendar1auto">
2554

@@ -103,6 +132,17 @@
103132
</ui5-calendar>
104133
</section>
105134

135+
<section>
136+
<ui5-title>Shadow Parts Demo - Custom Picker Styling</ui5-title>
137+
<p>Use F4 (month view) or Shift+F4 (year view) to see custom picker backgrounds</p>
138+
<ui5-calendar class="shadow-parts-demo"></ui5-calendar>
139+
</section>
140+
141+
<section>
142+
<ui5-title>Shadow Parts Demo - Custom Header Buttons</ui5-title>
143+
<ui5-calendar class="header-parts-demo"></ui5-calendar>
144+
</section>
145+
106146
</body>
107147

108148
<script>

0 commit comments

Comments
 (0)