1 import { type useVariant as useUnleashVariant } from '@unleash/proxy-client-react';
3 import { type FeatureFlag } from './UnleashFeatureFlags';
6 * List of feature flags with a variant.
8 export const FLAGS_WITH_VARIANT = ['MailOnboarding', 'InboxNewUpsellModals'] satisfies FeatureFlag[];
11 * Flags with variants variants.
12 * @description Union type of the list of feature flags with a variant.
14 * Naming convention: `${FlagName}Variant`
16 export type MailOnboardingVariant = 'none' | 'old' | 'new';
17 export type InboxNewUpsellModalsVariant = 'old' | 'new';
20 * @description Union type of the list of feature flags with a variant.
22 * Based on `FLAG_VARIANTS` list.
24 export type FeatureFlagsWithVariant = (typeof FLAGS_WITH_VARIANT)[number];
26 type VariantReturnType<TVariantNameValue extends string> = Partial<
27 // If flag is disabled, the variant name is 'disabled'
28 Omit<ReturnType<typeof useUnleashVariant>, 'name'> & { name?: TVariantNameValue | 'disabled' }
32 * @description Map of feature flags with a variant.
33 * Register your new variant here.
35 type FeatureFlagVariantMap = {
36 MailOnboarding: VariantReturnType<MailOnboardingVariant>;
37 InboxNewUpsellModals: VariantReturnType<InboxNewUpsellModalsVariant>;
41 * @param FlagName - The feature flag name
42 * @description Returns the Unleash variant value based on the declared `FeatureFlagsWithVariant` names
44 export type FeatureFlagVariant<FlagName extends FeatureFlagsWithVariant> = FlagName extends keyof FeatureFlagVariantMap
45 ? FeatureFlagVariantMap[FlagName]