@@ -19,7 +19,7 @@ import type {
1919} from 'bits-ui' ;
2020import { Popover } from 'bits-ui' ;
2121
22- type CalendarProps = WithoutChildrenOrChild < Calendar . RootProps > ;
22+ export type CalendarProps = WithoutChildrenOrChild < Calendar . RootProps > ;
2323
2424export interface ThemeComponents {
2525 Button : Component < HTMLButtonAttributes > ;
@@ -51,19 +51,32 @@ export interface ThemeComponents {
5151 Textarea : Component < WithElementRef < HTMLTextareaAttributes > , { } , 'value' | 'ref' > ;
5252}
5353
54+ export type DateFormatter = ( date : Date ) => string ;
55+
5456export interface ThemeContext {
5557 components : ThemeComponents ;
58+ formatDate ?: DateFormatter ;
5659}
5760
5861const THEME_CONTEXT = Symbol ( 'theme-context' ) ;
5962
60- export function getThemeContext ( ) : Required < ThemeContext > {
63+ export function getThemeContext ( ) : Required < Omit < ThemeContext , 'components' > > & {
64+ components : Required < ThemeComponents > ;
65+ } {
6166 return getContext ( THEME_CONTEXT ) ;
6267}
6368
6469export function setThemeContext ( ctx : ThemeContext ) {
6570 // TODO: Remove Proxy in next major
71+ const dateTimeFormat = new Intl . DateTimeFormat ( undefined , {
72+ year : 'numeric' ,
73+ month : '2-digit' ,
74+ day : 'numeric'
75+ } ) ;
6676 setContext ( THEME_CONTEXT , {
77+ get formatDate ( ) {
78+ return ctx . formatDate ?? ( ( date ) => dateTimeFormat . format ( date ) ) ;
79+ } ,
6780 get components ( ) {
6881 return new Proxy ( ctx . components , {
6982 get ( target , prop , receiver ) {
0 commit comments