Skip to content

Commit 0bc31d2

Browse files
authored
Merge pull request #10936 from justynleung/Accordion
Accordion made according to DS style in figma [issue #10748]
2 parents 9aeefb2 + f6e0570 commit 0bc31d2

File tree

11 files changed

+157
-16
lines changed

11 files changed

+157
-16
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { accordionAnatomy } from "@chakra-ui/anatomy"
2+
import { createMultiStyleConfigHelpers } from "@chakra-ui/react"
3+
4+
const { defineMultiStyleConfig, definePartsStyle } =
5+
createMultiStyleConfigHelpers(accordionAnatomy.keys)
6+
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+
_focusVisible: {
14+
outline: "4px solid",
15+
outlineColor: "primary.hover",
16+
outlineOffset: -1,
17+
bg: "background.highlight",
18+
color: "primary.hover",
19+
borderRadius: "base",
20+
},
21+
_expanded: {
22+
bg: "background.highlight",
23+
color: "primary.highContrast",
24+
svg: { transform: "rotate(180deg)" },
25+
},
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,
40+
})

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/@chakra-ui/components/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import { Accordion } from "./Accordion"
12
import { Alert } from "./Alert"
23
import { Avatar } from "./Avatar"
34
import { Badge } from "./Badge"
45
import { Breadcrumb } from "./Breadcrumb"
56
import { Button } from "./Button"
67
import { Checkbox } from "./Checkbox"
78
import {
8-
accordionDefaultTheme,
99
closeButtonDefaultTheme,
1010
codeDefaultTheme,
1111
dividerDefaultTheme,
@@ -31,7 +31,7 @@ import { Text } from "./Text"
3131

3232
// eslint-disable-next-line import/no-anonymous-default-export
3333
export default {
34-
Accordion: accordionDefaultTheme,
34+
Accordion,
3535
Alert,
3636
Avatar,
3737
Badge,
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+
}

src/components/ExpandableCard.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,22 @@ const ExpandableCard = ({
6565
_hover={{
6666
backgroundColor: "ednBackground",
6767
}}
68-
borderBottomWidth="0"
6968
index={isVisible ? [0] : []}
7069
>
7170
<AccordionItem borderTopWidth="0" flex="1">
7271
<Heading as="h3" m={0}>
7372
<AccordionButton
7473
width="100%"
75-
p={6}
74+
px="6"
75+
py="6"
7676
flex="1"
7777
onClick={onClick}
7878
_hover={{
7979
backgroundColor: "ednBackground",
8080
}}
81+
_expanded={{
82+
backgroundColor: "transparent",
83+
}}
8184
>
8285
<Box
8386
display="flex"
@@ -122,6 +125,8 @@ const ExpandableCard = ({
122125
</AccordionButton>
123126
</Heading>
124127
<AccordionPanel
128+
p="0"
129+
mt="0"
125130
paddingX="6"
126131
paddingBottom="6"
127132
paddingTop="0"

src/components/FindWallet/LanguageSupportFilter.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ export const LanguageSupportFilter = () => {
9191
color="inherit"
9292
fontWeight="inherit"
9393
fontSize="inherit"
94-
p={0}
94+
px={0}
95+
py={0}
9596
textAlign="initial"
9697
_hover={{ background: "transparent" }}
9798
>
@@ -103,6 +104,7 @@ export const LanguageSupportFilter = () => {
103104
color="primary.base"
104105
boxSize={9}
105106
_hover={{ color: "primary.hover" }}
107+
transform="rotate(0deg)"
106108
/>
107109
</AccordionButton>
108110
</Heading>

src/components/FindWallet/WalletFilterFeature.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ const WalletFilterFeature = ({
104104
color="inherit"
105105
fontWeight="inherit"
106106
fontSize="inherit"
107-
p={0}
107+
px={0}
108+
py={0}
108109
textAlign="initial"
109110
_hover={{ background: "transparent" }}
110111
>
@@ -116,6 +117,7 @@ const WalletFilterFeature = ({
116117
color="primary.base"
117118
boxSize={9}
118119
_hover={{ color: "primary.hover" }}
120+
transform="rotate(0deg)"
119121
/>
120122
</AccordionButton>
121123
</Heading>

src/components/Nav/Mobile/LvlAccordion.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ const LvlAccordion = ({
4444
const isActivePage = isLink && cleanPath(asPath) === action.href
4545
if (isLink)
4646
return (
47-
<AccordionItem key={label}>
47+
<AccordionItem
48+
key={label}
49+
borderTop="1px"
50+
borderColor="inherit"
51+
_last={{ borderBottomWidth: "1px" }}
52+
>
4853
<Button
4954
as={BaseLink}
5055
w="full"
@@ -92,7 +97,12 @@ const LvlAccordion = ({
9297
</AccordionItem>
9398
)
9499
return (
95-
<AccordionItem key={label}>
100+
<AccordionItem
101+
key={label}
102+
borderTop="1px"
103+
borderColor="inherit"
104+
_last={{ borderBottomWidth: "1px" }}
105+
>
96106
{({ isExpanded }) => (
97107
<>
98108
<Heading
@@ -137,7 +147,11 @@ const LvlAccordion = ({
137147
</AccordionButton>
138148
</Heading>
139149

140-
<AccordionPanel p="0" bg={menuColors.lvl[lvl + 1].background}>
150+
<AccordionPanel
151+
p="0"
152+
mt="0"
153+
bg={menuColors.lvl[lvl + 1].background}
154+
>
141155
<LvlAccordion
142156
lvl={(lvl + 1) as Level}
143157
items={action.items}

src/components/Nav/Mobile/MenuBody.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ const MenuBody = ({ linkSections, onToggle }: MenuBodyProps) => {
3535
{SECTION_LABELS.map((key) => {
3636
const { label, items } = linkSections[key]
3737
return (
38-
<AccordionItem key={label}>
38+
<AccordionItem
39+
key={label}
40+
borderTop="1px"
41+
borderColor="inherit"
42+
_last={{ borderBottomWidth: "1px" }}
43+
>
3944
{({ isExpanded }) => (
4045
<>
4146
<Heading
@@ -63,6 +68,7 @@ const MenuBody = ({ linkSections, onToggle }: MenuBodyProps) => {
6368
justifyContent="start"
6469
gap="2"
6570
_hover={{ bg: "none" }}
71+
px="4"
6672
py="4"
6773
>
6874
<ExpandIcon isOpen={isExpanded} />
@@ -78,7 +84,11 @@ const MenuBody = ({ linkSections, onToggle }: MenuBodyProps) => {
7884
</AccordionButton>
7985
</Heading>
8086

81-
<AccordionPanel p="0" bg={menuColors.lvl[2].background}>
87+
<AccordionPanel
88+
p="0"
89+
mt="0"
90+
bg={menuColors.lvl[2].background}
91+
>
8292
<LvlAccordion
8393
lvl={2 as Level}
8494
items={items}

src/components/StablecoinAccordion/AccordionCustomItem.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ export const AccordionCustomItem = (props: AccordionCustomItemProps) => {
5959
<AccordionButton
6060
justifyContent="space-between"
6161
alignItems="center"
62-
p={0}
62+
px="0"
63+
py="0"
64+
_expanded={{ background: "transparent" }}
6365
_hover={{ background: "ednBackground" }}
6466
>
6567
<Flex
@@ -103,7 +105,9 @@ export const AccordionCustomItem = (props: AccordionCustomItemProps) => {
103105
borderColor="border"
104106
mb="-1px"
105107
mx="-1px"
106-
p={0}
108+
mt="0"
109+
p="0"
110+
fontSize="md"
107111
>
108112
<Flex
109113
p={8}

0 commit comments

Comments
 (0)