Skip to content

Commit 6b669e6

Browse files
committed
remove custom accordion component & redefine ds in its theme file
1 parent 3131a5b commit 6b669e6

File tree

5 files changed

+101
-84
lines changed

5 files changed

+101
-84
lines changed
Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,40 @@
1-
import { defineStyleConfig } from "@chakra-ui/react"
1+
import { accordionAnatomy } from "@chakra-ui/anatomy"
2+
import { createMultiStyleConfigHelpers } from "@chakra-ui/react"
23

3-
import { accordionDefaultTheme, defineMergeStyles } from "./components.utils"
4+
const { defineMultiStyleConfig, definePartsStyle } =
5+
createMultiStyleConfigHelpers(accordionAnatomy.keys)
46

5-
export const Accordion = defineStyleConfig({
6-
baseStyle: defineMergeStyles(accordionDefaultTheme.baseStyle, {
7-
button: {
8-
_hover: { bg: "background.highlight", color: "primary.hover" },
9-
_focus: {
10-
outline: "4px solid var(--eth-colors-primary-hover)",
11-
outlineOffset: "-4px",
12-
bg: "background.highlight",
13-
color: "primary.hover",
14-
borderRadius: "md",
15-
},
16-
_expanded: { bg: "background.highlight" },
17-
py: "2",
18-
px: { base: 2, md: 4 },
7+
const baseStyle = definePartsStyle({
8+
button: {
9+
py: "2",
10+
px: { base: "2", md: "4" },
11+
gap: "2",
12+
_hover: { bg: "background.highlight", color: "primary.hover" },
13+
_focus: {
14+
outline: "4px solid",
15+
outlineColor: "primary.hover",
16+
outlineOffset: -1,
17+
bg: "background.highlight",
18+
color: "primary.hover",
19+
borderRadius: "base",
1920
},
20-
panel: {
21-
p: { base: 2, md: 4 },
21+
_expanded: {
22+
bg: "background.highlight",
23+
color: "primary.highContrast",
24+
svg: { transform: "rotate(180deg)" },
2225
},
23-
}),
26+
},
27+
panel: {
28+
mt: "2",
29+
p: { base: 2, md: 4 },
30+
fontSize: "sm",
31+
},
32+
icon: {
33+
fontSize: "2xl",
34+
transform: "rotate(270deg)",
35+
},
36+
})
37+
38+
export const Accordion = defineMultiStyleConfig({
39+
baseStyle,
2440
})

src/@chakra-ui/components/components.utils.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import merge from "lodash/merge"
22
import { cssVar, SystemStyleObject, theme } from "@chakra-ui/react"
33

44
const {
5-
Accordion: accordionDefaultTheme,
65
Alert: alertDefaultTheme,
76
Avatar: avatarDefaultTheme,
87
Badge: badgeDefaultTheme,
@@ -31,7 +30,6 @@ const {
3130
} = theme.components
3231

3332
export {
34-
accordionDefaultTheme,
3533
alertDefaultTheme,
3634
avatarDefaultTheme,
3735
badgeDefaultTheme,

src/components/Accordion/Accordion.stories.tsx

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/components/Accordion/index.tsx

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import {
2+
Accordion,
3+
AccordionButton,
4+
AccordionIcon,
5+
AccordionItem,
6+
AccordionPanel,
7+
Box,
8+
} from "@chakra-ui/react"
9+
import { Meta, StoryObj } from "@storybook/react"
10+
11+
type AccordionType = typeof Accordion
12+
13+
const meta: Meta<AccordionType> = {
14+
title: "Molecules / Disclosure Content / Accordions",
15+
component: Accordion,
16+
decorators: [
17+
(Story) => (
18+
<Box width="300px">
19+
<Story />
20+
</Box>
21+
),
22+
],
23+
} satisfies Meta<AccordionType>
24+
25+
export default meta
26+
27+
type Story = StoryObj<AccordionType>
28+
29+
export const Basic: Story = {
30+
render: () => (
31+
<Accordion allowToggle defaultIndex={0}>
32+
<AccordionItem>
33+
<h2>
34+
<AccordionButton>
35+
<Box as="span" flex="1" textAlign="left">
36+
Label text of the accordion
37+
</Box>
38+
<AccordionIcon />
39+
</AccordionButton>
40+
</h2>
41+
<AccordionPanel>
42+
Ethereum is open access to digital money and data-friendly services
43+
for everyone – no matter your background or location. It&apos;s a
44+
community-built technology behind the cryptocurrency ether (ETH) and
45+
thousands of applications you can use today.
46+
</AccordionPanel>
47+
</AccordionItem>
48+
<AccordionItem>
49+
<h2>
50+
<AccordionButton>
51+
<Box as="span" flex="1" textAlign="left">
52+
Label text of the accordion
53+
</Box>
54+
<AccordionIcon />
55+
</AccordionButton>
56+
</h2>
57+
<AccordionPanel>
58+
Ethereum is open access to digital money and data-friendly services
59+
for everyone – no matter your background or location. It&apos;s a
60+
community-built technology behind the cryptocurrency ether (ETH) and
61+
thousands of applications you can use today.
62+
</AccordionPanel>
63+
</AccordionItem>
64+
</Accordion>
65+
),
66+
}

0 commit comments

Comments
 (0)