feature-flags.mdx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { Canvas, Controls, Meta } from '@storybook/blocks';
  2. import * as FormatCurrency from './format-currency.stories'
  3. <Meta title="Storybook Guideline / Feature flags" />
  4. # Feature flags
  5. You can wrap your story with the `withSplitTests` utility to add split test variants to your Storybook stories, so you can toggle feature flags directly in the Storybook UI. See [withSplitTests on GitHub](https://github.com/overleaf/internal/blob/main/services/web/.storybook/utils/with-split-tests.tsx).
  6. 1. Define your split test argTypes:
  7. Add your split test configurations to the `splitTestsArgTypes` object.
  8. ```js
  9. export const splitTestsArgTypes = {
  10. 'local-ccy-format': {
  11. description: 'Use local currency formatting',
  12. control: { type: 'radio' },
  13. options: ['default', 'enabled'],
  14. },
  15. }
  16. ```
  17. 2. Wrap your story with `withSplitTests`.
  18. Import `withSplitTests` and `Meta` from '@storybook/react' in your stories.
  19. ```js
  20. export default {
  21. ...config,
  22. ...withSplitTests(config, ['local-ccy-format']),
  23. }
  24. ```
  25. ## Example
  26. Resulting stories will have added controls to define the variants of the split tests.
  27. <div>
  28. <Canvas of={FormatCurrency.Story} />
  29. <Controls of={FormatCurrency.Story} />
  30. </div>