Skip to content

Commit 76d8936

Browse files
authored
fix(docs): Added proper docs for creating custom pointer for react-wheel package. (#179)
1 parent d5e8577 commit 76d8936

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

packages/color-wheel/README.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,50 @@ function Demo() {
8585
);
8686
}
8787

88+
export default Demo;
89+
```
90+
### Custom Pointer
91+
92+
```tsx mdx:preview
93+
import React, { useState, Fragment } from 'react';
94+
import Wheel from '@uiw/react-color-wheel';
95+
import ShadeSlider from '@uiw/react-color-shade-slider';
96+
import { hsvaToHex } from '@uiw/color-convert';
97+
98+
function Demo() {
99+
const [hsva, setHsva] = useState({ h: 214, s: 43, v: 90, a: 1 });
100+
return (
101+
<Fragment>
102+
<Wheel color={hsva} onChange={(color) => setHsva({ ...hsva, ...color.hsva })}
103+
/* Passing the style prop is required in the topmost element. */
104+
pointer={({ color, style }) => {
105+
return (
106+
<div style={style}>
107+
<div
108+
style={{
109+
width: 12,
110+
height: 12,
111+
transform: 'translate(-5px, -5px)',
112+
backgroundColor: color,
113+
border: '1px solid #000',
114+
}}
115+
></div>
116+
</div>
117+
);
118+
}}
119+
/>
120+
<ShadeSlider
121+
hsva={hsva}
122+
style={{ width: 210, marginTop: 20 }}
123+
onChange={(newShade) => {
124+
setHsva({ ...hsva, ...newShade });
125+
}}
126+
/>
127+
<div style={{ width: '100%', height: 34, marginTop: 20, background: hsvaToHex(hsva) }}></div>
128+
</Fragment>
129+
);
130+
}
131+
88132
export default Demo;
89133
```
90134

@@ -107,7 +151,8 @@ export interface WheelProps extends Omit<React.HTMLAttributes<HTMLDivElement>, '
107151
angle?: number;
108152
/** Direction of the color wheel's hue gradient; either clockwise or anticlockwise. Default: `anticlockwise` */
109153
direction?: 'clockwise' | 'anticlockwise';
110-
pointer?: ({ prefixCls, left, top, color }: PointerProps) => JSX.Element;
154+
/** Passing the style prop is required in the topmost element. */
155+
pointer?: ({ color, style }: PointerProps) => JSX.Element;
111156
onChange?: (color: ColorResult) => void;
112157
}
113158
declare const Wheel: React.ForwardRefExoticComponent<WheelProps & React.RefAttributes<HTMLDivElement>>;

packages/color-wheel/src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const Wheel = React.forwardRef<HTMLDivElement, WheelProps>((props, ref) => {
5959
};
6060
const pointerStyle: React.CSSProperties = {
6161
zIndex: 1,
62+
position: 'absolute',
6263
transform: `translate(${positions.x}px, ${positions.y}px) ${
6364
oval === 'x' || oval === 'X' ? 'scaleY(2)' : oval === 'y' || oval === 'Y' ? 'scaleX(2)' : ''
6465
}`,

0 commit comments

Comments
 (0)