Skip to content

Commit bf3f122

Browse files
authored
Merge pull request #13970 from TylerAPfledderer/refactor/icons-to-IconBase
[ShadCN] refactor(icons): use react-icons `IconBase` composition
2 parents 00b026e + ce1f2e9 commit bf3f122

File tree

94 files changed

+1821
-1749
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+1821
-1749
lines changed

src/components/ExpandableCard.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ import {
1212
AccordionTrigger,
1313
} from "../../tailwind/ui/accordion"
1414

15+
import type { IconBaseType } from "./icons/icon-base"
16+
1517
export type ExpandableCardProps = {
1618
children?: ReactNode
1719
contentPreview?: ReactNode
1820
title: ReactNode
19-
svg?: React.ElementType
21+
svg?: IconBaseType
2022
eventAction?: string
2123
eventCategory?: string
2224
eventName?: string

src/components/FindWallet/WalletFilterFeature.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ const WalletFilterFeature = ({
182182
}
183183
>
184184
<GridItem>
185-
<LabelIcon boxSize={7} mt={0.5} aria-hidden />
185+
<LabelIcon className="mt-0.5 size-7" aria-hidden />
186186
</GridItem>
187187

188188
<GridItem as="span" lineHeight="1.1rem">

src/components/Quiz/QuizWidget/AnswerIcon.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type AnswerIconProps = {
1818
*/
1919
export const AnswerIcon = ({ answerStatus }: AnswerIconProps) => {
2020
const commonProps = {
21-
color: "neutral",
21+
className: "text-body-inverse",
2222
}
2323

2424
const IconWrapper = (props: ChildOnlyProp) => {
Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
1-
import * as React from "react"
2-
import { IconProps } from "@chakra-ui/react"
1+
import { StarConfettiIcon } from "@/components/icons/quiz/StarConfettiIcon"
32

4-
import { StarConfettiIcon } from "../../icons/quiz"
3+
import { cn } from "@/lib/utils/cn"
54

65
export const QuizConfetti = () => {
7-
const commonProps: IconProps = {
8-
fontSize: "184px",
9-
position: "absolute",
10-
top: 0,
11-
}
6+
const commonClasses = "h-[119px] absolute top-0"
127
return (
138
<>
14-
<StarConfettiIcon {...commonProps} insetInlineStart={0} />
9+
<StarConfettiIcon className={cn(commonClasses, "left-0")} />
1510

16-
<StarConfettiIcon
17-
{...commonProps}
18-
insetInlineEnd={0}
19-
transform="scaleX(-100%)"
20-
/>
11+
<StarConfettiIcon className={cn(commonClasses, "right-0 -scale-x-100")} />
2112
</>
2213
)
2314
}

src/components/Quiz/QuizzesStats.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ const QuizzesStats = ({
117117
justify={{ base: "center", lg: "flex-start" }}
118118
>
119119
<Circle size="64px" bg="primary.base">
120-
<TrophyIcon color="neutral" w="35.62px" h="35.62px" />
120+
<TrophyIcon className="w-[35.62px] text-body-inverse" />
121121
</Circle>
122122
<Text as="span" fontWeight="bold" fontSize="5xl">
123123
<Highlight

src/components/Staking/StakingComparison.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ const StakingComparison = ({ page, className }: StakingComparisonProps) => {
4646
eventName: "clicked solo staking",
4747
},
4848
color: stakingGold,
49-
glyph: <StakingGlyphCPUIcon color="stakingGold" boxSize="50px" />,
49+
glyph: (
50+
<StakingGlyphCPUIcon className="h-[50px] w-[50px]" color="stakingGold" />
51+
),
5052
}
5153
const saas: DataType = {
5254
title: "page-staking-saas-with-abbrev",
@@ -58,7 +60,12 @@ const StakingComparison = ({ page, className }: StakingComparisonProps) => {
5860
eventName: "clicked staking as a service",
5961
},
6062
color: stakingGreen,
61-
glyph: <StakingGlyphCloudIcon color="stakingGreen" w="50px" h="28px" />,
63+
glyph: (
64+
<StakingGlyphCloudIcon
65+
className="h-[28px] w-[50px]"
66+
color="stakingGreen"
67+
/>
68+
),
6269
}
6370
const pools: DataType = {
6471
title: "page-staking-dropdown-pools",
@@ -71,7 +78,10 @@ const StakingComparison = ({ page, className }: StakingComparisonProps) => {
7178
},
7279
color: stakingBlue,
7380
glyph: (
74-
<StakingGlyphTokenWalletIcon color="stakingBlue" w="50px" h="39px" />
81+
<StakingGlyphTokenWalletIcon
82+
className="h-[39px] w-[50px]"
83+
color="stakingBlue"
84+
/>
7585
),
7686
}
7787
const data: {

src/components/icons/Icons.stories.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { HighlightDarkIcon } from "./HighlightDarkIcon"
88
import { HighlightIcon } from "./HighlightIcon"
99
import {
1010
CorrectIcon,
11+
GreenTickIcon,
1112
IncorrectIcon,
1213
StarConfettiIcon,
1314
TrophyIcon,
@@ -31,15 +32,20 @@ import {
3132
AuditedIcon,
3233
AvadoGlyphIcon,
3334
BattleTestedIcon,
35+
BedrockGlyphIcon,
3436
BugBountyIcon,
3537
CautionProductGlyphIcon,
38+
ChainLaboGlyphIcon,
39+
ConsensysStakingGlyphIcon,
3640
DefaultOpenSourceGlyphIcon,
3741
DockerGlyphIcon,
3842
EconomicalIcon,
3943
EthpoolGlyphIcon,
44+
EverstakeGlyphIcon,
4045
FigmentGlyphIcon,
4146
GreenCheckProductGlyphIcon,
4247
KilnGlyphIcon,
48+
LaunchnodesGlyphIcon,
4349
LidoGlyphIcon,
4450
LiquidityTokenIcon,
4551
MultiClientIcon,
@@ -49,6 +55,8 @@ import {
4955
RocketPoolGlyphIcon,
5056
RockXGlyphIcon,
5157
SelfCustodyIcon,
58+
SenseiNodeGlyphIcon,
59+
SquidGlyphIcon,
5260
StafiGlyphIcon,
5361
StakefishGlyphIcon,
5462
StakewiseGlyphIcon,
@@ -98,6 +106,7 @@ export default meta
98106
const iconsDefinitions = [
99107
CorrectIcon,
100108
IncorrectIcon,
109+
GreenTickIcon,
101110
StarConfettiIcon,
102111
TrophyIcon,
103112
DappnodeIcon,
@@ -116,17 +125,22 @@ const iconsDefinitions = [
116125
AuditedIcon,
117126
AvadoGlyphIcon,
118127
BattleTestedIcon,
128+
BedrockGlyphIcon,
119129
BugBountyIcon,
120130
CautionProductGlyphIcon,
131+
ChainLaboGlyphIcon,
132+
ConsensysStakingGlyphIcon,
121133
StakingDappnodeGlyphIcon,
122134
DefaultOpenSourceGlyphIcon,
123135
DockerGlyphIcon,
124136
EconomicalIcon,
125137
EthpoolGlyphIcon,
138+
EverstakeGlyphIcon,
126139
FigmentGlyphIcon,
127140
GreenCheckProductGlyphIcon,
128141
P2PGlyphIcon,
129142
KilnGlyphIcon,
143+
LaunchnodesGlyphIcon,
130144
LidoGlyphIcon,
131145
LiquidityTokenIcon,
132146
MultiClientIcon,
@@ -135,6 +149,7 @@ const iconsDefinitions = [
135149
RocketPoolGlyphIcon,
136150
RockXGlyphIcon,
137151
SelfCustodyIcon,
152+
SenseiNodeGlyphIcon,
138153
StafiGlyphIcon,
139154
StakefishGlyphIcon,
140155
StakewiseGlyphIcon,
@@ -144,6 +159,7 @@ const iconsDefinitions = [
144159
StakingGlyphEtherCircleIcon,
145160
StakingGlyphTokenWalletIcon,
146161
StereumGlyphIcon,
162+
SquidGlyphIcon,
147163
TrustlessIcon,
148164
UnknownProductGlyphIcon,
149165
WagyuGlyphIcon,
@@ -178,9 +194,9 @@ const iconsDefinitions = [
178194
iconsDefinitions.sort((a, b) =>
179195
(a?.displayName || "") > (b?.displayName || "") ? 1 : -1
180196
)
181-
const items = iconsDefinitions.map((IconDef) => (
197+
const items = iconsDefinitions.map((IconDef, idx) => (
182198
<Flex
183-
key={IconDef.displayName}
199+
key={idx}
184200
direction="column"
185201
gap={4}
186202
p={4}
@@ -189,7 +205,12 @@ const items = iconsDefinitions.map((IconDef) => (
189205
borderColor="background.highlight"
190206
>
191207
<Center>
192-
<IconDef w="50px" h="50px" />
208+
<IconDef
209+
className="h-[50px] w-[50px]"
210+
// TODO: remove the following two props when migrations are complete
211+
w="50px"
212+
h="50px"
213+
/>
193214
</Center>
194215
<Center>{IconDef.displayName}</Center>
195216
</Flex>

src/components/icons/icon-base.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { IconBase as ReactIconBase, type IconBaseProps } from "react-icons"
2+
3+
import { cn } from "@/lib/utils/cn"
4+
5+
/**
6+
* Wrapper to generate an icon component, using the react-icons `IconBase` component.
7+
* Requires setting `displayName` and `children` props.
8+
*
9+
* **NOTE:** Setting SVG attributes in the `options` object become default values, which are overriden when passing props on render.
10+
*/
11+
export const createIconBase = (
12+
options: IconBaseProps & {
13+
displayName: string
14+
}
15+
) => {
16+
const {
17+
children,
18+
displayName,
19+
className: defaultClassName,
20+
...defaultProps
21+
} = options
22+
23+
const Comp = ({ className, ...props }: IconBaseProps) => {
24+
return (
25+
<ReactIconBase
26+
className={cn(defaultClassName, className)}
27+
// Remove default props that come from `ReactIconBase` with `undefined`
28+
strokeWidth={undefined}
29+
stroke={undefined}
30+
{...defaultProps}
31+
{...props}
32+
>
33+
{children}
34+
</ReactIconBase>
35+
)
36+
}
37+
38+
Comp.displayName = displayName
39+
40+
return Comp
41+
}
42+
43+
export type IconBaseType = ReturnType<typeof createIconBase>
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { createIcon } from "@chakra-ui/react"
1+
import { createIconBase } from "../icon-base"
22

3-
export const CorrectIcon = createIcon({
3+
export const CorrectIcon = createIconBase({
44
displayName: "CorrectIcon",
55
viewBox: "0 0 20 16",
6-
defaultProps: {
7-
width: "20px",
8-
height: "16px",
9-
},
10-
d: "M8 16L0 9.05375L2.75437 7.06313L7.49875 11.4325L16.8531 0L20 2L8 16Z",
6+
className: "h-auto w-[20px]",
7+
children: (
8+
<path d="M8 16L0 9.05375L2.75437 7.06313L7.49875 11.4325L16.8531 0L20 2L8 16Z" />
9+
),
1110
})

src/components/icons/quiz/GreenTickIcon.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import * as React from "react"
2-
import { createIcon } from "@chakra-ui/react"
32

4-
export const GreenTickIcon = createIcon({
3+
import { createIconBase } from "../icon-base"
4+
5+
export const GreenTickIcon = createIconBase({
56
displayName: "GreenTickIcon",
67
viewBox: "0 0 16 16",
7-
path: (
8+
children: (
89
<g>
910
<rect width={16} height={16} fill="#c8f7d8" rx={8} />
1011
<path

0 commit comments

Comments
 (0)