Skip to content

Commit

Permalink
feat: customIcon support slot
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjinzhou committed Jan 30, 2021
1 parent 3b9992d commit e53a0f6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/icons-vue/examples/custom-icon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const PandaSvg = (_, { attrs }) => (
);

const HeartIcon = (_, { attrs }) => {
return <Icon component={HeartSvg} {...attrs} />;
return <Icon {...attrs} v-slots={{ component: HeartSvg }} />;
};

const PandaIcon = (_, { attrs }) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/icons-vue/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ant-design/icons-vue",
"version": "6.0.0",
"version": "6.0.1",
"main": "./lib/index.js",
"module": "./es/index.js",
"sideEffects": false,
Expand Down
9 changes: 8 additions & 1 deletion packages/icons-vue/src/components/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ const Icon: IconType = (props, context) => {
} = { ...props, ...attrs } as any;
const children = slots.default && slots.default();
const hasChildren = children && children.length;
warning(Boolean(Component || hasChildren), 'Should have `component` prop or `children`.');
const slotsComponent = slots.component;
warning(
Boolean(Component || hasChildren || slotsComponent),
'Should have `component` prop/slot or `children`.',
);

useInsertStyles();

Expand Down Expand Up @@ -67,6 +71,9 @@ const Icon: IconType = (props, context) => {
if (Component) {
return <Component {...innerSvgProps}>{children}</Component>;
}
if (slotsComponent) {
return slotsComponent(innerSvgProps);
}
if (hasChildren) {
warning(
Boolean(viewBox) || (children.length === 1 && children[0] && children[0].type === 'use'),
Expand Down

0 comments on commit e53a0f6

Please sign in to comment.