fix: make mobile popover dialog styling nice (#3059)

* fix: make mobile popover dialog styling nice
Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
Nan Yu
2022-02-04 16:32:22 -08:00
committed by GitHub
parent 4cc7af7874
commit ae0644177b
2 changed files with 29 additions and 3 deletions

View File

@@ -132,6 +132,8 @@ export const Position = styled.div`
position: absolute; position: absolute;
z-index: ${(props) => props.theme.depths.menu}; z-index: ${(props) => props.theme.depths.menu};
// overrides make mobile-first coding style challenging
// so we explicitly define mobile breakpoint here
${breakpoint("mobile", "tablet")` ${breakpoint("mobile", "tablet")`
position: fixed !important; position: fixed !important;
transform: none !important; transform: none !important;

View File

@@ -1,6 +1,9 @@
import * as React from "react"; import * as React from "react";
import { Dialog } from "reakit/Dialog";
import { Popover as ReakitPopover } from "reakit/Popover"; import { Popover as ReakitPopover } from "reakit/Popover";
import styled from "styled-components"; import styled from "styled-components";
import breakpoint from "styled-components-breakpoint";
import useMobile from "~/hooks/useMobile";
import { fadeAndScaleIn } from "~/styles/animations"; import { fadeAndScaleIn } from "~/styles/animations";
type Props = { type Props = {
@@ -10,14 +13,24 @@ type Props = {
}; };
function Popover({ children, width = 380, ...rest }: Props) { function Popover({ children, width = 380, ...rest }: Props) {
const isMobile = useMobile();
if (isMobile) {
return (
<Dialog {...rest} modal>
<Contents>{children}</Contents>
</Dialog>
);
}
return ( return (
<ReakitPopover {...rest}> <ReakitPopover {...rest}>
<Contents width={width}>{children}</Contents> <Contents $width={width}>{children}</Contents>
</ReakitPopover> </ReakitPopover>
); );
} }
const Contents = styled.div<{ width: number }>` const Contents = styled.div<{ $width?: number }>`
animation: ${fadeAndScaleIn} 200ms ease; animation: ${fadeAndScaleIn} 200ms ease;
transform-origin: 75% 0; transform-origin: 75% 0;
background: ${(props) => props.theme.menuBackground}; background: ${(props) => props.theme.menuBackground};
@@ -25,8 +38,19 @@ const Contents = styled.div<{ width: number }>`
padding: 12px 24px; padding: 12px 24px;
max-height: 50vh; max-height: 50vh;
overflow-y: scroll; overflow-y: scroll;
width: ${(props) => props.width}px;
box-shadow: ${(props) => props.theme.menuShadow}; box-shadow: ${(props) => props.theme.menuShadow};
width: ${(props) => props.$width}px;
${breakpoint("mobile", "tablet")`
position: fixed;
z-index: ${(props: any) => props.theme.depths.menu};
// 50 is a magic number that positions us nicely under the top bar
top: 50px;
left: 8px;
right: 8px;
width: auto;
`};
`; `;
export default Popover; export default Popover;