1
Fork 0
mirror of https://github.com/Steffo99/festa.git synced 2024-12-23 15:14:23 +00:00
festa/components/editable/EditableText.tsx

17 lines
555 B
TypeScript
Raw Normal View History

2022-06-04 03:13:19 +00:00
import { HTMLProps } from "react";
2022-06-08 16:00:39 +00:00
import { EditingContext } from "./EditingContext";
2022-06-04 03:13:19 +00:00
import { useDefinedContext } from "../../utils/definedContext";
2022-06-08 16:00:39 +00:00
/**
* Controlled input component which displays an `input[type="text"]` in editing mode, and a `span` displaying the input in preview mode.
*/
export function EditableText(props: HTMLProps<HTMLInputElement> & {value: string}) {
2022-06-04 03:13:19 +00:00
const [editing,] = useDefinedContext(EditingContext)
return editing ? (
2022-06-08 16:00:39 +00:00
<input type="text" {...props}/>
2022-06-04 03:13:19 +00:00
) : (
2022-06-08 16:00:39 +00:00
<span>{props.value}</span>
2022-06-04 03:13:19 +00:00
)
}