// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import React from 'react' import {injectIntl, IntlShape, FormattedMessage} from 'react-intl' import {BlockIcons} from '../blockIcons' import {Board} from '../blocks/board' import mutator from '../mutator' import Menu from '../widgets/menu' import MenuWrapper from '../widgets/menuWrapper' import Editable from '../widgets/editable' import Button from './button' type Props = { board: Board intl: IntlShape } type State = { isHoverOnCover: boolean title: string } class ViewTitle extends React.Component { private titleEditor = React.createRef() shouldComponentUpdate(): boolean { return true } constructor(props: Props) { super(props) this.state = {isHoverOnCover: false, title: props.board.title} } render(): JSX.Element { const {board, intl} = this.props return ( <>
{ this.setState({isHoverOnCover: true}) }} onMouseLeave={() => { this.setState({isHoverOnCover: false}) }} >
{board.icon &&
{board.icon}
mutator.changeIcon(board, BlockIcons.shared.randomIcon())} /> mutator.changeIcon(board, undefined, 'remove icon')} />
} this.setState({title})} onBlur={() => mutator.changeTitle(board, this.state.title)} onFocus={() => this.titleEditor.current.focus()} onKeyDown={(e: React.KeyboardEvent): void => { if (e.keyCode === 27 && !(e.metaKey || e.ctrlKey) && !e.shiftKey && !e.altKey) { // ESC e.stopPropagation() this.setState({title: this.props.board.title}) setTimeout(() => this.titleEditor.current.blur(), 0) } else if (e.keyCode === 13 && !(e.metaKey || e.ctrlKey) && !e.shiftKey && !e.altKey) { // Return e.stopPropagation() mutator.changeTitle(board, this.state.title) this.titleEditor.current.blur() } }} />
) } } export default injectIntl(ViewTitle)