hongluan-ui
Version:
Hongluan Component Library for Vue 3
91 lines (88 loc) • 3.78 kB
JavaScript
import { defineComponent, openBlock, createElementBlock, unref, normalizeClass, withModifiers, createElementVNode, toDisplayString, createCommentVNode, Fragment, renderList, createVNode } from 'vue';
import { basicDateTableProps, basicDateTableEmits } from '../props/basic-date-table.mjs';
import { useBasicDateTable, useBasicDateTableDOM } from '../composables/use-basic-date-table.mjs';
import HlDatePickerCell from './basic-cell-render.mjs';
const _sfc_main = /* @__PURE__ */ defineComponent({
props: basicDateTableProps,
emits: basicDateTableEmits,
setup(__props, { expose, emit }) {
const props = __props;
const {
WEEKS,
rows,
tbodyRef,
currentCellRef,
focus,
isCurrent,
isWeekActive,
isSelectedCell,
handlePickDate,
handleMouseUp,
handleMouseDown,
handleMouseMove,
handleFocus
} = useBasicDateTable(props, emit);
const { getCellClasses, t } = useBasicDateTableDOM(props, {
isCurrent,
isWeekActive
});
expose({
focus
});
return (_ctx, _cache) => {
return openBlock(), createElementBlock("table", {
role: "grid",
"aria-label": unref(t)("hl.datepicker.dateTablePrompt"),
cellspacing: "0",
cellpadding: "0",
class: normalizeClass(["picker-table", { "is-week-mode": _ctx.selectionMode === "week" }]),
onClick: unref(handlePickDate),
onMousemove: unref(handleMouseMove),
onMousedown: withModifiers(unref(handleMouseDown), ["prevent"]),
onMouseup: unref(handleMouseUp)
}, [
createElementVNode("tbody", {
ref_key: "tbodyRef",
ref: tbodyRef
}, [
createElementVNode("tr", null, [
_ctx.showWeekNumber ? (openBlock(), createElementBlock("th", {
key: 0,
scope: "col"
}, toDisplayString(unref(t)("hl.datepicker.week")), 1)) : createCommentVNode("v-if", true),
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(WEEKS), (week, key) => {
return openBlock(), createElementBlock("th", {
key,
scope: "col",
"aria-label": unref(t)("hl.datepicker.weeksFull." + week)
}, toDisplayString(unref(t)("hl.datepicker.weeks." + week)), 9, ["aria-label"]);
}), 128))
]),
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(rows), (row, rowKey) => {
return openBlock(), createElementBlock("tr", {
key: rowKey,
class: normalizeClass(["table-row", { current: unref(isWeekActive)(row[1]) }])
}, [
(openBlock(true), createElementBlock(Fragment, null, renderList(row, (cell, columnKey) => {
return openBlock(), createElementBlock("td", {
key: `${rowKey}.${columnKey}`,
ref_for: true,
ref: (el) => unref(isSelectedCell)(cell) && (currentCellRef.value = el),
class: normalizeClass(unref(getCellClasses)(cell)),
"aria-current": cell.isCurrent ? "date" : void 0,
"aria-selected": cell.isCurrent,
tabindex: unref(isSelectedCell)(cell) ? 0 : -1,
onFocus: unref(handleFocus)
}, [
createVNode(unref(HlDatePickerCell), { cell }, null, 8, ["cell"])
], 42, ["aria-current", "aria-selected", "tabindex", "onFocus"]);
}), 128))
], 2);
}), 128))
], 512)
], 42, ["aria-label", "onClick", "onMousemove", "onMousedown", "onMouseup"]);
};
}
});
export { _sfc_main as default };
//# sourceMappingURL=basic-date-table.mjs.map