chore: move src/common/utils to @roleypoly/misc-utils

This commit is contained in:
41666 2021-03-12 16:54:08 -05:00
parent a374030438
commit 65a8760e86
36 changed files with 38 additions and 465 deletions

View file

@ -0,0 +1,19 @@
import * as React from 'react';
export enum FeatureFlag {
AllowListsBlockLists = 'AllowListsBlockLists',
}
export class FeatureFlagProvider {
activeFlags: FeatureFlag[] = [];
constructor(flags: FeatureFlag[] = []) {
this.activeFlags = flags;
}
has(flag: FeatureFlag) {
return this.activeFlags.includes(flag);
}
}
export const FeatureFlagsContext = React.createContext(new FeatureFlagProvider());

View file

@ -0,0 +1 @@
export * from './FeatureFlags';

View file

@ -0,0 +1,12 @@
import * as React from 'react';
import { FeatureFlag, FeatureFlagProvider, FeatureFlagsContext } from './FeatureFlags';
export const FeatureFlagDecorator = (flags: FeatureFlag[]) => (
storyFn: () => React.ReactNode
) => {
return (
<FeatureFlagsContext.Provider value={new FeatureFlagProvider(flags)}>
{storyFn()}
</FeatureFlagsContext.Provider>
);
};