Skip to content

Commit

Permalink
feat(datetime): add parts for calendar day and button wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
brandyscarney committed Aug 17, 2023
1 parent 9016798 commit 0293b9d
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 90 deletions.
3 changes: 3 additions & 0 deletions core/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ ion-datetime,css-prop,--background-rgb
ion-datetime,css-prop,--title-color
ion-datetime,css-prop,--wheel-fade-background-rgb
ion-datetime,css-prop,--wheel-highlight-background
ion-datetime,part,calendar-day
ion-datetime,part,calendar-day active
ion-datetime,part,calendar-day today
ion-datetime,part,month-year-button
ion-datetime,part,time-button
ion-datetime,part,time-button active
Expand Down
34 changes: 20 additions & 14 deletions core/src/components/datetime/datetime.ios.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@include padding($datetime-ios-padding, $datetime-ios-padding, $datetime-ios-padding, $datetime-ios-padding);

border-bottom: $datetime-ios-border-color;

font-size: 14px;
}

Expand Down Expand Up @@ -85,27 +85,33 @@
*/
@include padding($datetime-ios-padding * 0.5, $datetime-ios-padding * 0.5, $datetime-ios-padding * 0.5, $datetime-ios-padding * 0.5);

align-items: center;

height: calc(100% - #{$datetime-ios-padding});
}

:host .calendar-day {
font-size: 20px;
}
:host .calendar-day-wrapper {
@include padding(4px);

.calendar-day:focus .calendar-day-highlight,
.calendar-day.calendar-day-active .calendar-day-highlight {
opacity: 0.2;
// This is required so that the calendar day wrapper
// will collapse instead of expanding to fill the button
height: 0;

min-height: 16px;
}

.calendar-day.calendar-day-active .calendar-day-highlight {
background: current-color(base);
:host .calendar-day {
width: 40px;
min-width: 40px;

height: 40px;

font-size: 20px;
}

// !important is needed here to overwrite custom highlight background, which is inline.
// Does not apply to the active state because highlights aren't applied at all there.
.calendar-day:focus .calendar-day-highlight {
/* stylelint-disable-next-line declaration-no-important */
background: current-color(base) !important;
.calendar-day:focus,
.calendar-day.calendar-day-active {
background: current-color(base, 0.2);
}

/**
Expand Down
15 changes: 8 additions & 7 deletions core/src/components/datetime/datetime.md.scss
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,15 @@

// Individual day button in month
:host .calendar-day {
@include padding(13px, 0, 13px, 0px);
width: 42px;
min-width: 42px;

height: 42px;

font-size: $datetime-md-calendar-item-font-size;
}

.calendar-day:focus .calendar-day-highlight {
.calendar-day:focus {
background: current-color(base, 0.2);

box-shadow: 0px 0px 0px 4px current-color(base, 0.2);
Expand All @@ -85,11 +88,9 @@
* should have ion-color for text color.
*/
:host .calendar-day.calendar-day-today {
color: current-color(base);
}

.calendar-day.calendar-day-today .calendar-day-highlight {
border: 1px solid current-color(base);

color: current-color(base);
}

/**
Expand All @@ -101,7 +102,7 @@
color: current-color(contrast);
}

.calendar-day.calendar-day-active .calendar-day-highlight {
.calendar-day.calendar-day-active {
border: 1px solid current-color(base);

background: current-color(base);
Expand Down
33 changes: 20 additions & 13 deletions core/src/components/datetime/datetime.scss
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ ion-picker-column-internal {
}

:host .calendar-body .calendar-month {
display: flex;

flex-flow: column;

/**
* Swiping should snap to at
* most one month at a time.
Expand Down Expand Up @@ -325,13 +329,27 @@ ion-picker-column-internal {
grid-template-columns: repeat(7, 1fr);
}

:host .calendar-day-wrapper {
display: flex;

align-items: center;
justify-content: center;

min-width: 0;

min-height: 0;

overflow: visible;
}

/**
* Center the day text vertically
* and horizontally within its grid cell.
*/
:host .calendar-day {
@include padding(0px, 0px, 0px, 0px);
@include margin(0px, 0px, 0px, 0px);
@include border-radius(50%);
@include padding(0px);
@include margin(0px);

display: flex;

Expand Down Expand Up @@ -362,17 +380,6 @@ ion-picker-column-internal {
opacity: 0.4;
}

.calendar-day-highlight {
@include border-radius(32px, 32px, 32px, 32px);
@include padding(4px, 4px, 4px, 4px);

position: absolute;

width: 32px;
height: 32px;

z-index: -1;
}

// Time / Header
// -----------------------------------
Expand Down
115 changes: 59 additions & 56 deletions core/src/components/datetime/datetime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ import {
*
* @part month-year-button - The button that opens the month/year picker when
* using a grid style layout.
*
* @part calendar-day - The individual buttons that display a day inside of the datetime
* calendar.
* @part calendar-day active - The currently selected calendar day.
* @part calendar-day today - The calendar day that contains the current day.
*/
@Component({
tag: 'ion-datetime',
Expand Down Expand Up @@ -2080,68 +2085,66 @@ export class Datetime implements ComponentInterface {
}

return (
<button
tabindex="-1"
data-day={day}
data-month={month}
data-year={year}
data-index={index}
data-day-of-week={dayOfWeek}
disabled={isCalDayDisabled}
class={{
'calendar-day-padding': isCalendarPadding,
'calendar-day': true,
'calendar-day-active': isActive,
'calendar-day-today': isToday,
}}
style={
dateStyle && {
color: dateStyle.textColor,
}
}
aria-hidden={isCalendarPadding ? 'true' : null}
aria-selected={ariaSelected}
aria-label={ariaLabel}
onClick={() => {
if (isCalendarPadding) {
return;
<div class="calendar-day-wrapper">
<button
tabindex="-1"
data-day={day}
data-month={month}
data-year={year}
data-index={index}
data-day-of-week={dayOfWeek}
disabled={isCalDayDisabled}
class={{
'calendar-day-padding': isCalendarPadding,
'calendar-day': true,
'calendar-day-active': isActive,
'calendar-day-today': isToday,
}}
part={`calendar-day${isActive ? ' active' : ''}${isToday ? ' today' : ''}`}
style={
dateStyle && {
color: dateStyle.textColor,
backgroundColor: dateStyle.backgroundColor,
}
}

this.setWorkingParts({
...this.workingParts,
month,
day,
year,
});

// multiple only needs date info, so we can wipe out other fields like time
if (multiple) {
this.setActiveParts(
{
month,
day,
year,
},
isActive
);
} else {
this.setActiveParts({
...activePart,
aria-hidden={isCalendarPadding ? 'true' : null}
aria-selected={ariaSelected}
aria-label={ariaLabel}
onClick={() => {
if (isCalendarPadding) {
return;
}

this.setWorkingParts({
...this.workingParts,
month,
day,
year,
});
}
}}
>
<div
class="calendar-day-highlight"
style={{
backgroundColor: dateStyle?.backgroundColor,

// multiple only needs date info, so we can wipe out other fields like time
if (multiple) {
this.setActiveParts(
{
month,
day,
year,
},
isActive
);
} else {
this.setActiveParts({
...activePart,
month,
day,
year,
});
}
}}
></div>
{text}
</button>
>
{text}
</button>
</div>
);
})}
</div>
Expand Down

0 comments on commit 0293b9d

Please sign in to comment.