Skip to content

Commit

Permalink
fix(accordion): #5593 introduce styles.root for Accordion (#5595)
Browse files Browse the repository at this point in the history
  • Loading branch information
takethefake committed Feb 17, 2022
1 parent e5e0f25 commit 0542b8a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
10 changes: 10 additions & 0 deletions .changeset/young-poems-serve.md
@@ -0,0 +1,10 @@
---
"@chakra-ui/accordion": patch
"@chakra-ui/theme": patch
---

Updated style config for `Accordion` & `AccordionItem` (see
https://github.com/chakra-ui/chakra-ui/issues/5593)

This change introduces `styles.root` for styling the `Accordion`.
`styles.container` is still used for `AccordionItem`
15 changes: 7 additions & 8 deletions packages/accordion/src/accordion.tsx
Expand Up @@ -66,6 +66,7 @@ export const Accordion = forwardRef<AccordionProps, "div">(
ref={ref}
{...htmlProps}
className={cx("chakra-accordion", props.className)}
__css={styles.root}
>
{children}
</chakra.div>
Expand All @@ -86,14 +87,12 @@ if (__DEV__) {

type AccordionItemContext = Omit<UseAccordionItemReturn, "htmlProps">

const [
AccordionItemProvider,
useAccordionItemContext,
] = createContext<AccordionItemContext>({
name: "AccordionItemContext",
errorMessage:
"useAccordionItemContext: `context` is undefined. Seems you forgot to wrap the accordion item parts in `<AccordionItem />` ",
})
const [AccordionItemProvider, useAccordionItemContext] =
createContext<AccordionItemContext>({
name: "AccordionItemContext",
errorMessage:
"useAccordionItemContext: `context` is undefined. Seems you forgot to wrap the accordion item parts in `<AccordionItem />` ",
})

export interface AccordionItemProps
extends Omit<HTMLChakraProps<"div">, keyof UseAccordionItemProps>,
Expand Down
30 changes: 30 additions & 0 deletions packages/accordion/stories/accordion.stories.tsx
Expand Up @@ -9,11 +9,13 @@ import {
DrawerFooter,
DrawerHeader,
DrawerOverlay,
extendTheme,
useDisclosure,
} from "@chakra-ui/react"
import { chakra } from "@chakra-ui/system"
import * as React from "react"
import { ChangeEvent } from "react"
import { ChakraProvider } from "@chakra-ui/provider"
import {
Accordion,
AccordionButton,
Expand Down Expand Up @@ -324,3 +326,31 @@ export const WithDisabledAccordionItem = () => {
</Accordion>
)
}

export const OverridableAccordionContainer = () => {
return (
<ChakraProvider
theme={extendTheme({
components: {
Accordion: {
baseStyle: {
root: {
backgroundColor: "red",
},
container: {
backgroundColor: "green",
},
},
},
},
})}
>
<Accordion allowToggle>
<AccordionItem>
<AccordionButton>This should be green</AccordionButton>
<AccordionPanel>Turns out it's red</AccordionPanel>
</AccordionItem>
</Accordion>
</ChakraProvider>
)
}
5 changes: 3 additions & 2 deletions packages/anatomy/src/index.ts
Expand Up @@ -2,13 +2,14 @@ import { anatomy } from "@chakra-ui/theme-tools"

/**
* **Accordion anatomy**
* - Item: the accordion item contains the button and panel
* - Root: the root container of the accordion
* - Container: the accordion item contains the button and panel
* - Button: the button is the trigger for the panel
* - Panel: the panel is the content of the accordion item
* - Icon: the expanded/collapsed icon
*/
export const accordionAnatomy = anatomy("accordion")
.parts("container", "item", "button", "panel")
.parts("root", "container", "button", "panel")
.extend("icon")

/**
Expand Down
1 change: 1 addition & 0 deletions packages/theme/src/components/accordion.ts
Expand Up @@ -41,6 +41,7 @@ const baseStyleIcon: SystemStyleObject = {
}

const baseStyle: PartsStyleObject<typeof parts> = {
root: {},
container: baseStyleContainer,
button: baseStyleButton,
panel: baseStylePanel,
Expand Down

1 comment on commit 0542b8a

@vercel
Copy link

@vercel vercel bot commented on 0542b8a Feb 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.