ant-design/components/_util/ContextIsolator.tsx
lijianan 666f38d756
refactor: add ContextIsolator component (#49438)
* refactor: add ContextIsolator component

* fix: fix

* fix: fix

* test: fix test case

* test: add test case

---------

Co-authored-by: afc163 <afc163@gmail.com>
2024-06-21 02:10:21 +08:00

30 lines
750 B
TypeScript

import React from 'react';
import { NoFormStyle } from '../form/context';
import { NoCompactStyle } from '../space/Compact';
const ContextIsolator: React.FC<
Readonly<
React.PropsWithChildren<Partial<Record<'isolateSpaceContext' | 'isolateFormContext', boolean>>>
>
> = (props) => {
const { isolateSpaceContext, isolateFormContext, children } = props;
if (children === undefined || children === null) {
return null;
}
let result: React.ReactNode = children;
if (isolateFormContext) {
result = (
<NoFormStyle override status>
{result}
</NoFormStyle>
);
}
if (isolateSpaceContext) {
result = <NoCompactStyle>{result}</NoCompactStyle>;
}
return result;
};
export default ContextIsolator;