Skip to content

Commit 80d70d3

Browse files
committed
refactor(button,datetime): check if a button is inside of a datetime to apply styles
1 parent 9b0b84e commit 80d70d3

File tree

9 files changed

+65
-52
lines changed

9 files changed

+65
-52
lines changed

core/src/components/button/button.ionic.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,12 @@
334334
@include globals.position(null, globals.$ion-space-200, globals.$ion-space-200, null);
335335
}
336336
}
337+
338+
// Button in Datetime
339+
// --------------------------------------------------
340+
341+
:host(.in-datetime) {
342+
@include globals.typography(globals.$ion-body-action-md);
343+
344+
min-height: globals.$ion-space-1200;
345+
}

core/src/components/button/button.ios.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,20 @@
293293
background: var(--ion-toolbar-color, var(--color));
294294
color: #{var(--ion-toolbar-background, var(--background), ion-color(primary, contrast))};
295295
}
296+
297+
// Button in Datetime
298+
// --------------------------------------------------
299+
300+
:host(.in-datetime) {
301+
--padding-top: 3px;
302+
--padding-bottom: 3px;
303+
--padding-start: 5px;
304+
--padding-end: 5px;
305+
306+
@include margin(0px, 2px, 0px, 2px);
307+
308+
min-height: 32px;
309+
310+
font-size: dynamic-font-clamp(1, 17px, 1.24);
311+
font-weight: 400;
312+
}

core/src/components/button/button.md.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,18 @@
243243
background: var(--ion-toolbar-background, var(--color));
244244
color: #{var(--ion-toolbar-color, var(--background), ion-color(primary, contrast))};
245245
}
246+
247+
// Button in Datetime
248+
// --------------------------------------------------
249+
250+
:host(.in-datetime) {
251+
--padding-top: 3px;
252+
--padding-bottom: 3px;
253+
--padding-start: 8px;
254+
--padding-end: 8px;
255+
--box-shadow: none;
256+
257+
@include margin(0px, 2px, 0px, 2px);
258+
259+
min-height: 32px;
260+
}

core/src/components/button/button.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ import type { RouterDirection } from '../router/utils/interface';
3131
shadow: true,
3232
})
3333
export class Button implements ComponentInterface, AnchorInterface, ButtonInterface {
34+
private inDatetime = false;
3435
private inItem = false;
3536
private inListHeader = false;
36-
private inToolbar = false;
37+
private inButtons = false;
3738
private formButtonEl: HTMLButtonElement | null = null;
3839
private formEl: HTMLFormElement | null = null;
3940
private inheritedAttributes: Attributes = {};
@@ -216,7 +217,12 @@ export class Button implements ComponentInterface, AnchorInterface, ButtonInterf
216217
}
217218

218219
componentWillLoad() {
219-
this.inToolbar = !!this.el.closest('ion-buttons');
220+
// Check if element is inside a shadow root and get the host if so
221+
const rootNode = this.el.getRootNode();
222+
const shadowHost = rootNode instanceof ShadowRoot ? (rootNode as ShadowRoot).host : null;
223+
224+
this.inDatetime = !!this.el.closest('ion-datetime') || (shadowHost?.tagName === 'ION-DATETIME');
225+
this.inButtons = !!this.el.closest('ion-buttons');
220226
this.inListHeader = !!this.el.closest('ion-list-header');
221227
this.inItem = !!this.el.closest('ion-item') || !!this.el.closest('ion-item-divider');
222228
this.inheritedAttributes = inheritAriaAttributes(this.el);
@@ -233,9 +239,11 @@ export class Button implements ComponentInterface, AnchorInterface, ButtonInterf
233239
private get rippleType() {
234240
const hasClearFill = this.fill === undefined || this.fill === 'clear';
235241

236-
// If the button is in a toolbar, has a clear fill (which is the default)
237-
// and only has an icon we use the unbounded "circular" ripple effect
238-
if (hasClearFill && this.hasIconOnly && this.inToolbar) {
242+
// Use the unbounded "circular" ripple effect if it:
243+
// - Has a clear fill (the default)
244+
// - Only has an icon and
245+
// - Is inside of buttons (used in a toolbar) or a datetime
246+
if (hasClearFill && this.hasIconOnly && (this.inButtons || this.inDatetime)) {
239247
return 'unbounded';
240248
}
241249

@@ -400,7 +408,7 @@ export class Button implements ComponentInterface, AnchorInterface, ButtonInterf
400408
};
401409
let fill = this.fill;
402410
if (fill === undefined) {
403-
fill = this.inToolbar || this.inListHeader ? 'clear' : 'solid';
411+
fill = this.inDatetime || this.inButtons || this.inListHeader ? 'clear' : 'solid';
404412
}
405413

406414
/**
@@ -426,9 +434,10 @@ export class Button implements ComponentInterface, AnchorInterface, ButtonInterf
426434
[`${buttonType}-${shape}`]: true,
427435
[`${buttonType}-${fill}`]: true,
428436
[`${buttonType}-strong`]: strong,
437+
'in-datetime': this.inDatetime,
429438
'in-toolbar': hostContext('ion-toolbar', this.el),
430439
'in-toolbar-color': hostContext('ion-toolbar[color]', this.el),
431-
'in-buttons': hostContext('ion-buttons', this.el),
440+
'in-buttons': this.inButtons,
432441
'button-has-icon-only': hasIconOnly,
433442
'button-has-badge': hasBadge,
434443
'button-disabled': disabled,

core/src/components/datetime/datetime.common.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
}
151151

152152
:host .datetime-action-buttons,
153+
::slotted([slot="buttons"]),
153154
/**
154155
* The confirm and clear buttons are grouped in a
155156
* container so that they appear on the end opposite

core/src/components/datetime/datetime.ionic.scss

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,9 @@
252252
}
253253

254254
:host .datetime-buttons .datetime-action-buttons,
255-
.datetime-action-buttons .datetime-action-buttons-container {
255+
.datetime-action-buttons .datetime-action-buttons-container,
256+
::slotted([slot="buttons"]), {
256257
flex-flow: column;
257258
align-items: stretch;
258259
gap: globals.$ion-space-200;
259260
}
260-
261-
:host .datetime-buttons ion-button {
262-
@include globals.typography(globals.$ion-body-action-md);
263-
264-
min-height: globals.$ion-space-1200;
265-
}

core/src/components/datetime/datetime.ios.scss

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@
5454
@include margin(10px, 8px, 10px, 0);
5555
}
5656

57-
// These styles are copied from buttons.ios.scss
58-
:host ion-button {
59-
font-size: dynamic-font-clamp(1, 17px, 1.24);
60-
font-weight: 400;
61-
}
62-
6357
:host .calendar-action-buttons .calendar-month-year-toggle ion-icon,
6458
:host .calendar-action-buttons ion-button {
6559
color: current-color(base);
@@ -340,25 +334,15 @@
340334
border-top: $datetime-ios-border-color;
341335
}
342336

343-
:host .datetime-buttons {
337+
:host .datetime-buttons,
338+
::slotted([slot="buttons"]) {
344339
display: flex;
345340

346341
align-items: center;
347342
justify-content: space-between;
348343
}
349344

350-
:host .datetime-action-buttons {
345+
:host .datetime-action-buttons,
346+
::slotted([slot="buttons"]) {
351347
width: 100%;
352348
}
353-
354-
// These styles are copied from buttons.ios.scss
355-
:host .datetime-action-buttons ion-button {
356-
--padding-top: 3px;
357-
--padding-bottom: 3px;
358-
--padding-start: 5px;
359-
--padding-end: 5px;
360-
361-
@include margin(0px, 2px, 0px, 2px);
362-
363-
min-height: 32px;
364-
}

core/src/components/datetime/datetime.md.scss

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,3 @@
198198

199199
justify-content: flex-end;
200200
}
201-
202-
// These styles are copied from buttons.md.scss
203-
:host .datetime-action-buttons ion-button {
204-
--padding-top: 3px;
205-
--padding-bottom: 3px;
206-
--padding-start: 8px;
207-
--padding-end: 8px;
208-
--box-shadow: none;
209-
210-
@include margin(0px, 2px, 0px, 2px);
211-
212-
min-height: 32px;
213-
}

core/src/components/datetime/datetime.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ export class Datetime implements ComponentInterface {
15571557
* is disabled or readonly.
15581558
*/
15591559
const isButtonDisabled = disabled || readonly;
1560-
const confirmFill = theme === 'ionic' ? 'solid' : 'clear';
1560+
const confirmFill = theme === 'ionic' ? 'solid' : undefined;
15611561
const hasSlottedButtons = this.el.querySelector('[slot="buttons"]') !== null;
15621562
if (!hasSlottedButtons && !showDefaultButtons && !showClearButton) {
15631563
return;
@@ -1588,7 +1588,6 @@ export class Datetime implements ComponentInterface {
15881588
{showDefaultButtons && (
15891589
<ion-button
15901590
id="cancel-button"
1591-
fill="clear"
15921591
color={this.color}
15931592
onClick={() => this.cancel(true)}
15941593
disabled={isButtonDisabled}
@@ -1600,7 +1599,6 @@ export class Datetime implements ComponentInterface {
16001599
{showClearButton && (
16011600
<ion-button
16021601
id="clear-button"
1603-
fill="clear"
16041602
color={this.color}
16051603
onClick={() => clearButtonClick()}
16061604
disabled={isButtonDisabled}
@@ -2196,7 +2194,6 @@ export class Datetime implements ComponentInterface {
21962194
<div class="calendar-next-prev">
21972195
<ion-button
21982196
aria-label="Previous month"
2199-
fill="clear"
22002197
disabled={prevMonthDisabled}
22012198
onClick={() => this.prevMonth()}
22022199
>
@@ -2211,7 +2208,6 @@ export class Datetime implements ComponentInterface {
22112208
</ion-button>
22122209
<ion-button
22132210
aria-label="Next month"
2214-
fill="clear"
22152211
disabled={nextMonthDisabled}
22162212
onClick={() => this.nextMonth()}
22172213
>

0 commit comments

Comments
 (0)