Skip to content

Commit

Permalink
Merge pull request #142 from FormidableLabs/add-theme-plain-to-compon…
Browse files Browse the repository at this point in the history
…ents

Handle optional `theme.plain` object, add storybook example #139
  • Loading branch information
sofiapoh authored May 14, 2019
2 parents 2fe4222 + d04de57 commit d79447f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/components/Editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,19 @@ class CodeEditor extends Component {
);

render() {
const { style, code: _code, onChange, language, ...rest } = this.props;
const {
style,
code: _code,
onChange,
language,
theme,
...rest
} = this.props;
const { code } = this.state;

const baseTheme =
theme && typeof theme.plain === 'object' ? theme.plain : {};

return (
<Editor
value={code}
Expand All @@ -67,6 +77,7 @@ class CodeEditor extends Component {
style={{
whiteSpace: 'pre',
fontFamily: 'monospace',
...baseTheme,
...style
}}
{...rest}
Expand Down
16 changes: 15 additions & 1 deletion stories/Live.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import styled from 'styled-components';
import { storiesOf } from '@storybook/react';
import { withKnobs, boolean } from '@storybook/addon-knobs/react';
import { theme } from '../src/constants/theme';

import {
LiveProvider,
Expand Down Expand Up @@ -76,7 +77,7 @@ const StyledLivePreview = styled(LivePreview)`
`;

const StyledEditor = styled(LiveEditor)`
background: #322e3c;
background: #46424f;
`;

const StyledTextarea = styled.textarea`
Expand Down Expand Up @@ -165,6 +166,19 @@ storiesOf('Live', module)
<LivePreview />
</LiveProvider>
))
.add('component with theme', () => (
<LiveProvider
code={componentExample}
disabled={boolean('Disable editing', false)}
language="jsx"
noInline={boolean('No inline evaluation', false)}
theme={theme}
>
<StyledEditor />
<LiveError />
<LivePreview />
</LiveProvider>
))
.add('withLive example', () => (
<LiveProvider code={hooksExample}>
<LiveComponent />
Expand Down

0 comments on commit d79447f

Please sign in to comment.