ghost-portal/packages/app-toolbox/src/index.tsx
Jaco Greeff 7047f9b572
Introduce Tabs component for in-app menus (#267)
* Introduce Tabs component for in-app menus

* Change Addresses & Toolbox to Tabs

* Cleanup Tabs (directory -> file)

* Adjust disabled button opacity down
2018-08-29 14:34:01 +02:00

78 lines
1.7 KiB
TypeScript

// Copyright 2017-2018 @polkadot/app-toolbox authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import { I18nProps } from '@polkadot/ui-app/types';
import './index.css';
import React from 'react';
import Tabs from '@polkadot/ui-app/Tabs';
import Hash from './Hash';
import Sign from './Sign';
import Verify from './Verify';
import translate from './translate';
type Actions = 'hash' | 'sign' | 'verify';
type Props = I18nProps & {
basePath: string
};
type State = {
action: Actions
};
// FIXME React-router would probably be the best route, not home-grown
const Components: { [index: string]: React.ComponentType<any> } = { // Actions
'hash': Hash,
'sign': Sign,
'verify': Verify
};
class ToolboxApp extends React.PureComponent<Props, State> {
state: State = {
action: 'hash'
};
render () {
const { t } = this.props;
const { action } = this.state;
const Component = Components[action];
const items = [
{
name: 'hash',
text: t('app.hash', { defaultValue: 'Hash data' })
},
{
name: 'sign',
text: t('app.sign', { defaultValue: 'Sign message' })
},
{
name: 'verify',
text: t('app.verify', { defaultValue: 'Verify signature' })
}
];
return (
<main className='toolbox--App'>
<header>
<Tabs
activeItem={action}
items={items}
onChange={this.onMenuChange}
/>
</header>
<Component />
</main>
);
}
onMenuChange = (action: Actions) => {
this.setState({ action });
}
}
export default translate(ToolboxApp);