Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WRQ-32413: [POC] webOS ColorPicker - add responsiveness #1668

Merged
merged 3 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions ColorPickerPOC/ColorPickerSpectrum.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
const SpectrumColorPicker = (props) => {
const {selectedColor, selectedColorHandler} = props;
const canvasRef = useRef(null);
const [canvasHeight, setCanvasHeight] = useState(ri.scale(660));
const [canvasWidth, setCanvasWidth] = useState(ri.scale(800));
const [indicatorBgColor, setIndicatorBgColor] = useState('transparent');

Check warning on line 15 in ColorPickerPOC/ColorPickerSpectrum.js

View check run for this annotation

Codecov / codecov/patch

ColorPickerPOC/ColorPickerSpectrum.js#L13-L15

Added lines #L13 - L15 were not covered by tests
const [indicatorX, setIndicatorX] = useState(0);
const [indicatorY, setIndicatorY] = useState(0);
const [isDragging, setIsDragging] = useState(false);
const [indicatorBgColor, setIndicatorBgColor] = useState('transparent');
const [isIndicatorActive, setIsIndicatorActive] = useState(false);

useEffect(() => {
Expand Down Expand Up @@ -57,7 +59,15 @@
}
};
positionIndicator();
}, []); // eslint-disable-line react-hooks/exhaustive-deps

const handleResize = () => {
setCanvasHeight(canvas.parentElement.clientHeight);
setCanvasWidth(canvas.parentElement.clientWidth);

Check warning on line 65 in ColorPickerPOC/ColorPickerSpectrum.js

View check run for this annotation

Codecov / codecov/patch

ColorPickerPOC/ColorPickerSpectrum.js#L63-L65

Added lines #L63 - L65 were not covered by tests
};

window.addEventListener('resize', handleResize);
handleResize();

Check warning on line 69 in ColorPickerPOC/ColorPickerSpectrum.js

View check run for this annotation

Codecov / codecov/patch

ColorPickerPOC/ColorPickerSpectrum.js#L68-L69

Added lines #L68 - L69 were not covered by tests
}, [canvasHeight, canvasWidth]); // eslint-disable-line react-hooks/exhaustive-deps

const handleCanvasPointerDown = useCallback((e) => {
const canvas = canvasRef.current;
Expand Down Expand Up @@ -107,14 +117,14 @@
return (
<div className={css.colorPicker}>
<canvas
ref={canvasRef}
height={ri.scale(600)}
className={css.gradientCanvas}
height={canvasHeight}
onPointerDown={handleCanvasPointerDown}
onPointerLeave={handleCanvasPointerLeave}
onPointerMove={handleCanvasPointerMove}
onPointerUp={handleCanvasPointerUp}
style={{touchAction: 'none'}}
width={ri.scale(800)}
ref={canvasRef}
width={canvasWidth}
/>
<SpectrumIndicator
bgColor={indicatorBgColor}
Expand Down
6 changes: 6 additions & 0 deletions ColorPickerPOC/ColorPickerSpectrum.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

.colorPicker {
position: relative;

.gradientCanvas {
height: 100%;
touch-action: none;
width: 100%;
}
}

.circleIndicator {
Expand Down