Files
vscode-front-matter/src/components/features/FeatureFlag.tsx
2024-05-23 12:35:10 +02:00

25 lines
523 B
TypeScript

import * as React from 'react';
export interface IFeatureFlagProps {
flag: string;
features: string[] | null;
alternative?: JSX.Element;
}
export const FeatureFlag: React.FunctionComponent<IFeatureFlagProps> = ({
flag,
features,
alternative,
children
}: React.PropsWithChildren<IFeatureFlagProps>) => {
if (!features || features.length === 0 || (features.length > 0 && !features.includes(flag))) {
if (alternative) {
return alternative;
}
return null;
}
return <>{children}</>;
};