ActionBarButton.mjs 1.8 KB

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