import React, { useRef, useCallback } from 'react' import { useInputContext } from '../../context' import { styled } from '../../styles' import { useInputSetters } from '../../hooks' import { sanitizeValue } from '../../utils' import { Number } from '../Number' import type { CoordinateProps, VectorProps } from './vector-types' function Coordinate>({ value, id, valueKey, settings, onUpdate, innerLabelTrim, }: CoordinateProps) { // TODO make this better const valueRef = useRef(value[valueKey]) valueRef.current = value[valueKey] const setValue = useCallback( (newValue: any) => // @ts-expect-error onUpdate({ [valueKey]: sanitizeValue({ type: 'NUMBER', value: valueRef.current, settings }, newValue) }), [onUpdate, settings, valueKey] ) const number = useInputSetters({ type: 'NUMBER', value: value[valueKey], settings, setValue }) return ( ) } export const Container = styled('div', { display: 'grid', columnGap: '$colGap', gridAutoFlow: 'column dense', alignItems: 'center', variants: { withLock: { true: { gridTemplateColumns: '10px auto', '> svg': { cursor: 'pointer' }, }, }, }, }) // TODO increase click area function Lock({ locked, ...props }: React.HTMLAttributes & { locked: boolean }) { return ( {locked ? ( ) : ( )} ) } export function Vector>({ value, onUpdate, settings, innerLabelTrim, }: VectorProps) { const { id, setSettings } = useInputContext() // TODO atm if lock is explicitly set in settings we show the lock, this can probably be improved with better logic. const { lock, locked } = settings return ( {lock && setSettings({ locked: !locked })} />} {Object.keys(value).map((key, i) => ( ))} ) }