CalendarDay.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. var __defProp = Object.defineProperty;
  2. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  3. var __getOwnPropNames = Object.getOwnPropertyNames;
  4. var __hasOwnProp = Object.prototype.hasOwnProperty;
  5. var __export = (target, all) => {
  6. for (var name2 in all)
  7. __defProp(target, name2, { get: all[name2], enumerable: true });
  8. };
  9. var __copyProps = (to, from, except, desc) => {
  10. if (from && typeof from === "object" || typeof from === "function") {
  11. for (let key of __getOwnPropNames(from))
  12. if (!__hasOwnProp.call(to, key) && key !== except)
  13. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  14. }
  15. return to;
  16. };
  17. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  18. var stdin_exports = {};
  19. __export(stdin_exports, {
  20. default: () => stdin_default
  21. });
  22. module.exports = __toCommonJS(stdin_exports);
  23. var import_vue = require("vue");
  24. var import_utils = require("../utils");
  25. var import_utils2 = require("./utils");
  26. const [name] = (0, import_utils.createNamespace)("calendar-day");
  27. var stdin_default = (0, import_vue.defineComponent)({
  28. name,
  29. props: {
  30. item: (0, import_utils.makeRequiredProp)(Object),
  31. color: String,
  32. index: Number,
  33. offset: (0, import_utils.makeNumberProp)(0),
  34. rowHeight: String
  35. },
  36. emits: ["click", "clickDisabledDate"],
  37. setup(props, {
  38. emit,
  39. slots
  40. }) {
  41. const style = (0, import_vue.computed)(() => {
  42. var _a;
  43. const {
  44. item,
  45. index,
  46. color,
  47. offset,
  48. rowHeight
  49. } = props;
  50. const style2 = {
  51. height: rowHeight
  52. };
  53. if (item.type === "placeholder") {
  54. style2.width = "100%";
  55. return style2;
  56. }
  57. if (index === 0) {
  58. style2.marginLeft = `${100 * offset / 7}%`;
  59. }
  60. if (color) {
  61. switch (item.type) {
  62. case "end":
  63. case "start":
  64. case "start-end":
  65. case "multiple-middle":
  66. case "multiple-selected":
  67. style2.background = color;
  68. break;
  69. case "middle":
  70. style2.color = color;
  71. break;
  72. }
  73. }
  74. if (offset + (((_a = item.date) == null ? void 0 : _a.getDate()) || 1) > 28) {
  75. style2.marginBottom = 0;
  76. }
  77. return style2;
  78. });
  79. const onClick = () => {
  80. if (props.item.type !== "disabled") {
  81. emit("click", props.item);
  82. } else {
  83. emit("clickDisabledDate", props.item);
  84. }
  85. };
  86. const renderTopInfo = () => {
  87. const {
  88. topInfo
  89. } = props.item;
  90. if (topInfo || slots["top-info"]) {
  91. return (0, import_vue.createVNode)("div", {
  92. "class": (0, import_utils2.bem)("top-info")
  93. }, [slots["top-info"] ? slots["top-info"](props.item) : topInfo]);
  94. }
  95. };
  96. const renderBottomInfo = () => {
  97. const {
  98. bottomInfo
  99. } = props.item;
  100. if (bottomInfo || slots["bottom-info"]) {
  101. return (0, import_vue.createVNode)("div", {
  102. "class": (0, import_utils2.bem)("bottom-info")
  103. }, [slots["bottom-info"] ? slots["bottom-info"](props.item) : bottomInfo]);
  104. }
  105. };
  106. const renderText = () => {
  107. return slots.text ? slots.text(props.item) : props.item.text;
  108. };
  109. const renderContent = () => {
  110. const {
  111. item,
  112. color,
  113. rowHeight
  114. } = props;
  115. const {
  116. type
  117. } = item;
  118. const Nodes = [renderTopInfo(), renderText(), renderBottomInfo()];
  119. if (type === "selected") {
  120. return (0, import_vue.createVNode)("div", {
  121. "class": (0, import_utils2.bem)("selected-day"),
  122. "style": {
  123. width: rowHeight,
  124. height: rowHeight,
  125. background: color
  126. }
  127. }, [Nodes]);
  128. }
  129. return Nodes;
  130. };
  131. return () => {
  132. const {
  133. type,
  134. className
  135. } = props.item;
  136. if (type === "placeholder") {
  137. return (0, import_vue.createVNode)("div", {
  138. "class": (0, import_utils2.bem)("day"),
  139. "style": style.value
  140. }, null);
  141. }
  142. return (0, import_vue.createVNode)("div", {
  143. "role": "gridcell",
  144. "style": style.value,
  145. "class": [(0, import_utils2.bem)("day", type), className],
  146. "tabindex": type === "disabled" ? void 0 : -1,
  147. "onClick": onClick
  148. }, [renderContent()]);
  149. };
  150. }
  151. });