mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-27 20:49:53 +08:00
666f38d756
* refactor: add ContextIsolator component * fix: fix * fix: fix * test: fix test case * test: add test case --------- Co-authored-by: afc163 <afc163@gmail.com>
30 lines
750 B
TypeScript
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;
|