mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(ActionBarIcon): add badge-props prop (#10096)
This commit is contained in:
parent
b792ddfc16
commit
7596024ddf
@ -1,4 +1,4 @@
|
|||||||
import { defineComponent, type ExtractPropTypes } from 'vue';
|
import { defineComponent, type PropType, type ExtractPropTypes } from 'vue';
|
||||||
import { extend, createNamespace, unknownProp, numericProp } from '../utils';
|
import { extend, createNamespace, unknownProp, numericProp } from '../utils';
|
||||||
import { ACTION_BAR_KEY } from '../action-bar/ActionBar';
|
import { ACTION_BAR_KEY } from '../action-bar/ActionBar';
|
||||||
|
|
||||||
@ -8,7 +8,7 @@ import { useRoute, routeProps } from '../composables/use-route';
|
|||||||
|
|
||||||
// Components
|
// Components
|
||||||
import { Icon } from '../icon';
|
import { Icon } from '../icon';
|
||||||
import { Badge } from '../badge';
|
import { Badge, type BadgeProps } from '../badge';
|
||||||
|
|
||||||
const [name, bem] = createNamespace('action-bar-icon');
|
const [name, bem] = createNamespace('action-bar-icon');
|
||||||
|
|
||||||
@ -19,6 +19,7 @@ const actionBarIconProps = extend({}, routeProps, {
|
|||||||
color: String,
|
color: String,
|
||||||
badge: numericProp,
|
badge: numericProp,
|
||||||
iconClass: unknownProp,
|
iconClass: unknownProp,
|
||||||
|
badgeProps: Object as PropType<Partial<BadgeProps>>,
|
||||||
iconPrefix: String,
|
iconPrefix: String,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -35,15 +36,17 @@ export default defineComponent({
|
|||||||
useParent(ACTION_BAR_KEY);
|
useParent(ACTION_BAR_KEY);
|
||||||
|
|
||||||
const renderIcon = () => {
|
const renderIcon = () => {
|
||||||
const { dot, badge, icon, color, iconClass, iconPrefix } = props;
|
const { dot, badge, icon, color, iconClass, badgeProps, iconPrefix } =
|
||||||
|
props;
|
||||||
|
|
||||||
if (slots.icon) {
|
if (slots.icon) {
|
||||||
return (
|
return (
|
||||||
<Badge
|
<Badge
|
||||||
v-slots={{ default: slots.icon }}
|
v-slots={{ default: slots.icon }}
|
||||||
dot={dot}
|
dot={dot}
|
||||||
content={badge}
|
|
||||||
class={bem('icon')}
|
class={bem('icon')}
|
||||||
|
content={badge}
|
||||||
|
{...badgeProps}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -56,6 +59,7 @@ export default defineComponent({
|
|||||||
badge={badge}
|
badge={badge}
|
||||||
color={color}
|
color={color}
|
||||||
class={[bem('icon'), iconClass]}
|
class={[bem('icon'), iconClass]}
|
||||||
|
badgeProps={badgeProps}
|
||||||
classPrefix={iconPrefix}
|
classPrefix={iconPrefix}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
@ -59,3 +59,17 @@ test('should render icon slot with dot correctly', () => {
|
|||||||
|
|
||||||
expect(wrapper.html()).toMatchSnapshot();
|
expect(wrapper.html()).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should render badge-props prop correctly', async () => {
|
||||||
|
const wrapper = mount(ActionBarIcon, {
|
||||||
|
props: {
|
||||||
|
badge: 1,
|
||||||
|
badgeProps: {
|
||||||
|
color: 'blue',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const badge = wrapper.find('.van-badge');
|
||||||
|
expect(badge.style.backgroundColor).toEqual('blue');
|
||||||
|
});
|
||||||
|
@ -102,7 +102,8 @@ Use `badge` prop to show badge in icon.
|
|||||||
| icon-prefix `v3.0.17` | Icon className prefix | _string_ | `van-icon` |
|
| icon-prefix `v3.0.17` | Icon className prefix | _string_ | `van-icon` |
|
||||||
| dot | Whether to show red dot | _boolean_ | - |
|
| dot | Whether to show red dot | _boolean_ | - |
|
||||||
| badge | Content of the badge | _number \| string_ | - |
|
| badge | Content of the badge | _number \| string_ | - |
|
||||||
| url | Link | _string_ | - |
|
| badge-props `v3.2.8` | Props of Badge,see [Badge - props](#/en-US/badge#props) | _BadgeProps_ | - |
|
||||||
|
| url | Link URL | _string_ | - |
|
||||||
| to | Target route of the link, same as to of vue-router | _string \| object_ | - |
|
| to | Target route of the link, same as to of vue-router | _string \| object_ | - |
|
||||||
| replace | If true, the navigation will not leave a history record | _boolean_ | `false` |
|
| replace | If true, the navigation will not leave a history record | _boolean_ | `false` |
|
||||||
|
|
||||||
|
@ -106,6 +106,7 @@ export default {
|
|||||||
| icon-prefix `v3.0.17` | 图标类名前缀,等同于 Icon 组件的 [class-prefix 属性](#/zh-CN/icon#props) | _string_ | `van-icon` |
|
| icon-prefix `v3.0.17` | 图标类名前缀,等同于 Icon 组件的 [class-prefix 属性](#/zh-CN/icon#props) | _string_ | `van-icon` |
|
||||||
| dot | 是否显示图标右上角小红点 | _boolean_ | `false` |
|
| dot | 是否显示图标右上角小红点 | _boolean_ | `false` |
|
||||||
| badge | 图标右上角徽标的内容 | _number \| string_ | - |
|
| badge | 图标右上角徽标的内容 | _number \| string_ | - |
|
||||||
|
| badge-props `v3.2.8` | 自定义徽标的属性,传入的对象会被透传给 [Badge 组件的 props](#/zh-CN/badge#props) | _BadgeProps_ | - |
|
||||||
| url | 点击后跳转的链接地址 | _string_ | - |
|
| url | 点击后跳转的链接地址 | _string_ | - |
|
||||||
| to | 点击后跳转的目标路由对象,等同于 vue-router 的 [to 属性](https://router.vuejs.org/zh/api/#to) | _string \| object_ | - |
|
| to | 点击后跳转的目标路由对象,等同于 vue-router 的 [to 属性](https://router.vuejs.org/zh/api/#to) | _string \| object_ | - |
|
||||||
| replace | 是否在跳转时替换当前页面历史 | _boolean_ | `false` |
|
| replace | 是否在跳转时替换当前页面历史 | _boolean_ | `false` |
|
||||||
|
Loading…
x
Reference in New Issue
Block a user