Skip to content

Commit 26fce86

Browse files
committed
fix(Circle): fix pointProps props. #142
1 parent 3bedead commit 26fce86

3 files changed

Lines changed: 53 additions & 3 deletions

File tree

packages/color-circle/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,38 @@ export default function Demo() {
3636
}
3737
```
3838

39+
Modify point style
40+
41+
```jsx mdx:preview
42+
import React, { useState } from 'react';
43+
import Circle from '@uiw/react-color-circle';
44+
45+
export default function Demo() {
46+
const [hex, setHex] = useState('#F44E3B');
47+
return (
48+
<Circle
49+
colors={[
50+
'#f44336',
51+
'#e91e63',
52+
'#9c27b0',
53+
'#673ab7',
54+
'#3f51b5',
55+
'#2196f3',
56+
]}
57+
color={hex}
58+
pointProps={{
59+
style: {
60+
marginRight: 20,
61+
},
62+
}}
63+
onChange={(color) => {
64+
setHex(color.hex);
65+
}}
66+
/>
67+
);
68+
}
69+
```
70+
3971
## Props
4072

4173
```ts
@@ -45,6 +77,7 @@ import { SwatchProps } from '@uiw/react-color-swatch';
4577
export interface CircleProps extends Omit<SwatchProps, 'color' | 'onChange'> {
4678
color?: string | HsvaColor;
4779
onChange?: (color: ColorResult) => void;
80+
pointProps?: React.HTMLAttributes<HTMLDivElement>;
4881
}
4982
declare const Circle: React.ForwardRefExoticComponent<CircleProps & React.RefAttributes<HTMLDivElement>>;
5083
export default Circle;

packages/color-circle/src/Point.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export default function Point({ style, className, title, checked, color, onClick
3737
title={title}
3838
className={className}
3939
style={{
40-
...style,
4140
display: 'flex',
4241
alignItems: 'center',
4342
justifyContent: 'center',
@@ -51,6 +50,7 @@ export default function Point({ style, className, title, checked, color, onClick
5150
transform: 'scale(1)',
5251
boxShadow: `${color} 0px 0px ${checked ? 5 : 0}px`,
5352
transition: 'transform 100ms ease 0s, box-shadow 100ms ease 0s',
53+
...style,
5454
}}
5555
>
5656
<div {...rectProps} style={styleWrapper} />

packages/color-circle/src/index.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,16 @@ export interface CircleProps extends Omit<SwatchProps, 'color' | 'onChange'> {
1010
}
1111

1212
const Circle = React.forwardRef<HTMLDivElement, CircleProps>((props, ref) => {
13-
const { prefixCls = 'w-color-circle', className, color, colors = [], rectProps = {}, pointProps, onChange, ...other } = props;
13+
const {
14+
prefixCls = 'w-color-circle',
15+
className,
16+
color,
17+
colors = [],
18+
rectProps = {},
19+
pointProps = {},
20+
onChange,
21+
...other
22+
} = props;
1423
const hsva = (typeof color === 'string' && validHex(color) ? hexToHsva(color) : color || {}) as HsvaColor;
1524
const hex = color ? hsvaToHex(hsva) : '';
1625
const cls = [prefixCls, className].filter(Boolean).join(' ');
@@ -22,7 +31,15 @@ const Circle = React.forwardRef<HTMLDivElement, CircleProps>((props, ref) => {
2231
color={hex}
2332
{...other}
2433
className={cls}
25-
rectRender={({ ...props }) => <Point {...props} {...pointProps} className={clsPoint} rectProps={rectProps} />}
34+
rectRender={({ ...props }) => (
35+
<Point
36+
{...props}
37+
{...pointProps}
38+
style={{ ...props.style, ...pointProps.style }}
39+
className={clsPoint}
40+
rectProps={rectProps}
41+
/>
42+
)}
2643
onChange={(hsvColor) => {
2744
onChange && onChange(handleColor(hsvColor));
2845
}}

0 commit comments

Comments
 (0)