ActionBarButton.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. actionBarButtonProps: () => actionBarButtonProps,
  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_ActionBar = require("../action-bar/ActionBar");
  28. var import_use = require("@vant/use");
  29. var import_use_expose = require("../composables/use-expose");
  30. var import_use_route = require("../composables/use-route");
  31. var import_button = require("../button");
  32. const [name, bem] = (0, import_utils.createNamespace)("action-bar-button");
  33. const actionBarButtonProps = (0, import_utils.extend)({}, import_use_route.routeProps, {
  34. type: String,
  35. text: String,
  36. icon: String,
  37. color: String,
  38. loading: Boolean,
  39. disabled: Boolean
  40. });
  41. var stdin_default = (0, import_vue2.defineComponent)({
  42. name,
  43. props: actionBarButtonProps,
  44. setup(props, {
  45. slots
  46. }) {
  47. const route = (0, import_use_route.useRoute)();
  48. const {
  49. parent,
  50. index
  51. } = (0, import_use.useParent)(import_ActionBar.ACTION_BAR_KEY);
  52. const isFirst = (0, import_vue2.computed)(() => {
  53. if (parent) {
  54. const prev = parent.children[index.value - 1];
  55. return !(prev && "isButton" in prev);
  56. }
  57. });
  58. const isLast = (0, import_vue2.computed)(() => {
  59. if (parent) {
  60. const next = parent.children[index.value + 1];
  61. return !(next && "isButton" in next);
  62. }
  63. });
  64. (0, import_use_expose.useExpose)({
  65. isButton: true
  66. });
  67. return () => {
  68. const {
  69. type,
  70. icon,
  71. text,
  72. color,
  73. loading,
  74. disabled
  75. } = props;
  76. return (0, import_vue.createVNode)(import_button.Button, {
  77. "class": bem([type, {
  78. last: isLast.value,
  79. first: isFirst.value
  80. }]),
  81. "size": "large",
  82. "type": type,
  83. "icon": icon,
  84. "color": color,
  85. "loading": loading,
  86. "disabled": disabled,
  87. "onClick": route
  88. }, {
  89. default: () => [slots.default ? slots.default() : text]
  90. });
  91. };
  92. }
  93. });