2022-09-28 18:05:28 +00:00
|
|
|
import classNames from "classnames";
|
|
|
|
import React, { useState } from "react";
|
|
|
|
import { ControllerRenderProps } from "react-hook-form";
|
2022-03-17 16:48:23 +00:00
|
|
|
|
2022-11-23 02:55:25 +00:00
|
|
|
import { Icon } from "@calcom/ui";
|
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 && (
|
|
|
|
<Icon.FiEdit2 className="ml-1 inline h-4 w-4 align-top text-gray-700 group-hover:text-gray-500" />
|
|
|
|
)}
|
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(
|
|
|
|
"absolute top-0 left-0 w-full cursor-pointer border-none bg-transparent p-0 align-top text-xl text-gray-900 hover:text-gray-700 focus:text-black focus:outline-none focus:ring-0"
|
|
|
|
)}
|
|
|
|
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;
|