Skip to content

Commit d603693

Browse files
authored
feat(menu): extend menu theme with icon part (chakra-ui#7791)
1 parent 69ab1e5 commit d603693

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

.changeset/swift-yaks-shop.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@chakra-ui/anatomy": patch
3+
"@chakra-ui/theme": patch
4+
"@chakra-ui/menu": patch
5+
---
6+
7+
Allow styling `MenuIcon` as part of `Menu` theme

packages/components/anatomy/src/components.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export const listAnatomy = anatomy("list").parts("container", "item", "icon")
7979

8080
export const menuAnatomy = anatomy("menu")
8181
.parts("button", "list", "item")
82-
.extend("groupTitle", "command", "divider")
82+
.extend("groupTitle", "icon", "command", "divider")
8383

8484
export const modalAnatomy = anatomy("modal")
8585
.parts("overlay", "dialogContainer", "dialog")

packages/components/menu/src/menu-icon.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ import { HTMLChakraProps, chakra } from "@chakra-ui/system"
22
import { cx } from "@chakra-ui/shared-utils"
33

44
import { Children, cloneElement, isValidElement } from "react"
5+
import { useMenuStyles } from "./menu"
56

67
export const MenuIcon: React.FC<HTMLChakraProps<"span">> = (props) => {
78
const { className, children, ...rest } = props
89

10+
const styles = useMenuStyles()
11+
912
const child = Children.only(children)
1013

1114
const clone = isValidElement(child)
@@ -19,16 +22,7 @@ export const MenuIcon: React.FC<HTMLChakraProps<"span">> = (props) => {
1922
const _className = cx("chakra-menu__icon-wrapper", className)
2023

2124
return (
22-
<chakra.span
23-
className={_className}
24-
{...rest}
25-
__css={{
26-
display: "inline-flex",
27-
alignItems: "center",
28-
justifyContent: "center",
29-
flexShrink: 0,
30-
}}
31-
>
25+
<chakra.span className={_className} {...rest} __css={styles.icon}>
3226
{clone}
3327
</chakra.span>
3428
)

packages/components/theme/src/components/menu.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ const baseStyleGroupTitle = defineStyle({
6666
fontSize: "sm",
6767
})
6868

69+
const baseStyleIcon = defineStyle({
70+
display: "inline-flex",
71+
alignItems: "center",
72+
justifyContent: "center",
73+
flexShrink: 0,
74+
})
75+
6976
const baseStyleCommand = defineStyle({
7077
opacity: 0.6,
7178
})
@@ -88,6 +95,7 @@ const baseStyle = definePartsStyle({
8895
list: baseStyleList,
8996
item: baseStyleItem,
9097
groupTitle: baseStyleGroupTitle,
98+
icon: baseStyleIcon,
9199
command: baseStyleCommand,
92100
divider: baseStyleDivider,
93101
})

0 commit comments

Comments
 (0)