Skip to content

Commit

Permalink
fix(popper): arrow box shadow (chakra-ui#7137)
Browse files Browse the repository at this point in the history
  • Loading branch information
anubra266 authored Dec 21, 2022
1 parent e505a41 commit b374879
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-comics-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chakra-ui/popover": patch
---

Allow overriding arrow background and boxShadow
5 changes: 5 additions & 0 deletions .changeset/moody-dolls-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chakra-ui/popper": patch
---

Set `boxShadow` of inner arrow with css variable
8 changes: 6 additions & 2 deletions packages/components/popover/src/popover-arrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { usePopoverContext, usePopoverStyles } from "./popover-context"
export interface PopoverArrowProps extends HTMLChakraProps<"div"> {}

export function PopoverArrow(props: PopoverArrowProps) {
const { bg, bgColor, backgroundColor } = props
const { bg, bgColor, backgroundColor, shadow, boxShadow } = props
const { getArrowProps, getArrowInnerProps } = usePopoverContext()
const styles = usePopoverStyles()
const arrowBg = bg ?? bgColor ?? backgroundColor
const arrowShadow = shadow ?? boxShadow
return (
<chakra.div
{...getArrowProps()}
Expand All @@ -18,10 +19,13 @@ export function PopoverArrow(props: PopoverArrowProps) {
className={cx("chakra-popover__arrow", props.className)}
{...getArrowInnerProps(props)}
__css={{
...styles.arrow,
"--popper-arrow-bg": arrowBg
? `colors.${arrowBg}, ${arrowBg}`
: undefined,
"--popper-arrow-shadow": arrowShadow
? `shadows.${arrowShadow}, ${arrowShadow}`
: undefined,
...styles.arrow,
}}
/>
</chakra.div>
Expand Down
6 changes: 5 additions & 1 deletion packages/components/popper/src/modifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ const setInnerArrowStyles = (state: State) => {
) as HTMLElement | null

if (!inner) return
const boxShadow = getBoxShadow(state.placement)
if (boxShadow) {
inner.style.setProperty("--popper-arrow-default-shadow", boxShadow)
}

Object.assign(inner.style, {
transform: "rotate(45deg)",
Expand All @@ -140,6 +144,6 @@ const setInnerArrowStyles = (state: State) => {
height: "100%",
position: "absolute",
zIndex: "inherit",
boxShadow: getBoxShadow(state.placement),
boxShadow: `var(--popper-arrow-shadow, var(--popper-arrow-default-shadow))`,
})
}

0 comments on commit b374879

Please sign in to comment.