diff --git a/.gitignore b/.gitignore index 0aa51ed..3252b77 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ cypress/results/* cypress/reports/* cypress/screenshots/* cypress/videos/* + +playwright-report \ No newline at end of file diff --git a/e2e/spec.spec.js b/e2e/spec.spec.js index 8136298..1bb1e72 100644 --- a/e2e/spec.spec.js +++ b/e2e/spec.spec.js @@ -176,4 +176,29 @@ test.describe('basic', () => { 'Selected: None' ) }) + + test('should highlight today when highlightToday is enabled', async ({ + page, + }) => { + await page.goto('/') + + const today = new Date() + const todayISO = new Date( + today.getFullYear(), + today.getMonth(), + today.getDate() + ).toISOString() + + // Highlight today should be enabled by default + await expect(page.locator(`[data-date="${todayISO}"]`)).toHaveClass( + /preachjs-calendar--grid-cell-today/ + ) + + // Toggle off highlight today + await page.locator('[name="highlight-today"]').click() + + await expect(page.locator(`[data-date="${todayISO}"]`)).not.toHaveClass( + /preachjs-calendar--grid-cell-today/ + ) + }) }) diff --git a/example/src/main.css b/example/src/main.css index 559d3c6..ba4c9f5 100644 --- a/example/src/main.css +++ b/example/src/main.css @@ -275,6 +275,14 @@ button { background: #efefef; } +.preachjs-calendar + .preachjs-calendar--grid + .preachjs-calendar--grid-body + .preachjs-calendar--grid-cell.preachjs-calendar--grid-cell-today + button { + border: 1px solid black; +} + .preachjs-calendar .preachjs-calendar--grid .preachjs-calendar--grid-body diff --git a/example/src/main.js b/example/src/main.js index 32ea691..39675d9 100644 --- a/example/src/main.js +++ b/example/src/main.js @@ -8,6 +8,7 @@ const selectedDate = signal() const readOnly = signal(false) const minDate = signal() const maxDate = signal() +const highlightToday = signal(true) function parseDateInput(value) { if (!value) return undefined @@ -81,6 +82,15 @@ const App = () => { }} /> + { value={selectedDate.value} min={minDate.value} max={maxDate.value} + highlightToday={highlightToday.value} onSelect={value => { selectedDate.value = value }} diff --git a/playwright-report/index.html b/playwright-report/index.html deleted file mode 100644 index 4fe34e1..0000000 --- a/playwright-report/index.html +++ /dev/null @@ -1,90 +0,0 @@ - - - - - - - - - Playwright Test Report - - - - -
- - - \ No newline at end of file diff --git a/src/calendar.d.ts b/src/calendar.d.ts index 60bd68c..a610d5c 100644 --- a/src/calendar.d.ts +++ b/src/calendar.d.ts @@ -18,4 +18,5 @@ export type CalendarProps = { onSelect?: (nextValue: CalendarValue) => void min?: Date max?: Date + highlightToday?: boolean } diff --git a/src/calendar.js b/src/calendar.js index 22183ca..9281217 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -27,6 +27,7 @@ export function Calendar({ arrowRight: ArrowRight = () => <>>, min = undefined, max = undefined, + highlightToday = false, }) { const selecting = useRef(false) const refRange$ = useSignal([]) @@ -192,6 +193,10 @@ export function Calendar({ } } + const isToday = + highlightToday && + dateItem.date.toDateString() === new Date().toDateString() + const gridCellStyles = [ 'preachjs-calendar--grid-cell', readOnly && 'read-only', @@ -199,6 +204,7 @@ export function Calendar({ isRangeStart && 'preachjs-calendar--grid-cell-start', isInRange && 'preachjs-calendar--grid-cell-in-range', isRangeEnd && 'preachjs-calendar--grid-cell-end', + isToday && 'preachjs-calendar--grid-cell-today', ] const isDisabled =