Skip to content

Commit

Permalink
refactor(Breadcrumbs): update style usage
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerAPfledderer committed Sep 27, 2023
1 parent 34f3fec commit 61be715
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 42 deletions.
45 changes: 45 additions & 0 deletions src/@chakra-ui/gatsby-plugin/components/Breadcrumb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { createMultiStyleConfigHelpers } from "@chakra-ui/react"
import { breadcrumbAnatomy } from "@chakra-ui/anatomy"
import { breadcrumbDefaultTheme, defineMergeStyles } from "./components.utils"

const { defineMultiStyleConfig } = createMultiStyleConfigHelpers(
breadcrumbAnatomy.keys
)

const baseStyle = defineMergeStyles(breadcrumbDefaultTheme.baseStyle, {
list: {
m: 0,
lineHeight: "base",
flexWrap: "wrap",
},
item: {
color: "body.medium",
letterSpacing: "wider",
m: 0,
},
link: {
fontWeight: "normal",
_hover: {
color: "primary.base",
textDecor: "none",
},
_active: {
color: "primary.base",
},
/*
* `&[aria-current="page"]`
* Redundancy to ensure styling on the active
* link is applied.
*/
_activeLink: {
color: "primary.base",
},
},
separator: {
mx: "2.5",
},
})

export const Breadcrumb = defineMultiStyleConfig({
baseStyle,
})
4 changes: 2 additions & 2 deletions src/@chakra-ui/gatsby-plugin/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Alert } from "./Alert"
import { Avatar } from "./Avatar"
import { Badge } from "./Badge"
import { Button } from "./Button"
import { Breadcrumb } from "./Breadcrumb"
import { Heading } from "./Heading"
import { Link } from "./Link"
import { Tag } from "./Tag"
Expand All @@ -17,7 +18,6 @@ import { Switch } from "./Switch"
import { Input } from "./Input"
import {
accordionDefaultTheme,
breadcrumbDefaultTheme,
closeButtonDefaultTheme,
codeDefaultTheme,
dividerDefaultTheme,
Expand All @@ -34,7 +34,7 @@ export default {
Alert,
Avatar,
Badge,
Breadcrumb: breadcrumbDefaultTheme,
Breadcrumb,
Button,
Checkbox,
CloseButton: closeButtonDefaultTheme,
Expand Down
5 changes: 3 additions & 2 deletions src/components/Breadcrumbs/Breadcrumbs.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from "react"
import { Meta, StoryObj } from "@storybook/react"
import { Stack } from "@chakra-ui/react"
import BreadcrumbsComponent from "."

type BreadcumbsType = typeof BreadcrumbsComponent
Expand All @@ -15,10 +16,10 @@ type Story = StoryObj<typeof meta>

export const Breadcrumbs: Story = {
render: () => (
<>
<Stack spacing="8">
<BreadcrumbsComponent slug="/en/staking/" />
<BreadcrumbsComponent slug="/en/staking/solo/" />
<BreadcrumbsComponent slug="/en/roadmap/merge/issuance/" />
</>
</Stack>
),
}
34 changes: 2 additions & 32 deletions src/components/Breadcrumbs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,45 +68,15 @@ const Breadcrumbs: React.FC<IProps> = ({
.slice(startDepth)

return (
<Breadcrumb
dir="auto"
position="relative"
zIndex="1"
mb={8}
spacing="2.5"
listProps={{
m: 0,
lineHeight: 1.6,
flexWrap: "wrap",
}}
{...restProps}
>
<Breadcrumb dir="auto" {...restProps}>
{crumbs.map((crumb, idx) => {
const isCurrentPage = slug === crumb.fullPath
return (
<BreadcrumbItem
key={idx}
isCurrentPage={isCurrentPage}
color="body.medium"
letterSpacing="wider"
m={0}
>
<BreadcrumbItem key={idx} isCurrentPage={isCurrentPage}>
<BreadcrumbLink
as={BaseLink}
to={crumb.fullPath}
isPartiallyActive={isCurrentPage}
fontWeight="normal"
_hover={{ color: "primary.base", textDecor: "none" }}
_active={{ color: "primary.base" }}
sx={{
/*
* Redundancy to ensure styling on the active
* link is applied.
*/
'&[aria-current="page"]': {
color: "primary.base",
},
}}
>
{crumb.text.toUpperCase()}
</BreadcrumbLink>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/bug-bounty.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ const BugBountiesPage = ({
<Content>
<HeroCard>
<HeroContainer>
<Breadcrumbs slug={location.pathname} />
<Breadcrumbs slug={location.pathname} mb="8" />
<Row>
<On />
<Title>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/roadmap/vision.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const PageDivider = () => (
)

const PageContent = (props: ChildOnlyProp) => (
<Box py={4} px={8} w="full" {...props} />
<Flex flexDirection="column" gap="8" py={4} px={8} w="full" {...props} />
)

const H2 = (props: HeadingProps) => (
Expand Down
2 changes: 1 addition & 1 deletion src/templates/roadmap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ const RoadmapPage = ({
<HeroContainer>
<Flex w="100%" flexDirection={{ base: "column", md: "row" }}>
<TitleCard>
<Breadcrumbs slug={location.pathname} />
<Breadcrumbs slug={location.pathname} mb="8" />
<Title>{mdx.frontmatter.title}</Title>
<Text>{mdx.frontmatter.description}</Text>
{mdx?.frontmatter?.buttons && (
Expand Down
2 changes: 1 addition & 1 deletion src/templates/staking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ const StakingPage = ({
<Box position="relative" width="full">
<HeroContainer>
<Flex direction="column" justify="flex-start" w="full" p={8}>
<Breadcrumbs slug={location.pathname} />
<Breadcrumbs slug={location.pathname} mb="8" />
<Title>{mdx.frontmatter.title}</Title>
<UnorderedList>
{(summaryPoints || []).map((point, idx) => (
Expand Down
2 changes: 1 addition & 1 deletion src/templates/static.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ const StaticPage = ({
},
}}
>
<Breadcrumbs slug={slug} />
<Breadcrumbs slug={slug} mb="8" />
<Text
color="text200"
dir={isLangRightToLeft(language as Lang) ? "rtl" : "ltr"}
Expand Down
2 changes: 1 addition & 1 deletion src/templates/upgrade.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ const UpgradePage = ({
<Container>
<HeroContainer>
<TitleCard>
<Breadcrumbs slug={slug} startDepth={1} mt={2} />
<Breadcrumbs slug={slug} startDepth={1} mt={2} mb="8" />
<Title>{mdx.frontmatter.title}</Title>
<Box>
<List listStyleType="disc">
Expand Down

0 comments on commit 61be715

Please sign in to comment.