ActionBarIcon.mjs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { createVNode as _createVNode, mergeProps as _mergeProps } from "vue";
  2. import { defineComponent } from "vue";
  3. import { extend, createNamespace, unknownProp, numericProp } from "../utils/index.mjs";
  4. import { ACTION_BAR_KEY } from "../action-bar/ActionBar.mjs";
  5. import { useParent } from "@vant/use";
  6. import { useRoute, routeProps } from "../composables/use-route.mjs";
  7. import { Icon } from "../icon/index.mjs";
  8. import { Badge } from "../badge/index.mjs";
  9. const [name, bem] = createNamespace("action-bar-icon");
  10. const actionBarIconProps = extend({}, routeProps, {
  11. dot: Boolean,
  12. text: String,
  13. icon: String,
  14. color: String,
  15. badge: numericProp,
  16. iconClass: unknownProp,
  17. badgeProps: Object,
  18. iconPrefix: String
  19. });
  20. var stdin_default = defineComponent({
  21. name,
  22. props: actionBarIconProps,
  23. setup(props, {
  24. slots
  25. }) {
  26. const route = useRoute();
  27. useParent(ACTION_BAR_KEY);
  28. const renderIcon = () => {
  29. const {
  30. dot,
  31. badge,
  32. icon,
  33. color,
  34. iconClass,
  35. badgeProps,
  36. iconPrefix
  37. } = props;
  38. if (slots.icon) {
  39. return _createVNode(Badge, _mergeProps({
  40. "dot": dot,
  41. "class": bem("icon"),
  42. "content": badge
  43. }, badgeProps), {
  44. default: slots.icon
  45. });
  46. }
  47. return _createVNode(Icon, {
  48. "tag": "div",
  49. "dot": dot,
  50. "name": icon,
  51. "badge": badge,
  52. "color": color,
  53. "class": [bem("icon"), iconClass],
  54. "badgeProps": badgeProps,
  55. "classPrefix": iconPrefix
  56. }, null);
  57. };
  58. return () => _createVNode("div", {
  59. "role": "button",
  60. "class": bem(),
  61. "tabindex": 0,
  62. "onClick": route
  63. }, [renderIcon(), slots.default ? slots.default() : props.text]);
  64. }
  65. });
  66. export {
  67. stdin_default as default
  68. };