Skip to content

Commit 51e8d4d

Browse files
committed
feat: ColorBlock support inner style
1 parent 3895c8a commit 51e8d4d

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

src/components/ColorBlock.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ export type ColorBlockProps = {
66
prefixCls?: string;
77
className?: string;
88
style?: React.CSSProperties;
9+
/** Internal usage. Only used in antd ColorPicker semantic structure only */
10+
innerClassName?: string;
11+
/** Internal usage. Only used in antd ColorPicker semantic structure only */
12+
innerStyle?: React.CSSProperties;
913
onClick?: React.MouseEventHandler<HTMLDivElement>;
1014
};
1115

@@ -14,6 +18,8 @@ const ColorBlock: React.FC<ColorBlockProps> = ({
1418
prefixCls,
1519
className,
1620
style,
21+
innerClassName,
22+
innerStyle,
1723
onClick,
1824
}) => {
1925
const colorBlockCls = `${prefixCls}-color-block`;
@@ -23,7 +29,10 @@ const ColorBlock: React.FC<ColorBlockProps> = ({
2329
style={style}
2430
onClick={onClick}
2531
>
26-
<div className={`${colorBlockCls}-inner`} style={{ background: color }} />
32+
<div
33+
className={clsx(`${colorBlockCls}-inner`, innerClassName)}
34+
style={{ background: color, ...innerStyle }}
35+
/>
2736
</div>
2837
);
2938
};

tests/components.test.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { fireEvent, render } from '@testing-library/react';
33
import React from 'react';
44
import { expect } from 'vitest';
5-
import ColorPicker, { type BaseSliderProps } from '../src';
5+
import ColorPicker, { ColorBlock, type BaseSliderProps } from '../src';
66
import { defaultColor } from '../src/util';
77

88
describe('ColorPicker.Components', () => {
@@ -56,4 +56,19 @@ describe('ColorPicker.Components', () => {
5656
fireEvent.click(alphaEle);
5757
expect(alphaEle.textContent).toBe('0/100/33');
5858
});
59+
60+
it('ColorBlock support innerClassName and innerStyle', () => {
61+
const { container } = render(
62+
<ColorBlock
63+
prefixCls="test"
64+
color="red"
65+
innerClassName="my-inner-class"
66+
innerStyle={{ color: '#903' }}
67+
/>,
68+
);
69+
70+
const innerDiv = container.querySelector('.test-color-block-inner');
71+
expect(innerDiv).toHaveClass('my-inner-class');
72+
expect(innerDiv).toHaveStyle({ color: '#903' });
73+
});
5974
});

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"skipLibCheck": true,
99
"esModuleInterop": true,
1010
"module": "ESNext",
11-
"types": ["vitest/globals"],
11+
"types": ["vitest/globals", "@testing-library/jest-dom"],
1212
"paths": {
1313
"@@/*": [".dumi/tmp/*"],
1414
"@rc-component/color-picker": ["src/index.tsx"]

0 commit comments

Comments
 (0)