import * as React from "react"; import { useTranslation } from "react-i18next"; import { MenuButton, useMenuState } from "reakit/Menu"; import styled from "styled-components"; import { s } from "@shared/styles"; import lazyWithRetry from "~/utils/lazyWithRetry"; import ContextMenu from "./ContextMenu"; import DelayedMount from "./DelayedMount"; import Input, { Props as InputProps } from "./Input"; import NudeButton from "./NudeButton"; import Relative from "./Sidebar/components/Relative"; import Text from "./Text"; type Props = Omit & { value: string | undefined; onChange: (value: string) => void; }; const InputColor: React.FC = ({ value, onChange, ...rest }: Props) => { const { t } = useTranslation(); const menu = useMenuState({ modal: true, placement: "bottom-end", }); return ( onChange(event.target.value.replace(/^#?/, "#"))} placeholder="#" maxLength={7} {...rest} /> {(props) => ( )} {t("Loading")}… } > onChange(color.hex)} /> ); }; const SwatchButton = styled(NudeButton)<{ $background: string | undefined }>` background: ${(props) => props.$background}; border: 1px solid ${s("inputBorder")}; border-radius: 50%; position: absolute; bottom: 20px; right: 6px; `; const ColorPicker = lazyWithRetry( () => import("react-color/lib/components/chrome/Chrome") ); const StyledColorPicker = styled(ColorPicker)` background: inherit !important; box-shadow: none !important; border: 0 !important; border-radius: 0 !important; user-select: none; input { user-select: text; color: ${s("text")} !important; } `; export default InputColor;