Skip to content

Commit 092ed8a

Browse files
committed
Convert HeaderButton to CSS modules
1 parent 9bb9b81 commit 092ed8a

File tree

4 files changed

+65
-60
lines changed

4 files changed

+65
-60
lines changed

ui/frontend/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const ExecuteButton: React.SFC = () => {
6969

7070
return (
7171
<SegmentedButton isBuild onClick={execute}>
72-
<HeaderButton rightIcon={<BuildIcon />}>
72+
<HeaderButton bold rightIcon={<BuildIcon />}>
7373
{executionLabel}
7474
</HeaderButton>
7575
</SegmentedButton>

ui/frontend/HeaderButton.module.css

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
.container {
2+
display: flex;
3+
height: 3em;
4+
align-items: center;
5+
padding: 0 1.25em;
6+
font-weight: 600;
7+
text-decoration: none;
8+
text-transform: uppercase;
9+
white-space: nowrap;
10+
}
11+
12+
.bold {
13+
font-weight: 700;
14+
}
15+
16+
.expandable {
17+
composes: container;
18+
padding-right: 1em;
19+
}
20+
21+
.hasLeftIcon {
22+
composes: container;
23+
padding-left: 1em;
24+
}
25+
26+
.hasRightIcon {
27+
composes: container;
28+
padding-right: 1em;
29+
}
30+
31+
.iconOnly {
32+
composes: container;
33+
padding: 0 0.75em;
34+
}
35+
36+
.leftIcon {
37+
margin-right: 0.5em;
38+
}
39+
40+
.iconOnly .leftIcon {
41+
margin-right: 0;
42+
}
43+
44+
.drop {
45+
margin-left: 0.75em;
46+
}
47+
48+
.rightIcon {
49+
margin-left: 0.75em;
50+
}

ui/frontend/HeaderButton.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,30 @@ import React from 'react';
22

33
import { ExpandableIcon } from './Icon';
44

5+
import styles from './HeaderButton.module.css';
6+
57
interface HeaderButtonProps {
8+
bold?: boolean;
69
icon?: React.ReactNode;
710
rightIcon?: React.ReactNode;
811
isExpandable?: boolean;
912
}
1013

11-
const HeaderButton: React.SFC<HeaderButtonProps> = ({ icon, rightIcon, isExpandable, children }) => {
12-
const c = ['header-button'];
14+
const HeaderButton: React.SFC<HeaderButtonProps> = ({ bold, icon, rightIcon, isExpandable, children }) => {
15+
const c = [styles.container];
1316

14-
if (icon) { c.push('header-button--has-left-icon'); }
15-
if (rightIcon) { c.push('header-button--has-right-icon'); }
16-
if (isExpandable) { c.push('header-button--expandable'); }
17-
if ((icon || rightIcon) && !isExpandable && !children) { c.push('header-button--icon-only'); }
17+
if (bold) { c.push(styles.bold); }
18+
if (icon) { c.push(styles.hasLeftIcon); }
19+
if (rightIcon) { c.push(styles.hasRightIcon); }
20+
if (isExpandable) { c.push(styles.expandable); }
21+
if ((icon || rightIcon) && !isExpandable && !children) { c.push(styles.iconOnly); }
1822

1923
return (
2024
<div className={c.join(' ')}>
21-
{icon && <div className="header-button__left-icon">{icon}</div>}
22-
{children}
23-
{rightIcon && <div className="header-button__right-icon">{rightIcon}</div>}
24-
{isExpandable && <div className="header-button__drop"><ExpandableIcon /></div>}
25+
{icon && <div className={styles.leftIcon}>{icon}</div>}
26+
{ children}
27+
{ rightIcon && <div className={styles.rightIcon}>{rightIcon}</div>}
28+
{ isExpandable && <div className={styles.drop}><ExpandableIcon /></div>}
2529
</div>
2630
);
2731
};

ui/frontend/index.scss

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,6 @@ $header-transition: 0.2s ease-in-out;
411411
border-right-width: 0;
412412
}
413413

414-
.header-button {
415-
font-weight: 700;
416-
}
417-
418414
&:hover {
419415
background: $rust-dark;
420416
color: white;
@@ -652,51 +648,6 @@ $header-transition: 0.2s ease-in-out;
652648
}
653649
}
654650

655-
.header-button {
656-
height: 3em;
657-
padding: 0 1.25em;
658-
display: flex;
659-
align-items: center;
660-
661-
text-transform: uppercase;
662-
text-decoration: none;
663-
font-weight: 600;
664-
665-
white-space: nowrap;
666-
667-
&--expandable {
668-
padding-right: 1em;
669-
}
670-
671-
&--has-left-icon {
672-
padding-left: 1em;
673-
}
674-
675-
&--has-right-icon {
676-
padding-right: 1em;
677-
}
678-
679-
&--icon-only {
680-
padding: 0 0.75em;
681-
}
682-
683-
&__left-icon {
684-
margin-right: 0.5em;
685-
}
686-
687-
&--icon-only &__left-icon {
688-
margin-right: 0;
689-
}
690-
691-
&__drop {
692-
margin-left: 0.75em;
693-
}
694-
695-
&__right-icon {
696-
margin-left: 0.75em;
697-
}
698-
}
699-
700651
.icon {
701652
display: block;
702653
fill: currentColor;

0 commit comments

Comments
 (0)