diff --git a/packages/app-js/src/ActionButtons.tsx b/packages/app-js/src/ActionButtons.tsx new file mode 100644 index 0000000000..26a089a223 --- /dev/null +++ b/packages/app-js/src/ActionButtons.tsx @@ -0,0 +1,156 @@ +// 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/index'; + +import translate from './translate'; + +type Props = BareProps & I18nProps & { + isCustomExample: boolean, + isRunning: boolean, + saveSnippet: (snippetName: string) => void, + generateLink: () => void, + removeSnippet: () => void, + runJs: () => 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, 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); diff --git a/packages/app-js/src/LocalStorage.tsx b/packages/app-js/src/LocalStorage.tsx deleted file mode 100644 index 2b3323f411..0000000000 --- a/packages/app-js/src/LocalStorage.tsx +++ /dev/null @@ -1,111 +0,0 @@ -// 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/index'; - -import translate from './translate'; - -type Props = BareProps & I18nProps & { - isCustomExample: boolean, - saveSnippet: (snippetName: string) => void, - removeSnippet: () => void, - snippetName?: string -}; - -type State = { - snippetName: string, - isOpen: boolean -}; - -class LocalStorage extends React.PureComponent { - state: State = { - snippetName: '', - isOpen: false - }; - - render () { - const { - props: { isCustomExample, removeSnippet, t }, - state: { isOpen, snippetName } - } = this; - - if (isCustomExample) { - return ( - // FIXME: The event trigger on='hover' does not work together with the ui-app' - //