import * as React from "react"; import styled from "styled-components"; import type { Props as InputProps } from "./Input"; import Input from "./Input"; import Relative from "./Sidebar/components/Relative"; import { SwatchButton } from "./SwatchButton"; /** * Props for the InputColor component. */ type Props = Omit & { /** The current color value in hex format */ value: string | undefined; /** Callback function invoked when the color value changes */ onChange: (value: string) => void; }; /** * A color input component that combines a text input with a color picker swatch button. * Automatically formats hex color values with a leading # character. */ const InputColor: React.FC = ({ value, onChange, ...rest }: Props) => ( onChange(event.target.value.replace(/^#?/, "#"))} placeholder="#" maxLength={7} {...rest} /> ); const PositionedSwatchButton = styled(SwatchButton)` border: 1px solid ${(props) => props.theme.inputBorder}; position: absolute; bottom: 21px; right: 6px; `; export default InputColor;