UNPKG

@wordpress/components

Version:
1 lines • 28 kB
{"version":3,"file":"index.cjs","names":["inputToDate","useLilius","startOfDayInConfiguredTimezone","useState","styles","__","HStack","Button","isRTL","arrowRight","arrowLeft","subMonths","dateI18n","TIMEZONELESS_FORMAT","Heading","addMonths","isSameMonth","isEqual","isSameDay","setInConfiguredTimezone","formatDate","addDays","subWeeks","addWeeks","subDays","useRef","getSettings","sprintf","_n"],"sources":["../../../../style-runtime/src/index.ts","../../../src/date-time/date-picker/style.module.scss","../../../src/date-time/date-picker/index.tsx"],"sourcesContent":["type GlobalScopeWithStyleRuntime = typeof globalThis & {\n\t// This global is shared by separately bundled copies of this package.\n\t// Keep its shape backward compatible after release.\n\t__wpStyleRuntime?: {\n\t\tdocuments: Map< Document, number >;\n\t\tstyles: Map< string, string >;\n\t\tinjectedStyles: WeakMap< Document, Set< string > >;\n\t};\n};\n\nconst STYLE_HASH_ATTRIBUTE = 'data-wp-hash';\n\n/**\n * Returns the shared style runtime registry.\n *\n * The registry is stored on `globalThis` so separately bundled copies of this\n * package can coordinate through the same document and style maps.\n *\n * @return The shared runtime registry.\n */\nfunction getRuntime() {\n\tconst globalScope = globalThis as GlobalScopeWithStyleRuntime;\n\n\tif ( globalScope.__wpStyleRuntime ) {\n\t\treturn globalScope.__wpStyleRuntime;\n\t}\n\n\tglobalScope.__wpStyleRuntime = {\n\t\tdocuments: new Map(),\n\t\tstyles: new Map(),\n\t\tinjectedStyles: new WeakMap(),\n\t};\n\n\tif ( typeof document !== 'undefined' ) {\n\t\tregisterDocument( document );\n\t}\n\n\treturn globalScope.__wpStyleRuntime;\n}\n\n/**\n * Checks whether a document already contains a style tag for a hash.\n *\n * @param targetDocument Document to inspect.\n * @param hash Stable hash for the transformed CSS.\n *\n * @return Whether the style hash already exists in the document.\n */\nfunction documentContainsStyleHash(\n\ttargetDocument: Document,\n\thash: string\n): boolean {\n\tif ( ! targetDocument.head ) {\n\t\treturn false;\n\t}\n\n\tfor ( const style of targetDocument.head.querySelectorAll(\n\t\t`style[${ STYLE_HASH_ATTRIBUTE }]`\n\t) ) {\n\t\tif ( style.getAttribute( STYLE_HASH_ATTRIBUTE ) === hash ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Injects a registered style into a document, unless that document already\n * contains a style tag for the same hash.\n *\n * @param targetDocument Document to inject the style into.\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nfunction injectStyle( targetDocument: Document, hash: string, css: string ) {\n\tif ( ! targetDocument.head ) {\n\t\treturn;\n\t}\n\n\tconst runtime = getRuntime();\n\tlet injectedStyles = runtime.injectedStyles.get( targetDocument );\n\n\tif ( ! injectedStyles ) {\n\t\tinjectedStyles = new Set();\n\t\truntime.injectedStyles.set( targetDocument, injectedStyles );\n\t}\n\n\tif ( injectedStyles.has( hash ) ) {\n\t\treturn;\n\t}\n\n\t// Older generated CSS module output can still inject matching style tags\n\t// after this document's cache is created, so keep the DOM as the fallback\n\t// source of truth on cache misses.\n\tif ( documentContainsStyleHash( targetDocument, hash ) ) {\n\t\tinjectedStyles.add( hash );\n\t\treturn;\n\t}\n\n\tconst style = targetDocument.createElement( 'style' );\n\tstyle.setAttribute( STYLE_HASH_ATTRIBUTE, hash );\n\tstyle.appendChild( targetDocument.createTextNode( css ) );\n\ttargetDocument.head.appendChild( style );\n\tinjectedStyles.add( hash );\n}\n\n/**\n * Registers a document as a style injection target.\n *\n * Existing registered styles are replayed into the document immediately.\n * Documents are reference-counted so multiple providers can safely register the\n * same document without one cleanup removing it while another registration is\n * still active.\n *\n * @param targetDocument Document to receive registered styles.\n * @return Cleanup function that unregisters this document registration.\n */\nexport function registerDocument( targetDocument: Document ) {\n\tconst runtime = getRuntime();\n\n\truntime.documents.set(\n\t\ttargetDocument,\n\t\t( runtime.documents.get( targetDocument ) ?? 0 ) + 1\n\t);\n\n\tfor ( const [ hash, css ] of runtime.styles ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n\n\treturn () => {\n\t\tconst count = runtime.documents.get( targetDocument );\n\n\t\tif ( count === undefined ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( count <= 1 ) {\n\t\t\truntime.documents.delete( targetDocument );\n\t\t\treturn;\n\t\t}\n\n\t\truntime.documents.set( targetDocument, count - 1 );\n\t};\n}\n\n/**\n * Registers a style and injects it into all registered documents.\n *\n * The hash is used as the deduplication key, so calling this repeatedly with\n * the same hash will not add duplicate style tags to a document.\n * Registered styles are retained for the lifetime of the page so they can be\n * replayed into documents that are registered later.\n *\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nexport function registerStyle( hash: string, css: string ) {\n\tconst runtime = getRuntime();\n\n\truntime.styles.set( hash, css );\n\n\tfor ( const targetDocument of runtime.documents.keys() ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n}\n","import { registerStyle } from '@wordpress/style-runtime';\nif (typeof process === 'undefined' || process.env.NODE_ENV !== 'test') {\n\tregisterStyle(\"9ccda9ca28\", \"._4133ce7f8f5171a6__wrapper{box-sizing:border-box}._4133ce7f8f5171a6__wrapper *,._4133ce7f8f5171a6__wrapper :after,._4133ce7f8f5171a6__wrapper :before{box-sizing:inherit}._5d71bd33c79ccd8a__navigator{grid-template-columns:.5fr repeat(5,1fr) .5fr;justify-items:center;margin-bottom:var(--wpds-dimension-gap-lg,16px)}._5d71bd33c79ccd8a__navigator._5d71bd33c79ccd8a__navigator{display:grid}._84049a4038b5abaa__previous-month{grid-column:1/2}._2ed0fb8188d62fd2__next-month{grid-column:7/8}._640229ee401af16b__heading{grid-column:2/7}._640229ee401af16b__heading strong{font-weight:var(--wpds-typography-font-weight-emphasis,600)}._640229ee401af16b__heading._640229ee401af16b__heading{font-size:var(--wpds-typography-font-size-md,13px);font-weight:var(--wpds-typography-font-weight-default,400)}.a6fafdc57e4ec7ef__calendar{column-gap:var(--wpds-dimension-gap-sm,8px);display:grid;grid-template-columns:.5fr repeat(5,1fr) .5fr;justify-items:center;row-gap:var(--wpds-dimension-gap-sm,8px)}._8ea229147ce1d280__day-of-week{color:var(--wpds-color-foreground-content-neutral-weak,#6e6e6e);font-size:var(--wpds-typography-font-size-md,13px);line-height:1.4}._15b622d97c3ea916__day{grid-column:var(--_wp-components-date-picker-column);justify-content:center;padding:0;position:relative}._15b622d97c3ea916__day:where(:disabled){pointer-events:none}._15b622d97c3ea916__day:where(.f4c4764286fd7b88__has-events):before{border:var(--wpds-border-width-sm,2px) solid var(--wpds-color-stroke-interactive-brand,var(--wp-admin-theme-color,#3858e9));border-radius:50%;content:\\\" \\\";left:50%;position:absolute;transform:translate(-50%,9px)}._15b622d97c3ea916__day:where(.f4c4764286fd7b88__has-events.ddd970c7f061156e__is-selected):before{border-color:var(--wpds-color-foreground-interactive-brand-strong,#fff)}._15b622d97c3ea916__day._15b622d97c3ea916__day._15b622d97c3ea916__day{border-radius:50%;font-size:var(--wpds-typography-font-size-md,13px);font-weight:var(--wpds-typography-font-weight-default,400);height:28px;width:28px}._15b622d97c3ea916__day._15b622d97c3ea916__day._15b622d97c3ea916__day:where(.ddd970c7f061156e__is-selected){background:var(--wpds-color-background-interactive-brand-strong,var(--wp-admin-theme-color,#3858e9))}._15b622d97c3ea916__day._15b622d97c3ea916__day._15b622d97c3ea916__day:where(.ddd970c7f061156e__is-selected),._15b622d97c3ea916__day._15b622d97c3ea916__day._15b622d97c3ea916__day:where(.ddd970c7f061156e__is-selected):hover:not(:disabled,[aria-disabled=true]){color:var(--wpds-color-foreground-interactive-brand-strong,#fff)}._15b622d97c3ea916__day._15b622d97c3ea916__day._15b622d97c3ea916__day:where(.ddd970c7f061156e__is-selected):focus:not(:disabled){border:var(--wpds-border-width-focus,var(--wp-admin-border-width-focus,2px)) solid}._15b622d97c3ea916__day._15b622d97c3ea916__day._15b622d97c3ea916__day:where(.ddd970c7f061156e__is-selected):after{border:var(--wpds-border-width-xs,1px) solid transparent;border-radius:inherit;content:\\\"\\\";inset:0;pointer-events:none;position:absolute}._15b622d97c3ea916__day._15b622d97c3ea916__day._15b622d97c3ea916__day:where(._9af06b51a4cb7f3d__is-today){background:var(--wpds-color-background-surface-neutral-weak,#f3f3f3)}\");\n}\nexport default {\"wrapper\":\"_4133ce7f8f5171a6__wrapper\",\"navigator\":\"_5d71bd33c79ccd8a__navigator\",\"previous-month\":\"_84049a4038b5abaa__previous-month\",\"next-month\":\"_2ed0fb8188d62fd2__next-month\",\"heading\":\"_640229ee401af16b__heading\",\"calendar\":\"a6fafdc57e4ec7ef__calendar\",\"day-of-week\":\"_8ea229147ce1d280__day-of-week\",\"day\":\"_15b622d97c3ea916__day\",\"has-events\":\"f4c4764286fd7b88__has-events\",\"is-selected\":\"ddd970c7f061156e__is-selected\",\"is-today\":\"_9af06b51a4cb7f3d__is-today\"};\n","import {\n\tisSameDay,\n\tsubMonths,\n\taddMonths,\n\tisEqual,\n\taddDays,\n\tsubDays,\n\tsubWeeks,\n\taddWeeks,\n\tisSameMonth,\n} from 'date-fns';\nimport type { CSSProperties, KeyboardEventHandler } from 'react';\nimport clsx from 'clsx';\nimport { __, _n, sprintf, isRTL } from '@wordpress/i18n';\nimport { arrowLeft, arrowRight } from '@wordpress/icons';\nimport { dateI18n, date as formatDate, getSettings } from '@wordpress/date';\nimport { useState, useRef, useEffect } from '@wordpress/element';\nimport { useLilius } from './use-lilius';\nimport type { DatePickerProps } from '../types';\nimport Button from '../../button';\nimport { HStack } from '../../h-stack';\nimport { Heading } from '../../heading';\nimport styles from './style.module.scss';\nimport {\n\tinputToDate,\n\tsetInConfiguredTimezone,\n\tstartOfDayInConfiguredTimezone,\n} from '../utils';\nimport { TIMEZONELESS_FORMAT } from '../constants';\n\n/**\n * DatePicker is a React component that renders a calendar for date selection.\n *\n * ```jsx\n * import { DatePicker } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const MyDatePicker = () => {\n * const [ date, setDate ] = useState( new Date() );\n *\n * return (\n * <DatePicker\n * currentDate={ date }\n * onChange={ ( newDate ) => setDate( newDate ) }\n * />\n * );\n * };\n * ```\n */\nexport function DatePicker( {\n\tcurrentDate,\n\tonChange,\n\tevents = [],\n\tisInvalidDate,\n\tonMonthPreviewed,\n\tstartOfWeek: weekStartsOn = 0,\n}: DatePickerProps ) {\n\tconst date = inputToDate( currentDate ?? new Date() );\n\n\tconst {\n\t\tcalendar,\n\t\tviewing,\n\t\tsetSelected,\n\t\tsetViewing,\n\t\tisSelected,\n\t\tviewPreviousMonth,\n\t\tviewNextMonth,\n\t} = useLilius( {\n\t\tselected: [ startOfDayInConfiguredTimezone( date ) ],\n\t\tviewing: startOfDayInConfiguredTimezone( date ),\n\t\tweekStartsOn,\n\t} );\n\n\t// Used to implement a roving tab index. Tracks the day that receives focus\n\t// when the user tabs into the calendar.\n\tconst [ focusable, setFocusable ] = useState(\n\t\tstartOfDayInConfiguredTimezone( date )\n\t);\n\n\t// Allows us to only programmatically focus() a day when focus was already\n\t// within the calendar. This stops us stealing focus from e.g. a TimePicker\n\t// input.\n\tconst [ isFocusWithinCalendar, setIsFocusWithinCalendar ] =\n\t\tuseState( false );\n\n\t// Update internal state when currentDate prop changes.\n\tconst [ prevCurrentDate, setPrevCurrentDate ] = useState( currentDate );\n\tif ( currentDate !== prevCurrentDate ) {\n\t\tsetPrevCurrentDate( currentDate );\n\t\tsetSelected( [ startOfDayInConfiguredTimezone( date ) ] );\n\t\tsetViewing( startOfDayInConfiguredTimezone( date ) );\n\t\tsetFocusable( startOfDayInConfiguredTimezone( date ) );\n\t}\n\n\treturn (\n\t\t<div\n\t\t\tclassName={ clsx( 'components-datetime__date', styles.wrapper ) }\n\t\t\trole=\"application\"\n\t\t\taria-label={ __( 'Calendar' ) }\n\t\t>\n\t\t\t<HStack className={ styles.navigator }>\n\t\t\t\t<Button\n\t\t\t\t\tclassName={ styles[ 'previous-month' ] }\n\t\t\t\t\ticon={ isRTL() ? arrowRight : arrowLeft }\n\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\taria-label={ __( 'View previous month' ) }\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tviewPreviousMonth();\n\t\t\t\t\t\tsetFocusable( subMonths( focusable, 1 ) );\n\t\t\t\t\t\tconst prevMonth = subMonths( viewing, 1 );\n\t\t\t\t\t\tonMonthPreviewed?.(\n\t\t\t\t\t\t\tdateI18n(\n\t\t\t\t\t\t\t\tTIMEZONELESS_FORMAT,\n\t\t\t\t\t\t\t\tprevMonth,\n\t\t\t\t\t\t\t\t-prevMonth.getTimezoneOffset()\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t} }\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t/>\n\t\t\t\t<Heading level={ 3 } className={ styles.heading }>\n\t\t\t\t\t<strong>\n\t\t\t\t\t\t{ dateI18n(\n\t\t\t\t\t\t\t'F',\n\t\t\t\t\t\t\tviewing,\n\t\t\t\t\t\t\t-viewing.getTimezoneOffset()\n\t\t\t\t\t\t) }\n\t\t\t\t\t</strong>{ ' ' }\n\t\t\t\t\t{ dateI18n( 'Y', viewing, -viewing.getTimezoneOffset() ) }\n\t\t\t\t</Heading>\n\t\t\t\t<Button\n\t\t\t\t\tclassName={ styles[ 'next-month' ] }\n\t\t\t\t\ticon={ isRTL() ? arrowLeft : arrowRight }\n\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\taria-label={ __( 'View next month' ) }\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tviewNextMonth();\n\t\t\t\t\t\tsetFocusable( addMonths( focusable, 1 ) );\n\t\t\t\t\t\tconst nextMonth = addMonths( viewing, 1 );\n\t\t\t\t\t\tonMonthPreviewed?.(\n\t\t\t\t\t\t\tdateI18n(\n\t\t\t\t\t\t\t\tTIMEZONELESS_FORMAT,\n\t\t\t\t\t\t\t\tnextMonth,\n\t\t\t\t\t\t\t\t-nextMonth.getTimezoneOffset()\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t} }\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t/>\n\t\t\t</HStack>\n\t\t\t<div\n\t\t\t\tclassName={ styles.calendar }\n\t\t\t\tonFocus={ () => setIsFocusWithinCalendar( true ) }\n\t\t\t\tonBlur={ () => setIsFocusWithinCalendar( false ) }\n\t\t\t>\n\t\t\t\t{ calendar[ 0 ][ 0 ].map( ( day ) => (\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName={ styles[ 'day-of-week' ] }\n\t\t\t\t\t\tkey={ day.toString() }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ dateI18n( 'D', day, -day.getTimezoneOffset() ) }\n\t\t\t\t\t</div>\n\t\t\t\t) ) }\n\t\t\t\t{ calendar[ 0 ].map( ( week ) =>\n\t\t\t\t\tweek.map( ( day, index ) => {\n\t\t\t\t\t\tif ( ! isSameMonth( day, viewing ) ) {\n\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<Day\n\t\t\t\t\t\t\t\tkey={ day.toString() }\n\t\t\t\t\t\t\t\tday={ day }\n\t\t\t\t\t\t\t\tcolumn={ index + 1 }\n\t\t\t\t\t\t\t\tisSelected={ isSelected( day ) }\n\t\t\t\t\t\t\t\tisFocusable={ isEqual( day, focusable ) }\n\t\t\t\t\t\t\t\tisFocusAllowed={ isFocusWithinCalendar }\n\t\t\t\t\t\t\t\tisToday={ isSameDay(\n\t\t\t\t\t\t\t\t\tday,\n\t\t\t\t\t\t\t\t\tstartOfDayInConfiguredTimezone( new Date() )\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tisInvalid={\n\t\t\t\t\t\t\t\t\tisInvalidDate ? isInvalidDate( day ) : false\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tnumEvents={\n\t\t\t\t\t\t\t\t\tevents.filter( ( event ) =>\n\t\t\t\t\t\t\t\t\t\tisSameDay( event.date, day )\n\t\t\t\t\t\t\t\t\t).length\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\tsetSelected( [ day ] );\n\t\t\t\t\t\t\t\t\tsetFocusable( day );\n\t\t\t\t\t\t\t\t\tconst newDate = setInConfiguredTimezone(\n\t\t\t\t\t\t\t\t\t\tdate,\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tyear: day.getFullYear(),\n\t\t\t\t\t\t\t\t\t\t\tmonth: day.getMonth(),\n\t\t\t\t\t\t\t\t\t\t\tdate: day.getDate(),\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\tonChange?.(\n\t\t\t\t\t\t\t\t\t\tformatDate(\n\t\t\t\t\t\t\t\t\t\t\tTIMEZONELESS_FORMAT,\n\t\t\t\t\t\t\t\t\t\t\tnewDate\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\tonKeyDown={ ( event ) => {\n\t\t\t\t\t\t\t\t\tlet nextFocusable;\n\t\t\t\t\t\t\t\t\tif ( event.key === 'ArrowLeft' ) {\n\t\t\t\t\t\t\t\t\t\tnextFocusable = addDays(\n\t\t\t\t\t\t\t\t\t\t\tday,\n\t\t\t\t\t\t\t\t\t\t\tisRTL() ? 1 : -1\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif ( event.key === 'ArrowRight' ) {\n\t\t\t\t\t\t\t\t\t\tnextFocusable = addDays(\n\t\t\t\t\t\t\t\t\t\t\tday,\n\t\t\t\t\t\t\t\t\t\t\tisRTL() ? -1 : 1\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif ( event.key === 'ArrowUp' ) {\n\t\t\t\t\t\t\t\t\t\tnextFocusable = subWeeks( day, 1 );\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif ( event.key === 'ArrowDown' ) {\n\t\t\t\t\t\t\t\t\t\tnextFocusable = addWeeks( day, 1 );\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif ( event.key === 'PageUp' ) {\n\t\t\t\t\t\t\t\t\t\tnextFocusable = subMonths( day, 1 );\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif ( event.key === 'PageDown' ) {\n\t\t\t\t\t\t\t\t\t\tnextFocusable = addMonths( day, 1 );\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif ( event.key === 'Home' ) {\n\t\t\t\t\t\t\t\t\t\tconst dayOfWeek = day.getDay();\n\t\t\t\t\t\t\t\t\t\tconst daysToSubtract =\n\t\t\t\t\t\t\t\t\t\t\t( dayOfWeek - weekStartsOn + 7 ) %\n\t\t\t\t\t\t\t\t\t\t\t7;\n\t\t\t\t\t\t\t\t\t\tnextFocusable = subDays(\n\t\t\t\t\t\t\t\t\t\t\tday,\n\t\t\t\t\t\t\t\t\t\t\tdaysToSubtract\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif ( event.key === 'End' ) {\n\t\t\t\t\t\t\t\t\t\tconst dayOfWeek = day.getDay();\n\t\t\t\t\t\t\t\t\t\tconst daysToAdd =\n\t\t\t\t\t\t\t\t\t\t\t( weekStartsOn + 6 - dayOfWeek ) %\n\t\t\t\t\t\t\t\t\t\t\t7;\n\t\t\t\t\t\t\t\t\t\tnextFocusable = addDays(\n\t\t\t\t\t\t\t\t\t\t\tday,\n\t\t\t\t\t\t\t\t\t\t\tdaysToAdd\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif ( nextFocusable ) {\n\t\t\t\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\t\t\t\tsetFocusable( nextFocusable );\n\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t! isSameMonth(\n\t\t\t\t\t\t\t\t\t\t\t\tnextFocusable,\n\t\t\t\t\t\t\t\t\t\t\t\tviewing\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\tsetViewing( nextFocusable );\n\t\t\t\t\t\t\t\t\t\t\tonMonthPreviewed?.(\n\t\t\t\t\t\t\t\t\t\t\t\tdateI18n(\n\t\t\t\t\t\t\t\t\t\t\t\t\tTIMEZONELESS_FORMAT,\n\t\t\t\t\t\t\t\t\t\t\t\t\tnextFocusable,\n\t\t\t\t\t\t\t\t\t\t\t\t\t-nextFocusable.getTimezoneOffset()\n\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t);\n\t\t\t\t\t} )\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\ntype DayProps = {\n\tday: Date;\n\tcolumn: number;\n\tisSelected: boolean;\n\tisFocusable: boolean;\n\tisFocusAllowed: boolean;\n\tisToday: boolean;\n\tnumEvents: number;\n\tisInvalid: boolean;\n\tonClick: () => void;\n\tonKeyDown: KeyboardEventHandler;\n};\n\nfunction Day( {\n\tday,\n\tcolumn,\n\tisSelected,\n\tisFocusable,\n\tisFocusAllowed,\n\tisToday,\n\tisInvalid,\n\tnumEvents,\n\tonClick,\n\tonKeyDown,\n}: DayProps ) {\n\tconst ref = useRef< HTMLButtonElement >( null );\n\n\t// Focus the day when it becomes focusable, e.g. because an arrow key is\n\t// pressed. Only do this if focus is allowed - this stops us stealing focus\n\t// from e.g. a TimePicker input.\n\tuseEffect( () => {\n\t\tif ( ref.current && isFocusable && isFocusAllowed ) {\n\t\t\tref.current.focus();\n\t\t}\n\t\t// isFocusAllowed is not a dep as there is no point calling focus() on\n\t\t// an already focused element.\n\t}, [ isFocusable ] );\n\n\treturn (\n\t\t// Invalid dates intentionally cannot receive focus or be selected.\n\t\t// eslint-disable-next-line @wordpress/components-no-unsafe-button-disabled\n\t\t<Button\n\t\t\t__next40pxDefaultSize\n\t\t\tref={ ref }\n\t\t\tclassName={ clsx(\n\t\t\t\t'components-datetime__date__day', // Unused, for backwards compatibility.\n\t\t\t\tstyles.day,\n\t\t\t\t{\n\t\t\t\t\t[ styles[ 'is-selected' ] ]: isSelected,\n\t\t\t\t\t[ styles[ 'is-today' ] ]: ! isSelected && isToday,\n\t\t\t\t\t[ styles[ 'has-events' ] ]: numEvents > 0,\n\t\t\t\t}\n\t\t\t) }\n\t\t\tstyle={\n\t\t\t\t{\n\t\t\t\t\t'--_wp-components-date-picker-column': column,\n\t\t\t\t} as CSSProperties\n\t\t\t}\n\t\t\tdisabled={ isInvalid }\n\t\t\ttabIndex={ isFocusable ? 0 : -1 }\n\t\t\taria-label={ getDayLabel( day, isSelected, isToday, numEvents ) }\n\t\t\tonClick={ onClick }\n\t\t\tonKeyDown={ onKeyDown }\n\t\t>\n\t\t\t{ dateI18n( 'j', day, -day.getTimezoneOffset() ) }\n\t\t</Button>\n\t);\n}\n\nfunction getDayLabel(\n\tdate: Date,\n\tisSelected: boolean,\n\tisToday: boolean,\n\tnumEvents: number\n) {\n\tconst { formats } = getSettings();\n\tconst localizedDate = dateI18n(\n\t\tformats.date,\n\t\tdate,\n\t\t-date.getTimezoneOffset()\n\t);\n\n\tconst parts = [ localizedDate ];\n\n\tif ( isSelected ) {\n\t\tparts.push( __( 'Selected' ) );\n\t}\n\n\tif ( isToday ) {\n\t\tparts.push( __( 'Today' ) );\n\t}\n\n\tif ( numEvents > 0 ) {\n\t\tparts.push(\n\t\t\tsprintf(\n\t\t\t\t// translators: %d: Number of events on the calendar date.\n\t\t\t\t_n( 'There is %d event', 'There are %d events', numEvents ),\n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