import * as React from "react"; import { CSSObject, css } from "@emotion/css"; export type UseOneLineTextEditorResult = { text: string; element: () => React.ReactElement; }; /** * 1行のテキストエディタ * * 入力した内容を強制的に変更しない普通の用途にはこれを使う * @param id 入力欄を区別するID */ export const useOneLineTextEditor = (option: { initText: string; id: string; style?: CSSObject; }): UseOneLineTextEditorResult => { const [text, setText] = React.useState(option.initText); const element = (): React.ReactElement => { return ( ); }; return { text, element, }; }; /** * 1行のテキストエディタ * * 文字の変更を検知しないなら, `useOneLineTextEditor` を使うと良い */ export const OneLineTextEditor: React.VFC<{ value: string; onChange: ((value: string) => void) | undefined; id: string; style?: CSSObject | undefined; }> = React.memo((props) => ( { e.stopPropagation(); }} readOnly={props.onChange === undefined} onChange={(e) => { if (props.onChange !== undefined) { props.onChange(e.target.value); } }} /> )); OneLineTextEditor.displayName = "OneLineTextEditor";