ActionSheet.js 5.0 KB

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