react-cookie-consent/src/components/ConditionalWrapper.tsx
Mastermindzh c544f19c41 Switched to tsdx and Typescript
Added storybook with examples from readme
2022-07-31 12:04:58 +02:00

19 lines
613 B
TypeScript

import { FunctionComponent, ReactNode } from "react";
type Props = {
condition: boolean;
wrapper: (_: ReactNode) => any;
children: ReactNode;
};
/**
* A function to wrap elements with a "wrapper" on a condition
* @param {object} wrappingOptions
* condition == boolean condition, when to wrap
* wrapper == style to wrap. e.g <div>{children}</div>
* children == react passes whatever is between tags as children. Don't supply this yourself.
*/
export const ConditionalWrapper: FunctionComponent<Props> = ({ condition, wrapper, children }) => {
return condition ? wrapper(children) : children;
};