// Copyright 2017-2019 @polkadot/app-js authors & contributors // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. import { BareProps, I18nProps } from '@polkadot/ui-app/types'; import React from 'react'; import { Button as SUIB, Popup } from 'semantic-ui-react'; import { Button, Input } from '@polkadot/ui-app'; import translate from './translate'; type Props = BareProps & I18nProps & { isCustomExample: boolean, isRunning: boolean, generateLink: () => void, removeSnippet: () => void, runJs: () => void, saveSnippet: (snippetName: string) => void, snippetName?: string, stopJs: () => void }; type State = { isOpen: boolean, shareText: string, snippetName: string }; class ActionButtons extends React.PureComponent { state: State = { isOpen: false, shareText: this.props.t('Generate link to share code example'), snippetName: '' }; render () { const { props: { isCustomExample, isRunning, removeSnippet, runJs, stopJs, t }, state: { isOpen, shareText, snippetName } } = this; return (
} wide='very' /> { // FIXME: The event trigger on='hover' does not work together with the ui-app' //
); } private generateLink = (): void => { const { generateLink, t } = this.props; this.setState({ shareText: t('Copied to clipboard') } as State); generateLink(); } private onShareClose = (): void => { this.setState({ shareText: this.props.t('Generate link to share code example') } as State); } private onChangeName = (snippetName: string): void => { this.setState({ snippetName } as State); } private saveSnippet = (): void => { const { state: { snippetName }, props: { saveSnippet } } = this; saveSnippet(snippetName); this.setState({ snippetName: '', isOpen: false } as State); } private onPopupOpen = (): void => { this.setState({ isOpen: true, snippetName: this.props.snippetName || '' } as State); } private onPopupClose = (): void => { this.setState({ snippetName: '', isOpen: false } as State); } } export default translate(ActionButtons);