[new feature] GoodsActionIcon: add icon slot (#3705)

This commit is contained in:
neverland
2019-07-01 14:55:18 +08:00
committed by GitHub
parent a7b4b4c219
commit bb43ff270d
5 changed files with 63 additions and 8 deletions
+16 -8
View File
@@ -5,7 +5,7 @@ import { functionalRoute, routeProps, RouteProps } from '../utils/router';
// Types
import { CreateElement, RenderContext } from 'vue/types';
import { DefaultSlots } from '../utils/types';
import { DefaultSlots, ScopedSlot } from '../utils/types';
export type GoodsActionIconProps = RouteProps & {
icon: string;
@@ -14,12 +14,16 @@ export type GoodsActionIconProps = RouteProps & {
iconClass?: any;
};
export type GoodsActionIconSlots = DefaultSlots & {
icon?: ScopedSlot;
};
const [createComponent, bem] = createNamespace('goods-action-icon');
function GoodsActionIcon(
h: CreateElement,
props: GoodsActionIconProps,
slots: DefaultSlots,
slots: GoodsActionIconSlots,
ctx: RenderContext<GoodsActionIconProps>
) {
function onClick(event: Event) {
@@ -35,12 +39,16 @@ function GoodsActionIcon(
onClick={onClick}
{...inherit(ctx)}
>
<Icon
class={[bem('icon'), props.iconClass]}
tag="div"
info={props.info}
name={props.icon}
/>
{slots.icon ? (
<div class={bem('icon')}>{slots.icon()}</div>
) : (
<Icon
class={[bem('icon'), props.iconClass]}
tag="div"
info={props.info}
name={props.icon}
/>
)}
{slots.default ? slots.default() : props.text}
</div>
);