Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(accordion): introduce styles.root for Accordion #5595

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/young-poems-serve.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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")
TimKolberger marked this conversation as resolved.
Show resolved Hide resolved
.extend("icon")

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

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