Skip to content

Commit a1e20f7

Browse files
committed
Make PopButtons work in both up and down directions
The previous border would create an issue when the arrow was attached to the bottom of the pop up. This replaces the border with a dark shadow.
1 parent 8f62464 commit a1e20f7

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

ui/frontend/PopButton.module.css

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,22 @@ $arrow-width: 20px;
1313
}
1414
}
1515

16-
.content {
17-
margin: 0 $arrow-height $arrow-height $arrow-height;
16+
.-content {
17+
margin: $arrow-height;
1818
box-shadow:
19-
0 1px 4px -2px rgb(0 0 0 / 60%),
20-
inset 0 1px 0 white;
21-
border-right: 1px solid $vertical-border-color;
22-
border-bottom: 1px solid var(--header-accent-border);
23-
border-left: 1px solid $vertical-border-color;
19+
5px 5px 20px -3px rgb(0 0 0 / 25%),
20+
0 0 5px -2px rgb(0 0 0 / 90%);
2421
border-radius: var(--header-border-radius);
2522
background: $bg-color;
2623
color: $fg-color;
2724
}
25+
26+
.contentBottom {
27+
composes: -content;
28+
margin-top: 0;
29+
}
30+
31+
.contentTop {
32+
composes: -content;
33+
margin-bottom: 0;
34+
}

ui/frontend/PopButton.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
FloatingArrow,
33
FloatingFocusManager,
4+
Placement,
45
arrow,
56
autoUpdate,
67
flip,
@@ -31,20 +32,27 @@ interface NewPopProps {
3132
menuContainer?: React.RefObject<HTMLDivElement>;
3233
}
3334

35+
const CONTAINER_STYLE: { [key in Placement]?: string } = {
36+
top: styles.contentTop,
37+
bottom: styles.contentBottom,
38+
};
39+
3440
const PopButton: React.FC<NewPopProps> = ({ Button, Menu, menuContainer }) => {
3541
const [isOpen, setIsOpen] = useState(false);
3642
const toggle = useCallback(() => setIsOpen((v) => !v), []);
3743
const close = useCallback(() => setIsOpen(false), []);
3844

3945
const arrowRef = useRef(null);
4046

41-
const { x, y, refs, strategy, context } = useFloating({
47+
const { x, y, refs, strategy, context, placement } = useFloating({
4248
open: isOpen,
4349
onOpenChange: setIsOpen,
4450
middleware: [offset(10), flip(), shift(), arrow({ element: arrowRef })],
4551
whileElementsMounted: autoUpdate,
4652
});
4753

54+
const containerClass = CONTAINER_STYLE[placement] ?? '';
55+
4856
const click = useClick(context);
4957
const dismiss = useDismiss(context);
5058
const role = useRole(context);

0 commit comments

Comments
 (0)