Skip to content

Commit 874ca63

Browse files
authored
Merge pull request #14804 from JoeChenJ/Shadcn_Migrate_InfoBanner.tsx
Shadcn Migrate: InfoBanner.tsx
2 parents 1255d9e + f6cdb0e commit 874ca63

File tree

4 files changed

+42
-40
lines changed

4 files changed

+42
-40
lines changed

src/components/InfoBanner.tsx

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import type { ReactNode } from "react"
2-
import { Flex, type FlexProps, LightMode } from "@chakra-ui/react"
32

43
import Emoji from "@/components/Emoji"
5-
import Text from "@/components/OldText"
64

7-
type InfoBannerProps = FlexProps & {
5+
import { cn } from "@/lib/utils/cn"
6+
7+
import { Flex, VStack } from "./ui/flex"
8+
9+
type InfoBannerProps = {
810
children?: ReactNode
911
emoji?: string
1012
isWarning?: boolean
1113
shouldCenter?: boolean
1214
shouldSpaceBetween?: boolean
1315
title?: string
16+
id?: string
17+
className?: string
1418
}
1519

1620
const InfoBanner = ({
@@ -20,47 +24,45 @@ const InfoBanner = ({
2024
shouldCenter,
2125
shouldSpaceBetween,
2226
title,
27+
className,
2328
...props
2429
}: InfoBannerProps) => {
2530
const banner = (
26-
<LightMode>
31+
<VStack
32+
className={cn(
33+
"rounded-sm p-6 sm:flex-row",
34+
shouldCenter ? "max-w-[55rem]" : "max-w-full",
35+
isWarning
36+
? "bg-warning-light dark:text-body-inverse"
37+
: "bg-primary-low-contrast",
38+
className
39+
)}
40+
{...props}
41+
>
42+
{emoji && (
43+
<Emoji
44+
className="mb-2 me-0 flex-shrink-0 flex-grow-0 self-start text-4xl sm:mb-0 sm:me-6 sm:self-auto"
45+
text={emoji}
46+
/>
47+
)}
2748
<Flex
28-
align="center"
29-
p="6"
30-
borderRadius="sm"
31-
maxW={shouldCenter ? "55rem" : "100%"}
32-
sx={{
33-
":not(button)": {
34-
color: "black300 !important",
35-
},
36-
}}
37-
bg={isWarning ? "warning" : "infoBanner"}
38-
direction={{ base: "column", sm: "row" }}
39-
{...props}
40-
>
41-
{emoji && (
42-
<Emoji
43-
className="mb-2 me-0 flex-shrink-0 flex-grow-0 self-start text-4xl sm:mb-0 sm:me-6 sm:self-auto"
44-
text={emoji}
45-
/>
49+
className={cn(
50+
"block",
51+
shouldSpaceBetween
52+
? "w-full items-center justify-between sm:flex"
53+
: "w-auto sm:block"
4654
)}
47-
<Flex
48-
display={{ base: "block", sm: shouldSpaceBetween ? "flex" : "block" }}
49-
align={shouldSpaceBetween ? "center" : "auto"}
50-
w={shouldSpaceBetween ? "100%" : "auto"}
51-
justify={shouldSpaceBetween ? "space-between" : "auto"}
52-
>
53-
{title && (
54-
<Text fontSize="lg" fontWeight="bold">
55-
{title}
56-
</Text>
57-
)}
58-
{children}
59-
</Flex>
55+
>
56+
{title && <p className="mb-6 text-lg font-bold">{title}</p>}
57+
{children}
6058
</Flex>
61-
</LightMode>
59+
</VStack>
60+
)
61+
return shouldCenter ? (
62+
<Flex className="justify-center">{banner}</Flex>
63+
) : (
64+
banner
6265
)
63-
return shouldCenter ? <Flex justify="center">{banner}</Flex> : banner
6466
}
6567

6668
export default InfoBanner

src/pages/dapps.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ const StyledH3 = (props: ChildOnlyProp) => (
219219
)
220220

221221
const StyledInfoBanner = (props: ComponentPropsWithRef<typeof InfoBanner>) => (
222-
<InfoBanner w={{ lg: "50%" }} {...props} />
222+
<InfoBanner className="lg:w-1/2" {...props} />
223223
)
224224

225225
const Column = (props: ChildOnlyProp) => (

src/pages/gas.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ const GasPage = () => {
179179
w="full"
180180
>
181181
<Box flex="60%" w="full" me={{ base: "auto", lg: 2 }}>
182-
<InfoBanner mb={8} title={t("page-gas-summary-title")}>
182+
<InfoBanner className="mb-8" title={t("page-gas-summary-title")}>
183183
<UnorderedList>
184184
<ListItem>{t("page-gas-summary-item-1")}</ListItem>
185185
<ListItem>{t("page-gas-summary-item-2")}</ListItem>

src/pages/stablecoins.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ const StablecoinsPage = ({ markets, marketsHasError }) => {
546546
<MdHelpOutline className="ms-2 fill-body" size={16} />
547547
</Tooltip>
548548
</H3>
549-
<InfoBanner emoji="⚠️" isWarning mb="4">
549+
<InfoBanner className="mb-4" emoji="⚠️" isWarning>
550550
{t("page-stablecoins-algorithmic-disclaimer")}
551551
</InfoBanner>
552552
<p className="mb-6">

0 commit comments

Comments
 (0)