From 0ec475275fba25d58bcbc7d45f5d21553c0f8e38 Mon Sep 17 00:00:00 2001 From: Cody Olsen Date: Fri, 1 Nov 2024 15:55:47 +0100 Subject: [PATCH] fix: expand react compiler to dialog, menu, theme provider --- src/core/components/dialog/dialog.tsx | 6 ++++-- src/core/components/menu/menu.tsx | 4 +++- src/core/components/menu/menuGroup.tsx | 3 ++- src/core/components/menu/menuItem.tsx | 6 ++++-- src/core/theme/themeProvider.tsx | 10 ++++------ 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/core/components/dialog/dialog.tsx b/src/core/components/dialog/dialog.tsx index 159b3d3be..83bd88d2d 100644 --- a/src/core/components/dialog/dialog.tsx +++ b/src/core/components/dialog/dialog.tsx @@ -305,13 +305,15 @@ export const Dialog = forwardRef(function Dialog( onFocus, padding: paddingProp = 3, portal: portalProp, - position: positionProp = dialog.position || 'fixed', + position: _positionProp, scheme, width: widthProp = 0, - zOffset: zOffsetProp = dialog.zOffset || layer.dialog.zOffset, + zOffset: _zOffsetProp, animate: _animate = false, ...restProps } = props + const positionProp = _positionProp ?? (dialog.position || 'fixed') + const zOffsetProp = _zOffsetProp ?? (dialog.zOffset || layer.dialog.zOffset) const prefersReducedMotion = usePrefersReducedMotion() const animate = prefersReducedMotion ? false : _animate const portal = usePortal() diff --git a/src/core/components/menu/menu.tsx b/src/core/components/menu/menu.tsx index f13dbc79e..def9b01b7 100644 --- a/src/core/components/menu/menu.tsx +++ b/src/core/components/menu/menu.tsx @@ -57,10 +57,12 @@ export const Menu = forwardRef(function Menu( originElement, padding = 1, registerElement, - shouldFocus = (props.focusFirst && 'first') || (props.focusLast && 'last') || null, + shouldFocus: _shouldFocus, space = 1, ...restProps } = props + const shouldFocus = + _shouldFocus ?? ((props.focusFirst && 'first') || (props.focusLast && 'last') || null) const ref = useRef(null) diff --git a/src/core/components/menu/menuGroup.tsx b/src/core/components/menu/menuGroup.tsx index ed76aeb81..99abd4258 100644 --- a/src/core/components/menu/menuGroup.tsx +++ b/src/core/components/menu/menuGroup.tsx @@ -53,9 +53,10 @@ export function MenuGroup( onClickOutside, onEscape, onItemClick, - onItemMouseEnter = menu.onMouseEnter, + onItemMouseEnter: _onItemMouseEnter, registerElement, } = menu + const onItemMouseEnter = _onItemMouseEnter ?? menu.onMouseEnter const [rootElement, setRootElement] = useState(null) const [open, setOpen] = useState(false) const [shouldFocus, setShouldFocus] = useState<'first' | 'last' | null>(null) diff --git a/src/core/components/menu/menuItem.tsx b/src/core/components/menu/menuItem.tsx index accf543f1..d1abcf69e 100644 --- a/src/core/components/menu/menuItem.tsx +++ b/src/core/components/menu/menuItem.tsx @@ -72,9 +72,11 @@ export const MenuItem = forwardRef(function MenuItem( activeElement, mount, onItemClick, - onItemMouseEnter = menu.onMouseEnter, - onItemMouseLeave = menu.onMouseLeave, + onItemMouseEnter: _onItemMouseEnter, + onItemMouseLeave: _onItemMouseLeave, } = menu + const onItemMouseEnter = _onItemMouseEnter ?? menu.onMouseEnter + const onItemMouseLeave = _onItemMouseLeave ?? menu.onMouseLeave const [rootElement, setRootElement] = useState(null) const active = Boolean(activeElement) && activeElement === rootElement const ref = useRef(null) diff --git a/src/core/theme/themeProvider.tsx b/src/core/theme/themeProvider.tsx index 3864b1adc..ccda05dac 100644 --- a/src/core/theme/themeProvider.tsx +++ b/src/core/theme/themeProvider.tsx @@ -25,12 +25,10 @@ export interface ThemeProviderProps { */ export function ThemeProvider(props: ThemeProviderProps): React.ReactElement { const parentTheme = useContext(ThemeContext) - const { - children, - scheme = parentTheme?.scheme || 'light', - theme: rootTheme = parentTheme?.theme || null, - tone = parentTheme?.tone || 'default', - } = props + const {children} = props + const scheme = props.scheme ?? (parentTheme?.scheme || 'light') + const rootTheme = props.theme ?? (parentTheme?.theme || null) + const tone = props.tone ?? (parentTheme?.tone || 'default') const themeContext: ThemeContextValue | null = useMemo(() => { if (!rootTheme) return null