Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: color should be svg property #498

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/icons-react/src/components/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ export interface CustomIconComponentProps {
fill: string;
viewBox?: string;
className?: string;
color?: string
style?: React.CSSProperties;
}

export interface IconComponentProps extends IconBaseProps {
viewBox?: string;
component?: React.ComponentType<CustomIconComponentProps | React.SVGProps<SVGSVGElement>> | React.ForwardRefExoticComponent<CustomIconComponentProps>;
Expand All @@ -30,6 +32,7 @@ const Icon = React.forwardRef<HTMLSpanElement, IconComponentProps>((props, ref)

// affect inner <svg>...</svg>
component: Component,
color,
viewBox,
spin,
rotate,
Expand Down Expand Up @@ -69,6 +72,7 @@ const Icon = React.forwardRef<HTMLSpanElement, IconComponentProps>((props, ref)

const innerSvgProps: CustomIconComponentProps = {
...svgBaseProps,
color,
className: svgClassString,
style: svgStyle,
viewBox,
Expand Down
1 change: 1 addition & 0 deletions packages/icons-react/src/components/IconBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface IconProps {
icon: IconDefinition;
className?: string;
onClick?: React.MouseEventHandler<SVGSVGElement>;
color?: string;
style?: React.CSSProperties;
primaryColor?: string; // only for two-tone
secondaryColor?: string; // only for two-tone
Expand Down
1 change: 1 addition & 0 deletions packages/icons-react/tests/Icon.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('React AntdIcon Component', () => {
style: {
fontSize: '3rem',
},
color: 'red',
className: 'my-icon',
extraProps: { hello: 'world' },
} as any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`React AntdIcon Component should create SVG element. 1`] = `
<IconReact
className="my-icon"
color="red"
extraProps={
Object {
"hello": "world",
Expand Down
18 changes: 18 additions & 0 deletions packages/icons-react/tests/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,24 @@ exports[`Icon.createFromIconfontCN() should support iconfont.cn 1`] = `
/>
</svg>
</span>
<span
class="anticon abc"
role="img"
>
<svg
aria-hidden="true"
class=""
color="blue"
fill="currentColor"
focusable="false"
height="1em"
width="1em"
>
<use
href="#icon-twitter"
/>
</svg>
</span>
</div>
`;

Expand Down
1 change: 1 addition & 0 deletions packages/icons-react/tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ describe('Icon.createFromIconfontCN()', () => {
<IconFont type="icon-tuichu" />
<IconFont type="icon-facebook" />
<IconFont type="icon-twitter" />
<IconFont type="icon-twitter" color="blue" />
</div>,
);
expect(wrapper).toMatchSnapshot();
Expand Down