Skip to content

Commit 790d88f

Browse files
committed
feat(styles): add support for custom className and style props in DualScrollSyncLabel component
1 parent f082c49 commit 790d88f

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

lib/components/DualScrollSync/DualScrollSyncLabel/DualScrollSyncLabel.test.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,30 @@ describe('DualScrollSyncLabel', () => {
2424
expect(getByText('Bold Label')).toBeInTheDocument();
2525
expect(getByText('Bold Label').tagName).toBe('STRONG');
2626
});
27+
28+
it('should apply custom className and style', () => {
29+
const { getByText } = render(
30+
<DualScrollSyncLabel className="custom-class" style={{ borderWidth: '1px' }}>
31+
Styled Label
32+
</DualScrollSyncLabel>
33+
);
34+
35+
const label = getByText('Styled Label');
36+
37+
expect(label).toHaveClass('custom-class');
38+
expect(label).toHaveStyle('border-width: 1px');
39+
});
40+
41+
it('should not apply custom className or style if children is not a string', () => {
42+
const { getByText } = render(
43+
<DualScrollSyncLabel className="custom-class" style={{ borderWidth: '1px' }}>
44+
<span>Styled Child</span>
45+
</DualScrollSyncLabel>
46+
);
47+
48+
const label = getByText('Styled Child');
49+
50+
expect(label).not.toHaveClass('custom-class');
51+
expect(label).not.toHaveStyle('border-width: 1px');
52+
});
2753
});

lib/components/DualScrollSync/DualScrollSyncLabel/DualScrollSyncLabel.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1+
import clsx from 'clsx';
12
import type { FC } from 'react';
23

34
import { useDualScrollSyncContext } from '@/hooks';
45

56
import styles from './DualScrollSyncLabel.module.scss';
67
import type { DualScrollSyncLabelProps } from './DualScrollSyncLabel.types';
78

8-
export const DualScrollSyncLabel: FC<DualScrollSyncLabelProps> = ({ children }) => {
9+
export const DualScrollSyncLabel: FC<DualScrollSyncLabelProps> = ({
10+
children,
11+
className,
12+
style = {}
13+
}) => {
914
useDualScrollSyncContext();
1015

1116
if (typeof children !== 'string') return children;
1217

1318
return (
14-
<span className={styles.scrollSyncContentSectionLabel} title={children}>
19+
<span
20+
className={clsx(styles.scrollSyncContentSectionLabel, className)}
21+
title={children}
22+
style={style}
23+
>
1524
{children}
1625
</span>
1726
);

0 commit comments

Comments
 (0)