index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import _mergeJSXProps from "@vue/babel-helper-vue-jsx-merge-props";
  3. import { use } from '../utils';
  4. import { emit, inherit } from '../utils/functional';
  5. import { PopupMixin } from '../mixins/popup';
  6. import Icon from '../icon';
  7. import Loading from '../loading';
  8. import Popup from '../popup'; // Types
  9. var _use = use('actionsheet'),
  10. sfc = _use[0],
  11. bem = _use[1];
  12. function Actionsheet(h, props, slots, ctx) {
  13. var title = props.title,
  14. cancelText = props.cancelText;
  15. var onCancel = function onCancel() {
  16. emit(ctx, 'input', false);
  17. emit(ctx, 'cancel');
  18. };
  19. var Header = function Header() {
  20. return h("div", {
  21. "class": [bem('header'), 'van-hairline--top-bottom']
  22. }, [title, h(Icon, {
  23. "attrs": {
  24. "name": "close"
  25. },
  26. "class": bem('close'),
  27. "on": {
  28. "click": onCancel
  29. }
  30. })]);
  31. };
  32. var Option = function Option(item, index) {
  33. return h("div", {
  34. "class": [bem('item', {
  35. disabled: item.disabled || item.loading
  36. }), item.className, 'van-hairline--top'],
  37. "on": {
  38. "click": function click(event) {
  39. event.stopPropagation();
  40. if (!item.disabled && !item.loading) {
  41. if (item.callback) {
  42. item.callback(item);
  43. }
  44. emit(ctx, 'select', item, index);
  45. }
  46. }
  47. }
  48. }, [item.loading ? h(Loading, {
  49. "class": bem('loading'),
  50. "attrs": {
  51. "size": "20px"
  52. }
  53. }) : [h("span", {
  54. "class": bem('name')
  55. }, [item.name]), item.subname && h("span", {
  56. "class": bem('subname')
  57. }, [item.subname])]]);
  58. };
  59. return h(Popup, _mergeJSXProps([{
  60. "class": bem({
  61. 'safe-area-inset-bottom': props.safeAreaInsetBottom
  62. }),
  63. "attrs": {
  64. "value": props.value,
  65. "position": "bottom",
  66. "overlay": props.overlay,
  67. "lazyRender": props.lazyRender,
  68. "getContainer": props.getContainer,
  69. "closeOnClickOverlay": props.closeOnClickOverlay
  70. },
  71. "on": {
  72. "input": function input(value) {
  73. emit(ctx, 'input', value);
  74. }
  75. }
  76. }, inherit(ctx)]), [title ? Header() : props.actions.map(Option), slots["default"] && h("div", {
  77. "class": bem('content')
  78. }, [slots["default"]()]), cancelText && h("div", {
  79. "class": bem('cancel'),
  80. "on": {
  81. "click": onCancel
  82. }
  83. }, [cancelText])]);
  84. }
  85. Actionsheet.props = _extends({}, PopupMixin.props, {
  86. title: String,
  87. actions: Array,
  88. cancelText: String,
  89. safeAreaInsetBottom: Boolean,
  90. overlay: {
  91. type: Boolean,
  92. "default": true
  93. },
  94. closeOnClickOverlay: {
  95. type: Boolean,
  96. "default": true
  97. }
  98. });
  99. export default sfc(Actionsheet);