Skip to content

Commit 3500607

Browse files
committed
feat: further refine the API, stories, and documentation
1 parent 62ec2d8 commit 3500607

25 files changed

+472
-378
lines changed

src/BottomSheet/BottomSheet.story.tsx

Lines changed: 0 additions & 216 deletions
This file was deleted.

src/BottomSheet/BottomSheet.styled.tsx

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import type { AnimationProps } from "framer-motion";
77
import { motion } from "framer-motion";
88
import { transparentize } from "polished";
99
import styled from "styled-components";
10-
import { height, layout, maxHeight, maxWidth, space, width } from "styled-system";
10+
import { compose, height, layout, maxHeight, maxWidth, space, styleFn, width } from "styled-system";
1111
import type { HeightProps, LayoutProps, MaxHeightProps, MaxWidthProps, SpaceProps, WidthProps } from "styled-system";
1212
import { Heading2, Text } from "../Type";
13+
import { excludeStyledProps } from "../StyledProps";
1314

1415
const Overlay = styled(motion(ReachDialogOverlay))(({ theme }) => ({
1516
position: "fixed",
@@ -21,16 +22,20 @@ const Overlay = styled(motion(ReachDialogOverlay))(({ theme }) => ({
2122
}));
2223

2324
interface SheetProps
24-
extends WidthProps,
25+
extends DialogContentProps,
26+
AnimationProps,
27+
WidthProps,
2528
MaxWidthProps,
2629
HeightProps,
2730
MaxHeightProps,
28-
DialogContentProps,
2931
SpaceProps,
30-
LayoutProps,
31-
AnimationProps {}
32+
LayoutProps {}
3233

33-
const Sheet = styled(motion(ReachDialogContent))<SheetProps>(
34+
const styleFns = [width, maxWidth, height, maxHeight, space, layout];
35+
36+
const Sheet = styled(motion(ReachDialogContent)).withConfig({
37+
shouldForwardProp: excludeStyledProps(...styleFns),
38+
})<SheetProps>(
3439
({ theme }) => ({
3540
":focus": {
3641
outline: "none",
@@ -51,27 +56,14 @@ const Sheet = styled(motion(ReachDialogContent))<SheetProps>(
5156
WebkitFontSmoothing: "antialiased",
5257
WebkitTapHighlightColor: "transparent",
5358
MozOsxFontSmoothing: "grayscale",
54-
5559
position: "relative",
5660
overflow: "hidden",
5761
display: "flex",
5862
flexDirection: "column",
5963
background: "white",
60-
width: "100%",
61-
maxHeight: `calc(100dvh - ${theme.space.x7})`,
6264
boxShadow: theme.shadows.large,
63-
64-
[`@media (min-width: ${theme.breakpoints.small})`]: {
65-
maxWidth: `calc(100% - ${theme.space.x8})`,
66-
maxHeight: "85.4dvh", // Golden Ratio
67-
},
6865
}),
69-
width,
70-
maxWidth,
71-
height,
72-
maxHeight,
73-
space,
74-
layout
66+
compose(...styleFns)
7567
);
7668

7769
const ContentContainer = styled.div((_) => ({
@@ -99,7 +91,7 @@ const Footer = styled.div(({ theme }) => ({
9991
}));
10092

10193
const Header = styled.div(({ theme }) => ({
102-
textAlign: "center",
94+
textAlign: "left",
10395
paddingTop: theme.space.x3,
10496
paddingLeft: theme.space.x3,
10597
paddingRight: theme.space.x3,

src/BottomSheet/BottomSheet.tsx

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
import React from "react";
22
import { useTranslation } from "react-i18next";
3+
import { useTheme } from "styled-components";
34
import { WidthProps } from "styled-system";
45
import { Box } from "../Box";
5-
import { Button } from "../Button";
6+
import { QuietButton } from "../Button";
67
import { Flex } from "../Flex";
78
import { noop } from "../utils/noop";
89
import { BottomSheetParts } from "./BottomSheet.parts";
910

1011
interface Props {
11-
isOpen: boolean;
12+
isOpen?: boolean;
1213
"aria-label"?: string;
1314
onClose?: () => void;
1415
title?: string;
1516
helpText?: React.ReactNode;
16-
closeActionLabel?: string;
17+
closeButtonLabel?: string;
18+
hideCloseButton?: boolean;
1719
secondaryAction?: (props: { onClose: () => void }) => React.ReactElement;
1820
primaryAction?: (props: { onClose: () => void }) => React.ReactElement;
19-
onCloseEnd?: () => void;
20-
closeOnOverlayClick?: boolean;
21+
disableCloseOnOverlayClick?: boolean;
2122
sheetWidth?: WidthProps["width"];
2223
contentWidth?: WidthProps["width"];
2324
children?: React.ReactNode;
@@ -26,40 +27,54 @@ interface Props {
2627
export default function BottomSheet({
2728
title,
2829
helpText,
29-
closeActionLabel: closeButtonLabel,
30-
secondaryAction: secondaryButton,
31-
primaryAction: primaryButton,
32-
isOpen,
30+
closeButtonLabel,
31+
secondaryAction,
32+
primaryAction,
33+
isOpen = false,
3334
onClose = noop,
34-
closeOnOverlayClick,
35-
sheetWidth,
35+
sheetWidth = "100%",
3636
contentWidth = { small: "100%", medium: 704 },
37+
disableCloseOnOverlayClick = false,
38+
hideCloseButton = false,
3739
children,
3840
...props
3941
}: Props) {
4042
const { t } = useTranslation();
43+
const theme = useTheme();
44+
4145
closeButtonLabel ||= t("close");
46+
const closeOnClick = !disableCloseOnOverlayClick;
4247

4348
return (
4449
<BottomSheetParts.Root isOpen={isOpen} onClose={onClose}>
45-
<BottomSheetParts.Overlay closeOnClick={closeOnOverlayClick}>
46-
<BottomSheetParts.Sheet width={sheetWidth} aria-label={props["aria-label"] ?? title}>
50+
<BottomSheetParts.Overlay closeOnClick={closeOnClick}>
51+
<BottomSheetParts.Sheet
52+
width={sheetWidth}
53+
maxWidth={{ small: `calc(100% - ${theme.space.x8})` }}
54+
maxHeight={{ small: `calc(100dvh - ${theme.space.x7})`, medium: "85.4dvh" }}
55+
aria-label={props["aria-label"] ?? title}
56+
>
4757
<BottomSheetParts.ContentContainer>
4858
<Box width={contentWidth} margin="0 auto">
4959
<BottomSheetParts.Header>
5060
{title && <BottomSheetParts.Title>{title}</BottomSheetParts.Title>}
51-
{helpText && <BottomSheetParts.HelpText>{helpText}</BottomSheetParts.HelpText>}
61+
{helpText &&
62+
(typeof helpText === "string" ? (
63+
<BottomSheetParts.HelpText>{helpText}</BottomSheetParts.HelpText>
64+
) : (
65+
helpText
66+
))}
5267
</BottomSheetParts.Header>
5368
<Box px="x3" py="x4">
5469
{children}
5570
</Box>
5671
</Box>
5772
<BottomSheetParts.Footer>
58-
<Flex justifyContent="space-between">
59-
<Button onClick={onClose}>{closeButtonLabel}</Button>
60-
<Flex gap="x2">
61-
{secondaryButton && secondaryButton({ onClose })}
62-
{primaryButton && primaryButton({ onClose })}
73+
<Flex alignItems="center" justifyContent="space-between" gap="x2">
74+
{!hideCloseButton && <QuietButton onClick={onClose}>{closeButtonLabel}</QuietButton>}
75+
<Flex gap="x2" alignItems="center" ml="auto">
76+
{secondaryAction && secondaryAction({ onClose })}
77+
{primaryAction && primaryAction({ onClose })}
6378
</Flex>
6479
</Flex>
6580
</BottomSheetParts.Footer>

0 commit comments

Comments
 (0)