Skip to content

Commit 94c85a0

Browse files
committed
refactor: remove icon dependency
1 parent 4084548 commit 94c85a0

File tree

7 files changed

+168
-56
lines changed

7 files changed

+168
-56
lines changed

packages/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@
6363
},
6464
"dependencies": {
6565
"@popperjs/core": "^2.11.4",
66-
"@tiny-design/icons": "workspace:*",
6766
"@tiny-design/tokens": "workspace:*",
6867
"classnames": "^2.3.1",
6968
"tslib": "^2.3.1"
7069
},
7170
"devDependencies": {
7271
"@testing-library/jest-dom": "^6.0.0",
72+
"@tiny-design/icons": "workspace:*",
7373
"@testing-library/react": "^14.0.0",
7474
"@types/jest": "^29.0.0",
7575
"@types/react": "^18.2.0",

packages/react/src/_utils/components.tsx

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
import React from 'react';
1+
import React, { forwardRef, type SVGAttributes } from 'react';
22

33
type IconProps = {
44
className?: string;
55
style?: React.CSSProperties;
66
size?: number | string;
77
color?: string;
88
};
9+
10+
/** Props compatible with @tiny-design/icons IconProps */
11+
export interface SvgIconProps extends SVGAttributes<SVGSVGElement> {
12+
size?: string | number;
13+
color?: string;
14+
}
915
export const ArrowDown = (props: IconProps): React.ReactElement => {
1016
const { size = 20, color = 'currentcolor', ...otherProps } = props;
1117
return (
@@ -198,3 +204,45 @@ export const TreeArrow = (props: IconProps): React.ReactElement => {
198204
</svg>
199205
);
200206
};
207+
208+
export const LeftIcon = forwardRef<SVGSVGElement, SvgIconProps>((props, ref) => {
209+
const { size = '1em', color = 'currentColor', className, style, ...rest } = props;
210+
return (
211+
<svg
212+
ref={ref}
213+
viewBox="0 0 1024 1024"
214+
width={size}
215+
height={size}
216+
fill={color}
217+
className={className}
218+
style={{ verticalAlign: 'middle', ...style }}
219+
{...rest}
220+
>
221+
<g transform="translate(0, 896) scale(1, -1)">
222+
<path d="M724 677.7V755c0 6.7-7.7 10.4-12.9 6.3L260.3 409.2c-16.4-12.8-16.4-37.5 0-50.3l450.8-352.1c5.3-4.1 12.9-0.4 12.9 6.3v77.3c0 4.9-2.3 9.6-6.1 12.6l-360 281 360 281.1c3.8 3 6.1 7.7 6.1 12.6z" />
223+
</g>
224+
</svg>
225+
);
226+
});
227+
LeftIcon.displayName = 'LeftIcon';
228+
229+
export const StarFillIcon = forwardRef<SVGSVGElement, SvgIconProps>((props, ref) => {
230+
const { size = '1em', color = 'currentColor', className, style, ...rest } = props;
231+
return (
232+
<svg
233+
ref={ref}
234+
viewBox="0 0 1024 1024"
235+
width={size}
236+
height={size}
237+
fill={color}
238+
className={className}
239+
style={{ verticalAlign: 'middle', ...style }}
240+
{...rest}
241+
>
242+
<g transform="translate(0, 896) scale(1, -1)">
243+
<path d="M908.1 542.9l-253.9 36.9L540.7 809.9c-3.1 6.3-8.2 11.4-14.5 14.5-15.8 7.8-35 1.3-42.9-14.5L369.8 579.8l-253.9-36.9c-7-1-13.4-4.3-18.3-9.3-12.3-12.7-12.1-32.9 0.6-45.3l183.7-179.1-43.4-252.9c-1.2-6.9-0.1-14.1 3.2-20.3 8.2-15.6 27.6-21.7 43.2-13.4L512 142l227.1-119.4c6.2-3.3 13.4-4.4 20.3-3.2 17.4 3 29.1 19.5 26.1 36.9l-43.4 252.9 183.7 179.1c5 4.9 8.3 11.3 9.3 18.3 2.7 17.5-9.5 33.7-27 36.3z" />
244+
</g>
245+
</svg>
246+
);
247+
});
248+
StarFillIcon.displayName = 'StarFillIcon';

packages/react/src/layout/sidebar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { useState, useContext, useEffect } from 'react';
33
import classNames from 'classnames';
4-
import { IconLeft } from '@tiny-design/icons';
4+
import { LeftIcon } from '../_utils/components';
55
import { SidebarContext } from './sidebar-context';
66
import { ConfigContext } from '../config-provider/config-context';
77
import { getPrefixCls } from '../_utils/general';
@@ -63,7 +63,7 @@ const Sidebar = React.forwardRef<HTMLDivElement, SidebarProps>(
6363

6464
return (
6565
<button type="button" className={`${prefixCls}__trigger`} onClick={_collapseBtnOnClick} aria-label="Toggle sidebar">
66-
<IconLeft className={`${prefixCls}__trigger-icon`} />
66+
<LeftIcon className={`${prefixCls}__trigger-icon`} />
6767
</button>
6868
);
6969
};

packages/react/src/rate/rate.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState, useEffect, useContext } from 'react';
22
import classNames from 'classnames';
3-
import { IconStarFill } from '@tiny-design/icons';
3+
import { StarFillIcon } from '../_utils/components';
44
import { ConfigContext } from '../config-provider/config-context';
55
import { getPrefixCls } from '../_utils/general';
66
import { RateProps } from './types';
@@ -10,7 +10,7 @@ const Rate = React.forwardRef<HTMLUListElement, RateProps>(
1010
(props: RateProps, ref): JSX.Element => {
1111
const {
1212
color = '#FADB14',
13-
character = <IconStarFill size={20} />,
13+
character = <StarFillIcon size={20} />,
1414
clearable = true,
1515
half = false,
1616
count = 5,

packages/react/src/with-spin/__tests__/with-spin.test.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,33 @@
11
import React, { createRef } from 'react';
22
import { render } from '@testing-library/react';
3-
import { IconClose } from '@tiny-design/icons';
3+
import { Close } from '../../_utils/components';
44
import { withSpin } from '../with-spin';
5+
import { forwardRef } from 'react';
6+
import type { SvgIconProps } from '../../_utils/components';
7+
8+
// Wrap the simple Close component to make it forwardRef-compatible
9+
const CloseIcon = forwardRef<SVGSVGElement, SvgIconProps>((props, ref) => {
10+
const { size, color, className, style, ...rest } = props;
11+
return (
12+
<svg
13+
ref={ref}
14+
viewBox="0 0 1024 1024"
15+
width={size ?? '1em'}
16+
height={size ?? '1em'}
17+
fill={color ?? 'currentColor'}
18+
className={className}
19+
style={style}
20+
{...rest}
21+
>
22+
<path d="M782.426059 824.924989l-584.588225-584.727395c-11.987009-11.990079-11.984962-31.42778 0.005116-43.414789 11.990079-11.987009 31.42778-11.984962 43.414789 0.005117l584.588225 584.727395c11.987009 11.990079 11.984962 31.42778-0.005116 43.414788-11.989055 11.988032-31.42778 11.984962-43.414789-0.005116z" />
23+
<path d="M197.768249 824.856427c-11.987009-11.990079-11.984962-31.42778 0.005117-43.414788l584.727394-584.589249c11.990079-11.987009 31.42778-11.984962 43.414789 0.005117 11.987009 11.990079 11.984962 31.42778-0.005116 43.414788l-584.727395 584.589249c-11.990079 11.987009-31.42778 11.984962-43.414789-0.005117z" />
24+
</svg>
25+
);
26+
});
27+
CloseIcon.displayName = 'CloseIcon';
528

629
describe('withSpin HOC', () => {
7-
const SpinClose = withSpin(IconClose);
30+
const SpinClose = withSpin(CloseIcon);
831

932
it('applies ty-icon-spin CSS class', () => {
1033
const { container } = render(<SpinClose />);
@@ -33,6 +56,6 @@ describe('withSpin HOC', () => {
3356
});
3457

3558
it('sets displayName', () => {
36-
expect(SpinClose.displayName).toBe('withSpin(IconClose)');
59+
expect(SpinClose.displayName).toBe('withSpin(CloseIcon)');
3760
});
3861
});

packages/react/src/with-spin/with-spin.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { forwardRef, type ForwardRefExoticComponent, type RefAttributes } from 'react';
2-
import type { IconProps } from '@tiny-design/icons';
2+
import type { SvgIconProps } from '../_utils/components';
33
import classNames from 'classnames';
44

5-
type IconComponent = ForwardRefExoticComponent<IconProps & RefAttributes<SVGSVGElement>>;
5+
type IconComponent = ForwardRefExoticComponent<SvgIconProps & RefAttributes<SVGSVGElement>>;
66

77
export function withSpin(Icon: IconComponent): IconComponent {
8-
const SpinIcon = forwardRef<SVGSVGElement, IconProps>((props, ref) => {
8+
const SpinIcon = forwardRef<SVGSVGElement, SvgIconProps>((props, ref) => {
99
const { className, ...rest } = props;
1010

1111
return (

0 commit comments

Comments
 (0)