// tslint:disable:react-a11y-anchors import React from 'react'; import * as GoogleChrome from '../util/GoogleChrome'; import { AttachmentType } from '../types/Attachment'; import autoBind from 'auto-bind'; import { SessionButton, SessionButtonColor, SessionButtonType } from './basic/SessionButton'; import { SessionInput } from './basic/SessionInput'; interface Props { attachment: AttachmentType; url: string; caption?: string; onSave: (caption: string) => void; onClose: () => void; } interface State { caption: string; } export class CaptionEditor extends React.Component { private readonly inputRef: React.RefObject; constructor(props: Props) { super(props); const { caption } = props; this.state = { caption: caption || '', }; autoBind(this); this.inputRef = React.createRef(); } public onSave() { const { onSave } = this.props; const { caption } = this.state; onSave(caption); } public onChange(value: string) { this.setState({ caption: value, }); } public renderObject() { const { url, onClose, attachment } = this.props; const { contentType } = attachment || { contentType: null }; const isImageTypeSupported = GoogleChrome.isImageTypeSupported(contentType); if (isImageTypeSupported) { return ( {window.i18n('imageAttachmentAlt')} ); } const isVideoTypeSupported = GoogleChrome.isVideoTypeSupported(contentType); if (isVideoTypeSupported) { return ( ); } return
; } public render() { const { onClose } = this.props; const { caption } = this.state; return (
{this.renderObject()}
); } }