Skip to content

Commit 4697dfb

Browse files
committed
Convert PopButton to CSS modules
1 parent 08e263e commit 4697dfb

File tree

3 files changed

+49
-49
lines changed

3 files changed

+49
-49
lines changed

ui/frontend/PopButton.module.css

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
$fg-color: #222;
2+
$bg-color: white;
3+
$arrow-size: 10px;
4+
$vertical-border-color: #cacaca;
5+
6+
.container {
7+
z-index: 10;
8+
9+
/* Prevents the popper from shifting when adding it to the DOM
10+
* triggers showing the scrollbars.
11+
* https://github.com/FezVrasta/popper.js/issues/457#issuecomment-367692177
12+
*/
13+
top: 0;
14+
font-size: 12px;
15+
16+
button:enabled {
17+
cursor: pointer;
18+
}
19+
}
20+
21+
.arrow {
22+
position: absolute;
23+
border: $arrow-size solid transparent;
24+
margin: $arrow-size;
25+
}
26+
27+
.container[data-placement^='bottom'] .arrow {
28+
border-top-width: 0;
29+
border-bottom-color: $bg-color;
30+
margin-top: 0;
31+
}
32+
33+
.content {
34+
border-right: 1px solid $vertical-border-color;
35+
border-bottom: 1px solid var(--header-accent-border);
36+
border-left: 1px solid $vertical-border-color;
37+
margin: $arrow-size;
38+
background: $bg-color;
39+
border-radius: var(--header-border-radius);
40+
box-shadow: 0 1px 4px -2px rgba(0, 0, 0, 0.6), inset 0 1px 0 white;
41+
color: $fg-color;
42+
}

ui/frontend/PopButton.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React, { useCallback, useRef, useState, useEffect } from 'react';
22
import { Manager, Popper, Reference } from 'react-popper';
33
import { Portal } from 'react-portal';
44

5+
import styles from './PopButton.module.css';
6+
57
const POPPER_MODIFIERS = [
68
// Issue #303
79
{ name: 'computeStyles', options: { gpuAcceleration: false } },
@@ -47,17 +49,17 @@ const PopButton: React.SFC<NewPopProps> = ({ Button, Menu }) => {
4749
<Popper placement="bottom" innerRef={menuRef} modifiers={POPPER_MODIFIERS}>
4850
{({ ref, style, arrowProps, placement }) => (
4951
<div
50-
className="popper"
52+
className={styles.container}
5153
ref={ref}
5254
style={style}
5355
data-placement={placement}
5456
>
5557
<div
56-
className="popper__arrow"
58+
className={styles.arrow}
5759
ref={arrowProps.ref}
5860
style={arrowProps.style}
5961
/>
60-
<div className="popper__content">
62+
<div className={styles.content}>
6163
<Menu close={close} />
6264
</div>
6365
</div>

ui/frontend/index.scss

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -285,52 +285,6 @@ $header-transition: 0.2s ease-in-out;
285285
}
286286
}
287287

288-
.popper {
289-
z-index: 10;
290-
font-size: 12px;
291-
292-
// Prevents the popper from shifting when adding it to the DOM
293-
// triggers showing the scrollbars.
294-
// https://github.com/FezVrasta/popper.js/issues/457#issuecomment-367692177
295-
top: 0;
296-
297-
$fg-color: #222;
298-
$bg-color: white;
299-
$arrow-size: 10px;
300-
$vertical-border-color: #cacaca;
301-
302-
&__arrow {
303-
position: absolute;
304-
margin: $arrow-size;
305-
border: $arrow-size solid transparent;
306-
}
307-
308-
&[data-placement^="bottom"] &__arrow {
309-
margin-top: 0;
310-
border-top-width: 0;
311-
border-bottom-color: $bg-color;
312-
}
313-
314-
&__content {
315-
background: $bg-color;
316-
color: $fg-color;
317-
318-
margin: $arrow-size;
319-
320-
border-radius: $header-border-radius;
321-
322-
box-shadow: 0 1px 4px -2px rgba(0, 0, 0, 0.6), inset 0 1px 0px white;
323-
324-
border-left: 1px solid $vertical-border-color;
325-
border-right: 1px solid $vertical-border-color;
326-
border-bottom: 1px solid $header-accent-border;
327-
}
328-
329-
button:enabled {
330-
cursor: pointer;
331-
}
332-
}
333-
334288
.config-element {
335289
display: flex;
336290
align-items: center;
@@ -407,4 +361,6 @@ $header-transition: 0.2s ease-in-out;
407361
--header-main-border: #{$header-main-border};
408362
--header-transition: #{$header-transition};
409363
--header-tint: #{$header-tint};
364+
--header-border-radius: #{$header-border-radius};
365+
--header-accent-border: #{$header-accent-border};
410366
}

0 commit comments

Comments
 (0)