UNPKG

vant

Version:

Mobile UI Components built on Vue

77 lines (76 loc) 2.01 kB
import { defineComponent, mergeProps as _mergeProps, createVNode as _createVNode } from "vue"; import { extend, createNamespace, unknownProp, numericProp } from "../utils/index.mjs"; import { ACTION_BAR_KEY } from "../action-bar/ActionBar.mjs"; import { useParent } from "@vant/use"; import { useRoute, routeProps } from "../composables/use-route.mjs"; import { Icon } from "../icon/index.mjs"; import { Badge } from "../badge/index.mjs"; const [name, bem] = createNamespace("action-bar-icon"); const actionBarIconProps = extend({}, routeProps, { dot: Boolean, text: String, icon: String, color: String, badge: numericProp, iconClass: unknownProp, badgeProps: Object, iconPrefix: String, disabled: Boolean }); var stdin_default = defineComponent({ name, props: actionBarIconProps, setup(props, { slots }) { const route = useRoute(); useParent(ACTION_BAR_KEY); const renderIcon = () => { const { dot, badge, icon, color, iconClass, badgeProps, iconPrefix } = props; if (slots.icon) { return _createVNode(Badge, _mergeProps({ "dot": dot, "class": bem("icon"), "content": badge }, badgeProps), { default: slots.icon }); } return _createVNode(Icon, { "tag": "div", "dot": dot, "name": icon, "badge": badge, "color": color, "class": [bem("icon"), iconClass], "badgeProps": badgeProps, "classPrefix": iconPrefix }, null); }; const onClick = () => { if (!props.disabled) { route(); } }; return () => _createVNode("div", { "role": "button", "class": bem({ disabled: props.disabled }), "tabindex": props.disabled ? -1 : 0, "onClick": onClick }, [renderIcon(), slots.default ? slots.default() : props.text]); } }); export { actionBarIconProps, stdin_default as default };