CodeEditor: refactors story from knobs to controls (#35827)
* fixes storybook crash * CodeEditor: refactors story from knobs to controls * refactor codeEditor to work when showLineNumbers is set to false * fixes non functional controls in story * fixes arg 'value' formatting * revert monaco options config
This commit is contained in:
@@ -21,8 +21,8 @@
|
|||||||
"bundle": "rollup -c rollup.config.ts",
|
"bundle": "rollup -c rollup.config.ts",
|
||||||
"clean": "rimraf ./dist ./compiled",
|
"clean": "rimraf ./dist ./compiled",
|
||||||
"docsExtract": "mkdir -p ../../reports/docs && api-extractor run 2>&1 | tee ../../reports/docs/$(basename $(pwd)).log",
|
"docsExtract": "mkdir -p ../../reports/docs && api-extractor run 2>&1 | tee ../../reports/docs/$(basename $(pwd)).log",
|
||||||
"storybook": "start-storybook -p 9001 -c .storybook -s ../../public/img:public/img",
|
"storybook": "start-storybook -p 9001 -c .storybook -s ../../public/img:public/img,../../public/lib:public/lib",
|
||||||
"storybook:build": "build-storybook -o ./dist/storybook -c .storybook -s ../../public/img:public/img",
|
"storybook:build": "build-storybook -o ./dist/storybook -c .storybook -s ../../public/img:public/img,../../public/lib:public/lib",
|
||||||
"typecheck": "tsc --noEmit"
|
"typecheck": "tsc --noEmit"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -1,35 +1,10 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { number, text, boolean } from '@storybook/addon-knobs';
|
import { Meta, Story } from '@storybook/react';
|
||||||
import { action } from '@storybook/addon-actions';
|
import { action } from '@storybook/addon-actions';
|
||||||
import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
|
import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
|
||||||
import mdx from './CodeEditor.mdx';
|
import mdx from './CodeEditor.mdx';
|
||||||
import { CodeEditor } from './CodeEditorLazy';
|
import { CodeEditor } from './CodeEditorLazy';
|
||||||
|
|
||||||
const getKnobs = () => {
|
|
||||||
const CONTAINER_GROUP = 'Container options';
|
|
||||||
// ---
|
|
||||||
const containerWidth = number(
|
|
||||||
'Container width',
|
|
||||||
300,
|
|
||||||
{
|
|
||||||
range: true,
|
|
||||||
min: 100,
|
|
||||||
max: 500,
|
|
||||||
step: 10,
|
|
||||||
},
|
|
||||||
CONTAINER_GROUP
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
|
||||||
containerWidth,
|
|
||||||
text: text('Body', 'SELECT * FROM table LIMIT 10'),
|
|
||||||
language: text('Language', 'sql'),
|
|
||||||
showLineNumbers: boolean('Show line numbers', false),
|
|
||||||
showMiniMap: boolean('Show mini map', false),
|
|
||||||
readOnly: boolean('readonly', false),
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
title: 'CodeEditor',
|
title: 'CodeEditor',
|
||||||
component: CodeEditor,
|
component: CodeEditor,
|
||||||
@@ -38,26 +13,50 @@ export default {
|
|||||||
docs: {
|
docs: {
|
||||||
page: mdx,
|
page: mdx,
|
||||||
},
|
},
|
||||||
|
controls: {
|
||||||
|
exclude: ['monacoOptions', 'onEditorDidMount', 'onBlur', 'onSave', 'getSuggestions', 'showLineNumbers'],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
argTypes: {
|
||||||
|
width: { control: { type: 'range', min: 100, max: 500, step: 10 } },
|
||||||
|
height: { control: { type: 'range', min: 100, max: 800, step: 10 } },
|
||||||
|
language: { control: { type: 'select' }, options: ['sql', 'json'] },
|
||||||
|
},
|
||||||
|
} as Meta;
|
||||||
|
|
||||||
export const basic = () => {
|
export const Basic: Story = (args) => {
|
||||||
const { containerWidth, text, language, showLineNumbers, showMiniMap, readOnly } = getKnobs();
|
|
||||||
return (
|
return (
|
||||||
<CodeEditor
|
<CodeEditor
|
||||||
width={containerWidth}
|
width={args.width}
|
||||||
height={400}
|
height={args.height}
|
||||||
value={text}
|
value={args.value}
|
||||||
language={language}
|
language={args.language}
|
||||||
onBlur={(text: string) => {
|
onBlur={(text: string) => {
|
||||||
action('code blur')(text);
|
action('code blur')(text);
|
||||||
}}
|
}}
|
||||||
onSave={(text: string) => {
|
onSave={(text: string) => {
|
||||||
action('code saved')(text);
|
action('code saved')(text);
|
||||||
}}
|
}}
|
||||||
showLineNumbers={showLineNumbers}
|
showLineNumbers={args.showLineNumbers}
|
||||||
showMiniMap={showMiniMap}
|
showMiniMap={args.showMiniMap}
|
||||||
readOnly={readOnly}
|
readOnly={args.readOnly}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Basic.args = {
|
||||||
|
width: 300,
|
||||||
|
height: 400,
|
||||||
|
value: `CREATE TABLE Persons (
|
||||||
|
PersonID int,
|
||||||
|
LastName varchar(255),
|
||||||
|
FirstName varchar(255),
|
||||||
|
Address varchar(255),
|
||||||
|
City varchar(255)
|
||||||
|
);
|
||||||
|
SELECT * FROM Persons LIMIT 10 '
|
||||||
|
`,
|
||||||
|
language: 'sql',
|
||||||
|
showLineNumbers: false,
|
||||||
|
showMiniMap: false,
|
||||||
|
readOnly: false,
|
||||||
|
};
|
||||||
|
|||||||
@@ -125,7 +125,6 @@ class UnthemedCodeEditor extends React.PureComponent<Props> {
|
|||||||
tabSize: 2,
|
tabSize: 2,
|
||||||
codeLens: false,
|
codeLens: false,
|
||||||
contextmenu: false,
|
contextmenu: false,
|
||||||
|
|
||||||
minimap: {
|
minimap: {
|
||||||
enabled: longText && showMiniMap,
|
enabled: longText && showMiniMap,
|
||||||
renderCharacters: false,
|
renderCharacters: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user