Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cssresources-addon: Do not use SyntaxHighlighter with the very long code-content. #9360

Merged
merged 1 commit into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/cssresources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@storybook/api": "5.3.0-rc.12",
"@storybook/components": "5.3.0-rc.12",
"@storybook/core-events": "5.3.0-rc.12",
"@storybook/theming": "5.3.0-rc.12",
"core-js": "^3.0.1",
"global": "^4.3.2",
"react": "^16.8.3"
Expand Down
39 changes: 37 additions & 2 deletions addons/cssresources/src/css-resource-panel.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { Component, Fragment } from 'react';
import { SyntaxHighlighter } from '@storybook/components';
import { SyntaxHighlighter, Placeholder, Spaced, Icons } from '@storybook/components';
import { STORY_RENDERED } from '@storybook/core-events';
import { API } from '@storybook/api';
import { styled } from '@storybook/theming';

import { EVENTS, PARAM_KEY } from './constants';
import { CssResource } from './CssResource';
Expand All @@ -20,6 +21,27 @@ interface CssResourceLookup {
[key: string]: CssResource;
}

const maxLimitToUseSyntaxHighlighter = 100000;

const PlainCode = styled.pre({
textAlign: 'left',
fontWeight: 'normal',
});

const Warning = styled.div({
display: 'flex',
padding: '10px',
justifyContent: 'center',
alignItems: 'center',
background: '#fff3cd',
fontSize: 12,
'& svg': {
marginRight: 10,
width: 24,
height: 24,
},
});

export class CssResourcePanel extends Component<Props, State> {
constructor(props: Props) {
super(props);
Expand Down Expand Up @@ -96,7 +118,20 @@ export class CssResourcePanel extends Component<Props, State> {
<input type="checkbox" checked={picked} onChange={this.onChange} id={id} />
<span>#{id}</span>
</label>
{code ? <SyntaxHighlighter language="html">{code}</SyntaxHighlighter> : null}
{code && code.length < maxLimitToUseSyntaxHighlighter && (
<SyntaxHighlighter language="html">{code}</SyntaxHighlighter>
)}
{code && code.length >= maxLimitToUseSyntaxHighlighter && (
<Placeholder>
<Spaced row={1}>
<PlainCode>{code.substring(0, maxLimitToUseSyntaxHighlighter)} ...</PlainCode>
<Warning>
<Icons icon="alert" />
Rest of the content cannot be displayed
</Warning>
</Spaced>
</Placeholder>
)}
</div>
))}
</div>
Expand Down