-
-
Notifications
You must be signed in to change notification settings - Fork 615
Expand file tree
/
Copy pathCodeEditor.stories.ts
More file actions
150 lines (140 loc) · 4.21 KB
/
CodeEditor.stories.ts
File metadata and controls
150 lines (140 loc) · 4.21 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import type {Meta, StoryObj} from '@storybook/vue3';
import {CodeEditor} from '@ui';
import {ref} from 'vue';
const meta = {
title: 'Components/CodeEditor',
component: CodeEditor,
argTypes: {
indentType: {
control: 'select',
options: ['tabs', 'spaces'],
},
keyMap: {
control: 'select',
options: ['sublime', 'vim'],
},
mode: {
control: 'select',
options: ['clike', 'css', 'diff', 'go', 'haml', 'handlebars', 'htmlmixed', 'less', 'markdown', 'gfm', 'nginx', 'text/x-java', 'javascript', 'jsx', 'text/x-objectivec', 'php', 'python', 'ruby', 'scss', 'shell', 'sql', 'twig', 'vue', 'xml', 'yaml-frontmatter'],
},
colorMode: {
control: 'select',
options: ['system', 'light', 'dark'],
},
'update:mode': {
description: 'Event handler called when the syntax highlighting mode changes.',
table: {
category: 'events',
type: { summary: '(value: string) => void' }
}
},
'update:modelValue': {
description: 'Event handler called when the code editor value changes.',
table: {
category: 'events',
type: { summary: '(value: string) => void' }
}
},
},
} satisfies Meta<typeof CodeEditor>;
export default meta;
type Story = StoryObj<typeof meta>;
const defaultCode = `
<CodeEditor mode="javascript" v-model="code" />
`;
export const _DocsIntro: Story = {
tags: ['!dev'],
parameters: {
docs: {
source: { code: defaultCode }
}
},
render: () => ({
components: { CodeEditor },
setup() {
const code = ref('function hello() {\n console.log("Hello, world!");\n}');
return { code };
},
template: `<CodeEditor mode="javascript" v-model="code" /><PortalTargets />`,
}),
};
const modesCode = `
<div class="space-y-4">
<CodeEditor mode="javascript" v-model="jsCode" />
<CodeEditor mode="php" v-model="phpCode" />
<CodeEditor mode="yaml" v-model="yamlCode" />
</div>
`;
export const _Modes: Story = {
tags: ['!dev'],
parameters: {
docs: {
source: { code: modesCode }
}
},
render: () => ({
components: { CodeEditor },
setup() {
const jsCode = ref('const greeting = "Hello";');
const phpCode = ref('<?php\n$greeting = "Hello";\necho $greeting;');
const yamlCode = ref('title: My Site\nurl: https://example.com');
return { jsCode, phpCode, yamlCode };
},
template: `
<div class="space-y-4">
<CodeEditor mode="javascript" v-model="jsCode" />
<CodeEditor mode="php" v-model="phpCode" />
<CodeEditor mode="yaml" v-model="yamlCode" />
</div>
<PortalTargets />
`,
}),
};
const modeSelectionCode = `
<CodeEditor
v-model="code"
:mode="mode"
:allow-mode-selection="false"
@update:mode="mode = $event"
/>
`;
export const _ModeSelection: Story = {
tags: ['!dev'],
parameters: {
docs: {
source: { code: modeSelectionCode }
}
},
render: () => ({
components: { CodeEditor },
setup() {
const code = ref('console.log("Hello");');
const mode = ref('javascript');
return { code, mode };
},
template: `<CodeEditor v-model="code" :mode="mode" :allow-mode-selection="false" @update:mode="mode = $event" /><PortalTargets />`,
}),
};
const noLineNumbersCode = `
<CodeEditor
mode="markdown"
v-model="markdown"
:line-numbers="false"
/>
`;
export const _NoLineNumbers: Story = {
tags: ['!dev'],
parameters: {
docs: {
source: { code: noLineNumbersCode }
}
},
render: () => ({
components: { CodeEditor },
setup() {
const markdown = ref('# Hello\n\nThis is a markdown editor without line numbers.');
return { markdown };
},
template: `<CodeEditor mode="markdown" v-model="markdown" :line-numbers="false" /><PortalTargets />`,
}),
};