import * as React from "react"; import { Button } from "../controls/Button"; import { Input } from "../controls/Input"; export interface ColorPickerFieldProps { index: number; color: string; onColorChanged: (color: string) => void; onMoveColor: (up: boolean) => void; } export const ColorPickerField = (props: ColorPickerFieldProps) => { const { index, color, onColorChanged, onMoveColor } = props; const [currentColor, setCurrentColor] = React.useState(undefined); const onBlur = () => { if (currentColor) onColorChanged(currentColor); setCurrentColor(undefined); } const onColorPickerChanged = (e: React.ChangeEvent) => { setCurrentColor(e.target.value.toUpperCase()); } const onTextInputChanged = (newValue: string) => { newValue = newValue.trim(); if (newValue?.[0] != '#') { newValue = "#" + newValue; } if (newValue.length > 7) { newValue = newValue.substring(0, 7); } if (/#[0-9a-fA-F]{6}/.test(newValue)) { onColorChanged(newValue.toUpperCase()); } } return
{index}
}