diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index c65165a..f8e2ecd 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -33,6 +33,9 @@ "copiedLabel": { "message": "Copied." }, + "listenLabel": { + "message": "Listen" + }, "targetLangLabel": { "message": "Target language" }, diff --git a/src/popup/components/CopyButton.js b/src/popup/components/CopyButton.js new file mode 100644 index 0000000..01b470e --- /dev/null +++ b/src/popup/components/CopyButton.js @@ -0,0 +1,38 @@ +import React, { Component } from "react"; +import browser from "webextension-polyfill"; +import { CopyToClipboard } from "react-copy-to-clipboard"; +import CopyIcon from "../icons/copy.svg"; +import "../styles/CopyButton.scss"; + +export default class CopyButton extends Component { + constructor(props) { + super(props); + this.state = { isCopied: false }; + } + + handleCopy = () => { + this.setState({ isCopied: true }); + }; + + componentWillReceiveProps(nextProps) { + if (this.props.text !== nextProps.text) this.setState({ isCopied: false }); + } + + render() { + const { text } = this.props; + if (!text) return null; + + return ( +
+ {this.state.isCopied && ( + {browser.i18n.getMessage("copiedLabel")} + )} + + + +
+ ); + } +} diff --git a/src/popup/components/InputArea.js b/src/popup/components/InputArea.js index b97ab06..75f6f3f 100644 --- a/src/popup/components/InputArea.js +++ b/src/popup/components/InputArea.js @@ -1,6 +1,7 @@ import React, { Component } from "react"; import ReactDOM from "react-dom"; import browser from "webextension-polyfill"; +import ListenButton from "./ListenButton"; import "../styles/inputArea.scss"; export default class InputArea extends Component { @@ -16,7 +17,9 @@ export default class InputArea extends Component { }; shouldComponentUpdate(nextProps) { - const shouldUpdate = this.props.inputText !== nextProps.inputText; + const shouldUpdate = + this.props.inputText !== nextProps.inputText || + this.props.sourceLang !== nextProps.sourceLang; return shouldUpdate; } @@ -25,16 +28,20 @@ export default class InputArea extends Component { }; render() { + const { inputText, sourceLang } = this.props; return (