UNPKG

@gsretail.com/gui-core

Version:

A skeleton to create your own React component library using Rollup, TypeScript, Sass and Storybook

2 lines (1 loc) 6.12 kB
import e from"../../../@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.js";import a from"../../../@babel/runtime/helpers/esm/extends.js";import*as o from"react";import n from"../../../prop-types/index.js";import{clsx as t}from"../../../clsx/dist/clsx.m.js";import{styled as i,useThemeProps as s}from"@mui/material/styles";import{unstable_composeClasses as r}from"@mui/material";import{unstable_useId as l,useControlled as d,useEventCallback as u}from"@mui/material/utils";import{MonthPicker as c}from"../MonthPicker/MonthPicker.js";import{useCalendarState as m}from"./useCalendarState.js";import{useUtils as h,useDefaultDates as f}from"../internals/hooks/useUtils.js";import{PickersFadeTransitionGroup as b}from"./PickersFadeTransitionGroup.js";import{DayPicker as D}from"./DayPicker.js";import{useViews as g}from"../internals/hooks/useViews.js";import{PickersCalendarHeader as p}from"./PickersCalendarHeader.js";import{YearPicker as w}from"../YearPicker/YearPicker.js";import{parseNonNullablePickerDate as C,findClosestEnabledDate as y}from"../internals/utils/date-utils.js";import{defaultReduceAnimations as F}from"../internals/utils/defaultReduceAnimations.js";import{getCalendarPickerUtilityClass as M}from"./calendarPickerClasses.js";import{jsx as P,jsxs as V}from"react/jsx-runtime";import{PickerViewRoot as x}from"../internals/components/PickerViewRoot/PickerViewRoot.js";const j=["autoFocus","onViewChange","date","disableFuture","disablePast","defaultCalendarMonth","onChange","onYearChange","onMonthChange","reduceAnimations","shouldDisableDate","shouldDisableMonth","shouldDisableYear","view","views","openTo","className","disabled","readOnly","minDate","maxDate","disableHighlightToday","focusedView","onFocusedViewChange","classes"];const k=i(x,{name:"MuiCalendarPicker",slot:"Root",overridesResolver:(e,a)=>a.root})({display:"flex",flexDirection:"column"}),v=i(b,{name:"MuiCalendarPicker",slot:"ViewTransitionContainer",overridesResolver:(e,a)=>a.viewTransitionContainer})({}),T=o.forwardRef((function(n,i){const b=h(),x=l(),T=function(e,o){const n=h(),t=f(),i=s({props:e,name:o});return a({loading:!1,disablePast:!1,disableFuture:!1,openTo:"day",views:["year","day"],reduceAnimations:F,renderLoading:()=>P("span",{children:"..."})},i,{minDate:C(n,i.minDate,t.minDate),maxDate:C(n,i.maxDate,t.maxDate)})}(n,"MuiCalendarPicker"),{autoFocus:O,onViewChange:A,date:Y,disableFuture:R,disablePast:N,defaultCalendarMonth:S,onChange:E,onYearChange:B,onMonthChange:H,reduceAnimations:L,shouldDisableDate:q,shouldDisableMonth:I,shouldDisableYear:W,view:G,views:K,openTo:U,className:$,disabled:_,readOnly:z,minDate:J,maxDate:Q,disableHighlightToday:X,focusedView:Z,onFocusedViewChange:ee}=T,ae=e(T,j),{openView:oe,setOpenView:ne,openNext:te}=g({view:G,views:K,openTo:U,onChange:E,onViewChange:A}),{calendarState:ie,changeFocusedDay:se,changeMonth:re,handleChangeMonth:le,isDateDisabled:de,onMonthSwitchingAnimationEnd:ue}=m({date:Y,defaultCalendarMonth:S,reduceAnimations:L,onMonthChange:H,minDate:J,maxDate:Q,shouldDisableDate:q,disablePast:N,disableFuture:R}),ce=o.useCallback(((e,a)=>{const o=b.startOfMonth(e),n=b.endOfMonth(e),t=de(e)?y({utils:b,date:e,minDate:b.isBefore(J,o)?o:J,maxDate:b.isAfter(Q,n)?n:Q,disablePast:N,disableFuture:R,isDateDisabled:de}):e;t?(E(t,a),null==H||H(o)):(te(),re(o)),se(t,!0)}),[se,R,N,de,Q,J,E,H,re,te,b]),me=o.useCallback(((e,a)=>{const o=b.startOfYear(e),n=b.endOfYear(e),t=de(e)?y({utils:b,date:e,minDate:b.isBefore(J,o)?o:J,maxDate:b.isAfter(Q,n)?n:Q,disablePast:N,disableFuture:R,isDateDisabled:de}):e;t?(E(t,a),null==B||B(t)):(te(),re(o)),se(t,!0)}),[se,R,N,de,Q,J,E,B,te,b,re]),he=o.useCallback(((e,a)=>E(Y&&e?b.mergeDateAndTime(e,Y):e,a)),[b,Y,E]);o.useEffect((()=>{Y&&re(Y)}),[Y]);const fe=T,be=(e=>{const{classes:a}=e;return r({root:["root"],viewTransitionContainer:["viewTransitionContainer"]},M,a)})(fe),De={disablePast:N,disableFuture:R,maxDate:Q,minDate:J},ge=_&&Y||J,pe=_&&Y||Q,we={disableHighlightToday:X,readOnly:z,disabled:_},Ce=`${x}-grid-label`,[ye,Fe]=d({name:"DayPicker",state:"focusedView",controlled:Z,default:O?oe:null}),Me=null!==ye,Pe=u((e=>a=>{ee?ee(e)(a):Fe(a?e:a=>a===e?null:a)})),Ve=o.useRef(oe);return o.useEffect((()=>{Ve.current!==oe&&(Ve.current=oe,Pe(oe)(!0))}),[oe,Pe]),V(k,{ref:i,className:t(be.root,$),ownerState:fe,children:[P(p,a({},ae,{views:K,openView:oe,currentMonth:ie.currentMonth,onViewChange:ne,onMonthChange:(e,a)=>le({newMonth:e,direction:a}),minDate:ge,maxDate:pe,disabled:_,disablePast:N,disableFuture:R,reduceAnimations:L,labelId:Ce})),P(v,{reduceAnimations:L,className:be.viewTransitionContainer,transKey:oe,ownerState:fe,children:V("div",{children:["year"===oe&&P(w,a({},ae,De,we,{autoFocus:O,date:Y,onChange:me,shouldDisableYear:W,hasFocus:Me,onFocusedViewChange:Pe("year")})),"month"===oe&&P(c,a({},De,we,{autoFocus:O,hasFocus:Me,className:$,date:Y,onChange:ce,shouldDisableMonth:I,onFocusedViewChange:Pe("month")})),"day"===oe&&P(D,a({},ae,ie,De,we,{autoFocus:O,onMonthSwitchingAnimationEnd:ue,onFocusedDayChange:se,reduceAnimations:L,selectedDays:[Y],onSelectedDaysChange:he,shouldDisableDate:q,hasFocus:Me,onFocusedViewChange:Pe("day"),gridLabelId:Ce}))]})})]})}));"production"!==process.env.NODE_ENV&&(T.propTypes={autoFocus:n.bool,classes:n.object,className:n.string,components:n.object,componentsProps:n.object,date:n.any,dayOfWeekFormatter:n.func,defaultCalendarMonth:n.any,disabled:n.bool,disableFuture:n.bool,disableHighlightToday:n.bool,disablePast:n.bool,focusedView:n.oneOf(["day","month","year"]),getViewSwitchingButtonText:n.func,leftArrowButtonText:n.string,loading:n.bool,maxDate:n.any,minDate:n.any,onChange:n.func.isRequired,onFocusedViewChange:n.func,onMonthChange:n.func,onViewChange:n.func,onYearChange:n.func,openTo:n.oneOf(["day","month","year"]),readOnly:n.bool,reduceAnimations:n.bool,renderDay:n.func,renderLoading:n.func,rightArrowButtonText:n.string,shouldDisableDate:n.func,shouldDisableMonth:n.func,shouldDisableYear:n.func,showDaysOutsideCurrentMonth:n.bool,view:n.oneOf(["day","month","year"]),views:n.arrayOf(n.oneOf(["day","month","year"]).isRequired)});export{T as CalendarPicker};