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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugFix: When the feature flag is enabled and sx prop is passed in use, Box #5068

Merged
merged 4 commits into from
Oct 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
When the feature flag is enabled and sx prop is passed in use, Box
  • Loading branch information
jonrohan committed Oct 4, 2024
commit b45cefd2d4bf6ac7c8e07b18cd4e18ebf8f783fa
13 changes: 11 additions & 2 deletions packages/react/src/internal/utils/toggleStyledComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import React from 'react'
import {useFeatureFlag} from '../../FeatureFlags'
import Box from '../../Box'
import {defaultSxProp} from '../../utils/defaultSxProp'

type CSSModulesProps = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
as?: string | React.ComponentType<any>
sx?: React.CSSProperties
}

/**
Expand All @@ -18,12 +21,18 @@ type CSSModulesProps = {
* is disabled
*/
export function toggleStyledComponent<T, P extends CSSModulesProps>(flag: string, Component: React.ComponentType<P>) {
const Wrapper = React.forwardRef<T, P>(function Wrapper({as: BaseComponent = 'div', ...rest}, ref) {
const Wrapper = React.forwardRef<T, P>(function Wrapper(
{as: BaseComponent = 'div', sx: sxProp = defaultSxProp, ...rest},
ref,
) {
const enabled = useFeatureFlag(flag)
if (enabled) {
if (sxProp !== defaultSxProp) {
return <Box as={BaseComponent} {...rest} sx={sxProp} ref={ref} />
}
return <BaseComponent {...rest} ref={ref} />
}
return <Component as={BaseComponent} {...(rest as P)} ref={ref} />
return <Component as={BaseComponent} {...(rest as P)} sx={sxProp} ref={ref} />
})

return Wrapper
Expand Down
Loading