Skip to content

Commit cae3d96

Browse files
committed
Convert SegmentedButton to CSS modules
1 parent 9d718ba commit cae3d96

File tree

3 files changed

+77
-84
lines changed

3 files changed

+77
-84
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
$bg-light: #fff;
2+
$bg-dark: #f9f9f9;
3+
4+
.container {
5+
display: flex;
6+
align-items: center;
7+
border-radius: var(--header-border-radius);
8+
box-shadow: 0 2px 4px -2px rgba(0, 0, 0, 0.4), inset 0 1px 0 white;
9+
}
10+
11+
.button {
12+
composes: -buttonReset from './shared.module.css';
13+
border: 1px solid var(--header-main-border);
14+
background: linear-gradient($bg-light, $bg-dark);
15+
background-color: $bg-light;
16+
color: #444;
17+
18+
&:first-child {
19+
border-bottom-left-radius: var(--header-border-radius);
20+
border-top-left-radius: var(--header-border-radius);
21+
}
22+
23+
&:last-child {
24+
border-bottom-right-radius: var(--header-border-radius);
25+
border-top-right-radius: var(--header-border-radius);
26+
}
27+
28+
&:not(:first-child) {
29+
border-left: none;
30+
}
31+
32+
&:not(:last-child) {
33+
border-right: 1px solid var(--header-main-border);
34+
}
35+
36+
&:hover {
37+
background: linear-gradient($bg-light, #f3f3f3);
38+
color: #333;
39+
}
40+
41+
&:active {
42+
border-top-color: #bababa;
43+
border-bottom-color: #d6d6d6;
44+
background: linear-gradient($bg-dark, #ededed);
45+
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.2);
46+
}
47+
}
48+
49+
.buttonBuild {
50+
composes: button;
51+
border-color: hsl(15, 66.7%, 32%);
52+
background: var(--rust);
53+
color: white;
54+
55+
&:not(:last-child) {
56+
/* Silly specificity */
57+
border-right-width: 0;
58+
}
59+
60+
&:hover {
61+
background: var(--rust-dark);
62+
color: white;
63+
}
64+
65+
&:active {
66+
border-top-color: var(--rust-dark);
67+
border-bottom-color: var(--rust-dark);
68+
background: var(--rust-dark);
69+
}
70+
}

ui/frontend/SegmentedButton.tsx

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

33
import Link, { LinkProps } from './uss-router/Link';
44

5+
import styles from './SegmentedButton.module.css';
6+
57
export const SegmentedButtonSet: React.SFC = ({ children }) => (
6-
<div className="segmented-button">{children}</div>
8+
<div className={styles.container}>{children}</div>
79
);
810

911
type Button = JSX.IntrinsicElements['button'];
@@ -17,7 +19,7 @@ export const SegmentedButton = React.forwardRef<HTMLButtonElement, SegmentedButt
1719
<button
1820
ref={ref}
1921
{...props}
20-
className={`segmented-button__button ${isBuild ? 'segmented-button__button--build' : ''}`}
22+
className={isBuild ? styles.buttonBuild : styles.button}
2123
>
2224
{children}
2325
</button>
@@ -30,7 +32,7 @@ export const SegmentedLink = React.forwardRef<HTMLAnchorElement, LinkProps>(
3032
<Link
3133
ref={ref}
3234
{...props}
33-
className={'segmented-button__button'}
35+
className={styles.button}
3436
>
3537
{children}
3638
</Link>

ui/frontend/index.scss

Lines changed: 2 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -181,88 +181,9 @@ $header-accent-border: #bdbdbd;
181181
$header-border-radius: 4px;
182182
$header-transition: 0.2s ease-in-out;
183183

184-
@mixin active-button($bg-dark) {
185-
background: linear-gradient($bg-dark, #ededed);
186-
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.2);
187-
188-
border-top-color: #bababa;
189-
border-bottom-color: #d6d6d6;
190-
}
191-
192-
.segmented-button {
193-
display: flex;
194-
align-items: center;
195-
196-
border-radius: $header-border-radius;
197-
box-shadow: 0 2px 4px -2px rgba(0, 0, 0, 0.4), inset 0 1px 0px white;
198-
199-
&__button {
200-
@include button-reset;
201-
202-
$bg-light: #fff;
203-
$bg-dark: #f9f9f9;
204-
205-
background-color: $bg-light;
206-
background: linear-gradient($bg-light, $bg-dark);
207-
color: #444;
208-
209-
border: 1px solid $header-main-border;
210-
211-
&:first-child {
212-
border-top-left-radius: $header-border-radius;
213-
border-bottom-left-radius: $header-border-radius;
214-
}
215-
216-
&:last-child {
217-
border-top-right-radius: $header-border-radius;
218-
border-bottom-right-radius: $header-border-radius;
219-
}
220-
221-
&:not(:first-child) {
222-
border-left: none;
223-
}
224-
225-
&:not(:last-child) {
226-
border-right: 1px solid $header-main-border;
227-
}
228-
229-
&:hover {
230-
background: linear-gradient($bg-light, #f3f3f3);
231-
color: #333;
232-
}
233-
234-
&:active {
235-
@include active-button($bg-dark);
236-
}
237-
238-
&--build {
239-
$rust-dark: #80331a;
240-
241-
background: $rust;
242-
color: white;
243-
244-
border-color: hsl(15, 66.7%, 32%);
245-
246-
&:not(:last-child) {
247-
// Silly specificity
248-
border-right-width: 0;
249-
}
250-
251-
&:hover {
252-
background: $rust-dark;
253-
color: white;
254-
}
255-
256-
&:active {
257-
background: $rust-dark;
258-
border-top-color: $rust-dark;
259-
border-bottom-color: $rust-dark;
260-
}
261-
}
262-
}
263-
}
264-
265184
:root {
185+
--rust: #{$rust};
186+
--rust-dark: #80331a;
266187
--border-color: #{$border-color};
267188
--header-main-border: #{$header-main-border};
268189
--header-transition: #{$header-transition};

0 commit comments

Comments
 (0)