|
| 1 | +import type { Meta, StoryObj } from 'storybook' |
| 2 | + |
| 3 | +import Highlight from 'components/Highlight' |
| 4 | + |
| 5 | +const meta: Meta<typeof Highlight> = { |
| 6 | + component: Highlight, |
| 7 | + parameters: { |
| 8 | + docs: { |
| 9 | + description: { |
| 10 | + component: |
| 11 | + 'The code wrapper: renders a `<pre><code class="hljs">` block and runs ' + |
| 12 | + 'highlight.js over it. This is what the shared code theme styles (surface, ' + |
| 13 | + 'border, syntax palette). Toggle the theme in the toolbar to QA light vs dark; ' + |
| 14 | + '`className` is the highlight.js language.', |
| 15 | + }, |
| 16 | + }, |
| 17 | + layout: 'padded', |
| 18 | + }, |
| 19 | + title: 'Components/Highlight', |
| 20 | +} |
| 21 | + |
| 22 | +export default meta |
| 23 | + |
| 24 | +type Story = StoryObj<typeof Highlight> |
| 25 | + |
| 26 | +const js = `// Initialise the client |
| 27 | +import flagsmith from 'flagsmith' |
| 28 | +
|
| 29 | +flagsmith.init({ |
| 30 | + environmentID: 'YOUR_ENVIRONMENT_KEY', |
| 31 | + onChange: () => { |
| 32 | + const bannerSize = flagsmith.getValue('banner_size') |
| 33 | + }, |
| 34 | +})` |
| 35 | + |
| 36 | +const ts = `import { useFlags } from 'flagsmith/react' |
| 37 | +
|
| 38 | +type FlagName = 'banner_size' | 'my_feature' |
| 39 | +
|
| 40 | +const flags = useFlags<FlagName>(['banner_size']) |
| 41 | +const size: number = flags.banner_size.value ?? 0` |
| 42 | + |
| 43 | +const json = `{ |
| 44 | + "flags": [ |
| 45 | + { "feature": "banner_size", "enabled": true, "value": 42 }, |
| 46 | + { "feature": "my_feature", "enabled": false, "value": null } |
| 47 | + ] |
| 48 | +}` |
| 49 | + |
| 50 | +const yaml = `flags: |
| 51 | + - feature: banner_size |
| 52 | + enabled: true |
| 53 | + value: 42` |
| 54 | + |
| 55 | +export const JavaScript: Story = { |
| 56 | + args: { children: js, className: 'javascript', forceExpanded: true }, |
| 57 | +} |
| 58 | + |
| 59 | +export const TypeScript: Story = { |
| 60 | + args: { children: ts, className: 'typescript', forceExpanded: true }, |
| 61 | +} |
| 62 | + |
| 63 | +export const Json: Story = { |
| 64 | + args: { children: json, className: 'json', forceExpanded: true }, |
| 65 | +} |
| 66 | + |
| 67 | +export const Yaml: Story = { |
| 68 | + args: { children: yaml, className: 'yaml', forceExpanded: true }, |
| 69 | +} |
| 70 | + |
| 71 | +// Embedded variant: transparent, for code whose container owns the surface. |
| 72 | +export const Embedded: Story = { |
| 73 | + args: { |
| 74 | + children: js, |
| 75 | + className: 'javascript hljs--embedded', |
| 76 | + forceExpanded: true, |
| 77 | + }, |
| 78 | +} |
0 commit comments