ActionBarButton.mjs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { createVNode as _createVNode } from "vue";
  2. import { computed, defineComponent } from "vue";
  3. import { extend, createNamespace } from "../utils/index.mjs";
  4. import { ACTION_BAR_KEY } from "../action-bar/ActionBar.mjs";
  5. import { useParent } from "@vant/use";
  6. import { useExpose } from "../composables/use-expose.mjs";
  7. import { useRoute, routeProps } from "../composables/use-route.mjs";
  8. import { Button } from "../button/index.mjs";
  9. const [name, bem] = createNamespace("action-bar-button");
  10. const actionBarButtonProps = extend({}, routeProps, {
  11. type: String,
  12. text: String,
  13. icon: String,
  14. color: String,
  15. loading: Boolean,
  16. disabled: Boolean
  17. });
  18. var stdin_default = defineComponent({
  19. name,
  20. props: actionBarButtonProps,
  21. setup(props, {
  22. slots
  23. }) {
  24. const route = useRoute();
  25. const {
  26. parent,
  27. index
  28. } = useParent(ACTION_BAR_KEY);
  29. const isFirst = computed(() => {
  30. if (parent) {
  31. const prev = parent.children[index.value - 1];
  32. return !(prev && "isButton" in prev);
  33. }
  34. });
  35. const isLast = computed(() => {
  36. if (parent) {
  37. const next = parent.children[index.value + 1];
  38. return !(next && "isButton" in next);
  39. }
  40. });
  41. useExpose({
  42. isButton: true
  43. });
  44. return () => {
  45. const {
  46. type,
  47. icon,
  48. text,
  49. color,
  50. loading,
  51. disabled
  52. } = props;
  53. return _createVNode(Button, {
  54. "class": bem([type, {
  55. last: isLast.value,
  56. first: isFirst.value
  57. }]),
  58. "size": "large",
  59. "type": type,
  60. "icon": icon,
  61. "color": color,
  62. "loading": loading,
  63. "disabled": disabled,
  64. "onClick": route
  65. }, {
  66. default: () => [slots.default ? slots.default() : text]
  67. });
  68. };
  69. }
  70. });
  71. export {
  72. stdin_default as default
  73. };