Skip to content

feat(datetime): add parts for calendar day, active, and today #27641

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

Merged
merged 33 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0293b9d
feat(datetime): add parts for calendar day and button wrapper
brandyscarney Aug 17, 2023
6ca4cda
test(datetime): add test for customizing the css parts
brandyscarney Aug 17, 2023
8c28d11
refactor: remove unused css
brandyscarney Aug 17, 2023
c697ef9
chore(): add updated snapshots
Ionitron Aug 17, 2023
64fa7cb
fix(datetime): focus calendar day element when tabbing
brandyscarney Aug 17, 2023
16fdd91
test(datetime): remove test from color directory
brandyscarney Aug 24, 2023
cd6e0a4
test(datetime): add test to custom for customizing calendar days
brandyscarney Aug 24, 2023
1a588b0
test(datetime): target the specific grid datetime for the test
brandyscarney Aug 24, 2023
a0f6cd5
test(datetime): remove unused elements from test
brandyscarney Aug 24, 2023
71273b6
test(datetime): fix broken tests
brandyscarney Aug 24, 2023
c0772db
chore(): add updated snapshots
Ionitron Aug 24, 2023
ac71cfa
test(datetime): update colors to look better with dark mode
brandyscarney Aug 25, 2023
9b93291
fix(datetime): extract width/height to Sass vars
brandyscarney Aug 28, 2023
e314040
docs(datetime): comment on why the mins exist
brandyscarney Aug 28, 2023
f5c8c82
style: lint
brandyscarney Aug 28, 2023
141fc3b
git: revert image updates
brandyscarney Aug 28, 2023
d522a76
fix(datetime): don't add css shadow parts to spacer days
brandyscarney Aug 30, 2023
c062227
fix(datetime): add a focus ring around ios and make highlightedDates …
brandyscarney Aug 31, 2023
e34124a
actual property name
brandyscarney Aug 31, 2023
beec11c
Merge branch 'feature-7.4' into FW-1593
brandyscarney Aug 31, 2023
7d91ffa
chore(): add updated snapshots
Ionitron Aug 31, 2023
c2a5c32
test(datetime): fix incorrect selector & screenshot images
brandyscarney Aug 31, 2023
8bc0407
Merge branch 'feature-7.4' into FW-1593
liamdebeasi Sep 1, 2023
74547d6
test(datetime): oops those ids were used
brandyscarney Sep 1, 2023
de13e15
chore(): add updated snapshots
Ionitron Sep 1, 2023
85e250d
fix(datetime): check if the day is not calendar padding to add parts
brandyscarney Sep 1, 2023
9cfe971
fix(datetime): remove highlighted dates from other months
brandyscarney Sep 5, 2023
2a63bf5
refactor(datetime): combine the shared css
brandyscarney Sep 5, 2023
198bd3d
test(datetime): add tests for focus states
brandyscarney Sep 5, 2023
6f4d463
style: lint
brandyscarney Sep 5, 2023
aa3881e
chore(): add updated snapshots
Ionitron Sep 5, 2023
cbba937
test(datetime): don't screenshot rtl tests for focus
brandyscarney Sep 5, 2023
80af52c
Merge branch 'feature-7.4' into FW-1593
brandyscarney Sep 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 19 additions & 20 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,32 @@
*/
@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);

// This is required so that the calendar day wrapper
// will collapse instead of expanding to fill the button
height: 0;

.calendar-day:focus .calendar-day-highlight,
.calendar-day.calendar-day-active .calendar-day-highlight {
opacity: 0.2;
min-height: 16px;
}

.calendar-day.calendar-day-active .calendar-day-highlight {
background: current-color(base);
:host .calendar-day {
width: $datetime-ios-day-width;
min-width: $datetime-ios-day-width;

height: $datetime-ios-day-height;

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.calendar-day-active {
background: current-color(base, 0.2);
}

/**
Expand Down Expand Up @@ -135,12 +140,6 @@
color: current-color(contrast);
}

.calendar-day.calendar-day-today.calendar-day-active .calendar-day-highlight {
background: current-color(base);

opacity: 1;
}

// Time / Header
// -----------------------------------
:host .datetime-time {
Expand Down
6 changes: 6 additions & 0 deletions core/src/components/datetime/datetime.ios.vars.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ $datetime-ios-time-width: 68px !default;

/// @prop - Border radius of the time picker
$datetime-ios-time-border-radius: 8px !default;

/// @prop - Width of the calendar day
$datetime-ios-day-width: 40px !default;

/// @prop - Height of the calendar day
$datetime-ios-day-height: $datetime-ios-day-width !default;
19 changes: 7 additions & 12 deletions core/src/components/datetime/datetime.md.scss
Original file line number Diff line number Diff line change
Expand Up @@ -69,27 +69,22 @@

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

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

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

box-shadow: 0px 0px 0px 4px current-color(base, 0.2);
font-size: $datetime-md-calendar-item-font-size;
}

/**
* Day that today but not selected
* 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 +96,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
6 changes: 6 additions & 0 deletions core/src/components/datetime/datetime.md.vars.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ $datetime-md-header-padding: 20px !default;

/// @prop - Padding for content
$datetime-md-padding: 16px !default;

/// @prop - Width of the calendar day
$datetime-md-day-width: 42px !default;

/// @prop - Height of the calendar day
$datetime-md-day-height: $datetime-md-day-width !default;
38 changes: 27 additions & 11 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,31 @@ ion-picker-column-internal {
grid-template-columns: repeat(7, 1fr);
}

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

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

// Adding a min width and min height allows
// it to shrink smaller than its content
// which keeps the calendar day highlight
// larger while letting the grid items shrink
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,16 +384,10 @@ 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;
.calendar-day:focus {
background: current-color(base, 0.2);

z-index: -1;
box-shadow: 0px 0px 0px 4px current-color(base, 0.2);
}

// Time / Header
Expand Down
139 changes: 80 additions & 59 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 @@ -756,7 +761,7 @@ export class Datetime implements ComponentInterface {
/**
* Get the number of padding days so
* we know how much to offset our next selector by
* to grab the correct calenday-day element.
* to grab the correct calendar-day element.
*/
const padding = currentMonth.querySelectorAll('.calendar-day-padding');
const { day } = this.workingParts;
Expand All @@ -770,7 +775,7 @@ export class Datetime implements ComponentInterface {
* and focus it.
*/
const dayEl = currentMonth.querySelector(
`.calendar-day:nth-of-type(${padding.length + day})`
`.calendar-day-wrapper:nth-of-type(${padding.length + day}) .calendar-day`
) as HTMLElement | null;
if (dayEl) {
dayEl.focus();
Expand Down Expand Up @@ -2116,69 +2121,85 @@ export class Datetime implements ComponentInterface {
dateStyle = getHighlightStyles(highlightedDates, dateIsoString, el);
}

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;
}
let dateParts = undefined;

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,
// "Filler days" at the beginning of the grid should not get the calendar day
// CSS parts added to them
if (!isCalendarPadding) {
dateParts = `calendar-day${isActive ? ' active' : ''}${isToday ? ' today' : ''}`;
}

return (
<div class="calendar-day-wrapper">
<button
// We need to use !important for the inline styles here because
// otherwise the CSS shadow parts will override these styles.
// See https://github.com/WICG/webcomponents/issues/847
// Both the CSS shadow parts and highlightedDates styles are
// provided by the developer, but highlightedDates styles should
// always take priority.
ref={(el) => {
if (el) {
el.style.setProperty('color', `${dateStyle ? dateStyle.textColor : ''}`, 'important');
el.style.setProperty(
'background-color',
`${dateStyle ? dateStyle.backgroundColor : ''}`,
'important'
);
}
}}
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={dateParts}
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
Loading