Skip to content

Commit 36bb7f2

Browse files
authored
Merge pull request #14750 from TylerAPfledderer/feat/simulator-main-shadcn
[ShadCN]: Migrate Base Simulator Content
2 parents cf0fbfc + b16fd03 commit 36bb7f2

22 files changed

+409
-257
lines changed

src/components/Simulator/ClickAnimation.tsx

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1-
import React, { useEffect, useState } from "react"
1+
import { type ReactNode, useEffect, useState } from "react"
22
import { motion, type Transition } from "framer-motion"
3-
import { createIcon, Flex, Text, TextProps } from "@chakra-ui/react"
3+
4+
import { cn } from "@/lib/utils/cn"
5+
6+
import { createIconBase } from "../icons/icon-base"
7+
import { Flex } from "../ui/flex"
48

59
const MotionFlex = motion(Flex)
610

711
const DownArrowLong = motion(
8-
createIcon({
12+
createIconBase({
913
displayName: "DownArrowLong",
1014
viewBox: "0 0 8 24",
11-
defaultProps: { fill: "currentColor" },
12-
path: (
15+
className: "fill-current",
16+
children: (
1317
<path d="M3.64645 23.3536C3.84171 23.5488 4.15829 23.5488 4.35355 23.3536L7.53553 20.1716C7.7308 19.9763 7.7308 19.6597 7.53553 19.4645C7.34027 19.2692 7.02369 19.2692 6.82843 19.4645L4 22.2929L1.17157 19.4645C0.976312 19.2692 0.659729 19.2692 0.464467 19.4645C0.269205 19.6597 0.269205 19.9763 0.464467 20.1716L3.64645 23.3536ZM3.5 2.18557e-08L3.5 23L4.5 23L4.5 -2.18557e-08L3.5 2.18557e-08Z" />
1418
),
1519
})
1620
)
1721

18-
type ClickAnimationProps = Pick<TextProps, "children"> & {
22+
type ClickAnimationProps = {
23+
children: ReactNode
1924
below?: boolean
2025
delay?: number
2126
}
@@ -34,33 +39,28 @@ export const ClickAnimation = ({
3439
times: [0, 0.25, 0.5],
3540
repeat: Infinity,
3641
}
37-
const top = below ? "calc(100% + 0.5rem)" : "auto"
38-
const bottom = below ? "auto" : "calc(100% + 1rem)"
42+
const topClass = below ? "top-[calc(100%_+_0.5rem)]" : "top-auto"
43+
const bottomClass = below ? "bottom-auto" : "bottom-[calc(100%_+_1rem)]"
3944
const y = below ? [0, 20, 0] : [0, -20, 0]
40-
const direction = below ? "column-reverse" : "column"
41-
const transformOrigin = below ? { bottom: 0 } : { top: 0 }
45+
const directionClass = below ? "flex-col-reverse" : "flex-col"
4246
const rotate = below ? 180 : 0
4347
return visible ? (
4448
<MotionFlex
49+
className={cn(
50+
"absolute inset-x-0 justify-center text-primary",
51+
topClass,
52+
bottomClass
53+
)}
4554
animate={{ opacity: [0, 1] }} // Fade in once
46-
position="absolute"
47-
top={top}
48-
justify="center"
49-
bottom={bottom}
50-
insetInline={0}
51-
color="primary.base"
55+
data-testid="click-animation-el"
5256
>
5357
<MotionFlex
54-
direction={direction}
55-
alignItems="center"
58+
className={cn("items-center", directionClass)}
5659
animate={{ y }} // Slide up and down
5760
transition={transition}
5861
>
59-
<Text fontSize="xs" fontStyle="italic" textTransform="lowercase" m={0}>
60-
{children}
61-
</Text>
62+
<p className="m-0 text-xs lowercase italic">{children}</p>
6263
<DownArrowLong
63-
transformOrigin={transformOrigin}
6464
initial={{ scaleY: 1, rotate }}
6565
animate={{ scaleY: [1, 1.25, 1] }} // Arrow scales up and down
6666
transition={transition}

src/components/Simulator/Explanation.tsx

Lines changed: 32 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import React from "react"
22
import { motion } from "framer-motion"
33
import { MdArrowBack } from "react-icons/md"
4-
import { Box, Flex, Grid, Heading, Text } from "@chakra-ui/react"
54

65
import type { SimulatorNavProps } from "@/lib/types"
76

8-
import { Button, ButtonLink } from "../Buttons"
7+
import { cn } from "@/lib/utils/cn"
8+
9+
import { Button, ButtonLink } from "../ui/buttons/Button"
10+
import { Flex } from "../ui/flex"
911

1012
import type {
1113
LabelHref,
@@ -43,74 +45,51 @@ export const Explanation = ({
4345
hidden: { opacity: 0 },
4446
}
4547
return (
46-
<Flex direction="column" flex={1} zIndex={1}>
48+
<Flex className="z-[1] flex-1 flex-col">
4749
{/* Back button */}
4850
<Button
49-
as={motion.button}
5051
variant="ghost"
51-
leftIcon={<MdArrowBack size="18px" />}
52-
sx={{ paddingInlineStart: 0 }}
53-
mt={{ base: -6, md: 0 }}
54-
mb={{ base: 2, md: 8 }}
52+
className={cn(
53+
"-mt-6 mb-2 w-fit ps-0 [transition-duration:10ms] md:mb-8 md:mt-0",
54+
step === 0 ? "pointer-events-none" : "pointer-events-auto"
55+
)}
5556
onClick={regressStepper}
56-
pointerEvents={step === 0 ? "none" : "all"}
57-
variants={backButtonVariants}
58-
initial="hidden"
59-
animate={step === 0 ? "hidden" : "visible"}
60-
transitionDuration="10ms"
61-
w="fit-content"
57+
asChild
6258
>
63-
Back
59+
<motion.button
60+
initial="hidden"
61+
variants={backButtonVariants}
62+
animate={step === 0 ? "hidden" : "visible"}
63+
>
64+
<MdArrowBack size="18px" />
65+
Back
66+
</motion.button>
6467
</Button>
65-
<Flex direction={{ base: "row", md: "column" }} gap={{ base: 3, md: 2 }}>
68+
<Flex className="gap-3 md:flex-col md:gap-2">
6669
{/* Step counter */}
67-
<Grid
68-
placeItems="center"
69-
bg="body.light"
70-
borderRadius="lg"
71-
p={2}
72-
w={9}
73-
h={8}
74-
fontSize="xs"
75-
>
76-
<Text as="span" lineHeight={1} fontWeight="bold" m={0}>
70+
<div className="grid h-8 w-9 place-items-center rounded-lg bg-body-light p-2 text-xs">
71+
<span className="font-bold leading-none">
7772
{step + 1}/{totalSteps}
78-
</Text>
79-
</Grid>
73+
</span>
74+
</div>
8075
{/* Header and description */}
81-
<Box>
82-
<Heading
83-
as="h3"
84-
fontSize={{ base: "xl", sm: "2xl", md: "3xl", lg: "4xl" }}
85-
lineHeight={{ base: 8, md: 10 }}
86-
mt={0}
87-
mb={{ base: 4, md: 8 }}
88-
>
76+
<div>
77+
<h3 className="mb-4 mt-0 text-xl leading-8 sm:text-2xl md:mb-8 md:text-3xl md:leading-10 lg:text-4xl">
8978
{header}
90-
</Heading>
79+
</h3>
9180
{description && (
92-
<Box display={{ base: "block", md: "none" }} position="relative">
81+
<div className="relative md:hidden">
9382
<MoreInfoPopover isFirstStep={nav.step === 0}>
94-
<Box>{description}</Box>
83+
<div>{description}</div>
9584
</MoreInfoPopover>
96-
</Box>
85+
</div>
9786
)}
98-
</Box>
87+
</div>
9988
</Flex>
100-
{description && (
101-
<Box display={{ base: "none", md: "block" }}>{description}</Box>
102-
)}
89+
{description && <div className="max-md:hidden">{description}</div>}
10390
{/* Last step navigation buttons */}
10491
{isLastStep && (
105-
<Flex
106-
direction="column"
107-
gap={4}
108-
maxW="300px"
109-
w="full"
110-
mx={{ base: "auto", md: 0 }}
111-
mt={4}
112-
zIndex={-1}
113-
>
92+
<Flex className="z-[-1] mx-auto mt-4 w-full max-w-[300px] flex-col gap-4 md:mx-0">
11493
{nextPathSummary && openPath && nextPathId && (
11594
<PathButton
11695
pathSummary={nextPathSummary}

src/components/Simulator/MoreInfoPopover.tsx

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,47 @@
1-
import React, { useState } from "react"
1+
import { type ReactNode, useState } from "react"
22
import { motion } from "framer-motion"
3-
import { MdInfoOutline } from "react-icons/md"
3+
import { MdClose, MdInfoOutline } from "react-icons/md"
4+
5+
import { Button } from "../ui/buttons/Button"
46
import {
5-
Button,
6-
Icon,
77
Popover,
8-
PopoverArrow,
9-
PopoverBody,
10-
type PopoverBodyProps,
11-
PopoverCloseButton,
8+
PopoverClose,
129
PopoverContent,
1310
PopoverTrigger,
14-
} from "@chakra-ui/react"
11+
} from "../ui/popover"
1512

1613
import { PulseAnimation } from "./PulseAnimation"
1714

1815
const MotionButton = motion(Button)
1916

20-
type MoreInfoPopover = Pick<PopoverBodyProps, "children"> & {
17+
type MoreInfoPopover = {
2118
isFirstStep: boolean
19+
children: ReactNode
2220
}
2321
export const MoreInfoPopover = ({ isFirstStep, children }: MoreInfoPopover) => {
2422
const [clicked, setClicked] = useState(false)
2523
return (
2624
<Popover>
27-
<PopoverTrigger>
25+
<PopoverTrigger asChild>
2826
<MotionButton
29-
rightIcon={<Icon as={MdInfoOutline} size={24} />}
3027
variant="ghost"
31-
sx={{ paddingInlineStart: 0 }}
32-
color="body.medium"
33-
fontSize="sm"
34-
p={0}
28+
className="relative min-h-0 p-0 text-sm text-body-medium"
3529
onClick={() => setClicked(true)}
36-
position="relative"
30+
data-testid="more-info-popover-trigger"
3731
>
3832
More info
33+
<MdInfoOutline size={24} />
3934
{isFirstStep && !clicked && <PulseAnimation type="narrow-button" />}
4035
</MotionButton>
4136
</PopoverTrigger>
4237
<PopoverContent
43-
px={4}
44-
py={6}
45-
insetStart={{ base: 4, sm: 8 }}
46-
w={{ base: "calc(100vw - 3rem)", sm: "calc(100vw - 5rem)" }}
38+
className="relative start-4 w-[calc(100vw-3rem)] max-w-xs bg-background-highlight px-4 py-6 text-sm shadow-none sm:start-8 sm:w-[calc(100vw-5rem)]"
39+
data-testid="more-info-popover-content"
4740
>
48-
<PopoverArrow />
49-
<PopoverCloseButton ms="auto" />
50-
<PopoverBody sx={{ "p:last-of-type": { mb: 2 } }}>
51-
{children}
52-
</PopoverBody>
41+
<PopoverClose className="absolute right-2 top-1 ms-auto flex size-6 items-center justify-center text-xl leading-none">
42+
<MdClose />
43+
</PopoverClose>
44+
<div className="px-3 py-2 last-of-type:[&_p]:mb-2">{children}</div>
5345
</PopoverContent>
5446
</Popover>
5547
)

src/components/Simulator/NotificationPopover.tsx

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,45 @@
11
import React, { type ReactNode } from "react"
2+
import { MdClose } from "react-icons/md"
3+
4+
import { Flex } from "../ui/flex"
25
import {
3-
Flex,
46
Popover,
5-
PopoverBody,
6-
PopoverCloseButton,
7+
PopoverClose,
78
PopoverContent,
8-
PopoverContentProps,
9-
PopoverHeader,
10-
PopoverProps,
9+
type PopoverContentProps,
1110
PopoverTrigger,
12-
} from "@chakra-ui/react"
11+
} from "../ui/popover"
1312

14-
type NotificationPopoverProps = Omit<PopoverContentProps, "children"> &
15-
Pick<PopoverProps, "placement"> & {
16-
children: ReactNode
17-
}
13+
type NotificationPopoverProps = Omit<
14+
PopoverContentProps,
15+
"children" | "className"
16+
> & {
17+
children: ReactNode
18+
}
1819
export const NotificationPopover = ({
19-
placement,
2020
children,
2121
content,
2222
title,
2323
...restProps
2424
}: NotificationPopoverProps) => {
2525
return (
26-
<Popover placement={placement}>
27-
<PopoverTrigger>{children}</PopoverTrigger>
28-
<PopoverContent px={4} py={2} maxW="15rem" fontSize="xs" {...restProps}>
29-
<Flex gap={2}>
30-
<PopoverHeader fontWeight="bold" mb={2} flex={1} mt={0.5} p={0}>
26+
<Popover>
27+
<PopoverTrigger asChild className="text-start">
28+
<div>{children}</div>
29+
</PopoverTrigger>
30+
<PopoverContent
31+
className="max-w-[15rem] px-4 py-2 text-xs"
32+
{...restProps}
33+
>
34+
<Flex className="gap-2">
35+
<header className="mb-2 mt-0.5 flex-1 p-0 font-bold">
3136
{title || ""}
32-
</PopoverHeader>
33-
<PopoverCloseButton ms="auto" />
37+
</header>
38+
<PopoverClose className="absolute right-2 top-1 ms-auto flex size-6 items-center justify-center text-xl leading-none">
39+
<MdClose />
40+
</PopoverClose>
3441
</Flex>
35-
<PopoverBody p={0}>{content}</PopoverBody>
42+
<div>{content}</div>
3643
</PopoverContent>
3744
</Popover>
3845
)

src/components/Simulator/PathButton.tsx

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React from "react"
2-
import { Button, Flex, Text } from "@chakra-ui/react"
1+
import { Button } from "../ui/buttons/Button"
2+
import { Flex } from "../ui/flex"
33

44
import type { SimulatorPathSummary } from "./interfaces"
55

@@ -9,38 +9,27 @@ type PathButtonProps = {
99
}
1010
export const PathButton = ({ pathSummary, handleClick }: PathButtonProps) => {
1111
const { primaryText, secondaryText, Icon } = pathSummary
12+
// TODO: Convert this component to use ButtonLinkTwoLines
1213
return (
1314
<Button
1415
variant="outline"
15-
leftIcon={<Icon />}
16-
justifyContent="start"
17-
gap={3}
18-
textAlign="start"
19-
w="full"
20-
py={6}
16+
className="w-full justify-start gap-3 py-6 text-start"
2117
onClick={handleClick}
2218
>
23-
<Flex direction="column" as="span">
24-
<Text
25-
as="span"
26-
fontWeight="bold"
27-
m={0}
28-
lineHeight={6}
29-
letterSpacing="-1.1%"
30-
>
31-
{primaryText}
32-
</Text>
33-
{secondaryText && (
34-
<Text
35-
as="span"
36-
m={0}
37-
color="body.medium"
38-
fontSize="xs"
39-
lineHeight={5}
40-
>
41-
{secondaryText}
42-
</Text>
43-
)}
19+
<span className="me-2">
20+
<Icon />
21+
</span>
22+
<Flex className="flex-col" asChild>
23+
<span>
24+
<span className="m-0 font-bold leading-6 tracking-[-1.1%]">
25+
{primaryText}
26+
</span>
27+
{secondaryText && (
28+
<span className="m-0 text-xs leading-5 text-body-medium">
29+
{secondaryText}
30+
</span>
31+
)}
32+
</span>
4433
</Flex>
4534
</Button>
4635
)

0 commit comments

Comments
 (0)