Skip to content

Commit 0f85fe2

Browse files
committed
revert codemodal changes and implement custom variant in component definition
1 parent 22c7d02 commit 0f85fe2

File tree

4 files changed

+83
-29
lines changed

4 files changed

+83
-29
lines changed

src/@chakra-ui/components/Modal.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,15 @@ export const Modal = defineMultiStyleConfig({
2323
boxShadow: "none",
2424
},
2525
header: {
26+
flex: "1",
2627
padding: "0",
2728
fontWeight: "bold",
2829
fontSize: "2xl",
29-
minHeight: "6",
3030
me: "8",
3131
},
3232
closeButton: {
33-
boxSize: "8",
33+
position: "static",
3434
color: "body.base",
35-
top: "8",
36-
insetInlineEnd: "8",
3735
},
3836
body: {
3937
padding: "0",

src/components/CodeModal.tsx

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import type { ReactNode } from "react"
2+
import {
3+
Modal,
4+
ModalBody,
5+
ModalCloseButton,
6+
ModalContent,
7+
ModalHeader,
8+
ModalOverlay,
9+
useColorModeValue,
10+
} from "@chakra-ui/react"
11+
12+
type CodeModalProps = {
13+
title: string
14+
children: ReactNode
15+
isOpen: boolean
16+
setIsOpen: (isOpen: boolean) => void
17+
}
18+
19+
const CodeModal = ({ children, isOpen, setIsOpen, title }: CodeModalProps) => {
20+
const bgColor = useColorModeValue("rgb(247, 247, 247)", "rgb(25, 25, 25)")
21+
const borderColor = useColorModeValue("rgb(51, 51, 51)", "rgb(242, 242, 242)")
22+
23+
return (
24+
<Modal
25+
isOpen={isOpen}
26+
scrollBehavior="inside"
27+
onClose={() => setIsOpen(false)}
28+
>
29+
<ModalOverlay />
30+
<ModalContent
31+
maxW="100vw"
32+
marginTop="auto"
33+
marginBottom="0"
34+
maxHeight="50%"
35+
borderRadius="0"
36+
p="0"
37+
gap="0"
38+
>
39+
<ModalHeader
40+
bg={bgColor}
41+
borderColor={borderColor}
42+
borderTop="1px solid"
43+
borderBottom="1px solid"
44+
textTransform="uppercase"
45+
fontWeight="normal"
46+
fontSize="md"
47+
fontFamily="monospace"
48+
px="6"
49+
py="4"
50+
me="0"
51+
>
52+
{title}
53+
</ModalHeader>
54+
<ModalCloseButton
55+
position="absolute"
56+
padding="0"
57+
width="24px"
58+
height="24px"
59+
borderRadius="0"
60+
color="rgb(178, 178, 178)"
61+
fontSize="sm"
62+
margin="0"
63+
top="4"
64+
insetInlineEnd="4"
65+
bottom="4"
66+
/>
67+
<ModalBody p="0">{children}</ModalBody>
68+
</ModalContent>
69+
</Modal>
70+
)
71+
}
72+
73+
export default CodeModal

src/components/Modal/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from "react"
22
import {
33
Button,
4+
HStack,
45
Modal as ChakraModal,
56
ModalBody,
67
ModalCloseButton,
@@ -31,8 +32,10 @@ const Modal = ({
3132
<ModalOverlay />
3233

3334
<ModalContent {...contentProps}>
34-
<ModalHeader>{title}</ModalHeader>
35-
<ModalCloseButton />
35+
<HStack>
36+
<ModalHeader>{title}</ModalHeader>
37+
<ModalCloseButton />
38+
</HStack>
3639
<ModalBody>{children}</ModalBody>
3740
{actionButtonLabel && (
3841
<ModalFooter>

src/pages/index.tsx

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import ActionCard from "@/components/ActionCard"
2525
import ButtonLink from "@/components/Buttons/ButtonLink"
2626
import CalloutBanner from "@/components/CalloutBanner"
2727
import Codeblock from "@/components/Codeblock"
28+
import CodeModal from "@/components/CodeModal"
2829
import CommunityEvents from "@/components/CommunityEvents"
2930
import HomeHero from "@/components/Hero/HomeHero"
3031
import { Image } from "@/components/Image"
@@ -121,8 +122,6 @@ const StyledActionCard = chakra(ActionCard, {
121122
},
122123
})
123124

124-
const StyledCodeModal = chakra(Modal)
125-
126125
const StyledTitleCardList = chakra(TitleCardList)
127126

128127
const GrayContainer = (props: ChildOnlyProp) => (
@@ -535,29 +534,10 @@ const HomePage = ({
535534
</ButtonLink>
536535
</ButtonLinkRow>
537536
</FeatureContent>
538-
<StyledCodeModal
537+
<CodeModal
539538
isOpen={isModalOpen}
540539
setIsOpen={setModalOpen}
541540
title={codeExamples[activeCode].title}
542-
sx={{
543-
".modal-component-container": {
544-
padding: 0,
545-
left: 0,
546-
right: 0,
547-
bottom: 0,
548-
top: "50%",
549-
},
550-
".modal-component": {
551-
maxWidth: "100%",
552-
maxHeight: "50%",
553-
padding: 0,
554-
},
555-
".modal-component-content": {
556-
marginTop: "3rem",
557-
width: "100%",
558-
overflow: "auto",
559-
},
560-
}}
561541
>
562542
<Codeblock
563543
codeLanguage={codeExamples[activeCode].codeLanguage}
@@ -566,7 +546,7 @@ const HomePage = ({
566546
>
567547
{codeExamples[activeCode].code}
568548
</Codeblock>
569-
</StyledCodeModal>
549+
</CodeModal>
570550
</Row>
571551
</MainSectionContainer>
572552
{/* Eth Today Section */}

0 commit comments

Comments
 (0)