Skip to content

Commit 6c4e285

Browse files
committed
refactor: update props define
1 parent f617d6b commit 6c4e285

File tree

1 file changed

+22
-30
lines changed

1 file changed

+22
-30
lines changed

components/avatar/Avatar.tsx

+22-30
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { tuple, VueNode } from '../_util/type';
22
import {
33
CSSProperties,
44
defineComponent,
5+
ExtractPropTypes,
56
inject,
67
nextTick,
78
onMounted,
@@ -14,19 +15,28 @@ import { defaultConfigProvider } from '../config-provider';
1415
import { getPropsSlot } from '../_util/props-util';
1516
import PropTypes from '../_util/vue-types';
1617

17-
export interface AvatarProps {
18-
prefixCls?: string;
19-
shape?: 'circle' | 'square';
20-
size?: 'large' | 'small' | 'default' | number;
21-
src?: string;
22-
srcset?: string;
23-
icon?: typeof PropTypes.VNodeChild;
24-
alt?: string;
25-
loadError?: () => boolean;
26-
}
27-
28-
const Avatar = defineComponent<AvatarProps>({
18+
const avatarProps = {
19+
prefixCls: PropTypes.string,
20+
shape: PropTypes.oneOf(tuple('circle', 'square')),
21+
size: {
22+
type: [Number, String] as PropType<'large' | 'small' | 'default' | number>,
23+
default: 'default',
24+
},
25+
src: PropTypes.string,
26+
/** Srcset of image avatar */
27+
srcset: PropTypes.string,
28+
icon: PropTypes.VNodeChild,
29+
alt: PropTypes.string,
30+
loadError: {
31+
type: Function as PropType<() => boolean>,
32+
},
33+
};
34+
35+
export type AvatarProps = Partial<ExtractPropTypes<typeof avatarProps>>;
36+
37+
const Avatar = defineComponent({
2938
name: 'AAvatar',
39+
props: avatarProps,
3040
setup(props, { slots }) {
3141
const isImgExist = ref(true);
3242
const isMounted = ref(false);
@@ -73,7 +83,6 @@ const Avatar = defineComponent<AvatarProps>({
7383
nextTick(() => {
7484
isImgExist.value = true;
7585
scale.value = 1;
76-
// this.$forceUpdate();
7786
});
7887
},
7988
);
@@ -163,21 +172,4 @@ const Avatar = defineComponent<AvatarProps>({
163172
},
164173
});
165174

166-
Avatar.props = {
167-
prefixCls: PropTypes.string,
168-
shape: PropTypes.oneOf(tuple('circle', 'square')),
169-
size: {
170-
type: [Number, String] as PropType<'large' | 'small' | 'default' | number>,
171-
default: 'default',
172-
},
173-
src: PropTypes.string,
174-
/** Srcset of image avatar */
175-
srcset: PropTypes.string,
176-
icon: PropTypes.VNodeChild,
177-
alt: PropTypes.string,
178-
loadError: {
179-
type: Function as PropType<() => boolean>,
180-
},
181-
};
182-
183175
export default Avatar;

0 commit comments

Comments
 (0)