Browse Source

Merge pull request #537 from gre/disable-sidebar-list-item-if-no-accounts

Disable sidebar item if no accounts (send/receive)
master
Meriadec Pillet 7 years ago
committed by GitHub
parent
commit
5a98c0e463
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/components/MainSideBar/index.js
  2. 10
      src/components/base/Box/index.js
  3. 39
      src/components/base/SideBar/SideBarListItem.js

2
src/components/MainSideBar/index.js

@ -100,12 +100,14 @@ class MainSideBar extends PureComponent<Props> {
icon={IconSend} icon={IconSend}
iconActiveColor={'wallet'} iconActiveColor={'wallet'}
onClick={this.handleOpenSendModal} onClick={this.handleOpenSendModal}
disabled={accounts.length === 0}
/> />
<SideBarListItem <SideBarListItem
label={t('app:receive.title')} label={t('app:receive.title')}
icon={IconReceive} icon={IconReceive}
iconActiveColor={'wallet'} iconActiveColor={'wallet'}
onClick={this.handleOpenReceiveModal} onClick={this.handleOpenReceiveModal}
disabled={accounts.length === 0}
/> />
<SideBarListItem <SideBarListItem
label={t('app:sidebar.manager')} label={t('app:sidebar.manager')}

10
src/components/base/Box/index.js

@ -121,7 +121,15 @@ export class Tabbable extends PureComponent<any, TabbableState> {
} }
render() { render() {
return <Box tabIndex={0} onFocus={this.handleFocus} onBlur={this.handleBlur} {...this.props} /> const { disabled } = this.props
return (
<Box
tabIndex={disabled ? undefined : 0}
onFocus={this.handleFocus}
onBlur={this.handleBlur}
{...this.props}
/>
)
} }
} }

39
src/components/base/SideBar/SideBarListItem.js

@ -6,20 +6,11 @@ import styled from 'styled-components'
import Box, { Tabbable } from 'components/base/Box' import Box, { Tabbable } from 'components/base/Box'
import { rgba } from 'styles/helpers' import { rgba } from 'styles/helpers'
export type Item = {
label: string | (Props => React$Element<any>),
desc?: Props => any, // TODO: type should be more precise, but, eh ¯\_(ツ)_/¯
icon?: any, // TODO: type should be more precise, but, eh ¯\_(ツ)_/¯
iconActiveColor: ?string,
hasNotif?: boolean,
isActive?: boolean,
onClick?: void => void,
}
export type Props = { export type Props = {
label: string | (Props => React$Element<any>), label: string | (Props => React$Element<any>),
desc?: Props => any, // TODO: type should be more precise, but, eh ¯\_(ツ)_/¯ desc?: Props => any, // TODO: type should be more precise, but, eh ¯\_(ツ)_/¯
icon?: any, // TODO: type should be more precise, but, eh ¯\_(ツ)_/¯ icon?: any, // TODO: type should be more precise, but, eh ¯\_(ツ)_/¯
disabled?: boolean,
iconActiveColor: ?string, iconActiveColor: ?string,
hasNotif?: boolean, hasNotif?: boolean,
isActive?: boolean, isActive?: boolean,
@ -29,13 +20,23 @@ export type Props = {
class SideBarListItem extends PureComponent<Props> { class SideBarListItem extends PureComponent<Props> {
render() { render() {
const { icon: Icon, label, desc, iconActiveColor, hasNotif, onClick, isActive } = this.props const {
icon: Icon,
label,
desc,
iconActiveColor,
hasNotif,
onClick,
isActive,
disabled,
} = this.props
return ( return (
<Container <Container
data-role="side-bar-item" data-role="side-bar-item"
isActive={isActive} isActive={!disabled && isActive}
iconActiveColor={iconActiveColor} iconActiveColor={iconActiveColor}
onClick={onClick} onClick={disabled ? null : onClick}
disabled={disabled}
> >
{!!Icon && <Icon size={16} />} {!!Icon && <Icon size={16} />}
<Box grow shrink> <Box grow shrink>
@ -63,16 +64,17 @@ const Container = styled(Tabbable).attrs({
px: 3, px: 3,
py: 2, py: 2,
})` })`
cursor: ${p => (p.isActive ? 'default' : 'pointer')}; cursor: ${p => (p.disabled || p.isActive ? 'default' : 'pointer')};
color: ${p => (p.isActive ? p.theme.colors.dark : p.theme.colors.smoke)}; color: ${p => (p.isActive ? p.theme.colors.dark : p.theme.colors.smoke)};
background: ${p => (p.isActive ? p.theme.colors.lightGrey : '')}; background: ${p => (p.isActive ? p.theme.colors.lightGrey : '')};
opacity: ${p => (p.disabled ? 0.5 : 1)};
&:active { &:active {
background: ${p => p.theme.colors.lightGrey}; background: ${p => !p.disabled && p.theme.colors.lightGrey};
} }
&:hover { &:hover {
color: ${p => p.theme.colors.dark}; color: ${p => !p.disabled && p.theme.colors.dark};
} }
border: 1px solid transparent; border: 1px solid transparent;
@ -83,9 +85,10 @@ const Container = styled(Tabbable).attrs({
${p => { ${p => {
const iconActiveColor = p.theme.colors[p.iconActiveColor] || p.iconActiveColor const iconActiveColor = p.theme.colors[p.iconActiveColor] || p.iconActiveColor
const color = p.isActive ? iconActiveColor : p.theme.colors.grey
return ` return `
svg { color: ${p.isActive ? iconActiveColor : p.theme.colors.grey}; } svg { color: ${color}; }
&:hover svg { color: ${iconActiveColor}; } &:hover svg { color: ${p.disabled ? color : iconActiveColor}; }
` `
}}; }};
` `

Loading…
Cancel
Save