format-currency.stories.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import React from 'react'
  2. import { useSplitTest } from '@/shared/context/split-test-context'
  3. import { withSplitTests } from '../../../.storybook/utils/with-split-tests'
  4. const FormatCurrency = () => {
  5. const { variant } = useSplitTest('local-ccy-format')
  6. const formatCurrency = (amount: number, narrowSymbol: boolean) => {
  7. return variant === 'enabled'
  8. ? new Intl.NumberFormat('en-US', {
  9. style: 'currency',
  10. currency: 'USD',
  11. currencyDisplay: narrowSymbol ? 'narrowSymbol' : 'name',
  12. }).format(amount)
  13. : `USD ${amount}`
  14. }
  15. return (
  16. <div>
  17. <strong>Variant:</strong> {JSON.stringify(variant)}
  18. <br />
  19. <strong>Long:</strong> {formatCurrency(1234.56, false)}
  20. <br />
  21. <strong>Short:</strong> {formatCurrency(1234.56, true)}
  22. </div>
  23. )
  24. }
  25. const config = {
  26. title: 'Storybook Guideline / Feature Flags', // Must match MDX title exactly
  27. component: FormatCurrency,
  28. }
  29. export default {
  30. ...config,
  31. ...withSplitTests(config, ['local-ccy-format'], {
  32. 'local-ccy-format': {
  33. description: 'Use local currency formatting',
  34. control: { type: 'radio' as const },
  35. options: ['default', 'enabled'],
  36. },
  37. }),
  38. tags: ['!dev'], // hides in the sidebar
  39. }
  40. export const Story = {}