UNPKG

taro-ui-vue3

Version:

Taro UI Rewritten in Vue 3.0

83 lines (82 loc) 2.52 kB
import {h, defineComponent, computed} from "vue"; import {Text, View} from "@tarojs/components"; import * as constant from "../../common/constant"; const MAP = { [constant.TYPE_PRE_MONTH]: "pre", [constant.TYPE_NOW_MONTH]: "now", [constant.TYPE_NEXT_MONTH]: "next" }; const AtCalendarList = defineComponent({ name: "AtCalendarList", data: () => ({addGlobalClass: true}), props: { list: { type: Array, default: () => [] }, onClick: Function, onLongClick: Function }, setup(props) { const flexItemClass = computed(() => (item) => ({ flex__item: true, [`flex__item--${MAP[item.type]}`]: true, "flex__item--today": item.isToday, "flex__item--active": item.isActive, "flex__item--selected": item.isSelected, "flex__item--selected-head": item.isSelectedHead, "flex__item--selected-tail": item.isSelectedTail, "flex__item--blur": item.isDisabled || item.type === constant.TYPE_PRE_MONTH || item.type === constant.TYPE_NEXT_MONTH })); function handleClick(item) { var _a; (_a = props.onClick) == null ? void 0 : _a.call(props, item); } function handleLongClick(item) { var _a; (_a = props.onLongClick) == null ? void 0 : _a.call(props, item); } if (!props.list || props.list.length === 0) return null; return () => h(View, { class: "at-calendar__list flex" }, { default: () => props.list.map((item, index) => h(View, { key: `list-item-${item.value}-${index}`, class: flexItemClass.value(item), onTap: handleClick.bind(this, item), onLongpress: handleLongClick.bind(this, item) }, { default: () => [ h(View, { class: "flex__item-container" }, { default: () => [ h(View, { class: "container-text" }, {default: () => item.text}) ] }), h(View, { class: "flex__item-extra extra" }, { default: () => [ item.marks && item.marks.length > 0 && h(View, { class: "extra-marks" }, { default: () => item.marks.map((mark, key) => h(Text, { key, class: "mark" }, {default: () => mark.value})) }) ] }) ] })) }); } }); var date_list_default = AtCalendarList; export { date_list_default as default };