react-modular-datepicker 0.0.2-canary.4 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +217 -1
- package/dist/adapters/dayjs.d.ts +21 -0
- package/dist/classNames.d.ts +67 -0
- package/dist/components/Calendar.d.ts +14 -0
- package/dist/components/CalendarHeader.d.ts +19 -0
- package/dist/components/Day.d.ts +13 -0
- package/dist/components/MonthSelection.d.ts +13 -0
- package/dist/components/YearSelection.d.ts +12 -0
- package/dist/i18n.d.ts +9 -0
- package/dist/index.css +1543 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +316 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types.d.ts +42 -0
- package/dist/useDates-D9EvVlhK.js +2 -0
- package/dist/useDates-D9EvVlhK.js.map +1 -0
- package/dist/useDates-DQabq6Ux.mjs +201 -0
- package/dist/useDates-DQabq6Ux.mjs.map +1 -0
- package/dist/useDates.d.ts +63 -0
- package/dist/useDates.js +1 -0
- package/dist/useDates.mjs +3 -0
- package/dist/utils.d.ts +42 -0
- package/dist/utils.js +2 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.mjs +169 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +72 -5
- package/.gitattributes +0 -2
- package/.github/workflows/release.yml +0 -59
- package/index.js +0 -5
- package/scripts/bump-version.js +0 -41
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { useDates } from './useDates';
|
|
2
|
+
export type { UseDatesProps } from './useDates';
|
|
3
|
+
export * from './types';
|
|
4
|
+
export * from './utils';
|
|
5
|
+
export { Calendar } from './components/Calendar';
|
|
6
|
+
export { Day } from './components/Day';
|
|
7
|
+
export { MonthSelection } from './components/MonthSelection';
|
|
8
|
+
export { YearSelection } from './components/YearSelection';
|
|
9
|
+
export { DayjsAdapter, defaultAdapter } from './adapters/dayjs';
|
|
10
|
+
export * from './i18n';
|
|
11
|
+
export * from './classNames';
|
|
12
|
+
export { CalendarHeader, ChevronLeftIcon, ChevronRightIcon } from './components/CalendarHeader';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./useDates-D9EvVlhK.js"),t=require("./utils.js");let n=require("react");n=e.i(n);let r=require("react/jsx-runtime");var i=({dateObj:e,getDateProps:t,classNames:n,tooltip:i})=>{if(!e)return(0,r.jsx)(`div`,{className:`aspect-square bg-white`});let{date:a,selected:o,selectable:s,isRangeStart:c,isRangeEnd:l,isRangeBetween:u,isRangeHovering:d,isRangeActive:f}=e,p=n.day,m=`rounded-full`;m=c&&l?`${p.selected} rounded-full`:c?`${p.rangeStart} ${f?`rounded-l-full rounded-r-none`:`rounded-full`}`:l?`${p.rangeEnd} ${f?`rounded-r-full rounded-l-none`:`rounded-full`}`:u?p.rangeBetween||``:d?p.rangeHovering||``:o?p.selected||``:s?p.unselected||``:p.disabled||``;let h=[p.day,m,...(e.modifiers||[]).map(e=>p[e]||e)].filter(Boolean).join(` `);return(0,r.jsxs)(`button`,{...t({dateObj:e}),className:h,children:[a.getDate(),i&&(0,r.jsx)(`div`,{className:`absolute bottom-full left-1/2 -translate-x-1/2 mb-2 hidden group-hover:block z-10`,children:(0,r.jsxs)(`div`,{className:`bg-gray-800 text-white text-xs py-1 px-2 rounded whitespace-nowrap shadow-lg`,children:[i,(0,r.jsx)(`div`,{className:`absolute top-full left-1/2 -translate-x-1/2 border-8 border-transparent border-t-gray-800`})]})})]})};function a(t=e.r,n){return{months:t.getMonths(n),weekdays:t.getWeekdays(n),back:`Previous month`,forward:`Next month`}}function o(t=e.r,n,r){return{...a(t,n),...r}}var s=()=>(0,r.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,r.jsx)(`polyline`,{points:`15 18 9 12 15 6`})}),c=()=>(0,r.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,r.jsx)(`polyline`,{points:`9 18 15 12 9 6`})}),l=({calendars:e,getBackProps:t,getForwardProps:n,setView:i,monthNames:a,t:o,classNames:l,slideDirection:u,currentView:d})=>(0,r.jsxs)(`div`,{className:l.header,children:[(0,r.jsx)(`button`,{...t({calendars:e}),onMouseDown:e=>e.preventDefault(),className:`${l.navButton} ${d&&d!==`days`?`invisible pointer-events-none`:``}`,"aria-label":o.back,children:(0,r.jsx)(s,{})}),(0,r.jsx)(`div`,{className:l.monthYearContainer,children:e.length===1?(0,r.jsxs)(`div`,{className:`${l.monthYearLabel} ${u===`left`?`animate-slide-in-left`:u===`right`?`animate-slide-in-right`:``}`,children:[(0,r.jsx)(`button`,{onMouseDown:e=>e.preventDefault(),onClick:()=>i(d===`months`?`days`:`months`),className:l.monthYearButton,children:a[e[0].month]}),(0,r.jsx)(`button`,{onMouseDown:e=>e.preventDefault(),onClick:()=>i(d===`years`?`days`:`years`),className:l.monthYearButton,children:e[0].year})]},`${e[0].month}-${e[0].year}`):(0,r.jsx)(`div`,{className:`${l.monthYearLabel} ${u===`left`?`animate-slide-in-left`:u===`right`?`animate-slide-in-right`:``}`,children:(()=>{let t=e[0],n=e[e.length-1];return e.length===12&&t.month===0&&n.month===11&&t.year===n.year?(0,r.jsx)(`span`,{children:t.year}):t.year===n.year?(0,r.jsxs)(`span`,{children:[a[t.month],` - `,a[n.month],` `,t.year]}):(0,r.jsxs)(`span`,{children:[a[t.month],` `,t.year,` - `,a[n.month],` `,n.year]})})()})}),(0,r.jsx)(`button`,{...n({calendars:e}),onMouseDown:e=>e.preventDefault(),className:`${l.navButton} ${d&&d!==`days`?`invisible pointer-events-none`:``}`,"aria-label":o.forward,children:(0,r.jsx)(c,{})})]}),u={root:`w-fit flex flex-col p-4 bg-white rounded-lg shadow-lg`,header:`flex items-center justify-between border-b-2 border-brand-gray-light/40`,calendarsContainer:`flex flex-col md:flex-row gap-4`,calendarContainer:`flex-1 min-w-[280px] min-h-[260px]`,weekdayGrid:`grid grid-cols-7 gap-1 mb-1 border-b border-brand-gray-light/40`,weekday:`text-center text-xs text-gray-400 py-2`,daysGrid:`grid grid-cols-7 gap-px bg-brand-gray-light/20`,footer:`mt-4`,navButton:`p-2 hover:bg-gray-100 rounded-full transition-colors cursor-pointer disabled:opacity-30 disabled:pointer-events-none`,monthYearContainer:`flex gap-8`,monthYearLabel:`flex gap-1 items-center font-semibold text-brand-text`,monthYearButton:`hover:bg-gray-100 px-2 py-1 rounded cursor-pointer`,day:{day:`aspect-square flex items-center justify-center text-sm font-medium transition-all relative group cursor-pointer p-px`,selected:`bg-brand-gold text-white rounded-full`,unselected:`bg-white hover:bg-brand-gray-light text-brand-text`,disabled:`bg-white text-gray-300 cursor-not-allowed`,rangeStart:`bg-brand-gold text-white`,rangeEnd:`bg-brand-gold text-white`,rangeBetween:`bg-brand-gray-light text-brand-text`,rangeHovering:`bg-brand-gray-light text-brand-text`},monthsGrid:`grid grid-cols-3 gap-2 animate-slide-in-top`,monthButton:`py-4 rounded-lg hover:bg-brand-gray-light transition-colors cursor-pointer disabled:opacity-30 disabled:pointer-events-none`,monthButtonSelected:`bg-brand-gold text-white`,monthButtonUnselected:`text-brand-text`,yearsGrid:`grid grid-cols-3 gap-2 max-h-[300px] overflow-y-auto pr-2 animate-slide-in-top`,yearButton:`py-3 rounded-lg hover:bg-brand-gray-light transition-colors cursor-pointer disabled:opacity-30 disabled:pointer-events-none`,yearButtonSelected:`bg-brand-gold text-white`,yearButtonUnselected:`text-brand-text`},d=e=>{let t={...u};if(!e)return t;for(let n in e){let r=n;r===`day`&&e.day?t.day={...u.day,...e.day}:e[r]&&(t[r]=e[r])}return t},f=({year:e,month:t,monthNames:n,minDate:i,maxDate:a,onMonthSelect:o,classNames:s})=>{let c=t=>!!(i&&e===i.getFullYear()&&t<i.getMonth()||a&&e===a.getFullYear()&&t>a.getMonth());return(0,r.jsx)(`div`,{className:s.monthsGrid,children:n.map((e,n)=>{let i=c(n);return(0,r.jsx)(`button`,{onMouseDown:e=>e.preventDefault(),onClick:()=>!i&&o(n),className:`${s.monthButton} ${n===t?s.monthButtonSelected:s.monthButtonUnselected}`,disabled:i,children:e},e)})})},p=({year:e,minDate:t,maxDate:i,adapter:a,onYearSelect:o,classNames:s})=>{let c=(0,n.useRef)(null);(0,n.useEffect)(()=>{if(c.current){let e=c.current.querySelector(`[data-selected="true"]`);e&&e.scrollIntoView({block:`center`})}},[]);let l=t?a.get(a.date(t),`year`):e-50,u=i?a.get(a.date(i),`year`):e+50,d=[];for(let e=l;e<=u;e++)d.push(e);return(0,r.jsx)(`div`,{ref:c,className:s.yearsGrid,children:d.map(t=>(0,r.jsx)(`button`,{"data-selected":t===e,onMouseDown:e=>e.preventDefault(),onClick:()=>o(t),className:`${s.yearButton} ${t===e?s.yearButtonSelected:s.yearButtonUnselected}`,children:t},t))})},m=t=>{let{classNames:a,locale:s,translations:c,adapter:u=e.r,firstDayOfWeek:m=0,header:h,footer:g,renderDayTooltip:_,...v}=t,y=d(a),[b,x]=(0,n.useState)(`days`),[S,C]=(0,n.useState)(null),w=o(u,s,c),T=w.weekdays,E=w.months,{calendars:D,getBackProps:O,getForwardProps:k,getDateProps:A,setOffset:j}=e.t({...v,adapter:u,firstDayOfWeek:m}),M=[...T.slice(m),...T.slice(0,m)],{month:N,year:P}=D[0],F=e=>{let n=u.set(u.set(u.date(t.date||new Date),`year`,P),`month`,N),r=u.set(n,`month`,e),i=u.startOf(u.date(t.date||new Date),`month`),a=u.diff(r,i,`month`);C(null),j(a),x(`days`)},I=e=>{let n=u.set(u.set(u.date(t.date||new Date),`year`,P),`month`,N),r=u.set(n,`year`,e),i=u.startOf(u.date(t.date||new Date),`month`),a=u.diff(r,i,`month`);C(null),j(a),x(`days`)},L=e=>{let t=O(e);return{...t,onClick:e=>{C(`left`),t.onClick?.(e)}}},R=e=>{let t=k(e);return{...t,onClick:e=>{C(`right`),t.onClick?.(e)}}};return(0,r.jsxs)(`div`,{className:y.root,children:[typeof h==`function`?h({calendars:D,getBackProps:L,getForwardProps:R,setView:x,monthNames:E,t:w,slideDirection:S,currentView:b}):h||(0,r.jsx)(l,{calendars:D,getBackProps:L,getForwardProps:R,setView:x,monthNames:E,t:w,classNames:y,slideDirection:S,currentView:b}),(0,r.jsxs)(`div`,{className:y.calendarsContainer,children:[b===`months`&&D.map(e=>(0,r.jsx)(`div`,{className:y.calendarContainer,children:(0,r.jsx)(f,{year:e.year,month:e.month,monthNames:E,minDate:t.minDate,maxDate:t.maxDate,onMonthSelect:F,classNames:y})},`months-${e.year}`)),b===`years`&&D.map(e=>(0,r.jsx)(`div`,{className:y.calendarContainer,children:(0,r.jsx)(p,{year:e.year,minDate:t.minDate,maxDate:t.maxDate,adapter:u,onYearSelect:I,classNames:y})},`years-${e.year}`)),b===`days`&&D.map(e=>(0,r.jsxs)(`div`,{className:y.calendarContainer,children:[D.length>1&&(0,r.jsxs)(`div`,{className:`text-center font-semibold mb-2 text-brand-text`,children:[E[e.month],` `,D[0].year===D[D.length-1].year?``:e.year]}),(0,r.jsx)(`div`,{className:y.weekdayGrid,children:M.map(e=>(0,r.jsx)(`div`,{className:y.weekday,children:e},e))}),(0,r.jsx)(`div`,{className:`${y.daysGrid} ${S===`left`?`animate-slide-in-left`:S===`right`?`animate-slide-in-right`:``}`,children:e.weeks.map((e,t)=>e.map((e,n)=>(0,r.jsx)(i,{dateObj:e,getDateProps:A,classNames:y,tooltip:e&&_?.(e)},`${t}-${n}`)))})]},`${e.month}-${e.year}`))]}),g&&(0,r.jsx)(`div`,{className:y.footer,children:g})]})};exports.Calendar=m,exports.CalendarHeader=l,exports.ChevronLeftIcon=s,exports.ChevronRightIcon=c,exports.Day=i,exports.DayjsAdapter=e.n,exports.MonthSelection=f,exports.YearSelection=p,exports.addMonth=t.addMonth,exports.composeEventHandlers=t.composeEventHandlers,exports.defaultAdapter=e.r,exports.defaultClassNames=u,exports.getCalendars=t.getCalendars,exports.getDefaults=a,exports.getTranslations=o,exports.isBackDisabled=t.isBackDisabled,exports.isForwardDisabled=t.isForwardDisabled,exports.mergeClassNames=d,exports.subtractMonth=t.subtractMonth,exports.useDates=e.t;
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/components/Day.tsx","../src/i18n.ts","../src/components/CalendarHeader.tsx","../src/classNames.ts","../src/components/MonthSelection.tsx","../src/components/YearSelection.tsx","../src/components/Calendar.tsx"],"sourcesContent":["import React from 'react';\nimport type { CalendarClassNames, DateObj } from '../types';\n\ninterface DayProps {\n dateObj: DateObj | null;\n getDateProps: (args: { dateObj: DateObj, [key: string]: any }) => any;\n tooltip?: React.ReactNode;\n classNames: Required<CalendarClassNames>;\n}\n\nexport const Day: React.FC<DayProps> = ({ dateObj, getDateProps, classNames, tooltip }) => {\n if (!dateObj) {\n return <div className=\"aspect-square bg-white\" />;\n }\n\n const { date, selected, selectable, isRangeStart, isRangeEnd, isRangeBetween, isRangeHovering, isRangeActive } = dateObj;\n const dayClasses = classNames.day;\n\n let stateClasses = \"rounded-full\";\n if (isRangeStart && isRangeEnd) {\n stateClasses = `${dayClasses.selected} rounded-full`;\n } else if (isRangeStart) {\n stateClasses = `${dayClasses.rangeStart} ${isRangeActive ? 'rounded-l-full rounded-r-none' : 'rounded-full'}`;\n } else if (isRangeEnd) {\n stateClasses = `${dayClasses.rangeEnd} ${isRangeActive ? 'rounded-r-full rounded-l-none' : 'rounded-full'}`;\n } else if (isRangeBetween) {\n stateClasses = dayClasses.rangeBetween || '';\n } else if (isRangeHovering) {\n stateClasses = dayClasses.rangeHovering || '';\n } else if (selected) {\n stateClasses = dayClasses.selected || '';\n } else if (!selectable) {\n stateClasses = dayClasses.disabled || '';\n } else {\n stateClasses = dayClasses.unselected || '';\n }\n\n const className = [\n dayClasses.day,\n stateClasses,\n ...(dateObj.modifiers || []).map(m => (dayClasses as any)[m] || m)\n ].filter(Boolean).join(' ');\n\n return (\n <button\n {...getDateProps({ dateObj })}\n className={className}\n >\n {date.getDate()}\n {tooltip && (\n <div className=\"absolute bottom-full left-1/2 -translate-x-1/2 mb-2 hidden group-hover:block z-10\">\n <div className=\"bg-gray-800 text-white text-xs py-1 px-2 rounded whitespace-nowrap shadow-lg\">\n {tooltip}\n <div className=\"absolute top-full left-1/2 -translate-x-1/2 border-8 border-transparent border-t-gray-800\" />\n </div>\n </div>\n )}\n </button>\n );\n};\n","import { DateAdapter } from \"./types\";\nimport { defaultAdapter } from \"./adapters/dayjs\";\n\nexport interface Translations {\n months: string[];\n weekdays: string[];\n back: string;\n forward: string;\n}\n\nexport function getDefaults(adapter: DateAdapter = defaultAdapter, locale?: string): Translations {\n return {\n months: adapter.getMonths(locale),\n weekdays: adapter.getWeekdays(locale),\n back: 'Previous month',\n forward: 'Next month'\n };\n}\n\nexport function getTranslations(\n adapter: DateAdapter = defaultAdapter,\n locale?: string,\n custom?: Partial<Translations>\n): Translations {\n const base = getDefaults(adapter, locale);\n return { ...base, ...custom };\n}\n","import React from 'react';\nimport { Calendar, CalendarClassNames } from '../types';\n\nexport interface HeaderProps {\n calendars: Calendar[];\n getBackProps: (args: any) => any;\n getForwardProps: (args: any) => any;\n setView: (view: 'days' | 'months' | 'years') => void;\n monthNames: string[];\n t: { back: string; forward: string };\n classNames: Required<CalendarClassNames>;\n slideDirection?: 'left' | 'right' | null;\n currentView?: 'days' | 'months' | 'years';\n}\n\nexport const ChevronLeftIcon = () => (\n <svg width=\"20\" height=\"20\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n <polyline points=\"15 18 9 12 15 6\"></polyline>\n </svg>\n);\n\nexport const ChevronRightIcon = () => (\n <svg width=\"20\" height=\"20\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n <polyline points=\"9 18 15 12 9 6\"></polyline>\n </svg>\n);\n\nexport const CalendarHeader: React.FC<HeaderProps> = ({\n calendars,\n getBackProps,\n getForwardProps,\n setView,\n monthNames,\n t,\n classNames,\n slideDirection,\n currentView\n}) => {\n return (\n <div className={classNames.header}>\n <button\n {...getBackProps({ calendars })}\n onMouseDown={(e) => e.preventDefault()}\n className={`${classNames.navButton} ${currentView && currentView !== 'days' ? 'invisible pointer-events-none' : ''}`}\n aria-label={t.back}\n >\n <ChevronLeftIcon />\n </button>\n\n <div className={classNames.monthYearContainer}>\n {calendars.length === 1 ? (\n <div key={`${calendars[0].month}-${calendars[0].year}`} className={`${classNames.monthYearLabel} ${slideDirection === 'left' ? 'animate-slide-in-left' : slideDirection === 'right' ? 'animate-slide-in-right' : ''}`}>\n <button\n onMouseDown={(e) => e.preventDefault()}\n onClick={() => setView(currentView === 'months' ? 'days' : 'months')}\n className={classNames.monthYearButton}\n >\n {monthNames[calendars[0].month]}\n </button>\n <button\n onMouseDown={(e) => e.preventDefault()}\n onClick={() => setView(currentView === 'years' ? 'days' : 'years')}\n className={classNames.monthYearButton}\n >\n {calendars[0].year}\n </button>\n </div>\n ) : (\n <div className={`${classNames.monthYearLabel} ${slideDirection === 'left' ? 'animate-slide-in-left' : slideDirection === 'right' ? 'animate-slide-in-right' : ''}`}>\n {(() => {\n const first = calendars[0];\n const last = calendars[calendars.length - 1];\n const isFullYear = calendars.length === 12 && first.month === 0 && last.month === 11 && first.year === last.year;\n\n if (isFullYear) {\n return <span>{first.year}</span>;\n } else if (first.year === last.year) {\n return <span>{monthNames[first.month]} - {monthNames[last.month]} {first.year}</span>;\n } else {\n return <span>{monthNames[first.month]} {first.year} - {monthNames[last.month]} {last.year}</span>;\n }\n })()}\n </div>\n )}\n </div>\n\n <button\n {...getForwardProps({ calendars })}\n onMouseDown={(e) => e.preventDefault()}\n className={`${classNames.navButton} ${currentView && currentView !== 'days' ? 'invisible pointer-events-none' : ''}`}\n aria-label={t.forward}\n >\n <ChevronRightIcon />\n </button>\n </div>\n );\n};\n","export interface DayClassNames {\n day?: string;\n selected?: string;\n unselected?: string;\n disabled?: string;\n rangeStart?: string;\n rangeEnd?: string;\n rangeBetween?: string;\n rangeHovering?: string;\n [key: string]: string | undefined;\n}\n\nexport const defaultClassNames = {\n root: \"w-fit flex flex-col p-4 bg-white rounded-lg shadow-lg\",\n header: \"flex items-center justify-between border-b-2 border-brand-gray-light/40\",\n calendarsContainer: \"flex flex-col md:flex-row gap-4\",\n calendarContainer: \"flex-1 min-w-[280px] min-h-[260px]\",\n weekdayGrid: \"grid grid-cols-7 gap-1 mb-1 border-b border-brand-gray-light/40\",\n weekday: \"text-center text-xs text-gray-400 py-2\",\n daysGrid: \"grid grid-cols-7 gap-px bg-brand-gray-light/20\",\n footer: \"mt-4\",\n\n navButton: \"p-2 hover:bg-gray-100 rounded-full transition-colors cursor-pointer disabled:opacity-30 disabled:pointer-events-none\",\n monthYearContainer: \"flex gap-8\",\n monthYearLabel: \"flex gap-1 items-center font-semibold text-brand-text\",\n monthYearButton: \"hover:bg-gray-100 px-2 py-1 rounded cursor-pointer\",\n\n day: {\n day: \"aspect-square flex items-center justify-center text-sm font-medium transition-all relative group cursor-pointer p-px\",\n selected: \"bg-brand-gold text-white rounded-full\",\n unselected: \"bg-white hover:bg-brand-gray-light text-brand-text\",\n disabled: \"bg-white text-gray-300 cursor-not-allowed\",\n rangeStart: \"bg-brand-gold text-white\",\n rangeEnd: \"bg-brand-gold text-white\",\n rangeBetween: \"bg-brand-gray-light text-brand-text\",\n rangeHovering: \"bg-brand-gray-light text-brand-text\",\n },\n\n monthsGrid: \"grid grid-cols-3 gap-2 animate-slide-in-top\",\n monthButton: \"py-4 rounded-lg hover:bg-brand-gray-light transition-colors cursor-pointer disabled:opacity-30 disabled:pointer-events-none\",\n monthButtonSelected: \"bg-brand-gold text-white\",\n monthButtonUnselected: \"text-brand-text\",\n\n yearsGrid: \"grid grid-cols-3 gap-2 max-h-[300px] overflow-y-auto pr-2 animate-slide-in-top\",\n yearButton: \"py-3 rounded-lg hover:bg-brand-gray-light transition-colors cursor-pointer disabled:opacity-30 disabled:pointer-events-none\",\n yearButtonSelected: \"bg-brand-gold text-white\",\n yearButtonUnselected: \"text-brand-text\",\n}\n\nexport interface CalendarClassNames {\n root?: string;\n header?: string;\n calendarsContainer?: string;\n calendarContainer?: string;\n weekdayGrid?: string;\n weekday?: string;\n daysGrid?: string;\n footer?: string;\n\n navButton?: string;\n monthYearContainer?: string;\n monthYearLabel?: string;\n monthYearButton?: string;\n\n day?: DayClassNames;\n\n monthsGrid?: string;\n monthButton?: string;\n monthButtonSelected?: string;\n monthButtonUnselected?: string;\n\n yearsGrid?: string;\n yearButton?: string;\n yearButtonSelected?: string;\n yearButtonUnselected?: string;\n}\n\nexport const mergeClassNames = (custom?: CalendarClassNames): Required<CalendarClassNames> => {\n const result = { ...defaultClassNames };\n if (!custom) return result;\n\n for (const key in custom) {\n const k = key as keyof CalendarClassNames;\n if (k === 'day' && custom.day) {\n result.day = { ...defaultClassNames.day, ...custom.day };\n } else if (custom[k]) {\n (result as any)[k] = custom[k];\n }\n }\n return result;\n};\n","import React from 'react';\nimport { CalendarClassNames } from '../types';\n\ninterface MonthSelectionProps {\n year: number;\n month: number;\n monthNames: string[];\n minDate?: Date | null;\n maxDate?: Date | null;\n onMonthSelect: (month: number) => void;\n classNames: Required<CalendarClassNames>;\n}\n\nexport const MonthSelection: React.FC<MonthSelectionProps> = ({\n year,\n month,\n monthNames,\n minDate,\n maxDate,\n onMonthSelect,\n classNames,\n}) => {\n const isMonthDisabled = (monthIdx: number) => {\n if (minDate && year === minDate.getFullYear() && monthIdx < minDate.getMonth()) {\n return true;\n }\n if (maxDate && year === maxDate.getFullYear() && monthIdx > maxDate.getMonth()) {\n return true;\n }\n return false;\n };\n\n return (\n <div className={classNames.monthsGrid}>\n {monthNames.map((name, idx) => {\n const disabled = isMonthDisabled(idx);\n return (\n <button\n key={name}\n onMouseDown={(e) => e.preventDefault()}\n onClick={() => !disabled && onMonthSelect(idx)}\n className={`${classNames.monthButton} ${idx === month ? classNames.monthButtonSelected : classNames.monthButtonUnselected}`}\n disabled={disabled}\n >\n {name}\n </button>\n );\n })}\n </div>\n );\n};\n","import React, { useEffect, useRef } from 'react';\nimport { CalendarClassNames, DateAdapter } from '../types';\n\ninterface YearSelectionProps {\n year: number;\n minDate?: Date | null;\n maxDate?: Date | null;\n adapter: DateAdapter;\n onYearSelect: (year: number) => void;\n classNames: Required<CalendarClassNames>;\n}\n\nexport const YearSelection: React.FC<YearSelectionProps> = ({\n year,\n minDate,\n maxDate,\n adapter,\n onYearSelect,\n classNames,\n}) => {\n const yearListRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (yearListRef.current) {\n const selectedYearBtn = yearListRef.current.querySelector('[data-selected=\"true\"]');\n if (selectedYearBtn) {\n selectedYearBtn.scrollIntoView({ block: 'center' });\n }\n }\n }, []);\n\n const startYear = minDate ? adapter.get(adapter.date(minDate), 'year') : year - 50;\n const endYear = maxDate ? adapter.get(adapter.date(maxDate), 'year') : year + 50;\n const years = [];\n for (let y = startYear; y <= endYear; y++) {\n years.push(y);\n }\n\n return (\n <div ref={yearListRef} className={classNames.yearsGrid}>\n {years.map((y) => (\n <button\n key={y}\n data-selected={y === year}\n onMouseDown={(e) => e.preventDefault()}\n onClick={() => onYearSelect(y)}\n className={`${classNames.yearButton} ${y === year ? classNames.yearButtonSelected : classNames.yearButtonUnselected}`}\n >\n {y}\n </button>\n ))}\n </div>\n );\n};\n","import React, { useState } from 'react';\nimport { useDates, UseDatesProps } from '../useDates';\nimport { Day } from './Day';\nimport { defaultAdapter } from '../adapters/dayjs';\nimport { getTranslations, Translations } from '../i18n';\nimport { CalendarHeader } from './CalendarHeader';\nimport { DateObj, CalendarClassNames } from '../types';\nimport { mergeClassNames } from '../classNames';\nimport { MonthSelection } from './MonthSelection';\nimport { YearSelection } from './YearSelection';\n\ninterface CalendarProps extends UseDatesProps {\n classNames?: CalendarClassNames;\n locale?: string;\n translations?: Partial<Translations>;\n header?: React.ReactNode | ((props: any) => React.ReactNode);\n footer?: React.ReactNode;\n renderDayTooltip?: (dateObj: DateObj) => React.ReactNode;\n}\n\ntype CalendarView = 'days' | 'months' | 'years';\n\nexport const Calendar: React.FC<CalendarProps> = (props) => {\n const {\n classNames: customClassNames,\n locale,\n translations: customTranslations,\n adapter = defaultAdapter,\n firstDayOfWeek = 0,\n header,\n footer,\n renderDayTooltip,\n ...useDatesProps\n } = props;\n\n const classNames = mergeClassNames(customClassNames);\n\n const [view, setView] = useState<CalendarView>('days');\n const [slideDirection, setSlideDirection] = useState<'left' | 'right' | null>(null);\n\n const t = getTranslations(adapter, locale, customTranslations);\n const weekdayNames = t.weekdays;\n const monthNames = t.months;\n\n const {\n calendars,\n getBackProps,\n getForwardProps,\n getDateProps,\n setOffset\n } = useDates({ ...useDatesProps, adapter, firstDayOfWeek });\n\n // Adjust weekday names based on firstDayOfWeek\n const sortedWeekdays = [...weekdayNames.slice(firstDayOfWeek), ...weekdayNames.slice(0, firstDayOfWeek)];\n\n const currentCalendar = calendars[0];\n const { month, year } = currentCalendar;\n\n const handleMonthSelect = (newMonth: number) => {\n const currentMonth = adapter.set(adapter.set(adapter.date(props.date || new Date()), 'year', year), 'month', month);\n const targetMonth = adapter.set(currentMonth, 'month', newMonth);\n const baseMonth = adapter.startOf(adapter.date(props.date || new Date()), 'month');\n const newOffset = adapter.diff(targetMonth, baseMonth, 'month');\n setSlideDirection(null);\n setOffset(newOffset);\n setView('days');\n };\n\n const handleYearSelect = (newYear: number) => {\n const currentMonth = adapter.set(adapter.set(adapter.date(props.date || new Date()), 'year', year), 'month', month);\n const targetMonth = adapter.set(currentMonth, 'year', newYear);\n const baseMonth = adapter.startOf(adapter.date(props.date || new Date()), 'month');\n const newOffset = adapter.diff(targetMonth, baseMonth, 'month');\n setSlideDirection(null);\n setOffset(newOffset);\n setView('days');\n };\n\n const wrappedGetBackProps = (args: any) => {\n const props = getBackProps(args);\n return {\n ...props,\n onClick: (e: any) => {\n setSlideDirection('left');\n props.onClick?.(e);\n }\n };\n };\n\n const wrappedGetForwardProps = (args: any) => {\n const props = getForwardProps(args);\n return {\n ...props,\n onClick: (e: any) => {\n setSlideDirection('right');\n props.onClick?.(e);\n }\n };\n };\n\n const renderDefaultHeader = () => (\n <CalendarHeader\n calendars={calendars}\n getBackProps={wrappedGetBackProps}\n getForwardProps={wrappedGetForwardProps}\n setView={setView}\n monthNames={monthNames}\n t={t}\n classNames={classNames}\n slideDirection={slideDirection}\n currentView={view}\n />\n );\n\n return (\n <div className={classNames.root}>\n {typeof header === 'function' ? header({\n calendars,\n getBackProps: wrappedGetBackProps,\n getForwardProps: wrappedGetForwardProps,\n setView,\n monthNames,\n t,\n slideDirection,\n currentView: view\n }) : (header || renderDefaultHeader())}\n\n <div className={classNames.calendarsContainer}>\n {view === 'months' && calendars.map((calendar) => (\n <div key={`months-${calendar.year}`} className={classNames.calendarContainer}>\n <MonthSelection\n year={calendar.year}\n month={calendar.month}\n monthNames={monthNames}\n minDate={props.minDate}\n maxDate={props.maxDate}\n onMonthSelect={handleMonthSelect}\n classNames={classNames}\n />\n </div>\n ))}\n {view === 'years' && calendars.map((calendar) => (\n <div key={`years-${calendar.year}`} className={classNames.calendarContainer}>\n <YearSelection\n year={calendar.year}\n minDate={props.minDate}\n maxDate={props.maxDate}\n adapter={adapter}\n onYearSelect={handleYearSelect}\n classNames={classNames}\n />\n </div>\n ))}\n {view === 'days' && calendars.map((calendar) => (\n <div key={`${calendar.month}-${calendar.year}`} className={classNames.calendarContainer}>\n {calendars.length > 1 && (\n <div className=\"text-center font-semibold mb-2 text-brand-text\">\n {monthNames[calendar.month]} {calendars[0].year !== calendars[calendars.length - 1].year ? calendar.year : ''}\n </div>\n )}\n <div className={classNames.weekdayGrid}>\n {sortedWeekdays.map((day) => (\n <div key={day} className={classNames.weekday}>{day}</div>\n ))}\n </div>\n <div className={`${classNames.daysGrid} ${slideDirection === 'left' ? 'animate-slide-in-left' : slideDirection === 'right' ? 'animate-slide-in-right' : ''}`}>\n {calendar.weeks.map((week, wi) =>\n week.map((dateObj, di) => (\n <Day\n key={`${wi}-${di}`}\n dateObj={dateObj}\n getDateProps={getDateProps}\n classNames={classNames}\n tooltip={dateObj && renderDayTooltip?.(dateObj)}\n />\n ))\n )}\n </div>\n </div>\n ))}\n </div>\n {footer && <div className={classNames.footer}>{footer}</div>}\n </div>\n );\n};\n"],"mappings":"wMAUA,IAAa,GAA2B,CAAE,UAAS,eAAc,aAAY,aAAc,CACzF,GAAI,CAAC,EACH,OAAO,EAAA,EAAA,IAAA,CAAC,MAAD,CAAK,UAAU,wBAA0B,CAAA,EAGlD,GAAM,CAAE,OAAM,WAAU,aAAY,eAAc,aAAY,iBAAgB,kBAAiB,iBAAkB,EAC3G,EAAa,EAAW,IAE1B,EAAe,eACnB,AAaE,EAbE,GAAgB,EACH,GAAG,EAAW,SAAS,eAC7B,EACM,GAAG,EAAW,WAAW,GAAG,EAAgB,gCAAkC,iBACpF,EACM,GAAG,EAAW,SAAS,GAAG,EAAgB,gCAAkC,iBAClF,EACM,EAAW,cAAgB,GACjC,EACM,EAAW,eAAiB,GAClC,EACM,EAAW,UAAY,GAC5B,EAGK,EAAW,YAAc,GAFzB,EAAW,UAAY,GAKxC,IAAM,EAAY,CAChB,EAAW,IACX,EACA,IAAI,EAAQ,WAAa,CAAC,EAAA,CAAG,IAAI,GAAM,EAAmB,IAAM,CAAC,CACnE,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,EAE1B,OACE,EAAA,EAAA,KAAA,CAAC,SAAD,CACE,GAAI,EAAa,CAAE,SAAQ,CAAC,EACjB,YAFb,SAAA,CAIG,EAAK,QAAQ,EACb,IACC,E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AAM,QACN,UACT,aAAc,EACF,YACb,CAAA,CACE,EATK,SAAS,EAAS,MASvB,CACN,EACA,IAAS,QAAU,EAAU,IAAK,IACjC,EAAA,EAAA,KAAA,CAAC,MAAD,CAAgD,UAAW,EAAW,kBAAtE,SAAA,CACG,EAAU,OAAS,IAClB,EAAA,EAAA,KAAA,CAAC,MAAD,CAAK,UAAU,iDAAf,SAAA,CACG,EAAW,EAAS,OAAO,IAAE,EAAU,EAAE,CAAC,OAAS,EAAU,EAAU,OAAS,EAAE,CAAC,KAAuB,GAAhB,EAAS,IACjG,KAEP,EAAA,EAAA,IAAA,CAAC,MAAD,CAAK,UAAW,EAAW,YACxB,SAAA,EAAe,IAAK,IACnB,EAAA,EAAA,IAAA,CAAC,MAAD,CAAe,UAAW,EAAW,QAAU,SAAA,CAAS,EAA9C,CAA8C,CACzD,CACE,CAAA,GACL,EAAA,EAAA,IAAA,CAAC,MAAD,CAAK,UAAW,GAAG,EAAW,SAAS,GAAG,IAAmB,OAAS,wBAA0B,IAAmB,QAAU,yBAA2B,KACrJ,SAAA,EAAS,MAAM,KAAK,EAAM,IACzB,EAAK,KAAK,EAAS,KACjB,EAAA,EAAA,IAAA,CAAC,EAAD,CAEW,UACK,eACF,aACZ,QAAS,GAAW,IAAmB,CAAO,CAC/C,EALM,GAAG,EAAG,GAAG,GAKf,CACF,CACH,CACG,CAAA,CACF,CAxBK,EAAA,GAAG,EAAS,MAAM,GAAG,EAAS,MAwBnC,CACN,CACE,IACJ,IAAU,EAAA,EAAA,IAAA,CAAC,MAAD,CAAK,UAAW,EAAW,OAAS,SAAA,CAAY,CAAA,CACxD,GAET"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { n as e, r as t, t as n } from "./useDates-DQabq6Ux.mjs";
|
|
2
|
+
import { addMonth as r, composeEventHandlers as i, getCalendars as a, isBackDisabled as o, isForwardDisabled as s, subtractMonth as c } from "./utils.mjs";
|
|
3
|
+
import { useEffect as l, useRef as u, useState as d } from "react";
|
|
4
|
+
import { jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
5
|
+
//#region src/components/Day.tsx
|
|
6
|
+
var m = ({ dateObj: e, getDateProps: t, classNames: n, tooltip: r }) => {
|
|
7
|
+
if (!e) return /* @__PURE__ */ f("div", { className: "aspect-square bg-white" });
|
|
8
|
+
let { date: i, selected: a, selectable: o, isRangeStart: s, isRangeEnd: c, isRangeBetween: l, isRangeHovering: u, isRangeActive: d } = e, m = n.day, h = "rounded-full";
|
|
9
|
+
h = s && c ? `${m.selected} rounded-full` : s ? `${m.rangeStart} ${d ? "rounded-l-full rounded-r-none" : "rounded-full"}` : c ? `${m.rangeEnd} ${d ? "rounded-r-full rounded-l-none" : "rounded-full"}` : l ? m.rangeBetween || "" : u ? m.rangeHovering || "" : a ? m.selected || "" : o ? m.unselected || "" : m.disabled || "";
|
|
10
|
+
let g = [
|
|
11
|
+
m.day,
|
|
12
|
+
h,
|
|
13
|
+
...(e.modifiers || []).map((e) => m[e] || e)
|
|
14
|
+
].filter(Boolean).join(" ");
|
|
15
|
+
return /* @__PURE__ */ p("button", {
|
|
16
|
+
...t({ dateObj: e }),
|
|
17
|
+
className: g,
|
|
18
|
+
children: [i.getDate(), r && /* @__PURE__ */ f("div", {
|
|
19
|
+
className: "absolute bottom-full left-1/2 -translate-x-1/2 mb-2 hidden group-hover:block z-10",
|
|
20
|
+
children: /* @__PURE__ */ p("div", {
|
|
21
|
+
className: "bg-gray-800 text-white text-xs py-1 px-2 rounded whitespace-nowrap shadow-lg",
|
|
22
|
+
children: [r, /* @__PURE__ */ f("div", { className: "absolute top-full left-1/2 -translate-x-1/2 border-8 border-transparent border-t-gray-800" })]
|
|
23
|
+
})
|
|
24
|
+
})]
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/i18n.ts
|
|
29
|
+
function h(e = t, n) {
|
|
30
|
+
return {
|
|
31
|
+
months: e.getMonths(n),
|
|
32
|
+
weekdays: e.getWeekdays(n),
|
|
33
|
+
back: "Previous month",
|
|
34
|
+
forward: "Next month"
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function g(e = t, n, r) {
|
|
38
|
+
return {
|
|
39
|
+
...h(e, n),
|
|
40
|
+
...r
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/components/CalendarHeader.tsx
|
|
45
|
+
var _ = () => /* @__PURE__ */ f("svg", {
|
|
46
|
+
width: "20",
|
|
47
|
+
height: "20",
|
|
48
|
+
viewBox: "0 0 24 24",
|
|
49
|
+
fill: "none",
|
|
50
|
+
stroke: "currentColor",
|
|
51
|
+
strokeWidth: "2",
|
|
52
|
+
strokeLinecap: "round",
|
|
53
|
+
strokeLinejoin: "round",
|
|
54
|
+
children: /* @__PURE__ */ f("polyline", { points: "15 18 9 12 15 6" })
|
|
55
|
+
}), v = () => /* @__PURE__ */ f("svg", {
|
|
56
|
+
width: "20",
|
|
57
|
+
height: "20",
|
|
58
|
+
viewBox: "0 0 24 24",
|
|
59
|
+
fill: "none",
|
|
60
|
+
stroke: "currentColor",
|
|
61
|
+
strokeWidth: "2",
|
|
62
|
+
strokeLinecap: "round",
|
|
63
|
+
strokeLinejoin: "round",
|
|
64
|
+
children: /* @__PURE__ */ f("polyline", { points: "9 18 15 12 9 6" })
|
|
65
|
+
}), y = ({ calendars: e, getBackProps: t, getForwardProps: n, setView: r, monthNames: i, t: a, classNames: o, slideDirection: s, currentView: c }) => /* @__PURE__ */ p("div", {
|
|
66
|
+
className: o.header,
|
|
67
|
+
children: [
|
|
68
|
+
/* @__PURE__ */ f("button", {
|
|
69
|
+
...t({ calendars: e }),
|
|
70
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
71
|
+
className: `${o.navButton} ${c && c !== "days" ? "invisible pointer-events-none" : ""}`,
|
|
72
|
+
"aria-label": a.back,
|
|
73
|
+
children: /* @__PURE__ */ f(_, {})
|
|
74
|
+
}),
|
|
75
|
+
/* @__PURE__ */ f("div", {
|
|
76
|
+
className: o.monthYearContainer,
|
|
77
|
+
children: e.length === 1 ? /* @__PURE__ */ p("div", {
|
|
78
|
+
className: `${o.monthYearLabel} ${s === "left" ? "animate-slide-in-left" : s === "right" ? "animate-slide-in-right" : ""}`,
|
|
79
|
+
children: [/* @__PURE__ */ f("button", {
|
|
80
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
81
|
+
onClick: () => r(c === "months" ? "days" : "months"),
|
|
82
|
+
className: o.monthYearButton,
|
|
83
|
+
children: i[e[0].month]
|
|
84
|
+
}), /* @__PURE__ */ f("button", {
|
|
85
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
86
|
+
onClick: () => r(c === "years" ? "days" : "years"),
|
|
87
|
+
className: o.monthYearButton,
|
|
88
|
+
children: e[0].year
|
|
89
|
+
})]
|
|
90
|
+
}, `${e[0].month}-${e[0].year}`) : /* @__PURE__ */ f("div", {
|
|
91
|
+
className: `${o.monthYearLabel} ${s === "left" ? "animate-slide-in-left" : s === "right" ? "animate-slide-in-right" : ""}`,
|
|
92
|
+
children: (() => {
|
|
93
|
+
let t = e[0], n = e[e.length - 1];
|
|
94
|
+
return e.length === 12 && t.month === 0 && n.month === 11 && t.year === n.year ? /* @__PURE__ */ f("span", { children: t.year }) : t.year === n.year ? /* @__PURE__ */ p("span", { children: [
|
|
95
|
+
i[t.month],
|
|
96
|
+
" - ",
|
|
97
|
+
i[n.month],
|
|
98
|
+
" ",
|
|
99
|
+
t.year
|
|
100
|
+
] }) : /* @__PURE__ */ p("span", { children: [
|
|
101
|
+
i[t.month],
|
|
102
|
+
" ",
|
|
103
|
+
t.year,
|
|
104
|
+
" - ",
|
|
105
|
+
i[n.month],
|
|
106
|
+
" ",
|
|
107
|
+
n.year
|
|
108
|
+
] });
|
|
109
|
+
})()
|
|
110
|
+
})
|
|
111
|
+
}),
|
|
112
|
+
/* @__PURE__ */ f("button", {
|
|
113
|
+
...n({ calendars: e }),
|
|
114
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
115
|
+
className: `${o.navButton} ${c && c !== "days" ? "invisible pointer-events-none" : ""}`,
|
|
116
|
+
"aria-label": a.forward,
|
|
117
|
+
children: /* @__PURE__ */ f(v, {})
|
|
118
|
+
})
|
|
119
|
+
]
|
|
120
|
+
}), b = {
|
|
121
|
+
root: "w-fit flex flex-col p-4 bg-white rounded-lg shadow-lg",
|
|
122
|
+
header: "flex items-center justify-between border-b-2 border-brand-gray-light/40",
|
|
123
|
+
calendarsContainer: "flex flex-col md:flex-row gap-4",
|
|
124
|
+
calendarContainer: "flex-1 min-w-[280px] min-h-[260px]",
|
|
125
|
+
weekdayGrid: "grid grid-cols-7 gap-1 mb-1 border-b border-brand-gray-light/40",
|
|
126
|
+
weekday: "text-center text-xs text-gray-400 py-2",
|
|
127
|
+
daysGrid: "grid grid-cols-7 gap-px bg-brand-gray-light/20",
|
|
128
|
+
footer: "mt-4",
|
|
129
|
+
navButton: "p-2 hover:bg-gray-100 rounded-full transition-colors cursor-pointer disabled:opacity-30 disabled:pointer-events-none",
|
|
130
|
+
monthYearContainer: "flex gap-8",
|
|
131
|
+
monthYearLabel: "flex gap-1 items-center font-semibold text-brand-text",
|
|
132
|
+
monthYearButton: "hover:bg-gray-100 px-2 py-1 rounded cursor-pointer",
|
|
133
|
+
day: {
|
|
134
|
+
day: "aspect-square flex items-center justify-center text-sm font-medium transition-all relative group cursor-pointer p-px",
|
|
135
|
+
selected: "bg-brand-gold text-white rounded-full",
|
|
136
|
+
unselected: "bg-white hover:bg-brand-gray-light text-brand-text",
|
|
137
|
+
disabled: "bg-white text-gray-300 cursor-not-allowed",
|
|
138
|
+
rangeStart: "bg-brand-gold text-white",
|
|
139
|
+
rangeEnd: "bg-brand-gold text-white",
|
|
140
|
+
rangeBetween: "bg-brand-gray-light text-brand-text",
|
|
141
|
+
rangeHovering: "bg-brand-gray-light text-brand-text"
|
|
142
|
+
},
|
|
143
|
+
monthsGrid: "grid grid-cols-3 gap-2 animate-slide-in-top",
|
|
144
|
+
monthButton: "py-4 rounded-lg hover:bg-brand-gray-light transition-colors cursor-pointer disabled:opacity-30 disabled:pointer-events-none",
|
|
145
|
+
monthButtonSelected: "bg-brand-gold text-white",
|
|
146
|
+
monthButtonUnselected: "text-brand-text",
|
|
147
|
+
yearsGrid: "grid grid-cols-3 gap-2 max-h-[300px] overflow-y-auto pr-2 animate-slide-in-top",
|
|
148
|
+
yearButton: "py-3 rounded-lg hover:bg-brand-gray-light transition-colors cursor-pointer disabled:opacity-30 disabled:pointer-events-none",
|
|
149
|
+
yearButtonSelected: "bg-brand-gold text-white",
|
|
150
|
+
yearButtonUnselected: "text-brand-text"
|
|
151
|
+
}, x = (e) => {
|
|
152
|
+
let t = { ...b };
|
|
153
|
+
if (!e) return t;
|
|
154
|
+
for (let n in e) {
|
|
155
|
+
let r = n;
|
|
156
|
+
r === "day" && e.day ? t.day = {
|
|
157
|
+
...b.day,
|
|
158
|
+
...e.day
|
|
159
|
+
} : e[r] && (t[r] = e[r]);
|
|
160
|
+
}
|
|
161
|
+
return t;
|
|
162
|
+
}, S = ({ year: e, month: t, monthNames: n, minDate: r, maxDate: i, onMonthSelect: a, classNames: o }) => {
|
|
163
|
+
let s = (t) => !!(r && e === r.getFullYear() && t < r.getMonth() || i && e === i.getFullYear() && t > i.getMonth());
|
|
164
|
+
return /* @__PURE__ */ f("div", {
|
|
165
|
+
className: o.monthsGrid,
|
|
166
|
+
children: n.map((e, n) => {
|
|
167
|
+
let r = s(n);
|
|
168
|
+
return /* @__PURE__ */ f("button", {
|
|
169
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
170
|
+
onClick: () => !r && a(n),
|
|
171
|
+
className: `${o.monthButton} ${n === t ? o.monthButtonSelected : o.monthButtonUnselected}`,
|
|
172
|
+
disabled: r,
|
|
173
|
+
children: e
|
|
174
|
+
}, e);
|
|
175
|
+
})
|
|
176
|
+
});
|
|
177
|
+
}, C = ({ year: e, minDate: t, maxDate: n, adapter: r, onYearSelect: i, classNames: a }) => {
|
|
178
|
+
let o = u(null);
|
|
179
|
+
l(() => {
|
|
180
|
+
if (o.current) {
|
|
181
|
+
let e = o.current.querySelector("[data-selected=\"true\"]");
|
|
182
|
+
e && e.scrollIntoView({ block: "center" });
|
|
183
|
+
}
|
|
184
|
+
}, []);
|
|
185
|
+
let s = t ? r.get(r.date(t), "year") : e - 50, c = n ? r.get(r.date(n), "year") : e + 50, d = [];
|
|
186
|
+
for (let e = s; e <= c; e++) d.push(e);
|
|
187
|
+
return /* @__PURE__ */ f("div", {
|
|
188
|
+
ref: o,
|
|
189
|
+
className: a.yearsGrid,
|
|
190
|
+
children: d.map((t) => /* @__PURE__ */ f("button", {
|
|
191
|
+
"data-selected": t === e,
|
|
192
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
193
|
+
onClick: () => i(t),
|
|
194
|
+
className: `${a.yearButton} ${t === e ? a.yearButtonSelected : a.yearButtonUnselected}`,
|
|
195
|
+
children: t
|
|
196
|
+
}, t))
|
|
197
|
+
});
|
|
198
|
+
}, w = (e) => {
|
|
199
|
+
let { classNames: r, locale: i, translations: a, adapter: o = t, firstDayOfWeek: s = 0, header: c, footer: l, renderDayTooltip: u, ...h } = e, _ = x(r), [v, b] = d("days"), [w, T] = d(null), E = g(o, i, a), D = E.weekdays, O = E.months, { calendars: k, getBackProps: A, getForwardProps: j, getDateProps: M, setOffset: N } = n({
|
|
200
|
+
...h,
|
|
201
|
+
adapter: o,
|
|
202
|
+
firstDayOfWeek: s
|
|
203
|
+
}), P = [...D.slice(s), ...D.slice(0, s)], { month: F, year: I } = k[0], L = (t) => {
|
|
204
|
+
let n = o.set(o.set(o.date(e.date || /* @__PURE__ */ new Date()), "year", I), "month", F), r = o.set(n, "month", t), i = o.startOf(o.date(e.date || /* @__PURE__ */ new Date()), "month"), a = o.diff(r, i, "month");
|
|
205
|
+
T(null), N(a), b("days");
|
|
206
|
+
}, R = (t) => {
|
|
207
|
+
let n = o.set(o.set(o.date(e.date || /* @__PURE__ */ new Date()), "year", I), "month", F), r = o.set(n, "year", t), i = o.startOf(o.date(e.date || /* @__PURE__ */ new Date()), "month"), a = o.diff(r, i, "month");
|
|
208
|
+
T(null), N(a), b("days");
|
|
209
|
+
}, z = (e) => {
|
|
210
|
+
let t = A(e);
|
|
211
|
+
return {
|
|
212
|
+
...t,
|
|
213
|
+
onClick: (e) => {
|
|
214
|
+
T("left"), t.onClick?.(e);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
}, B = (e) => {
|
|
218
|
+
let t = j(e);
|
|
219
|
+
return {
|
|
220
|
+
...t,
|
|
221
|
+
onClick: (e) => {
|
|
222
|
+
T("right"), t.onClick?.(e);
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
return /* @__PURE__ */ p("div", {
|
|
227
|
+
className: _.root,
|
|
228
|
+
children: [
|
|
229
|
+
typeof c == "function" ? c({
|
|
230
|
+
calendars: k,
|
|
231
|
+
getBackProps: z,
|
|
232
|
+
getForwardProps: B,
|
|
233
|
+
setView: b,
|
|
234
|
+
monthNames: O,
|
|
235
|
+
t: E,
|
|
236
|
+
slideDirection: w,
|
|
237
|
+
currentView: v
|
|
238
|
+
}) : c || /* @__PURE__ */ f(y, {
|
|
239
|
+
calendars: k,
|
|
240
|
+
getBackProps: z,
|
|
241
|
+
getForwardProps: B,
|
|
242
|
+
setView: b,
|
|
243
|
+
monthNames: O,
|
|
244
|
+
t: E,
|
|
245
|
+
classNames: _,
|
|
246
|
+
slideDirection: w,
|
|
247
|
+
currentView: v
|
|
248
|
+
}),
|
|
249
|
+
/* @__PURE__ */ p("div", {
|
|
250
|
+
className: _.calendarsContainer,
|
|
251
|
+
children: [
|
|
252
|
+
v === "months" && k.map((t) => /* @__PURE__ */ f("div", {
|
|
253
|
+
className: _.calendarContainer,
|
|
254
|
+
children: /* @__PURE__ */ f(S, {
|
|
255
|
+
year: t.year,
|
|
256
|
+
month: t.month,
|
|
257
|
+
monthNames: O,
|
|
258
|
+
minDate: e.minDate,
|
|
259
|
+
maxDate: e.maxDate,
|
|
260
|
+
onMonthSelect: L,
|
|
261
|
+
classNames: _
|
|
262
|
+
})
|
|
263
|
+
}, `months-${t.year}`)),
|
|
264
|
+
v === "years" && k.map((t) => /* @__PURE__ */ f("div", {
|
|
265
|
+
className: _.calendarContainer,
|
|
266
|
+
children: /* @__PURE__ */ f(C, {
|
|
267
|
+
year: t.year,
|
|
268
|
+
minDate: e.minDate,
|
|
269
|
+
maxDate: e.maxDate,
|
|
270
|
+
adapter: o,
|
|
271
|
+
onYearSelect: R,
|
|
272
|
+
classNames: _
|
|
273
|
+
})
|
|
274
|
+
}, `years-${t.year}`)),
|
|
275
|
+
v === "days" && k.map((e) => /* @__PURE__ */ p("div", {
|
|
276
|
+
className: _.calendarContainer,
|
|
277
|
+
children: [
|
|
278
|
+
k.length > 1 && /* @__PURE__ */ p("div", {
|
|
279
|
+
className: "text-center font-semibold mb-2 text-brand-text",
|
|
280
|
+
children: [
|
|
281
|
+
O[e.month],
|
|
282
|
+
" ",
|
|
283
|
+
k[0].year === k[k.length - 1].year ? "" : e.year
|
|
284
|
+
]
|
|
285
|
+
}),
|
|
286
|
+
/* @__PURE__ */ f("div", {
|
|
287
|
+
className: _.weekdayGrid,
|
|
288
|
+
children: P.map((e) => /* @__PURE__ */ f("div", {
|
|
289
|
+
className: _.weekday,
|
|
290
|
+
children: e
|
|
291
|
+
}, e))
|
|
292
|
+
}),
|
|
293
|
+
/* @__PURE__ */ f("div", {
|
|
294
|
+
className: `${_.daysGrid} ${w === "left" ? "animate-slide-in-left" : w === "right" ? "animate-slide-in-right" : ""}`,
|
|
295
|
+
children: e.weeks.map((e, t) => e.map((e, n) => /* @__PURE__ */ f(m, {
|
|
296
|
+
dateObj: e,
|
|
297
|
+
getDateProps: M,
|
|
298
|
+
classNames: _,
|
|
299
|
+
tooltip: e && u?.(e)
|
|
300
|
+
}, `${t}-${n}`)))
|
|
301
|
+
})
|
|
302
|
+
]
|
|
303
|
+
}, `${e.month}-${e.year}`))
|
|
304
|
+
]
|
|
305
|
+
}),
|
|
306
|
+
l && /* @__PURE__ */ f("div", {
|
|
307
|
+
className: _.footer,
|
|
308
|
+
children: l
|
|
309
|
+
})
|
|
310
|
+
]
|
|
311
|
+
});
|
|
312
|
+
};
|
|
313
|
+
//#endregion
|
|
314
|
+
export { w as Calendar, y as CalendarHeader, _ as ChevronLeftIcon, v as ChevronRightIcon, m as Day, e as DayjsAdapter, S as MonthSelection, C as YearSelection, r as addMonth, i as composeEventHandlers, t as defaultAdapter, b as defaultClassNames, a as getCalendars, h as getDefaults, g as getTranslations, o as isBackDisabled, s as isForwardDisabled, x as mergeClassNames, c as subtractMonth, n as useDates };
|
|
315
|
+
|
|
316
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/components/Day.tsx","../src/i18n.ts","../src/components/CalendarHeader.tsx","../src/classNames.ts","../src/components/MonthSelection.tsx","../src/components/YearSelection.tsx","../src/components/Calendar.tsx"],"sourcesContent":["import React from 'react';\nimport type { CalendarClassNames, DateObj } from '../types';\n\ninterface DayProps {\n dateObj: DateObj | null;\n getDateProps: (args: { dateObj: DateObj, [key: string]: any }) => any;\n tooltip?: React.ReactNode;\n classNames: Required<CalendarClassNames>;\n}\n\nexport const Day: React.FC<DayProps> = ({ dateObj, getDateProps, classNames, tooltip }) => {\n if (!dateObj) {\n return <div className=\"aspect-square bg-white\" />;\n }\n\n const { date, selected, selectable, isRangeStart, isRangeEnd, isRangeBetween, isRangeHovering, isRangeActive } = dateObj;\n const dayClasses = classNames.day;\n\n let stateClasses = \"rounded-full\";\n if (isRangeStart && isRangeEnd) {\n stateClasses = `${dayClasses.selected} rounded-full`;\n } else if (isRangeStart) {\n stateClasses = `${dayClasses.rangeStart} ${isRangeActive ? 'rounded-l-full rounded-r-none' : 'rounded-full'}`;\n } else if (isRangeEnd) {\n stateClasses = `${dayClasses.rangeEnd} ${isRangeActive ? 'rounded-r-full rounded-l-none' : 'rounded-full'}`;\n } else if (isRangeBetween) {\n stateClasses = dayClasses.rangeBetween || '';\n } else if (isRangeHovering) {\n stateClasses = dayClasses.rangeHovering || '';\n } else if (selected) {\n stateClasses = dayClasses.selected || '';\n } else if (!selectable) {\n stateClasses = dayClasses.disabled || '';\n } else {\n stateClasses = dayClasses.unselected || '';\n }\n\n const className = [\n dayClasses.day,\n stateClasses,\n ...(dateObj.modifiers || []).map(m => (dayClasses as any)[m] || m)\n ].filter(Boolean).join(' ');\n\n return (\n <button\n {...getDateProps({ dateObj })}\n className={className}\n >\n {date.getDate()}\n {tooltip && (\n <div className=\"absolute bottom-full left-1/2 -translate-x-1/2 mb-2 hidden group-hover:block z-10\">\n <div className=\"bg-gray-800 text-white text-xs py-1 px-2 rounded whitespace-nowrap shadow-lg\">\n {tooltip}\n <div className=\"absolute top-full left-1/2 -translate-x-1/2 border-8 border-transparent border-t-gray-800\" />\n </div>\n </div>\n )}\n </button>\n );\n};\n","import { DateAdapter } from \"./types\";\nimport { defaultAdapter } from \"./adapters/dayjs\";\n\nexport interface Translations {\n months: string[];\n weekdays: string[];\n back: string;\n forward: string;\n}\n\nexport function getDefaults(adapter: DateAdapter = defaultAdapter, locale?: string): Translations {\n return {\n months: adapter.getMonths(locale),\n weekdays: adapter.getWeekdays(locale),\n back: 'Previous month',\n forward: 'Next month'\n };\n}\n\nexport function getTranslations(\n adapter: DateAdapter = defaultAdapter,\n locale?: string,\n custom?: Partial<Translations>\n): Translations {\n const base = getDefaults(adapter, locale);\n return { ...base, ...custom };\n}\n","import React from 'react';\nimport { Calendar, CalendarClassNames } from '../types';\n\nexport interface HeaderProps {\n calendars: Calendar[];\n getBackProps: (args: any) => any;\n getForwardProps: (args: any) => any;\n setView: (view: 'days' | 'months' | 'years') => void;\n monthNames: string[];\n t: { back: string; forward: string };\n classNames: Required<CalendarClassNames>;\n slideDirection?: 'left' | 'right' | null;\n currentView?: 'days' | 'months' | 'years';\n}\n\nexport const ChevronLeftIcon = () => (\n <svg width=\"20\" height=\"20\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n <polyline points=\"15 18 9 12 15 6\"></polyline>\n </svg>\n);\n\nexport const ChevronRightIcon = () => (\n <svg width=\"20\" height=\"20\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n <polyline points=\"9 18 15 12 9 6\"></polyline>\n </svg>\n);\n\nexport const CalendarHeader: React.FC<HeaderProps> = ({\n calendars,\n getBackProps,\n getForwardProps,\n setView,\n monthNames,\n t,\n classNames,\n slideDirection,\n currentView\n}) => {\n return (\n <div className={classNames.header}>\n <button\n {...getBackProps({ calendars })}\n onMouseDown={(e) => e.preventDefault()}\n className={`${classNames.navButton} ${currentView && currentView !== 'days' ? 'invisible pointer-events-none' : ''}`}\n aria-label={t.back}\n >\n <ChevronLeftIcon />\n </button>\n\n <div className={classNames.monthYearContainer}>\n {calendars.length === 1 ? (\n <div key={`${calendars[0].month}-${calendars[0].year}`} className={`${classNames.monthYearLabel} ${slideDirection === 'left' ? 'animate-slide-in-left' : slideDirection === 'right' ? 'animate-slide-in-right' : ''}`}>\n <button\n onMouseDown={(e) => e.preventDefault()}\n onClick={() => setView(currentView === 'months' ? 'days' : 'months')}\n className={classNames.monthYearButton}\n >\n {monthNames[calendars[0].month]}\n </button>\n <button\n onMouseDown={(e) => e.preventDefault()}\n onClick={() => setView(currentView === 'years' ? 'days' : 'years')}\n className={classNames.monthYearButton}\n >\n {calendars[0].year}\n </button>\n </div>\n ) : (\n <div className={`${classNames.monthYearLabel} ${slideDirection === 'left' ? 'animate-slide-in-left' : slideDirection === 'right' ? 'animate-slide-in-right' : ''}`}>\n {(() => {\n const first = calendars[0];\n const last = calendars[calendars.length - 1];\n const isFullYear = calendars.length === 12 && first.month === 0 && last.month === 11 && first.year === last.year;\n\n if (isFullYear) {\n return <span>{first.year}</span>;\n } else if (first.year === last.year) {\n return <span>{monthNames[first.month]} - {monthNames[last.month]} {first.year}</span>;\n } else {\n return <span>{monthNames[first.month]} {first.year} - {monthNames[last.month]} {last.year}</span>;\n }\n })()}\n </div>\n )}\n </div>\n\n <button\n {...getForwardProps({ calendars })}\n onMouseDown={(e) => e.preventDefault()}\n className={`${classNames.navButton} ${currentView && currentView !== 'days' ? 'invisible pointer-events-none' : ''}`}\n aria-label={t.forward}\n >\n <ChevronRightIcon />\n </button>\n </div>\n );\n};\n","export interface DayClassNames {\n day?: string;\n selected?: string;\n unselected?: string;\n disabled?: string;\n rangeStart?: string;\n rangeEnd?: string;\n rangeBetween?: string;\n rangeHovering?: string;\n [key: string]: string | undefined;\n}\n\nexport const defaultClassNames = {\n root: \"w-fit flex flex-col p-4 bg-white rounded-lg shadow-lg\",\n header: \"flex items-center justify-between border-b-2 border-brand-gray-light/40\",\n calendarsContainer: \"flex flex-col md:flex-row gap-4\",\n calendarContainer: \"flex-1 min-w-[280px] min-h-[260px]\",\n weekdayGrid: \"grid grid-cols-7 gap-1 mb-1 border-b border-brand-gray-light/40\",\n weekday: \"text-center text-xs text-gray-400 py-2\",\n daysGrid: \"grid grid-cols-7 gap-px bg-brand-gray-light/20\",\n footer: \"mt-4\",\n\n navButton: \"p-2 hover:bg-gray-100 rounded-full transition-colors cursor-pointer disabled:opacity-30 disabled:pointer-events-none\",\n monthYearContainer: \"flex gap-8\",\n monthYearLabel: \"flex gap-1 items-center font-semibold text-brand-text\",\n monthYearButton: \"hover:bg-gray-100 px-2 py-1 rounded cursor-pointer\",\n\n day: {\n day: \"aspect-square flex items-center justify-center text-sm font-medium transition-all relative group cursor-pointer p-px\",\n selected: \"bg-brand-gold text-white rounded-full\",\n unselected: \"bg-white hover:bg-brand-gray-light text-brand-text\",\n disabled: \"bg-white text-gray-300 cursor-not-allowed\",\n rangeStart: \"bg-brand-gold text-white\",\n rangeEnd: \"bg-brand-gold text-white\",\n rangeBetween: \"bg-brand-gray-light text-brand-text\",\n rangeHovering: \"bg-brand-gray-light text-brand-text\",\n },\n\n monthsGrid: \"grid grid-cols-3 gap-2 animate-slide-in-top\",\n monthButton: \"py-4 rounded-lg hover:bg-brand-gray-light transition-colors cursor-pointer disabled:opacity-30 disabled:pointer-events-none\",\n monthButtonSelected: \"bg-brand-gold text-white\",\n monthButtonUnselected: \"text-brand-text\",\n\n yearsGrid: \"grid grid-cols-3 gap-2 max-h-[300px] overflow-y-auto pr-2 animate-slide-in-top\",\n yearButton: \"py-3 rounded-lg hover:bg-brand-gray-light transition-colors cursor-pointer disabled:opacity-30 disabled:pointer-events-none\",\n yearButtonSelected: \"bg-brand-gold text-white\",\n yearButtonUnselected: \"text-brand-text\",\n}\n\nexport interface CalendarClassNames {\n root?: string;\n header?: string;\n calendarsContainer?: string;\n calendarContainer?: string;\n weekdayGrid?: string;\n weekday?: string;\n daysGrid?: string;\n footer?: string;\n\n navButton?: string;\n monthYearContainer?: string;\n monthYearLabel?: string;\n monthYearButton?: string;\n\n day?: DayClassNames;\n\n monthsGrid?: string;\n monthButton?: string;\n monthButtonSelected?: string;\n monthButtonUnselected?: string;\n\n yearsGrid?: string;\n yearButton?: string;\n yearButtonSelected?: string;\n yearButtonUnselected?: string;\n}\n\nexport const mergeClassNames = (custom?: CalendarClassNames): Required<CalendarClassNames> => {\n const result = { ...defaultClassNames };\n if (!custom) return result;\n\n for (const key in custom) {\n const k = key as keyof CalendarClassNames;\n if (k === 'day' && custom.day) {\n result.day = { ...defaultClassNames.day, ...custom.day };\n } else if (custom[k]) {\n (result as any)[k] = custom[k];\n }\n }\n return result;\n};\n","import React from 'react';\nimport { CalendarClassNames } from '../types';\n\ninterface MonthSelectionProps {\n year: number;\n month: number;\n monthNames: string[];\n minDate?: Date | null;\n maxDate?: Date | null;\n onMonthSelect: (month: number) => void;\n classNames: Required<CalendarClassNames>;\n}\n\nexport const MonthSelection: React.FC<MonthSelectionProps> = ({\n year,\n month,\n monthNames,\n minDate,\n maxDate,\n onMonthSelect,\n classNames,\n}) => {\n const isMonthDisabled = (monthIdx: number) => {\n if (minDate && year === minDate.getFullYear() && monthIdx < minDate.getMonth()) {\n return true;\n }\n if (maxDate && year === maxDate.getFullYear() && monthIdx > maxDate.getMonth()) {\n return true;\n }\n return false;\n };\n\n return (\n <div className={classNames.monthsGrid}>\n {monthNames.map((name, idx) => {\n const disabled = isMonthDisabled(idx);\n return (\n <button\n key={name}\n onMouseDown={(e) => e.preventDefault()}\n onClick={() => !disabled && onMonthSelect(idx)}\n className={`${classNames.monthButton} ${idx === month ? classNames.monthButtonSelected : classNames.monthButtonUnselected}`}\n disabled={disabled}\n >\n {name}\n </button>\n );\n })}\n </div>\n );\n};\n","import React, { useEffect, useRef } from 'react';\nimport { CalendarClassNames, DateAdapter } from '../types';\n\ninterface YearSelectionProps {\n year: number;\n minDate?: Date | null;\n maxDate?: Date | null;\n adapter: DateAdapter;\n onYearSelect: (year: number) => void;\n classNames: Required<CalendarClassNames>;\n}\n\nexport const YearSelection: React.FC<YearSelectionProps> = ({\n year,\n minDate,\n maxDate,\n adapter,\n onYearSelect,\n classNames,\n}) => {\n const yearListRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (yearListRef.current) {\n const selectedYearBtn = yearListRef.current.querySelector('[data-selected=\"true\"]');\n if (selectedYearBtn) {\n selectedYearBtn.scrollIntoView({ block: 'center' });\n }\n }\n }, []);\n\n const startYear = minDate ? adapter.get(adapter.date(minDate), 'year') : year - 50;\n const endYear = maxDate ? adapter.get(adapter.date(maxDate), 'year') : year + 50;\n const years = [];\n for (let y = startYear; y <= endYear; y++) {\n years.push(y);\n }\n\n return (\n <div ref={yearListRef} className={classNames.yearsGrid}>\n {years.map((y) => (\n <button\n key={y}\n data-selected={y === year}\n onMouseDown={(e) => e.preventDefault()}\n onClick={() => onYearSelect(y)}\n className={`${classNames.yearButton} ${y === year ? classNames.yearButtonSelected : classNames.yearButtonUnselected}`}\n >\n {y}\n </button>\n ))}\n </div>\n );\n};\n","import React, { useState } from 'react';\nimport { useDates, UseDatesProps } from '../useDates';\nimport { Day } from './Day';\nimport { defaultAdapter } from '../adapters/dayjs';\nimport { getTranslations, Translations } from '../i18n';\nimport { CalendarHeader } from './CalendarHeader';\nimport { DateObj, CalendarClassNames } from '../types';\nimport { mergeClassNames } from '../classNames';\nimport { MonthSelection } from './MonthSelection';\nimport { YearSelection } from './YearSelection';\n\ninterface CalendarProps extends UseDatesProps {\n classNames?: CalendarClassNames;\n locale?: string;\n translations?: Partial<Translations>;\n header?: React.ReactNode | ((props: any) => React.ReactNode);\n footer?: React.ReactNode;\n renderDayTooltip?: (dateObj: DateObj) => React.ReactNode;\n}\n\ntype CalendarView = 'days' | 'months' | 'years';\n\nexport const Calendar: React.FC<CalendarProps> = (props) => {\n const {\n classNames: customClassNames,\n locale,\n translations: customTranslations,\n adapter = defaultAdapter,\n firstDayOfWeek = 0,\n header,\n footer,\n renderDayTooltip,\n ...useDatesProps\n } = props;\n\n const classNames = mergeClassNames(customClassNames);\n\n const [view, setView] = useState<CalendarView>('days');\n const [slideDirection, setSlideDirection] = useState<'left' | 'right' | null>(null);\n\n const t = getTranslations(adapter, locale, customTranslations);\n const weekdayNames = t.weekdays;\n const monthNames = t.months;\n\n const {\n calendars,\n getBackProps,\n getForwardProps,\n getDateProps,\n setOffset\n } = useDates({ ...useDatesProps, adapter, firstDayOfWeek });\n\n // Adjust weekday names based on firstDayOfWeek\n const sortedWeekdays = [...weekdayNames.slice(firstDayOfWeek), ...weekdayNames.slice(0, firstDayOfWeek)];\n\n const currentCalendar = calendars[0];\n const { month, year } = currentCalendar;\n\n const handleMonthSelect = (newMonth: number) => {\n const currentMonth = adapter.set(adapter.set(adapter.date(props.date || new Date()), 'year', year), 'month', month);\n const targetMonth = adapter.set(currentMonth, 'month', newMonth);\n const baseMonth = adapter.startOf(adapter.date(props.date || new Date()), 'month');\n const newOffset = adapter.diff(targetMonth, baseMonth, 'month');\n setSlideDirection(null);\n setOffset(newOffset);\n setView('days');\n };\n\n const handleYearSelect = (newYear: number) => {\n const currentMonth = adapter.set(adapter.set(adapter.date(props.date || new Date()), 'year', year), 'month', month);\n const targetMonth = adapter.set(currentMonth, 'year', newYear);\n const baseMonth = adapter.startOf(adapter.date(props.date || new Date()), 'month');\n const newOffset = adapter.diff(targetMonth, baseMonth, 'month');\n setSlideDirection(null);\n setOffset(newOffset);\n setView('days');\n };\n\n const wrappedGetBackProps = (args: any) => {\n const props = getBackProps(args);\n return {\n ...props,\n onClick: (e: any) => {\n setSlideDirection('left');\n props.onClick?.(e);\n }\n };\n };\n\n const wrappedGetForwardProps = (args: any) => {\n const props = getForwardProps(args);\n return {\n ...props,\n onClick: (e: any) => {\n setSlideDirection('right');\n props.onClick?.(e);\n }\n };\n };\n\n const renderDefaultHeader = () => (\n <CalendarHeader\n calendars={calendars}\n getBackProps={wrappedGetBackProps}\n getForwardProps={wrappedGetForwardProps}\n setView={setView}\n monthNames={monthNames}\n t={t}\n classNames={classNames}\n slideDirection={slideDirection}\n currentView={view}\n />\n );\n\n return (\n <div className={classNames.root}>\n {typeof header === 'function' ? header({\n calendars,\n getBackProps: wrappedGetBackProps,\n getForwardProps: wrappedGetForwardProps,\n setView,\n monthNames,\n t,\n slideDirection,\n currentView: view\n }) : (header || renderDefaultHeader())}\n\n <div className={classNames.calendarsContainer}>\n {view === 'months' && calendars.map((calendar) => (\n <div key={`months-${calendar.year}`} className={classNames.calendarContainer}>\n <MonthSelection\n year={calendar.year}\n month={calendar.month}\n monthNames={monthNames}\n minDate={props.minDate}\n maxDate={props.maxDate}\n onMonthSelect={handleMonthSelect}\n classNames={classNames}\n />\n </div>\n ))}\n {view === 'years' && calendars.map((calendar) => (\n <div key={`years-${calendar.year}`} className={classNames.calendarContainer}>\n <YearSelection\n year={calendar.year}\n minDate={props.minDate}\n maxDate={props.maxDate}\n adapter={adapter}\n onYearSelect={handleYearSelect}\n classNames={classNames}\n />\n </div>\n ))}\n {view === 'days' && calendars.map((calendar) => (\n <div key={`${calendar.month}-${calendar.year}`} className={classNames.calendarContainer}>\n {calendars.length > 1 && (\n <div className=\"text-center font-semibold mb-2 text-brand-text\">\n {monthNames[calendar.month]} {calendars[0].year !== calendars[calendars.length - 1].year ? calendar.year : ''}\n </div>\n )}\n <div className={classNames.weekdayGrid}>\n {sortedWeekdays.map((day) => (\n <div key={day} className={classNames.weekday}>{day}</div>\n ))}\n </div>\n <div className={`${classNames.daysGrid} ${slideDirection === 'left' ? 'animate-slide-in-left' : slideDirection === 'right' ? 'animate-slide-in-right' : ''}`}>\n {calendar.weeks.map((week, wi) =>\n week.map((dateObj, di) => (\n <Day\n key={`${wi}-${di}`}\n dateObj={dateObj}\n getDateProps={getDateProps}\n classNames={classNames}\n tooltip={dateObj && renderDayTooltip?.(dateObj)}\n />\n ))\n )}\n </div>\n </div>\n ))}\n </div>\n {footer && <div className={classNames.footer}>{footer}</div>}\n </div>\n );\n};\n"],"mappings":";;;;;AAUA,IAAa,KAA2B,EAAE,YAAS,iBAAc,eAAY,iBAAc;CACzF,IAAI,CAAC,GACH,OAAO,kBAAC,OAAD,EAAK,WAAU,yBAA0B,CAAA;CAGlD,IAAM,EAAE,SAAM,aAAU,eAAY,iBAAc,eAAY,mBAAgB,oBAAiB,qBAAkB,GAC3G,IAAa,EAAW,KAE1B,IAAe;CACnB,AAaE,IAbE,KAAgB,IACH,GAAG,EAAW,SAAS,iBAC7B,IACM,GAAG,EAAW,WAAW,GAAG,IAAgB,kCAAkC,mBACpF,IACM,GAAG,EAAW,SAAS,GAAG,IAAgB,kCAAkC,mBAClF,IACM,EAAW,gBAAgB,KACjC,IACM,EAAW,iBAAiB,KAClC,IACM,EAAW,YAAY,KAC5B,IAGK,EAAW,cAAc,KAFzB,EAAW,YAAY;CAKxC,IAAM,IAAY;EAChB,EAAW;EACX;EACA,IAAI,EAAQ,aAAa,C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e,KAAK,MACnB,kBAAC,OAAD;SAAe,WAAW,EAAW;SAAU,UAAA;QAAS,GAA9C,CAA8C,CACzD;OACE,CAAA;OACL,kBAAC,OAAD;QAAK,WAAW,GAAG,EAAW,SAAS,GAAG,MAAmB,SAAS,0BAA0B,MAAmB,UAAU,2BAA2B;QACrJ,UAAA,EAAS,MAAM,KAAK,GAAM,MACzB,EAAK,KAAK,GAAS,MACjB,kBAAC,GAAD;SAEW;SACK;SACF;SACZ,SAAS,KAAW,IAAmB,CAAO;QAC/C,GALM,GAAG,EAAG,GAAG,GAKf,CACF,CACH;OACG,CAAA;MACF;KAxBK,GAAA,GAAG,EAAS,MAAM,GAAG,EAAS,MAwBnC,CACN;IACE;;GACJ,KAAU,kBAAC,OAAD;IAAK,WAAW,EAAW;IAAS,UAAA;GAAY,CAAA;EACxD;;AAET"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { CalendarClassNames } from './classNames';
|
|
2
|
+
export interface DateAdapter<T = any> {
|
|
3
|
+
date(value?: any): T;
|
|
4
|
+
add(date: T, amount: number, unit: 'day' | 'month' | 'year'): T;
|
|
5
|
+
subtract(date: T, amount: number, unit: 'day' | 'month' | 'year'): T;
|
|
6
|
+
startOf(date: T, unit: 'day' | 'month' | 'year'): T;
|
|
7
|
+
endOf(date: T, unit: 'day' | 'month' | 'year'): T;
|
|
8
|
+
isBefore(date: T, comparison: T, unit?: 'day' | 'month' | 'year'): boolean;
|
|
9
|
+
isAfter(date: T, comparison: T, unit?: 'day' | 'month' | 'year'): boolean;
|
|
10
|
+
isSame(date: T, comparison: T, unit?: 'day' | 'month' | 'year'): boolean;
|
|
11
|
+
set(date: T, unit: 'day' | 'month' | 'year', value: number): T;
|
|
12
|
+
get(date: T, unit: 'day' | 'month' | 'year'): number;
|
|
13
|
+
format(date: T, formatStr: string, locale?: string): string;
|
|
14
|
+
getDaysInMonth(date: T): number;
|
|
15
|
+
toDate(date: T): Date;
|
|
16
|
+
diff(date: T, comparison: T, unit: 'month' | 'year'): number;
|
|
17
|
+
getMonths(locale?: string): string[];
|
|
18
|
+
getWeekdays(locale?: string): string[];
|
|
19
|
+
}
|
|
20
|
+
export type SelectionMode = 'single' | 'range' | 'multiple';
|
|
21
|
+
export interface DateObj {
|
|
22
|
+
date: Date;
|
|
23
|
+
selected: boolean;
|
|
24
|
+
selectable: boolean;
|
|
25
|
+
today: boolean;
|
|
26
|
+
prevMonth: boolean;
|
|
27
|
+
nextMonth: boolean;
|
|
28
|
+
isRangeStart?: boolean;
|
|
29
|
+
isRangeEnd?: boolean;
|
|
30
|
+
isRangeBetween?: boolean;
|
|
31
|
+
isRangeHovering?: boolean;
|
|
32
|
+
isRangeActive?: boolean;
|
|
33
|
+
modifiers?: string[];
|
|
34
|
+
}
|
|
35
|
+
export interface Calendar {
|
|
36
|
+
firstDayOfMonth: Date;
|
|
37
|
+
lastDayOfMonth: Date;
|
|
38
|
+
month: number;
|
|
39
|
+
year: number;
|
|
40
|
+
weeks: (DateObj | null)[][];
|
|
41
|
+
}
|
|
42
|
+
export type { CalendarClassNames };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));const c=require("./utils.js");let l=require("react"),u=require("dayjs");u=s(u);let d=require("dayjs/plugin/isBetween");d=s(d);let f=require("dayjs/plugin/customParseFormat");f=s(f);let p=require("dayjs/plugin/localeData");p=s(p),u.default.extend(d.default),u.default.extend(f.default),u.default.extend(p.default);var m=class{date(e){return(0,u.default)(e)}add(e,t,n){return e.add(t,n)}subtract(e,t,n){return e.subtract(t,n)}startOf(e,t){return e.startOf(t)}endOf(e,t){return e.endOf(t)}isBefore(e,t,n){return e.isBefore(t,n)}isAfter(e,t,n){return e.isAfter(t,n)}isSame(e,t,n){return e.isSame(t,n)}set(e,t,n){return t===`day`?e.date(n):e.set(t,n)}get(e,t){return t===`day`?e.date():e.get(t)}format(e,t,n){return n?e.locale(n).format(t):e.format(t)}getDaysInMonth(e){return e.daysInMonth()}toDate(e){return e.toDate()}diff(e,t,n){return e.diff(t,n)}getMonths(e){return e?(0,u.default)().locale(e).localeData().months():u.default.localeData().months()}getWeekdays(e){return e?(0,u.default)().locale(e).localeData().weekdaysShort().map(e=>e.toUpperCase()):u.default.localeData().weekdaysShort().map(e=>e.toUpperCase())}},h=new m;function g(e){return e!==void 0}function _(e,t=0){return g(e)?e:t}function v(e,{onClick:t,dateObj:n,...r}){return{onClick:c.composeEventHandlers(t,t=>{e(n,t)}),disabled:!n.selectable,"aria-label":n.date.toDateString(),"aria-pressed":n.selected,role:`button`,...r}}function y({minDate:e,offsetMonth:t,handleOffsetChanged:n,adapter:r},{onClick:i,offset:a=1,calendars:o,...s}){return{onClick:c.composeEventHandlers(i,()=>{n(t-c.subtractMonth({calendars:o,offset:a,minDate:e,adapter:r}))}),disabled:c.isBackDisabled({calendars:o,minDate:e,adapter:r}),"aria-label":`Go back ${a} month${a===1?``:`s`}`,...s}}function b({maxDate:e,offsetMonth:t,handleOffsetChanged:n,adapter:r},{onClick:i,offset:a=1,calendars:o,...s}){return{onClick:c.composeEventHandlers(i,()=>{n(t+c.addMonth({calendars:o,offset:a,maxDate:e,adapter:r}))}),disabled:c.isForwardDisabled({calendars:o,maxDate:e,adapter:r}),"aria-label":`Go forward ${a} month${a===1?``:`s`}`,...s}}function x({date:e=new Date,maxDate:t,minDate:n,disabledDates:r,monthsToDisplay:i=1,firstDayOfWeek:a=0,showOutsideDays:o=!1,offset:s,onDateSelected:u,onOffsetChanged:d=()=>{},selected:f,modifiers:p,selectionMode:m=`single`,adapter:x=h,onChange:S,onMonthChange:C,onYearChange:w}){let[T,E]=(0,l.useState)(0),[D,O]=(0,l.useState)(void 0),k=_(s,T),A=(0,l.useCallback)(t=>{g(s)||E(t),d(t);let n=x.toDate(x.add(x.startOf(x.date(e),`month`),t,`month`));C?.(n),w?.(n)},[s,d,e,x,C,w]),j=(0,l.useCallback)((e,t)=>{if(u?.(e,t),S){if(m===`single`)S(e.date);else if(m===`multiple`){let t=Array.isArray(f)?f:f?[f]:[];t.some(t=>x.isSame(x.date(t),x.date(e.date),`day`))?S(t.filter(t=>!x.isSame(x.date(t),x.date(e.date),`day`))):S([...t,e.date])}else if(m===`range`){let t=f&&typeof f==`object`&&!(f instanceof Date)&&!Array.isArray(f)?f:{start:void 0,end:void 0};!t.start||t.start&&t.end?S({start:e.date,end:void 0}):x.isBefore(x.date(e.date),x.date(t.start),`day`)?S({start:e.date,end:t.start}):S({start:t.start,end:e.date})}}},[u,S,m,f,x]);return{calendars:c.getCalendars({date:e,selected:f,disabledDates:r,modifiers:p,monthsToDisplay:i,minDate:n,maxDate:t,offset:k,firstDayOfWeek:a,showOutsideDays:o,adapter:x,selectionMode:m,hoveredDate:D}),getDateProps:e=>({...v(j,e),onMouseEnter:c.composeEventHandlers(e.onMouseEnter,()=>{O(e.dateObj.date)}),onMouseLeave:c.composeEventHandlers(e.onMouseLeave,()=>{O(void 0)})}),getBackProps:y.bind(null,{minDate:n,offsetMonth:k,handleOffsetChanged:A,adapter:x}),getForwardProps:b.bind(null,{maxDate:t,offsetMonth:k,handleOffsetChanged:A,adapter:x}),setOffset:A}}Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return x}});
|
|
2
|
+
//# sourceMappingURL=useDates-D9EvVlhK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDates-D9EvVlhK.js","names":[],"sources":["../src/adapters/dayjs.ts","../src/useDates.tsx"],"sourcesContent":["import dayjs from 'dayjs';\nimport type { Dayjs } from 'dayjs';\nimport isBetween from 'dayjs/plugin/isBetween';\nimport customParseFormat from 'dayjs/plugin/customParseFormat';\nimport localeData from 'dayjs/plugin/localeData';\nimport type { DateAdapter } from '../types';\n\ndayjs.extend(isBetween);\ndayjs.extend(customParseFormat);\ndayjs.extend(localeData);\n\nexport class DayjsAdapter implements DateAdapter<Dayjs> {\n date(value?: any): Dayjs {\n return dayjs(value);\n }\n\n add(date: Dayjs, amount: number, unit: 'day' | 'month' | 'year'): Dayjs {\n return date.add(amount, unit);\n }\n\n subtract(date: Dayjs, amount: number, unit: 'day' | 'month' | 'year'): Dayjs {\n return date.subtract(amount, unit);\n }\n\n startOf(date: Dayjs, unit: 'day' | 'month' | 'year'): Dayjs {\n return date.startOf(unit);\n }\n\n endOf(date: Dayjs, unit: 'day' | 'month' | 'year'): Dayjs {\n return date.endOf(unit);\n }\n\n isBefore(date: Dayjs, comparison: Dayjs, unit?: 'day' | 'month' | 'year'): boolean {\n return date.isBefore(comparison, unit);\n }\n\n isAfter(date: Dayjs, comparison: Dayjs, unit?: 'day' | 'month' | 'year'): boolean {\n return date.isAfter(comparison, unit);\n }\n\n isSame(date: Dayjs, comparison: Dayjs, unit?: 'day' | 'month' | 'year'): boolean {\n return date.isSame(comparison, unit);\n }\n\n set(date: Dayjs, unit: 'day' | 'month' | 'year', value: number): Dayjs {\n if (unit === 'day') return date.date(value);\n return date.set(unit, value);\n }\n\n get(date: Dayjs, unit: 'day' | 'month' | 'year'): number {\n if (unit === 'day') return date.date();\n return date.get(unit);\n }\n\n format(date: Dayjs, formatStr: string, locale?: string): string {\n if (locale) {\n return date.locale(locale).format(formatStr);\n }\n return date.format(formatStr);\n }\n\n getDaysInMonth(date: Dayjs): number {\n return date.daysInMonth();\n }\n\n toDate(date: Dayjs): Date {\n return date.toDate();\n }\n\n diff(date: Dayjs, comparison: Dayjs, unit: 'month' | 'year'): number {\n return date.diff(comparison, unit);\n }\n\n getMonths(locale?: string): string[] {\n return locale ? dayjs().locale(locale).localeData().months() : dayjs.localeData().months();\n }\n\n getWeekdays(locale?: string): string[] {\n return locale ? dayjs().locale(locale).localeData().weekdaysShort().map(d => d.toUpperCase()) : dayjs.localeData().weekdaysShort().map(d => d.toUpperCase());\n }\n}\n\nexport const defaultAdapter = new DayjsAdapter();\n","import { useState, useCallback } from 'react';\nimport type { DateAdapter, DateObj, SelectionMode, Calendar } from './types';\nimport { defaultAdapter } from './adapters/dayjs';\nimport {\n addMonth,\n composeEventHandlers,\n getCalendars,\n isBackDisabled,\n isForwardDisabled,\n subtractMonth\n} from './utils';\n\nfunction isOffsetControlled(propOffset?: number) {\n return propOffset !== undefined;\n}\n\nfunction getOffset(prop?: number, state: number = 0): number {\n return isOffsetControlled(prop) ? prop! : state;\n}\n\nfunction getDateProps(\n onDateSelected: (dateObj: DateObj, event: any) => void,\n { onClick, dateObj, ...rest }: { onClick?: (event: any) => void, dateObj: DateObj, [key: string]: any }\n) {\n return {\n onClick: composeEventHandlers(onClick, (event: any) => {\n onDateSelected(dateObj, event);\n }),\n disabled: !dateObj.selectable,\n 'aria-label': dateObj.date.toDateString(),\n 'aria-pressed': dateObj.selected,\n role: 'button',\n ...rest\n };\n}\n\nfunction getBackProps(\n { minDate, offsetMonth, handleOffsetChanged, adapter }: { minDate?: Date, offsetMonth: number, handleOffsetChanged: (newOffset: number) => void, adapter: DateAdapter },\n {\n onClick,\n offset = 1,\n calendars,\n ...rest\n }: { onClick?: (event: any) => void, offset?: number, calendars: Calendar[], [key: string]: any }\n) {\n return {\n onClick: composeEventHandlers(onClick, () => {\n handleOffsetChanged(\n offsetMonth - subtractMonth({ calendars, offset, minDate, adapter })\n );\n }),\n disabled: isBackDisabled({ calendars, minDate, adapter }),\n 'aria-label': `Go back ${offset} month${offset === 1 ? '' : 's'}`,\n ...rest\n };\n}\n\nfunction getForwardProps(\n { maxDate, offsetMonth, handleOffsetChanged, adapter }: { maxDate?: Date, offsetMonth: number, handleOffsetChanged: (newOffset: number) => void, adapter: DateAdapter },\n {\n onClick,\n offset = 1,\n calendars,\n ...rest\n }: { onClick?: (event: any) => void, offset?: number, calendars: Calendar[], [key: string]: any }\n) {\n return {\n onClick: composeEventHandlers(onClick, () => {\n handleOffsetChanged(\n offsetMonth + addMonth({ calendars, offset, maxDate, adapter })\n );\n }),\n disabled: isForwardDisabled({ calendars, maxDate, adapter }),\n 'aria-label': `Go forward ${offset} month${offset === 1 ? '' : 's'}`,\n ...rest\n };\n}\n\nexport interface UseDatesProps {\n date?: Date;\n maxDate?: Date;\n minDate?: Date;\n disabledDates?: Date[];\n monthsToDisplay?: number;\n firstDayOfWeek?: number;\n showOutsideDays?: boolean;\n offset?: number;\n onDateSelected?: (dateObj: DateObj, event: any) => void;\n onOffsetChanged?: (newOffset: number) => void;\n selected?: Date | Date[] | { start?: Date, end?: Date };\n modifiers?: Record<string, (date: Date, month: number, year: number) => boolean>;\n selectionMode?: SelectionMode;\n adapter?: DateAdapter;\n onChange?: (selected: Date | Date[] | { start?: Date, end?: Date } | null) => void;\n onMonthChange?: (date: Date) => void;\n onYearChange?: (date: Date) => void;\n}\n\nexport function useDates({\n date = new Date(),\n maxDate,\n minDate,\n disabledDates,\n monthsToDisplay = 1,\n firstDayOfWeek = 0,\n showOutsideDays = false,\n offset,\n onDateSelected,\n onOffsetChanged = () => { },\n selected,\n modifiers,\n selectionMode = 'single',\n adapter = defaultAdapter,\n onChange,\n onMonthChange,\n onYearChange\n}: UseDatesProps) {\n const [stateOffset, setStateOffset] = useState(0);\n const [hoveredDate, setHoveredDate] = useState<Date | undefined>(undefined);\n const offsetMonth = getOffset(offset, stateOffset);\n\n const handleOffsetChanged = useCallback((newOffset: number) => {\n if (!isOffsetControlled(offset)) {\n setStateOffset(newOffset);\n }\n onOffsetChanged(newOffset);\n\n const newDate = adapter.toDate(adapter.add(adapter.startOf(adapter.date(date), 'month'), newOffset, 'month'));\n onMonthChange?.(newDate);\n onYearChange?.(newDate);\n }, [offset, onOffsetChanged, date, adapter, onMonthChange, onYearChange]);\n\n const handleDateSelected = useCallback((dateObj: DateObj, event: any) => {\n onDateSelected?.(dateObj, event);\n\n if (!onChange) return;\n\n if (selectionMode === 'single') {\n onChange(dateObj.date);\n } else if (selectionMode === 'multiple') {\n const currentSelected = Array.isArray(selected) ? selected : (selected ? [selected as Date] : []);\n const isAlreadySelected = currentSelected.some(d => adapter.isSame(adapter.date(d), adapter.date(dateObj.date), 'day'));\n if (isAlreadySelected) {\n onChange(currentSelected.filter(d => !adapter.isSame(adapter.date(d), adapter.date(dateObj.date), 'day')));\n } else {\n onChange([...currentSelected, dateObj.date]);\n }\n } else if (selectionMode === 'range') {\n const range = (selected && typeof selected === 'object' && !(selected instanceof Date) && !Array.isArray(selected)) ? (selected as { start?: Date, end?: Date }) : { start: undefined, end: undefined };\n if (!range.start || (range.start && range.end)) {\n onChange({ start: dateObj.date, end: undefined });\n } else {\n if (adapter.isBefore(adapter.date(dateObj.date), adapter.date(range.start), 'day')) {\n onChange({ start: dateObj.date, end: range.start });\n } else {\n onChange({ start: range.start, end: dateObj.date });\n }\n }\n }\n }, [onDateSelected, onChange, selectionMode, selected, adapter]);\n\n const calendars = getCalendars({\n date,\n selected,\n disabledDates,\n modifiers,\n monthsToDisplay,\n minDate,\n maxDate,\n offset: offsetMonth,\n firstDayOfWeek,\n showOutsideDays,\n adapter,\n selectionMode,\n hoveredDate\n });\n\n return {\n calendars,\n getDateProps: (args: { onClick?: (event: any) => void, dateObj: DateObj, [key: string]: any }) => {\n const props = getDateProps(handleDateSelected, args);\n return {\n ...props,\n onMouseEnter: composeEventHandlers(args.onMouseEnter, () => {\n setHoveredDate(args.dateObj.date);\n }),\n onMouseLeave: composeEventHandlers(args.onMouseLeave, () => {\n setHoveredDate(undefined);\n })\n };\n },\n getBackProps: getBackProps.bind(null, {\n minDate,\n offsetMonth,\n handleOffsetChanged,\n adapter\n }),\n getForwardProps: getForwardProps.bind(null, {\n maxDate,\n offsetMonth,\n handleOffsetChanged,\n adapter\n }),\n setOffset: handleOffsetChanged\n };\n}\n"],"mappings":"ytBAOA,EAAA,QAAM,OAAO,EAAA,OAAS,EACtB,EAAA,QAAM,OAAO,EAAA,OAAiB,EAC9B,EAAA,QAAM,OAAO,EAAA,OAAU,EAEvB,IAAa,EAAb,KAAwD,CACtD,KAAK,EAAoB,CACvB,OAAA,EAAO,EAAA,QAAA,CAAM,CAAK,CACpB,CAEA,IAAI,EAAa,EAAgB,EAAuC,CACtE,OAAO,EAAK,IAAI,EAAQ,CAAI,CAC9B,CAEA,SAAS,EAAa,EAAgB,EAAuC,CAC3E,OAAO,EAAK,SAAS,EAAQ,CAAI,CACnC,CAEA,QAAQ,EAAa,EAAuC,CAC1D,OAAO,EAAK,QAAQ,CAAI,CAC1B,CAEA,MAAM,EAAa,EAAuC,CACxD,OAAO,EAAK,MAAM,CAAI,CACxB,CAEA,SAAS,EAAa,EAAmB,EAA0C,CACjF,OAAO,EAAK,SAAS,EAAY,CAAI,CACvC,CAEA,QAAQ,EAAa,EAAmB,EAA0C,CAChF,OAAO,EAAK,QAAQ,EAAY,CAAI,CACtC,CAEA,OAAO,EAAa,EAAmB,EAA0C,CAC/E,OAAO,EAAK,OAAO,EAAY,CAAI,CACrC,CAEA,IAAI,EAAa,EAAgC,EAAsB,CAErE,OADI,IAAS,MAAc,EAAK,KAAK,CAAK,EACnC,EAAK,IAAI,EAAM,CAAK,CAC7B,CAEA,IAAI,EAAa,EAAwC,CAEvD,OADI,IAAS,MAAc,EAAK,KAAK,EAC9B,EAAK,IAAI,CAAI,CACtB,CAEA,OAAO,EAAa,EAAmB,EAAyB,CAI9D,OAHI,EACO,EAAK,OAAO,CAAM,CAAC,CAAC,OAA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