ghost-portal/packages/ui-app/src/Tabs.tsx
Jaco Greeff a8ed300dc4
Small init changes (static state) (#663)
* Small init changes (static state)

* Hide vanity on empty accounts

* Require accounts for apps, cleanup needsApi/needsCalls

* Display InputAddress when disable (but no options)

* Filter toolbox based on accounts

* Accounts gated via app, don't display add

* Cleanup linting

* Validation display & clear on settings types

* Split save for developer & general

* Add Reset button to dev settings
2019-01-31 18:02:47 +01:00

68 lines
1.6 KiB
TypeScript

// Copyright 2017-2019 @polkadot/ui-app 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 } from './types';
import React from 'react';
import { withRouter } from 'react-router';
import { NavLink } from 'react-router-dom';
import classes from './util/classes';
export type TabItem = {
hasParams?: boolean,
name: string,
text: React.ReactNode
};
type Props = BareProps & {
basePath: string,
hidden?: Array<string>,
items: Array<TabItem>
};
class Tabs extends React.PureComponent<Props> {
render () {
const { className, hidden = [], items, style } = this.props;
return (
<div
className={classes('ui--Menu ui menu tabular', className)}
style={style}
>
{
items
.filter(({ name }) => !hidden.includes(name))
.map(this.renderItem)
}
</div>
);
}
private renderItem = ({ hasParams, name, text }: TabItem, index: number) => {
const { basePath } = this.props;
const to = index === 0
? basePath
: `${basePath}/${name}`;
// only do exact matching when not the fallback (first position tab),
// params are problematic for dynamic hidden such as app-accounts
const isExact = !hasParams || index === 0;
return (
<NavLink
activeClassName='active'
className='item'
exact={isExact}
key={to}
strict={isExact}
to={to}
>
{text}
</NavLink>
);
}
}
export default withRouter(Tabs as React.ComponentType<any>) as any as React.ComponentType<Props>;