import { Vector3Array } from "@granity/helpers"; import { Box, BoxProps, TextField, TextFieldProps, Typography, TypographyProps, } from "@ui/components/atoms"; import { pxToRem } from "@ui/theme"; import { ChangeEvent, FC } from "react"; type Vector3InputStyles = { section?: BoxProps; inputGroup?: BoxProps; formField?: TextFieldProps; title?: TypographyProps; }; const styles: Vector3InputStyles = { section: { sx: { marginBottom: pxToRem(12), "&:last-child": { marginBottom: 0, }, }, }, inputGroup: { sx: { display: "flex", alignItems: "center", }, }, formField: { sx: { width: "100%", maxWidth: `calc(100% / 3 - ${pxToRem(12)})`, marginRight: pxToRem(12), marginBottom: 0, }, }, title: { sx: { marginBottom: pxToRem(8), }, }, }; export type Vector3InputProps = { title?: string; value?: Vector3Array; onChange?: (inputValue: number, index: number) => void; }; const mapVector3ArrayLabel = (index: number) => { switch (index) { case 0: return "x"; case 1: return "y"; case 2: return "z"; default: return "x"; } }; const Vector3Input: FC = ({ title, value, onChange }) => { return ( {title !== undefined && {title}} {(value || []).map((x, i) => ( ) => onChange?.(Number(target.value), i) } {...styles.formField} /> ))} ); }; export default Vector3Input;