Skip to content

Commit 066b2f3

Browse files
talissoncostaclaude
andcommitted
test(storybook): add Highlight stories
Cover the code wrapper across languages plus the embedded variant. Stub the isMobile global so components that read it render in Storybook. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent a06a48e commit 066b2f3

2 files changed

Lines changed: 81 additions & 0 deletions

File tree

‎frontend/.storybook/preview.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ global.Select = (props) =>
5555
window.Tooltip = Tooltip
5656
window.Row = Row
5757
window.FormGroup = FormGroup
58+
// project-components.js sets this at app boot; stub it so components that read
59+
// the global render in Storybook.
60+
window.isMobile = false
5861

5962
/** @type { import('storybook').Preview } */
6063
const preview = {
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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

Comments
 (0)