feat(datetime): add border property to highlightedDates (#30534)
Issue number: resolves #29833 --------- - Adds the `border` property for customizing the border of highlighted dates - Adds the `border` to the e2e test for highlightedDates - Updates screenshots --------- Co-authored-by: Brandy Smith <6577830+brandyscarney@users.noreply.github.com>
@ -22,15 +22,15 @@ export type DatetimePresentation = 'date-time' | 'time-date' | 'date' | 'time' |
|
|||||||
|
|
||||||
export type TitleSelectedDatesFormatter = (selectedDates: string[]) => string;
|
export type TitleSelectedDatesFormatter = (selectedDates: string[]) => string;
|
||||||
|
|
||||||
export type DatetimeHighlightStyle =
|
/**
|
||||||
| {
|
* DatetimeHighlightStyle must include textColor, backgroundColor, or border.
|
||||||
textColor: string;
|
* It cannot be an empty object.
|
||||||
backgroundColor?: string;
|
*/
|
||||||
}
|
export type DatetimeHighlightStyle = {
|
||||||
| {
|
|
||||||
textColor?: string;
|
textColor?: string;
|
||||||
backgroundColor: string;
|
backgroundColor?: string;
|
||||||
};
|
border?: string;
|
||||||
|
} & ({ textColor: string } | { backgroundColor: string } | { border: string });
|
||||||
|
|
||||||
export type DatetimeHighlight = { date: string } & DatetimeHighlightStyle;
|
export type DatetimeHighlight = { date: string } & DatetimeHighlightStyle;
|
||||||
|
|
||||||
|
|||||||
@ -2335,6 +2335,7 @@ export class Datetime implements ComponentInterface {
|
|||||||
`${dateStyle ? dateStyle.backgroundColor : ''}`,
|
`${dateStyle ? dateStyle.backgroundColor : ''}`,
|
||||||
'important'
|
'important'
|
||||||
);
|
);
|
||||||
|
el.style.setProperty('border', `${dateStyle ? dateStyle.border : ''}`, 'important');
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
|
|||||||
@ -21,16 +21,19 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
|
|||||||
date: '2023-01-01', // ensure selected date style overrides highlight
|
date: '2023-01-01', // ensure selected date style overrides highlight
|
||||||
textColor: '#800080',
|
textColor: '#800080',
|
||||||
backgroundColor: '#ffc0cb',
|
backgroundColor: '#ffc0cb',
|
||||||
|
border: '2px solid purple',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
date: '2023-01-02',
|
date: '2023-01-02',
|
||||||
textColor: '#b22222',
|
textColor: '#b22222',
|
||||||
backgroundColor: '#fa8072',
|
backgroundColor: '#fa8072',
|
||||||
|
border: '2px solid purple',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
date: '2023-01-03',
|
date: '2023-01-03',
|
||||||
textColor: '#0000ff',
|
textColor: '#0000ff',
|
||||||
backgroundColor: '#add8e6',
|
backgroundColor: '#add8e6',
|
||||||
|
border: '2px solid purple',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
@ -52,6 +55,7 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
|
|||||||
return {
|
return {
|
||||||
textColor: '#b22222',
|
textColor: '#b22222',
|
||||||
backgroundColor: '#fa8072',
|
backgroundColor: '#fa8072',
|
||||||
|
border: '2px solid purple',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,6 +63,7 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
|
|||||||
return {
|
return {
|
||||||
textColor: '#800080',
|
textColor: '#800080',
|
||||||
backgroundColor: '#ffc0cb',
|
backgroundColor: '#ffc0cb',
|
||||||
|
border: '2px solid purple',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,6 +71,7 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
|
|||||||
return {
|
return {
|
||||||
textColor: '#0000ff',
|
textColor: '#0000ff',
|
||||||
backgroundColor: '#add8e6',
|
backgroundColor: '#add8e6',
|
||||||
|
border: '2px solid purple',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +83,7 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
|
|||||||
await expect(datetime).toHaveScreenshot(screenshot(`datetime-highlightedDates-callback`));
|
await expect(datetime).toHaveScreenshot(screenshot(`datetime-highlightedDates-callback`));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should render highlights correctly when only using one color or the other', async ({ page }) => {
|
test('should render highlights correctly when only using only one color property', async ({ page }) => {
|
||||||
const datetime = page.locator('ion-datetime');
|
const datetime = page.locator('ion-datetime');
|
||||||
|
|
||||||
await datetime.evaluate((el: HTMLIonDatetimeElement) => {
|
await datetime.evaluate((el: HTMLIonDatetimeElement) => {
|
||||||
@ -90,6 +96,10 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
|
|||||||
date: '2023-01-03',
|
date: '2023-01-03',
|
||||||
textColor: '#0000ff',
|
textColor: '#0000ff',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
date: '2023-01-04',
|
||||||
|
border: '2px solid purple',
|
||||||
|
},
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 20 KiB |
@ -78,6 +78,10 @@
|
|||||||
textColor: 'blue',
|
textColor: 'blue',
|
||||||
backgroundColor: 'lightblue',
|
backgroundColor: 'lightblue',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
date: '2023-01-07',
|
||||||
|
border: '2px dotted red',
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
document.querySelector('#withCallback').highlightedDates = (isoString) => {
|
document.querySelector('#withCallback').highlightedDates = (isoString) => {
|
||||||
@ -103,6 +107,7 @@
|
|||||||
date: new Date().toISOString().split('T')[0],
|
date: new Date().toISOString().split('T')[0],
|
||||||
textColor: 'purple',
|
textColor: 'purple',
|
||||||
backgroundColor: 'pink',
|
backgroundColor: 'pink',
|
||||||
|
border: '2px solid purple',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -207,6 +207,7 @@ export const getHighlightStyles = (
|
|||||||
return {
|
return {
|
||||||
textColor: matchingHighlight.textColor,
|
textColor: matchingHighlight.textColor,
|
||||||
backgroundColor: matchingHighlight.backgroundColor,
|
backgroundColor: matchingHighlight.backgroundColor,
|
||||||
|
border: matchingHighlight.border,
|
||||||
} as DatetimeHighlightStyle;
|
} as DatetimeHighlightStyle;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||