index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. exports.__esModule = true;
  4. exports.default = void 0;
  5. var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  6. var _babelHelperVueJsxMergeProps = _interopRequireDefault(require("@vue/babel-helper-vue-jsx-merge-props"));
  7. var _vue = _interopRequireDefault(require("vue"));
  8. var _utils = require("../utils");
  9. var _functional = require("../utils/functional");
  10. var _popup = require("../mixins/popup");
  11. var _icon = _interopRequireDefault(require("../icon"));
  12. var _popup2 = _interopRequireDefault(require("../popup"));
  13. var _loading = _interopRequireDefault(require("../loading"));
  14. // Utils
  15. // Mixins
  16. // Components
  17. var _createNamespace = (0, _utils.createNamespace)('action-sheet'),
  18. createComponent = _createNamespace[0],
  19. bem = _createNamespace[1];
  20. function ActionSheet(h, props, slots, ctx) {
  21. var title = props.title,
  22. cancelText = props.cancelText,
  23. closeable = props.closeable;
  24. function onCancel() {
  25. (0, _functional.emit)(ctx, 'input', false);
  26. (0, _functional.emit)(ctx, 'cancel');
  27. }
  28. function Header() {
  29. if (title) {
  30. return h("div", {
  31. "class": bem('header')
  32. }, [title, closeable && h(_icon.default, {
  33. "attrs": {
  34. "name": props.closeIcon
  35. },
  36. "class": bem('close'),
  37. "on": {
  38. "click": onCancel
  39. }
  40. })]);
  41. }
  42. }
  43. function Option(item, index) {
  44. var disabled = item.disabled,
  45. loading = item.loading,
  46. callback = item.callback;
  47. function onClickOption(event) {
  48. event.stopPropagation();
  49. if (disabled || loading) {
  50. return;
  51. }
  52. if (callback) {
  53. callback(item);
  54. }
  55. if (props.closeOnClickAction) {
  56. (0, _functional.emit)(ctx, 'input', false);
  57. }
  58. _vue.default.nextTick(function () {
  59. (0, _functional.emit)(ctx, 'select', item, index);
  60. });
  61. }
  62. function OptionContent() {
  63. if (loading) {
  64. return h(_loading.default, {
  65. "class": bem('loading-icon')
  66. });
  67. }
  68. return [h("span", {
  69. "class": bem('name')
  70. }, [item.name]), item.subname && h("div", {
  71. "class": bem('subname')
  72. }, [item.subname])];
  73. }
  74. return h("button", {
  75. "attrs": {
  76. "type": "button"
  77. },
  78. "class": [bem('item', {
  79. disabled: disabled,
  80. loading: loading
  81. }), item.className],
  82. "style": {
  83. color: item.color
  84. },
  85. "on": {
  86. "click": onClickOption
  87. }
  88. }, [OptionContent()]);
  89. }
  90. function CancelText() {
  91. if (cancelText) {
  92. return [h("div", {
  93. "class": bem('gap')
  94. }), h("button", {
  95. "attrs": {
  96. "type": "button"
  97. },
  98. "class": bem('cancel'),
  99. "on": {
  100. "click": onCancel
  101. }
  102. }, [cancelText])];
  103. }
  104. }
  105. function Description() {
  106. var description = (slots.description == null ? void 0 : slots.description()) || props.description;
  107. if (description) {
  108. return h("div", {
  109. "class": bem('description')
  110. }, [description]);
  111. }
  112. }
  113. return h(_popup2.default, (0, _babelHelperVueJsxMergeProps.default)([{
  114. "class": bem(),
  115. "attrs": {
  116. "position": "bottom",
  117. "round": props.round,
  118. "value": props.value,
  119. "overlay": props.overlay,
  120. "duration": props.duration,
  121. "lazyRender": props.lazyRender,
  122. "lockScroll": props.lockScroll,
  123. "getContainer": props.getContainer,
  124. "closeOnPopstate": props.closeOnPopstate,
  125. "closeOnClickOverlay": props.closeOnClickOverlay,
  126. "safeAreaInsetBottom": props.safeAreaInsetBottom
  127. }
  128. }, (0, _functional.inherit)(ctx, true)]), [Header(), Description(), h("div", {
  129. "class": bem('content')
  130. }, [props.actions && props.actions.map(Option), slots.default == null ? void 0 : slots.default()]), CancelText()]);
  131. }
  132. ActionSheet.props = (0, _extends2.default)({}, _popup.popupMixinProps, {
  133. title: String,
  134. actions: Array,
  135. duration: [Number, String],
  136. cancelText: String,
  137. description: String,
  138. getContainer: [String, Function],
  139. closeOnPopstate: Boolean,
  140. closeOnClickAction: Boolean,
  141. round: {
  142. type: Boolean,
  143. default: true
  144. },
  145. closeable: {
  146. type: Boolean,
  147. default: true
  148. },
  149. closeIcon: {
  150. type: String,
  151. default: 'cross'
  152. },
  153. safeAreaInsetBottom: {
  154. type: Boolean,
  155. default: true
  156. },
  157. overlay: {
  158. type: Boolean,
  159. default: true
  160. },
  161. closeOnClickOverlay: {
  162. type: Boolean,
  163. default: true
  164. }
  165. });
  166. var _default = createComponent(ActionSheet);
  167. exports.default = _default;