ratio-lock
Version:
A TypeScript library for managing n numbers with locked ratios. When the ratio is locked, changing one value automatically adjusts all other values to maintain their proportional relationships.
19 lines • 706 B
JavaScript
/**
* Creates an onChange handler for a specific field index
*/
export function createFieldChangeHandler(index, ratioLock, names, setFormValue) {
return (e) => {
const newValue = Number(e.target.value);
ratioLock.setValue(index, newValue);
const newValues = ratioLock.getValues();
for (let i = 0; i < names.length; i++) {
const name = names[i];
const value = newValues[i];
if (name !== undefined && value !== undefined) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
setFormValue(name, value);
}
}
};
}
//# sourceMappingURL=create-field-change-handler.js.map