excalidraw/src/components/ProjectName.tsx
Lipis 53994e71e5
Add more ESLint rules and change the formatting scripts (#626)
* Add curly rule in ESLint for consistency

* Fix rules

* More rules

* REturn

* Push

* no else return

* prefer const

* destructing
2020-02-02 18:04:35 +00:00

50 lines
1.1 KiB
TypeScript

import "./ProjectName.css";
import React, { Component } from "react";
import { selectNode, removeSelection } from "../utils";
type Props = {
value: string;
onChange: (value: string) => void;
label: string;
};
export class ProjectName extends Component<Props> {
private handleFocus = (e: React.FocusEvent<HTMLElement>) => {
selectNode(e.currentTarget);
};
private handleBlur = (e: React.FocusEvent<HTMLElement>) => {
const value = e.currentTarget.innerText.trim();
if (value !== this.props.value) {
this.props.onChange(value);
}
removeSelection();
};
private handleKeyDown = (e: React.KeyboardEvent<HTMLElement>) => {
if (e.key === "Enter") {
e.preventDefault();
e.currentTarget.blur();
}
};
public render() {
return (
<span
suppressContentEditableWarning
contentEditable="true"
data-type="wysiwyg"
className="ProjectName"
role="textbox"
aria-label={this.props.label}
onBlur={this.handleBlur}
onKeyDown={this.handleKeyDown}
onFocus={this.handleFocus}
>
{this.props.value}
</span>
);
}
}