UNPKG

dtd

Version:

根据数梦工场视觉规范打造的组件库,感谢react-components和ant design

1 lines 3.18 kB
import*as React from"react";import createReactClass from"create-react-class";import*as PropTypes from"prop-types";import cx from"classnames";import DateConstants from"./DateConstants";import{getTitleString,getTodayTime}from"../util/";function isSameDay(e,a){return e&&a&&e.isSame(a,"day")}function beforeCurrentMonthYear(e,a){return e.year()<a.year()?1:e.year()===a.year()&&e.month()<a.month()}function afterCurrentMonthYear(e,a){return e.year()>a.year()?1:e.year()===a.year()&&e.month()>a.month()}function getIdFromDate(e){return"rc-calendar-"+e.year()+"-"+e.month()+"-"+e.date()}var DateTBody=createReactClass({displayName:"DateTBody",propTypes:{contentRender:PropTypes.func,dateRender:PropTypes.func,disabledDate:PropTypes.func,prefixCls:PropTypes.string,selectedValue:PropTypes.oneOfType([PropTypes.object,PropTypes.arrayOf(PropTypes.object)]),value:PropTypes.object,hoverValue:PropTypes.any,showWeekNumber:PropTypes.bool},getDefaultProps:function(){return{hoverValue:[]}},render:function(){var e=this.props,a=e.contentRender,t=e.prefixCls,r=e.selectedValue,o=e.value,n=e.showWeekNumber,s=e.dateRender,l=e.disabledDate,d=e.hoverValue,c=void 0,i=void 0,y=void 0,p=[],m=getTodayTime(o),u=t+"-cell",f=t+"-week-number-cell",T=t+"-date",v=t+"-today",D=t+"-selected-day",C=t+"-selected-date",h=t+"-selected-start-date",b=t+"-selected-end-date",g=t+"-in-range-cell",k=t+"-last-month-cell",R=t+"-next-month-btn-day",N=t+"-disabled-cell",O=t+"-disabled-cell-first-of-row",P=t+"-disabled-cell-last-of-row",w=t+"-weekend-cell",E=o.clone();E.date(1);var S=(E.day()+7-o.localeData().firstDayOfWeek())%7,_=E.clone();_.add(0-S,"days");var A=0;for(c=0;c<DateConstants.DATE_ROW_COUNT;c++)for(i=0;i<DateConstants.DATE_COL_COUNT;i++)y=_,A&&(y=y.clone()).add(A,"days"),p.push(y),A++;var x=[];for(A=0,c=0;c<DateConstants.DATE_ROW_COUNT;c++){var M=void 0,U=void 0,V=void 0,W=!1,B=[];for(n&&(V=React.createElement("td",{key:p[A].week(),role:"gridcell",className:f},p[A].week())),i=0;i<DateConstants.DATE_COL_COUNT;i++){var Y=null,j=null;y=p[A],i<DateConstants.DATE_COL_COUNT-1&&(Y=p[A+1]),i>0&&(j=p[A-1]);var L=u,F=!1,H=!1;isSameDay(y,m)&&(L+=" "+v,U=!0);var I=beforeCurrentMonthYear(y,o),q=afterCurrentMonthYear(y,o);if(r&&Array.isArray(r)){var z=d.length?d:r;if(!I&&!q){var G=z[0],J=z[1];G&&isSameDay(y,G)&&(H=!0,W=!0,L+=" "+h),G&&J&&(isSameDay(y,J)?(H=!0,W=!0,L+=" "+b):y.isAfter(G,"day")&&y.isBefore(J,"day")&&(L+=" "+g))}}else isSameDay(y,o)&&(H=!0,W=!0);isSameDay(y,r)&&(L+=" "+C),I&&(L+=" "+k),q&&(L+=" "+R),l&&l(y,o)&&(F=!0,j&&l(j,o)||(L+=" "+O),Y&&l(Y,o)||(L+=" "+P)),H&&(L+=" "+D),F&&(L+=" "+N);var K=void 0;if(s)K=s(y,o);else{var Q=a?a(y,o):y.date();K=React.createElement("div",{key:getIdFromDate(y),className:T,"aria-selected":H,"aria-disabled":F},Q)}B.push(React.createElement("td",{key:A,onClick:F?void 0:e.onSelect.bind(null,y),onMouseEnter:F?void 0:e.onDayHover&&e.onDayHover.bind(null,y)||void 0,role:"gridcell",title:getTitleString(y),className:cx(L,i>4?w:null)},K)),A++}x.push(React.createElement("tr",{key:c,role:"row",className:cx((M={},M[t+"-current-week"]=U,M[t+"-active-week"]=W,M))},V,B))}return React.createElement("tbody",{className:t+"-tbody"},x)}});export default DateTBody;