Skip to content

Commit f75f3c9

Browse files
committed
style(Circle): fix Circle style issue.
1 parent dc36de1 commit f75f3c9

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

packages/color-circle/README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
</div>
3131
<hr>
3232

33-
React Color Swatch
33+
React Color Circle
3434
===
3535

3636
[![Buy me a coffee](https://img.shields.io/badge/Buy%20me%20a%20coffee-048754?logo=buymeacoffee)](https://jaywcjlove.github.io/#/sponsor)
@@ -87,9 +87,21 @@ export default function Demo() {
8787
'#2196f3',
8888
]}
8989
color={hex}
90+
style={{
91+
gap: 23
92+
}}
93+
rectProps={{
94+
style: {
95+
borderRadius: 2,
96+
width: 18,
97+
height: 18,
98+
}
99+
}}
90100
pointProps={{
91101
style: {
92-
marginRight: 20,
102+
width: 26,
103+
height: 26,
104+
borderRadius: 5
93105
},
94106
}}
95107
onChange={(color) => {

packages/color-circle/src/Point.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ export default function Point({ style, className, title, checked, color, onClick
1717
btn.current!.style['transform'] = 'scale(1)';
1818
}, []);
1919

20+
let width = rectProps?.style?.width || '100%';
21+
let height = rectProps?.style?.height || '100%';
2022
const styleWrapper = {
2123
'--circle-point-background-color': '#fff',
22-
height: checked ? '100%' : 0,
23-
width: checked ? '100%' : 0,
24-
borderRadius: '50%',
2524
backgroundColor: 'var(--circle-point-background-color)',
2625
boxSizing: 'border-box',
2726
transition: 'height 100ms ease 0s, width 100ms ease 0s',
2827
...rectProps!.style,
28+
borderRadius: rectProps?.style?.borderRadius || '50%',
29+
height: checked ? height : 0,
30+
width: checked ? width : 0,
2931
} as CSSProperties;
3032

3133
return (

packages/color-circle/src/index.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,27 @@ const Circle = React.forwardRef<HTMLDivElement, CircleProps>((props, ref) => {
1717
colors = [],
1818
rectProps = {},
1919
pointProps = {},
20+
style = {},
2021
onChange,
2122
...other
2223
} = props;
2324
const hsva = (typeof color === 'string' && validHex(color) ? hexToHsva(color) : color || {}) as HsvaColor;
2425
const hex = color ? hsvaToHex(hsva) : '';
2526
const cls = [prefixCls, className].filter(Boolean).join(' ');
2627
const clsPoint = [`${prefixCls}-point`, pointProps?.className].filter(Boolean).join(' ');
28+
pointProps.style = pointProps.style || {};
29+
pointProps.style.borderRadius = pointProps.style?.borderRadius || '50%';
30+
pointProps.style.width = pointProps.style?.width || 26;
31+
pointProps.style.height = pointProps.style?.height || 26;
32+
pointProps.style.marginRight = pointProps.style?.marginRight || 0;
33+
pointProps.style.marginBottom = pointProps.style?.marginBottom || 0;
34+
style.gap = style.gap || 10;
2735
return (
2836
<Swatch
2937
ref={ref}
3038
colors={colors}
3139
color={hex}
40+
style={style}
3241
{...other}
3342
className={cls}
3443
rectRender={({ ...props }) => (

website/src/pages/home/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function Example() {
6262
'#795548',
6363
'#607d8b',
6464
]}
65-
style={{ width: 252 }}
65+
style={{ width: 222 }}
6666
color={hsva}
6767
onChange={(color) => {
6868
dispatch!({ hsva: { ...hsva, ...color.hsva } });

0 commit comments

Comments
 (0)