1
1
import React from "react" ;
2
2
import { useTranslation } from "react-i18next" ;
3
+ import { useTheme } from "styled-components" ;
3
4
import { WidthProps } from "styled-system" ;
4
5
import { Box } from "../Box" ;
5
- import { Button } from "../Button" ;
6
+ import { QuietButton } from "../Button" ;
6
7
import { Flex } from "../Flex" ;
7
8
import { noop } from "../utils/noop" ;
8
9
import { BottomSheetParts } from "./BottomSheet.parts" ;
9
10
10
11
interface Props {
11
- isOpen : boolean ;
12
+ isOpen ? : boolean ;
12
13
"aria-label" ?: string ;
13
14
onClose ?: ( ) => void ;
14
15
title ?: string ;
15
16
helpText ?: React . ReactNode ;
16
- closeActionLabel ?: string ;
17
+ closeButtonLabel ?: string ;
18
+ hideCloseButton ?: boolean ;
17
19
secondaryAction ?: ( props : { onClose : ( ) => void } ) => React . ReactElement ;
18
20
primaryAction ?: ( props : { onClose : ( ) => void } ) => React . ReactElement ;
19
- onCloseEnd ?: ( ) => void ;
20
- closeOnOverlayClick ?: boolean ;
21
+ disableCloseOnOverlayClick ?: boolean ;
21
22
sheetWidth ?: WidthProps [ "width" ] ;
22
23
contentWidth ?: WidthProps [ "width" ] ;
23
24
children ?: React . ReactNode ;
@@ -26,40 +27,54 @@ interface Props {
26
27
export default function BottomSheet ( {
27
28
title,
28
29
helpText,
29
- closeActionLabel : closeButtonLabel ,
30
- secondaryAction : secondaryButton ,
31
- primaryAction : primaryButton ,
32
- isOpen,
30
+ closeButtonLabel,
31
+ secondaryAction,
32
+ primaryAction,
33
+ isOpen = false ,
33
34
onClose = noop ,
34
- closeOnOverlayClick,
35
- sheetWidth,
35
+ sheetWidth = "100%" ,
36
36
contentWidth = { small : "100%" , medium : 704 } ,
37
+ disableCloseOnOverlayClick = false ,
38
+ hideCloseButton = false ,
37
39
children,
38
40
...props
39
41
} : Props ) {
40
42
const { t } = useTranslation ( ) ;
43
+ const theme = useTheme ( ) ;
44
+
41
45
closeButtonLabel ||= t ( "close" ) ;
46
+ const closeOnClick = ! disableCloseOnOverlayClick ;
42
47
43
48
return (
44
49
< 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
+ >
47
57
< BottomSheetParts . ContentContainer >
48
58
< Box width = { contentWidth } margin = "0 auto" >
49
59
< BottomSheetParts . Header >
50
60
{ 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
+ ) ) }
52
67
</ BottomSheetParts . Header >
53
68
< Box px = "x3" py = "x4" >
54
69
{ children }
55
70
</ Box >
56
71
</ Box >
57
72
< 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 } ) }
63
78
</ Flex >
64
79
</ Flex >
65
80
</ BottomSheetParts . Footer >
0 commit comments