make source-language configurable

This commit is contained in:
Yngve Bakken-Nilsen 2021-02-10 22:49:13 +01:00
parent 659bfa3a9f
commit b7c44a13a1
3 changed files with 9 additions and 3 deletions

View File

@ -93,7 +93,7 @@ export const getSourceProps = (
docsContext: DocsContextProps,
sourceContext: SourceContextProps
): PureSourceProps => {
const { id: currentId } = docsContext;
const { id: currentId, parameters = {} } = docsContext;
const codeProps = props as CodeProps;
const singleProps = props as SingleSourceProps;
@ -112,8 +112,13 @@ export const getSourceProps = (
})
.join('\n\n');
}
const { docs: docsParameters = {} } = parameters;
const { source: sourceParameters = {} } = docsParameters;
const { language: docsLanguage = null } = sourceParameters;
return source
? { code: source, language: props.language || 'jsx', dark: props.dark || false }
? { code: source, language: props.language || docsLanguage || 'jsx', dark: props.dark || false }
: { error: SourceError.SOURCE_UNAVAILABLE };
};

View File

@ -8,6 +8,7 @@ export const parameters = {
extractComponentDescription,
source: {
type: SourceType.DYNAMIC,
language: 'html',
},
},
};

View File

@ -214,7 +214,7 @@ Storybook Docs displays a storys source code using the `Source` block. The sn
In DocsPage, the `Source` block appears automatically within each storys [Canvas](#canvas) block.
To customize the source snippet thats displayed for a story, set the `docs.source.code` parameter:
To customize the source snippet thats displayed for a story, set the `docs.source.code` and optionally the `docs.source.language` parameters:
<!-- prettier-ignore-start -->