-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathButton.stories.tsx
75 lines (67 loc) · 2.15 KB
/
Button.stories.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import type { Meta, StoryObj } from '@storybook/react';
import { createLiveEditStory } from 'storybook-addon-code-editor';
import * as ExampleLibrary from '../../index';
import ButtonJsSource from './editableStory.source.js?raw';
import ButtonTsSource from './editableStory.source.tsx?raw';
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
const meta = {
title: 'Stories/Button',
component: ExampleLibrary.Button,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
} satisfies Meta<typeof ExampleLibrary.Button>;
export default meta;
type Story = StoryObj<typeof meta>;
export const EditableStoryJSSource = createLiveEditStory<Story>({
availableImports: { 'example-library': ExampleLibrary },
code: ButtonJsSource,
modifyEditor(monaco, editor) {
monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
noSemanticValidation: true,
});
monaco.editor.setTheme('vs-light');
},
});
export const EditableStoryTSSource = createLiveEditStory<Story>({
availableImports: { 'example-library': ExampleLibrary },
code: ButtonTsSource,
modifyEditor(monaco, editor) {
monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
noSemanticValidation: false,
});
monaco.editor.setTheme('vs-dark');
editor.focus();
},
});
export const EditableStoryWithControls = createLiveEditStory<Story>({
availableImports: { 'example-library': ExampleLibrary },
code: `
import { Button } from 'example-library';
export default (props: React.ComponentProps<typeof Button>) => {
return <Button {...props} />;
};
`
.trim()
.replace(/^ {4}/gm, ''),
modifyEditor(monaco, editor) {
monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
noSemanticValidation: false,
});
monaco.editor.setTheme('vs-dark');
},
args: {
backgroundColor: 'black',
children: 'Set this text in the controls tab',
},
});
export const nonEditableStoryArgs: Story = {
args: {
backgroundColor: 'lightblue',
children: 'Use the controls tab to edit me',
},
parameters: {
liveCodeEditor: { disable: true },
},
};