ActionBarButton.js 2.8 KB

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