import { State } from '../../types/store' ; import { createElement } from '../../utils/element' ; import { Header } from '../components/header' ; import { Day } from '../components/date&week' ; import { Month , Year } from '../components/month&year' ; import { PickerConfigMap } from '../../types/components' ; import { classNames } from '../../utils/attribute' ; import mixins from '../watch/mixins' ; import { linkMonth } from '../watch/date&week' ; import { LinkYear , watchYM } from '../watch/month&year' ; import { startMonthAndYear } from '../watch/public' ; function rangeComponent ( child ) { const children = [ Header , child ] ; return [ { class : [ 'range-wrapper' ] , children : [ { children , componentType : 'start' , } , { children , componentType : 'end' , } , ] , } , ] ; } const dateAndWeek = [ Header , Day ] ; const pickersMap = { date : { children : dateAndWeek , watch : [ watchYM ( false ) , watchYM ( ) , startMonthAndYear ] , } , 'date-range' : { children : rangeComponent ( Day ) , watch : [ linkMonth ( ) , linkMonth ( 'end' ) ] , } , week : { children : dateAndWeek , watch : [ watchYM ( false ) , watchYM ( ) , startMonthAndYear ] , } , month : { children : [ Header , Month , Year ] , watch : [ watchYM ( ) , watchYM ( false ) ] , } , 'month-range' : { children : rangeComponent ( Month ) , watch : [ watchYM ( ) , LinkYear ( ) , LinkYear ( 'end' ) , watchYM ( true , 'end' ) ] , } , year : { children : [ Header , Year ] , watch : [ watchYM ( false ) ] , } , 'year-range' : { children : rangeComponent ( Year ) , watch : [ watchYM ( false ) , watchYM ( false , 'end' ) , LinkYear ( 'start' , true ) , LinkYear ( 'end' , true ) , ] , } , } ; export function createPicker ( state ) { const { children , watch } = pickersMap [ state . type ] ; state . popover = createElement ( { class : classNames ( 'wrapper' ) , children , hidden : true , style : { display : 'inline-block' , position : 'absolute' , zIndex : state . zIndex , } , watch : mixins . concat ( watch ) , } , state ) as HTMLElement ; }