UNPKG

@guruhotel/aura-ui

Version:

⚛️ React UI library by GuruHotel

1 lines 2.87 kB
import o from"react";import{useDateFormatter as e}from"@react-aria/i18n";import{CheckSolid as r,ChevronDownRegular as t,ChevronUpRegular as c}from"../icons";import{SelectIcon as n,SelectItem as l,SelectItemIndicator as a,SelectViewport as i,Select as d,SelectItemText as s,SelectValue as m,SelectContent as h,SelectScrollUpButton as u,SelectScrollDownButton as f,SelectTrigger as $}from"../select";import{Box as b}from"../box";import{capitalizeFirstLetter as p}from"./utils";import{useCalendarProps as S}from"./calendar-props.provider";import{increaseResponsiveValue as x}from"./utils";import{jsx as D}from"react/jsx-runtime";import{jsxs as v}from"react/jsx-runtime";export const MonthSelector=({state:o})=>{const{monthDateFormat:{month:g},rounded:z,colorScheme:Z,size:j}=S(),w=[],C=e({month:g,timeZone:o.timeZone}),F=o.focusedDate.calendar.getMonthsInYear(o.focusedDate);for(let e=1;e<=F;e++){const r=o.focusedDate.set({month:e});w.push(p(C.format(r.toDate(o.timeZone))))}const y=x(j,"fontSize");return v(d,{onValueChange:e=>{const r=Number(e),t=o.focusedDate.set({month:r});o.setFocusedDate(t)},value:o.focusedDate.month.toString(),size:j,children:[v($,{"aria-label":"Month",rounded:z,colorScheme:Z,css:{boxShadow:"none",fontWeight:700,color:`$${Z}12`,"&:hover":{backgroundColor:`$${Z}4`},"&:focus":{boxShadow:`0 0 0 2px $colors$${Z}12`},...y},children:[D(m,{}),D(n,{children:D(b,{css:{mb:"$1"},children:D(t,{label:"",color:"currentcolor"})})})]}),v(h,{rounded:z,colorScheme:Z,children:[D(u,{children:D(c,{label:"",color:"currentcolor"})}),D(i,{children:w.map(((o,e)=>v(l,{value:(e+1).toString(),children:[D(s,{children:o}),D(a,{children:D(r,{label:"",color:"currentcolor"})})]},`${o}-${e}`)))}),D(f,{children:D(t,{label:"",color:"currentcolor"})})]})]})};export const YearSelector=({state:o})=>{const{monthDateFormat:{year:p},rounded:g,colorScheme:z,size:Z}=S(),j=[],w=e({year:p,timeZone:o.timeZone});for(let e=-10;e<=10;e++){const r=o.focusedDate.add({years:e});j.push({value:r,formatted:w.format(r.toDate(o.timeZone))})}const C=x(Z,"fontSize");return v(d,{onValueChange:e=>{var r;const t=Number(e),c=null==(r=j[t])?void 0:r.value;c&&o.setFocusedDate(c)},value:"10",size:Z,children:[v($,{"aria-label":"Year",rounded:g,colorScheme:z,css:{boxShadow:"none",fontWeight:700,color:`$${z}12`,"&:hover":{backgroundColor:`$${z}4`},"&:focus":{boxShadow:`0 0 0 2px $colors$${z}12`},...C},children:[D(m,{}),D(n,{children:D(b,{css:{mb:"$1"},children:D(t,{label:"",color:"currentcolor"})})})]}),v(h,{rounded:g,colorScheme:z,children:[D(u,{children:D(c,{label:"",color:"currentcolor"})}),D(i,{children:j.map(((o,e)=>v(l,{value:e.toString(),css:{rounded:g?"$base":"$none",fontSize:"$md",color:`$${z}11`},children:[D(s,{children:o.formatted}),D(a,{children:D(r,{label:"",color:"currentcolor"})})]},`${o.formatted}-${e}`)))}),D(f,{children:D(t,{label:"",color:"currentcolor"})})]})]})};