ActionSheet.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. actionSheetProps: () => actionSheetProps,
  21. default: () => stdin_default
  22. });
  23. module.exports = __toCommonJS(stdin_exports);
  24. var import_vue = require("vue");
  25. var import_vue2 = require("vue");
  26. var import_utils = require("../utils");
  27. var import_icon = require("../icon");
  28. var import_popup = require("../popup");
  29. var import_loading = require("../loading");
  30. var import_shared = require("../popup/shared");
  31. const [name, bem] = (0, import_utils.createNamespace)("action-sheet");
  32. const actionSheetProps = (0, import_utils.extend)({}, import_shared.popupSharedProps, {
  33. title: String,
  34. round: import_utils.truthProp,
  35. actions: (0, import_utils.makeArrayProp)(),
  36. closeIcon: (0, import_utils.makeStringProp)("cross"),
  37. closeable: import_utils.truthProp,
  38. cancelText: String,
  39. description: String,
  40. closeOnPopstate: import_utils.truthProp,
  41. closeOnClickAction: Boolean,
  42. safeAreaInsetBottom: import_utils.truthProp
  43. });
  44. const popupInheritKeys = [...import_shared.popupSharedPropKeys, "round", "closeOnPopstate", "safeAreaInsetBottom"];
  45. var stdin_default = (0, import_vue2.defineComponent)({
  46. name,
  47. props: actionSheetProps,
  48. emits: ["select", "cancel", "update:show"],
  49. setup(props, {
  50. slots,
  51. emit
  52. }) {
  53. const updateShow = (show) => emit("update:show", show);
  54. const onCancel = () => {
  55. updateShow(false);
  56. emit("cancel");
  57. };
  58. const renderHeader = () => {
  59. if (props.title) {
  60. return (0, import_vue.createVNode)("div", {
  61. "class": bem("header")
  62. }, [props.title, props.closeable && (0, import_vue.createVNode)(import_icon.Icon, {
  63. "name": props.closeIcon,
  64. "class": [bem("close"), import_utils.HAPTICS_FEEDBACK],
  65. "onClick": onCancel
  66. }, null)]);
  67. }
  68. };
  69. const renderCancel = () => {
  70. if (slots.cancel || props.cancelText) {
  71. return [(0, import_vue.createVNode)("div", {
  72. "class": bem("gap")
  73. }, null), (0, import_vue.createVNode)("button", {
  74. "type": "button",
  75. "class": bem("cancel"),
  76. "onClick": onCancel
  77. }, [slots.cancel ? slots.cancel() : props.cancelText])];
  78. }
  79. };
  80. const renderActionContent = (action, index) => {
  81. if (action.loading) {
  82. return (0, import_vue.createVNode)(import_loading.Loading, {
  83. "class": bem("loading-icon")
  84. }, null);
  85. }
  86. if (slots.action) {
  87. return slots.action({
  88. action,
  89. index
  90. });
  91. }
  92. return [(0, import_vue.createVNode)("span", {
  93. "class": bem("name")
  94. }, [action.name]), action.subname && (0, import_vue.createVNode)("div", {
  95. "class": bem("subname")
  96. }, [action.subname])];
  97. };
  98. const renderAction = (action, index) => {
  99. const {
  100. color,
  101. loading,
  102. callback,
  103. disabled,
  104. className
  105. } = action;
  106. const onClick = () => {
  107. if (disabled || loading) {
  108. return;
  109. }
  110. if (callback) {
  111. callback(action);
  112. }
  113. if (props.closeOnClickAction) {
  114. updateShow(false);
  115. }
  116. (0, import_vue2.nextTick)(() => emit("select", action, index));
  117. };
  118. return (0, import_vue.createVNode)("button", {
  119. "type": "button",
  120. "style": {
  121. color
  122. },
  123. "class": [bem("item", {
  124. loading,
  125. disabled
  126. }), className],
  127. "onClick": onClick
  128. }, [renderActionContent(action, index)]);
  129. };
  130. const renderDescription = () => {
  131. if (props.description || slots.description) {
  132. const content = slots.description ? slots.description() : props.description;
  133. return (0, import_vue.createVNode)("div", {
  134. "class": bem("description")
  135. }, [content]);
  136. }
  137. };
  138. return () => (0, import_vue.createVNode)(import_popup.Popup, (0, import_vue.mergeProps)({
  139. "class": bem(),
  140. "position": "bottom",
  141. "onUpdate:show": updateShow
  142. }, (0, import_utils.pick)(props, popupInheritKeys)), {
  143. default: () => {
  144. var _a;
  145. return [renderHeader(), renderDescription(), (0, import_vue.createVNode)("div", {
  146. "class": bem("content")
  147. }, [props.actions.map(renderAction), (_a = slots.default) == null ? void 0 : _a.call(slots)]), renderCancel()];
  148. }
  149. });
  150. }
  151. });