Skip to content

Commit

Permalink
Merge pull request #213 from ubilabs/feat/layer-selector
Browse files Browse the repository at this point in the history
feat(layer-selector): disable compare tab when no main layer is selected
  • Loading branch information
KatvonRivia authored Nov 26, 2019
2 parents 0f5b12f + d8ec6b3 commit 4bb5a66
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/scripts/components/layer-selector/layer-selector.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {FunctionComponent, useState} from 'react';
import {useSelector} from 'react-redux';
import {useIntl} from 'react-intl';
import {useParams} from 'react-router-dom';

import {layersSelector} from '../../selectors/layers/list';
import {LayersIcon} from '../icons/layers-icon';
Expand All @@ -15,16 +16,19 @@ import styles from './layer-selector.styl';
const LayerSelector: FunctionComponent = () => {
const intl = useIntl();
const layers = useSelector(layersSelector);
const {mainLayerId} = useParams();
const tabs: Tab[] = [
{
id: 'main',
label: intl.formatMessage({id: 'layerSelector.main'}),
icon: LayersIcon
icon: LayersIcon,
disabled: false
},
{
id: 'compare',
label: intl.formatMessage({id: 'layerSelector.compare'}),
icon: CompareIcon
icon: CompareIcon,
disabled: !mainLayerId
}
];

Expand All @@ -39,7 +43,6 @@ const LayerSelector: FunctionComponent = () => {
setIsOpen(true);
return;
}

if (activeTabId === id) {
setIsOpen(false);
}
Expand Down
6 changes: 6 additions & 0 deletions src/scripts/components/tab/tab.styl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
cursor: pointer
fill: #fff

.disabled
border-color: #999
background-color: #333
color: #999
fill: #999

.tabActive
border: 1px solid #ccc
background-color: #fff
Expand Down
11 changes: 9 additions & 2 deletions src/scripts/components/tab/tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,30 @@ interface Props {
id: string;
label: string;
activeTabId: string;
disabled: boolean;
onSelectTabId: (id: string) => void;
}

const Tab: FunctionComponent<Props> = ({
id,
label,
activeTabId,
disabled,
onSelectTabId,
children
}) => {
const isActive = activeTabId === id;
const tabClasses = cx(styles.tab, isActive && styles.tabActive);
const tabClasses = cx(
styles.tab,
isActive && styles.tabActive,
disabled && styles.disabled
);

return (
<button
title={label}
className={tabClasses}
onClick={() => onSelectTabId(id)}>
onClick={() => !disabled && onSelectTabId(id)}>
{children}
</button>
);
Expand Down
1 change: 1 addition & 0 deletions src/scripts/components/tabs/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const Tabs: FunctionComponent<Props> = ({tabs, activeTabId, onTabChanged}) => (
<Tab
key={tab.id}
id={tab.id}
disabled={tab.disabled}
label={tab.label}
activeTabId={activeTabId}
onSelectTabId={id => onTabChanged(id)}>
Expand Down
1 change: 1 addition & 0 deletions src/scripts/types/tab.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import {FunctionComponent} from 'react';
export interface Tab {
id: string;
label: string;
disabled: boolean;
icon?: FunctionComponent;
}

0 comments on commit 4bb5a66

Please sign in to comment.