Skip to content

Commit ae99e17

Browse files
authored
Merge pull request #8601 from TylerAPfledderer/refactor/pill-to-badge
Convert `Pill` component to using Chakra `Badge` Component
2 parents d02ee69 + cb3a6ce commit ae99e17

File tree

15 files changed

+99
-77
lines changed

15 files changed

+99
-77
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { ComponentStyleConfig, SystemStyleObject } from "@chakra-ui/react"
2+
3+
const variantSecondary: SystemStyleObject = {
4+
borderColor: "primary100",
5+
color: "text",
6+
}
7+
8+
const variantSolid: SystemStyleObject = {
9+
color: "black300",
10+
background: "primary100",
11+
}
12+
13+
export const Badge: ComponentStyleConfig = {
14+
baseStyle: {
15+
borderRadius: "base",
16+
border: "1px solid",
17+
borderColor: "transparent",
18+
fontWeight: "initial",
19+
py: 1,
20+
px: 2,
21+
textTransform: "uppercase",
22+
},
23+
variants: {
24+
solid: variantSolid,
25+
secondary: variantSecondary,
26+
},
27+
sizes: {
28+
sm: {
29+
py: 0,
30+
},
31+
lg: {
32+
px: 3,
33+
},
34+
},
35+
defaultProps: {
36+
// Remove the default from Chakra
37+
variant: "solid",
38+
},
39+
}

src/@chakra-ui/gatsby-plugin/components/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Badge } from "./Badge"
12
import { Button } from "./Button"
23
import { Link } from "./Link"
34
import { Tag } from "./Tag"
@@ -6,6 +7,7 @@ import { Checkbox } from "./Checkbox"
67
import { Tabs } from "./Tabs"
78

89
export default {
10+
Badge,
911
Button,
1012
Link,
1113
Tag,

src/components/ProductCard.tsx

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { ReactNode } from "react"
22
import { GatsbyImage, IGatsbyImageData } from "gatsby-plugin-image"
33
import { useQuery, gql } from "@apollo/client"
44
import {
5+
Badge,
56
Box,
67
Center,
78
Flex,
@@ -36,11 +37,11 @@ const REPO_DATA = gql`
3637
}
3738
`
3839

39-
const SubjectPill: React.FC<{ subject: string; children: ReactNode }> = ({
40-
subject,
41-
children,
42-
}) => {
43-
const bgColor = () => {
40+
const SubjectBadge: React.FC<{
41+
subject: string
42+
children: React.ReactNode
43+
}> = ({ subject, children }) => {
44+
const backgroundProp = () => {
4445
switch (subject) {
4546
case "Solidity":
4647
return "tagYellow"
@@ -67,18 +68,9 @@ const SubjectPill: React.FC<{ subject: string; children: ReactNode }> = ({
6768
}
6869
}
6970
return (
70-
<Box
71-
background={bgColor()}
72-
border="1px"
73-
borderColor="lightBorder"
74-
borderRadius="base"
75-
color="black300"
76-
fontSize="xs"
77-
textAlign="center"
78-
px={2}
79-
>
71+
<Badge size="sm" textTransform="unset" background={backgroundProp()}>
8072
{children}
81-
</Box>
73+
</Badge>
8274
)
8375
}
8476

@@ -192,16 +184,16 @@ const ProductCard: React.FC<IProps> = ({
192184
<HStack mt={5} mb={2} px={6} spacing={3}>
193185
{subjects &&
194186
subjects.map((subject, idx) => (
195-
<SubjectPill key={idx} subject={subject}>
187+
<SubjectBadge key={idx} subject={subject}>
196188
{subject}
197-
</SubjectPill>
189+
</SubjectBadge>
198190
))}
199191
{hasRepoData &&
200192
data.repository.languages.nodes.map(
201193
({ name }: { name: string }, idx: number) => (
202-
<SubjectPill key={idx} subject={name}>
194+
<SubjectBadge key={idx} subject={name}>
203195
{name.toUpperCase()}
204-
</SubjectPill>
196+
</SubjectBadge>
205197
)
206198
)}
207199
</HStack>

src/components/Staking/StakingProductsCardGrid.tsx

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import React, {
77
} from "react"
88
import { shuffle } from "lodash"
99
import {
10+
Badge,
1011
Box,
1112
BoxProps,
1213
Center,
@@ -104,35 +105,21 @@ const Status: React.FC<{ status: FlagType }> = ({ status }) => {
104105
}
105106
}
106107

107-
const StakingPill: React.FC<{ type: string; children: ReactNode }> = ({
108-
type,
109-
children,
110-
}) => {
111-
const backgroundColor = () => {
112-
if (!type) return "transparent"
113-
switch (type.toLowerCase()) {
114-
case "ui":
115-
return "stakingPillUI"
116-
case "platform":
117-
return "stakingPillPlatform"
118-
default:
119-
return "tagGray"
120-
}
121-
}
108+
const StakingBadge: React.FC<{
109+
type: "ui" | "platform"
110+
children: React.ReactNode
111+
}> = ({ type, children }) => {
112+
const uiTypeColor = type === "ui" && "stakingPillUI"
113+
const platformTypeColor = type === "platform" && "stakingPillPlatform"
114+
122115
return (
123-
<Box
124-
background={backgroundColor()}
125-
border="1px"
126-
borderColor="lightBorder"
127-
borderRadius="base"
128-
color={type ? "rgba(0,0,0,0.6)" : "text200"}
129-
fontSize="xs"
130-
px={3}
131-
py={1}
132-
textAlign="center"
116+
<Badge
117+
size="lg"
118+
background={uiTypeColor || platformTypeColor || undefined}
119+
textTransform="initial"
133120
>
134121
{children}
135-
</Box>
122+
</Badge>
136123
)
137124
}
138125

@@ -281,15 +268,15 @@ const StakingProductCard: React.FC<ICardProps> = ({
281268
>
282269
{platforms &&
283270
platforms.map((platform, idx) => (
284-
<StakingPill type="platform" key={idx}>
271+
<StakingBadge type="platform" key={idx}>
285272
{platform}
286-
</StakingPill>
273+
</StakingBadge>
287274
))}
288275
{ui &&
289276
ui.map((_ui, idx) => (
290-
<StakingPill type="ui" key={idx}>
277+
<StakingBadge type="ui" key={idx}>
291278
{_ui}
292-
</StakingPill>
279+
</StakingBadge>
293280
))}
294281
</Flex>
295282
<Box {...PADDED_DIV_STYLE} py={0}>

src/components/TutorialMetadata.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from "react"
22
import { useIntl } from "react-intl"
3-
import { Box, Flex, HStack, Text } from "@chakra-ui/react"
3+
import { Badge, Box, Flex, HStack, Text } from "@chakra-ui/react"
44
import CopyToClipboard from "./CopyToClipboard"
5-
import Pill from "./Pill"
65
import Link from "./Link"
76
import TutorialTags from "./TutorialTags"
87
import { getLocaleTimestamp } from "../utils/time"
@@ -45,11 +44,11 @@ const TutorialMetadata: React.FC<IProps> = ({ tutorial }) => {
4544
<TutorialTags tags={frontmatter.tags} />
4645
</Flex>
4746
<Flex
48-
as={Pill}
47+
as={Badge}
48+
variant="secondary"
4949
alignSelf="flex-start"
5050
mb={2}
5151
whiteSpace="nowrap"
52-
isSecondary={true}
5352
>
5453
<Translation id={getSkillTranslationId(frontmatter.skill)} />
5554
</Flex>

src/components/TutorialTags.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
import { Badge } from "@chakra-ui/react"
12
import React from "react"
23

3-
import Pill from "./Pill"
4-
54
// Represent string as 32-bit integer
65
const hashCode = (string) => {
76
let hash = 0
@@ -37,9 +36,9 @@ const TutorialTags: React.FC<IProps> = ({ tags }) => {
3736
const tagColorIdx = hashCode(tag) % colors.length
3837
const tagColor = colors[tagColorIdx]
3938
return (
40-
<Pill key={idx} me={2} mb={2} background={tagColor}>
39+
<Badge key={idx} me={2} mb={2} background={tagColor}>
4140
{tag}
42-
</Pill>
41+
</Badge>
4342
)
4443
})}
4544
</>

src/pages-conditional/dapps.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { graphql, PageProps } from "gatsby"
55
import { useIntl } from "react-intl"
66

77
import Translation from "../components/Translation"
8-
import Pill from "../components/Pill"
98
import BoxGrid from "../components/BoxGrid"
109
import Card from "../components/Card"
1110
import Callout from "../components/Callout"
@@ -37,6 +36,7 @@ import FeedbackCard from "../components/FeedbackCard"
3736
import { translateMessageId } from "../utils/translations"
3837
import { getImage, getSrc } from "../utils/image"
3938
import { Context } from "../types"
39+
import { Badge } from "@chakra-ui/react"
4040

4141
const MagiciansImage = styled(GatsbyImage)`
4242
background-size: cover;
@@ -1261,7 +1261,9 @@ const DappsPage = ({
12611261
image={choice.image!}
12621262
name={choice.name}
12631263
>
1264-
<Pill color={choice.pillColor}>{choice.type}</Pill>
1264+
<Badge size="sm" background={choice.pillColor}>
1265+
{choice.type}
1266+
</Badge>
12651267
</ProductCard>
12661268
))}
12671269
</StyledCardGrid>

src/pages/developers/tutorials.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import ButtonLink from "../../components/ButtonLink"
1010
import Link from "../../components/Link"
1111
import Modal from "../../components/Modal"
1212
import PageMetadata from "../../components/PageMetadata"
13-
import Pill from "../../components/Pill"
1413
import Tag from "../../components/Tag"
1514
import TutorialTags from "../../components/TutorialTags"
1615
import Emoji from "../../components/Emoji"
@@ -31,6 +30,7 @@ import {
3130
filterTutorialsByLang,
3231
getSortedTutorialTagsForLang,
3332
} from "../../utils/tutorials"
33+
import { Badge } from "@chakra-ui/react"
3434

3535
const SubSlogan = styled.p`
3636
font-size: 1.25rem;
@@ -420,9 +420,9 @@ const TutorialsPage = ({
420420
>
421421
<TitleContainer>
422422
<Title isExternal={tutorial.isExternal}>{tutorial.title}</Title>
423-
<Pill isSecondary={true}>
423+
<Badge variant="secondary">
424424
<Translation id={getSkillTranslationId(tutorial.skill!)} />
425-
</Pill>
425+
</Badge>
426426
</TitleContainer>
427427
<Author>
428428
{/* TODO: Refactor each tutorial tag as a component */}

src/pages/layer-2.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { graphql, PageProps } from "gatsby"
44
import { GatsbyImage } from "gatsby-plugin-image"
55
import styled from "@emotion/styled"
66
import { useIntl } from "react-intl"
7+
import { Badge } from "@chakra-ui/react"
78

89
// Data
910
import layer2Data from "../data/layer-2/layer-2.json"
@@ -21,7 +22,6 @@ import Link from "../components/Link"
2122
import OrderedList from "../components/OrderedList"
2223
import PageHero from "../components/PageHero"
2324
import PageMetadata from "../components/PageMetadata"
24-
import Pill from "../components/Pill"
2525
import ProductList from "../components/ProductList"
2626
import QuizWidget from "../components/Quiz/QuizWidget"
2727
import Tooltip from "../components/Tooltip"
@@ -773,7 +773,9 @@ const Layer2Page = ({ data }: PageProps<Queries.Layer2PageQuery>) => {
773773
tokenLists={l2.tokenLists}
774774
>
775775
{l2.purpose.map((purpose, index) => (
776-
<Pill key={index}>{purpose}</Pill>
776+
<Badge key={index} me={2}>
777+
{purpose}
778+
</Badge>
777779
))}
778780
</Layer2ProductCard>
779781
)

src/templates/docs.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { graphql, PageProps } from "gatsby"
33
import { MDXProvider } from "@mdx-js/react"
44
import { MDXRenderer } from "gatsby-plugin-mdx"
55
import styled from "@emotion/styled"
6+
import { Badge } from "@chakra-ui/react"
67

78
import BannerNotification from "../components/BannerNotification"
89
import ButtonLink from "../components/ButtonLink"
@@ -15,7 +16,6 @@ import InfoBanner from "../components/InfoBanner"
1516
import Link from "../components/Link"
1617
import MarkdownTable from "../components/MarkdownTable"
1718
import PageMetadata from "../components/PageMetadata"
18-
import Pill from "../components/Pill"
1919
import TableOfContents, {
2020
Item as ItemTableOfContents,
2121
} from "../components/TableOfContents"
@@ -150,7 +150,7 @@ const components = {
150150
Card,
151151
Divider,
152152
SectionNav,
153-
Pill,
153+
Badge,
154154
CallToContribute,
155155
Emoji,
156156
DeveloperDocsLinks,

0 commit comments

Comments
 (0)