Completed color value editor component.
This commit is contained in:
+19
@@ -1,3 +1,7 @@
|
||||
import type { RefObject } from "react";
|
||||
|
||||
import type { CartesianSpace } from "./types";
|
||||
|
||||
export function minmax(number: number, min: number, max: number) {
|
||||
return Math.min(max, Math.max(min, number));
|
||||
}
|
||||
@@ -25,3 +29,18 @@ export function extractEventCoordinates(event: MouseEvent | TouchEvent): {
|
||||
clientY: event.clientY,
|
||||
};
|
||||
}
|
||||
|
||||
export function setMeasurements(
|
||||
ref: RefObject<HTMLElement | null>,
|
||||
setOrigin: (newOrigin: CartesianSpace) => void,
|
||||
setDimensions: (newDimensions: CartesianSpace) => void,
|
||||
) {
|
||||
const el = ref.current;
|
||||
|
||||
if (el) {
|
||||
const rect = el.getBoundingClientRect();
|
||||
|
||||
setOrigin({ x: rect.left, y: rect.top });
|
||||
setDimensions({ x: rect.width, y: rect.height });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user