UNPKG

@guruhotel/aura-ui

Version:

⚛️ React UI library by GuruHotel

1 lines 3.24 kB
import e,{useRef as t}from"react";import{useCalendarCell as o}from"@react-aria/calendar";import{isSameDay as i,getDayOfWeek as r,isSameMonth as s}from"@internationalized/date";import{useLocale as a,useDateFormatter as n}from"@react-aria/i18n";import{useFocusRing as l}from"@react-aria/focus";import{mergeProps as d}from"@react-aria/utils";import{DayText as c,HorizontalContainer as m,NumberDayText as h,Td as u,TdContainer as p,TdHorizontal as f,TdText as S}from"./calendar.styles";import{getStylesWithColorScheme as b}from"./utils";import{HorizontalTooltip as g,TooltipWrapper as v}from"./tooltip-wrapper";import{Status as D}from"../status";import{DOT_CSS as x}from"./calendar.constants";import{useCalendarProps as y}from"./calendar-props.provider";import{decreaseResponsiveValue as $,increaseResponsiveValue as F}from"./utils";import{jsx as V}from"react/jsx-runtime";import{jsxs as R}from"react/jsx-runtime";export function CalendarCell({state:e,date:n,currentMonth:c,numberOfDays:m}){const{rounded:h,colorScheme:f,tooltip:g,dateUnavailableStyle:$}=y(),F=t(null),{cellProps:E,buttonProps:P,isSelected:C,isDisabled:w,formattedDate:z}=o({date:n},e,F),j=e.isCellUnavailable(n)&&!w,I=!s(c,n),U=e.highlightedRange?i(n,e.highlightedRange.start):C,Z=e.highlightedRange?i(n,e.highlightedRange.end):C,{locale:k}=a(),L=r(n,k),M=C&&(U||0===L||1===n.day)&&void 0!==h,O=C&&(Z||6===L||n.day===n.calendar.getDaysInMonth(n))&&void 0!==h,T=C&&Z&&!j,W=C&&U&&!j,{focusProps:B,isFocusVisible:H}=l(),N=b({isRoundedLeft:M,isSelected:C,colorScheme:f,isSelectionStart:U,isSelectionEnd:Z,isFocusVisible:H,isUnavailable:j,isDisabled:w}),q=()=>{if("dot"===$){if(j)return V(D,{colorScheme:"red",css:{...x}});if(!(C||H||w))return V(D,{css:{...x}})}return null};return V(u,{...E,isCell:!0,isFocusVisible:H,children:V(p,{...d(P,B),ref:F,hidden:I,isRoundedLeft:M?h:void 0,isRoundedRight:O?h:void 0,isDisabled:w,css:{bg:N.containerBg},children:V(v,{hoverEndSelection:T,hoverStartSelection:W,numberOfDays:m,tooltip:g,children:R(S,{isSelected:C,isDisabled:w,isFocusVisible:H,isSelectionStart:U,isSelectionEnd:Z,isUnavailable:j,containDot:"dot"===$,rounded:h,css:{boxShadow:N.boxShadowFocusVisible,...N.stylesWhenIsSelectionStart,...N.stylesWhenIsSelectionEnd,...N.compoundVariantsForSelectionStart,...N.compoundVariantsForSelectionEnd,...N.hoverElementThatIsNotSelection,...N.hoverStartSelection,...N.hoverEndSelection},children:[z,V(q,{})]})})})})}export function CalendarHorizontalCell(e){const{size:i,colorScheme:r,rounded:s}=y(),a=$(i,"fontSize"),u=F(i,"fontSize"),p=t(null),{cellProps:S,buttonProps:b,isDisabled:v,isSelected:D}=o(e,e.state,p),x=n({day:"2-digit",weekday:"short",month:"long",timeZone:e.state.timeZone,calendar:e.date.calendar.identifier}),E=x.formatToParts(e.date.toDate(e.state.timeZone)),{focusProps:P,isFocusVisible:C}=l();return V(g,{extendedDate:x.format(e.date.toDate(e.state.timeZone)),children:V(f,{...S,children:R(m,{isDisabled:v,colorScheme:r,rounded:s,isFocusVisible:C,...d(b,P),ref:p,css:{color:C?`$${r}9`:void 0,background:D?`$${r}3`:void 0,boxShadow:D?`0 0 0 2px $colors$${r}9`:void 0},children:[V(c,{as:"span",css:{...a},children:E[0].value}),V(h,{as:"span",isSelected:D,css:{color:D?`$${r}9`:"$text11",...u},children:E[2].value})]})})})}