Skip to content

Commit

Permalink
feat(menu): extend menu theme with icon part (chakra-ui#7791)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitelak committed Jul 11, 2023
1 parent 69ab1e5 commit d603693
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
7 changes: 7 additions & 0 deletions .changeset/swift-yaks-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@chakra-ui/anatomy": patch
"@chakra-ui/theme": patch
"@chakra-ui/menu": patch
---

Allow styling `MenuIcon` as part of `Menu` theme
2 changes: 1 addition & 1 deletion packages/components/anatomy/src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const listAnatomy = anatomy("list").parts("container", "item", "icon")

export const menuAnatomy = anatomy("menu")
.parts("button", "list", "item")
.extend("groupTitle", "command", "divider")
.extend("groupTitle", "icon", "command", "divider")

export const modalAnatomy = anatomy("modal")
.parts("overlay", "dialogContainer", "dialog")
Expand Down
14 changes: 4 additions & 10 deletions packages/components/menu/src/menu-icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import { HTMLChakraProps, chakra } from "@chakra-ui/system"
import { cx } from "@chakra-ui/shared-utils"

import { Children, cloneElement, isValidElement } from "react"
import { useMenuStyles } from "./menu"

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

const styles = useMenuStyles()

const child = Children.only(children)

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

return (
<chakra.span
className={_className}
{...rest}
__css={{
display: "inline-flex",
alignItems: "center",
justifyContent: "center",
flexShrink: 0,
}}
>
<chakra.span className={_className} {...rest} __css={styles.icon}>
{clone}
</chakra.span>
)
Expand Down
8 changes: 8 additions & 0 deletions packages/components/theme/src/components/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ const baseStyleGroupTitle = defineStyle({
fontSize: "sm",
})

const baseStyleIcon = defineStyle({
display: "inline-flex",
alignItems: "center",
justifyContent: "center",
flexShrink: 0,
})

const baseStyleCommand = defineStyle({
opacity: 0.6,
})
Expand All @@ -88,6 +95,7 @@ const baseStyle = definePartsStyle({
list: baseStyleList,
item: baseStyleItem,
groupTitle: baseStyleGroupTitle,
icon: baseStyleIcon,
command: baseStyleCommand,
divider: baseStyleDivider,
})
Expand Down

0 comments on commit d603693

Please sign in to comment.