Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #262 from codaco/feature/color-code-thumbnails
Browse files Browse the repository at this point in the history
protocol thumbnail color based on schema
  • Loading branch information
jthrilly committed Nov 18, 2019
2 parents bdb7327 + 0f438fe commit 7830d06
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
20 changes: 19 additions & 1 deletion src/renderer/components/ProtocolThumbnail.js
@@ -1,5 +1,7 @@
import React, { PureComponent } from 'react';
import { NavLink } from 'react-router-dom';
import cx from 'classnames';
import { replace } from 'lodash';

import Types from '../types';

Expand All @@ -11,11 +13,27 @@ class ProtocolThumbnail extends PureComponent {
this.state = { hover: false };
}

getSchemaColorIndex = (version) => {
const parsedVersion = parseInt(replace(version, /\./g, ''), 10);
if (isNaN(parsedVersion)) {
return 0;
}
return (parsedVersion % 9) + 1;
}

render() {
const { protocol } = this.props;
const schemaColorIndex = this.getSchemaColorIndex(protocol.schemaVersion);
const protocolColorClasses = cx(
'protocol-thumbnail',
{
[`protocol-thumbnail__schema-color-seq-${schemaColorIndex}`]: schemaColorIndex,
},
);

return (
<NavLink
className="protocol-thumbnail"
className={protocolColorClasses}
activeClassName="protocol-thumbnail--active"
to={`/workspaces/${protocol.id}`}
>
Expand Down
12 changes: 11 additions & 1 deletion src/renderer/components/__tests__/ProtocolThumbnail-test.js
Expand Up @@ -8,7 +8,7 @@ describe('<ProtocolThumbnail />', () => {
let mockProtocol;
let wrapper;
beforeEach(() => {
mockProtocol = { id: '1', name: 'MyProtocol', createdAt: new Date(), version: '2.0' };
mockProtocol = { id: '1', name: 'MyProtocol', createdAt: new Date(), schemaVersion: '2.0' };
wrapper = shallow(<ProtocolThumbnail protocol={mockProtocol} />);
});

Expand All @@ -25,4 +25,14 @@ describe('<ProtocolThumbnail />', () => {
expect(navText).toMatch(new RegExp(`^${mockProtocol.name.substring(0, 1)}`));
expect(navText).toHaveLength(2);
});

it('uses color classes based on schema', () => {
expect(wrapper.find('NavLink').prop('className')).toMatch('protocol-thumbnail protocol-thumbnail__schema-color-seq-3');
});

it('uses different color classes', () => {
mockProtocol = { id: '1', name: 'MyProtocol', createdAt: new Date(), schemaVersion: '3.0' };
wrapper = shallow(<ProtocolThumbnail protocol={mockProtocol} />);
expect(wrapper.find('NavLink').prop('className')).toMatch('protocol-thumbnail protocol-thumbnail__schema-color-seq-4');
});
});
14 changes: 11 additions & 3 deletions src/renderer/styles/components/_protocol-thumbnail.scss
@@ -1,13 +1,21 @@
.protocol-thumbnail {
$protocol-border-highlight: rgba(255, 255, 255, 0.15);
$protocol-border-selected: rgba(255, 255, 255, 0.5);
$protocol-border-highlight: rgba(255, 255, 255, 0.2);
$protocol-border-transparent: rgba(255, 255, 255, 0);

--border-selected: #{$protocol-border-selected};
--border-highlight: #{$protocol-border-highlight};
--border-transparent: #{$protocol-border-transparent};
--border-width: 6px;
--thumbnail-size: calc(var(--app-sidebar-width) * 0.6);

background-color: var(--color-cyber-grape);
@for $i from 1 through 9 {
&.protocol-thumbnail__schema-color-seq-#{$i} {
background-color: var(--schema-color-seq-#{$i});
}
}

border: var(--border-width) solid var(--border-transparent);
border-radius: 0.75rem;
color: var(--color-white);
Expand All @@ -26,7 +34,7 @@
width: var(--thumbnail-size);

@include modifier(active) {
background-color: var(--color-sea-green);
border-color: var(--border-selected);
}

@include modifier(add) {
Expand All @@ -39,7 +47,7 @@
}
}

&:hover {
&:hover:not(.protocol-thumbnail--active) {
border-color: var(--border-highlight);
}
}
2 changes: 1 addition & 1 deletion src/renderer/ui
Submodule ui updated from 622035 to 2020d4

0 comments on commit 7830d06

Please sign in to comment.