Skip to content

Commit f075f0b

Browse files
feat: Line support semantic structure
1 parent 090325f commit f075f0b

2 files changed

Lines changed: 36 additions & 5 deletions

File tree

‎src/Line.tsx‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const Line: React.FC<ProgressProps> = (props) => {
1919
railWidth,
2020
transition,
2121
loading,
22+
classNames = {},
23+
styles = {},
2224
...restProps
2325
} = {
2426
...defaultProps,
@@ -51,20 +53,24 @@ const Line: React.FC<ProgressProps> = (props) => {
5153
return (
5254
<svg
5355
id={id}
54-
className={clsx(`${prefixCls}-line`, className)}
56+
className={clsx(`${prefixCls}-line`, classNames.root, className)}
5557
viewBox={viewBoxString}
5658
preserveAspectRatio="none"
57-
style={style}
59+
style={{
60+
...styles.root,
61+
...style,
62+
}}
5863
role="presentation"
5964
{...restProps}
6065
>
6166
<path
62-
className={`${prefixCls}-line-rail`}
67+
className={clsx(`${prefixCls}-line-rail`, classNames.rail)}
6368
d={pathString}
6469
strokeLinecap={strokeLinecap}
6570
stroke={railColor}
6671
strokeWidth={railWidth ?? strokeWidth}
6772
fillOpacity="0"
73+
style={styles.rail}
6874
/>
6975
{percentList.map((ptg, index) => {
7076
const dashPercent =
@@ -86,7 +92,7 @@ const Line: React.FC<ProgressProps> = (props) => {
8692
return (
8793
<path
8894
key={index}
89-
className={`${prefixCls}-line-path`}
95+
className={clsx(`${prefixCls}-line-path`, classNames.track)}
9096
d={pathString}
9197
strokeLinecap={strokeLinecap}
9298
stroke={color as string}
@@ -100,7 +106,7 @@ const Line: React.FC<ProgressProps> = (props) => {
100106

101107
paths[index] = elem;
102108
}}
103-
style={pathStyle}
109+
style={{ ...pathStyle, ...styles.track }}
104110
/>
105111
);
106112
})}

‎tests/semantic.spec.tsx‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,29 @@ describe('Semantic', () => {
9898
},
9999
);
100100
});
101+
102+
describe('Line', () => {
103+
it('supports semantic classNames and styles', () => {
104+
const classNames: ProgressProps['classNames'] = {
105+
root: 'my-root',
106+
rail: 'my-rail',
107+
track: 'my-track',
108+
};
109+
const styles = {
110+
root: { background: 'red' },
111+
rail: { background: 'blue' },
112+
track: { background: 'green' },
113+
};
114+
115+
const { container } = render(<Line percent={50} classNames={classNames} styles={styles} />);
116+
117+
expect(container.querySelector('.rc-progress-line')).toHaveClass(classNames.root);
118+
expect(container.querySelector('.rc-progress-line-rail')).toHaveClass(classNames.rail);
119+
expect(container.querySelector('.rc-progress-line-path')).toHaveClass(classNames.track);
120+
121+
expect(container.querySelector('.my-root')).toHaveStyle(styles.root);
122+
expect(container.querySelector('.my-rail')).toHaveStyle(styles.rail);
123+
expect(container.querySelector('.my-track')).toHaveStyle(styles.track);
124+
});
125+
});
101126
});

0 commit comments

Comments
 (0)