2022-09-28 18:05:28 +00:00
|
|
|
import classNames from "classnames";
|
2023-01-23 23:08:01 +00:00
|
|
|
import { useState } from "react";
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { ControllerRenderProps } from "react-hook-form";
|
2022-03-17 16:48:23 +00:00
|
|
|
|
2023-01-23 23:08:01 +00:00
|
|
|
import { FiEdit2 } from "@calcom/ui/components/icon";
|
2022-07-27 02:24:00 +00:00
|
|
|
|
2022-09-28 18:05:28 +00:00
|
|
|
const EditableHeading = function EditableHeading({
|
|
|
|
value,
|
2022-07-22 20:51:38 +00:00
|
|
|
onChange,
|
2022-09-28 18:05:28 +00:00
|
|
|
isReady,
|
|
|
|
...passThroughProps
|
2022-07-22 20:51:38 +00:00
|
|
|
}: {
|
2022-09-28 18:05:28 +00:00
|
|
|
isReady?: boolean;
|
|
|
|
} & Omit<JSX.IntrinsicElements["input"], "name" | "onChange"> &
|
|
|
|
ControllerRenderProps) {
|
2022-07-22 20:51:38 +00:00
|
|
|
const [isEditing, setIsEditing] = useState(false);
|
2022-09-28 18:05:28 +00:00
|
|
|
const enableEditing = () => setIsEditing(true);
|
2022-03-17 16:48:23 +00:00
|
|
|
return (
|
2022-07-22 20:51:38 +00:00
|
|
|
<div className="group relative cursor-pointer" onClick={enableEditing}>
|
2022-09-28 18:05:28 +00:00
|
|
|
<div className="flex items-center">
|
|
|
|
<label className="min-w-8 relative inline-block">
|
|
|
|
<span className="whitespace-pre text-xl tracking-normal text-transparent">{value} </span>
|
|
|
|
{!isEditing && isReady && (
|
2023-04-05 18:14:46 +00:00
|
|
|
<FiEdit2 className=" text-subtle group-hover:text-subtle ml-1 -mt-px inline h-3 w-3" />
|
2022-09-28 18:05:28 +00:00
|
|
|
)}
|
2022-03-17 16:48:23 +00:00
|
|
|
<input
|
2022-09-28 18:05:28 +00:00
|
|
|
{...passThroughProps}
|
2022-03-17 16:48:23 +00:00
|
|
|
type="text"
|
2022-09-28 18:05:28 +00:00
|
|
|
value={value}
|
2022-03-17 16:48:23 +00:00
|
|
|
required
|
2022-09-28 18:05:28 +00:00
|
|
|
className={classNames(
|
2023-04-05 18:14:46 +00:00
|
|
|
"text-emphasis hover:text-default focus:text-emphasis absolute top-0 left-0 w-full cursor-pointer border-none bg-transparent p-0 align-top text-xl focus:outline-none focus:ring-0"
|
2022-09-28 18:05:28 +00:00
|
|
|
)}
|
|
|
|
onFocus={(e) => {
|
|
|
|
setIsEditing(true);
|
|
|
|
passThroughProps.onFocus && passThroughProps.onFocus(e);
|
|
|
|
}}
|
2022-07-22 20:51:38 +00:00
|
|
|
onBlur={(e) => {
|
|
|
|
setIsEditing(false);
|
2022-09-28 18:05:28 +00:00
|
|
|
passThroughProps.onBlur && passThroughProps.onBlur(e);
|
2022-07-22 20:51:38 +00:00
|
|
|
}}
|
2022-09-28 18:05:28 +00:00
|
|
|
onChange={(e) => onChange && onChange(e.target.value)}
|
2022-03-17 16:48:23 +00:00
|
|
|
/>
|
2022-09-28 18:05:28 +00:00
|
|
|
</label>
|
|
|
|
</div>
|
2022-03-17 16:48:23 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default EditableHeading;
|