2022-03-17 16:48:23 +00:00
|
|
|
import { useState } from "react";
|
|
|
|
|
2022-07-27 02:24:00 +00:00
|
|
|
import { Icon } from "@calcom/ui/Icon";
|
|
|
|
|
2022-07-22 20:51:38 +00:00
|
|
|
const EditableHeading = ({
|
|
|
|
title,
|
|
|
|
onChange,
|
|
|
|
placeholder = "",
|
|
|
|
readOnly = false,
|
|
|
|
}: {
|
|
|
|
title: string;
|
|
|
|
onChange?: (value: string) => void;
|
|
|
|
placeholder?: string;
|
|
|
|
readOnly?: boolean;
|
|
|
|
}) => {
|
|
|
|
const [isEditing, setIsEditing] = useState(false);
|
|
|
|
const enableEditing = () => !readOnly && 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}>
|
|
|
|
{!isEditing ? (
|
2022-03-17 16:48:23 +00:00
|
|
|
<>
|
|
|
|
<h1
|
|
|
|
style={{ fontSize: 22, letterSpacing: "-0.0009em" }}
|
2022-07-22 20:51:38 +00:00
|
|
|
className="inline pl-0 normal-case text-gray-900 focus:text-black group-hover:text-gray-500">
|
2022-03-17 16:48:23 +00:00
|
|
|
{title}
|
|
|
|
</h1>
|
2022-07-22 20:51:38 +00:00
|
|
|
{!readOnly ? (
|
2022-07-27 02:24:00 +00:00
|
|
|
<Icon.Edit2 className="ml-1 -mt-1 inline h-4 w-4 text-gray-700 group-hover:text-gray-500" />
|
2022-07-22 20:51:38 +00:00
|
|
|
) : null}
|
2022-03-17 16:48:23 +00:00
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<div style={{ marginBottom: -11 }}>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
autoFocus
|
|
|
|
style={{ top: -6, fontSize: 22 }}
|
|
|
|
required
|
|
|
|
className="relative h-10 w-full cursor-pointer border-none bg-transparent pl-0 text-gray-900 hover:text-gray-700 focus:text-black focus:outline-none focus:ring-0"
|
2022-07-22 20:51:38 +00:00
|
|
|
placeholder={placeholder}
|
2022-03-17 16:48:23 +00:00
|
|
|
defaultValue={title}
|
2022-07-22 20:51:38 +00:00
|
|
|
onBlur={(e) => {
|
|
|
|
setIsEditing(false);
|
|
|
|
onChange && onChange(e.target.value);
|
|
|
|
}}
|
2022-03-17 16:48:23 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default EditableHeading;
|