diff --git a/packages/styleguide/src/components/Preview/Preview.js b/packages/styleguide/src/components/Preview/Preview.js
index 528a311d4c0..8daf2d9cb80 100644
--- a/packages/styleguide/src/components/Preview/Preview.js
+++ b/packages/styleguide/src/components/Preview/Preview.js
@@ -1,8 +1,8 @@
import React, { Component } from 'react';
-import { string, node, object, bool } from 'prop-types';
+import { string, node, object, bool, arrayOf } from 'prop-types';
import cx from 'classnames';
import Select from 'react-select';
-import styled from 'styled-components';
+import styled, { withTheme } from 'styled-components';
import chroma from 'chroma-js';
import PreviewTitleBar from './PreviewTitleBar';
@@ -12,21 +12,20 @@ import Frame from './Frame';
import Card from './../Card';
import Icon from './../Icon';
-import { colors, previewBackgrounds, fontFamily } from './../../style/theme';
import { ButtonBaseCSS } from '../../style/common';
const CLASS_ROOT = '';
-function getBackgroundsAsArray(previewBackgrounds) {
- return Object.keys(previewBackgrounds).map(key => {
- return {
+function getBackgroundsAsArray(previewBackgrounds, excludedColors = []) {
+ return Object.keys(previewBackgrounds)
+ .filter(colorName => !excludedColors.includes(colorName))
+ .map(key => ({
value: previewBackgrounds[key],
label: key
- };
- });
+ }));
}
-export default class Preview extends Component {
+class Preview extends Component {
static displayName = 'Preview';
static propTypes = {
@@ -34,6 +33,7 @@ export default class Preview extends Component {
code: node,
codeJSXOptions: object,
bgTheme: string,
+ bgThemeExcludedColors: arrayOf(string),
hasCodePreview: bool,
html: string,
isIframe: bool,
@@ -43,9 +43,24 @@ export default class Preview extends Component {
static defaultProps = {
bgTheme: 'white',
+ bgThemeExcludedColors: [],
hasCodePreview: true
};
+ componentWillReceiveProps(props) {
+ if (
+ this.state.previewBackground &&
+ props.bgTheme !== this.state.previewBackground.label
+ ) {
+ this.setState({
+ previewBackground: {
+ label: props.bgTheme,
+ value: props.theme.previewBackgrounds[props.bgTheme]
+ }
+ });
+ }
+ }
+
constructor(props) {
super(props);
@@ -55,8 +70,11 @@ export default class Preview extends Component {
state = {
isCodeShown: false,
- previewBackground: previewBackgrounds
- ? getBackgroundsAsArray(previewBackgrounds)[0]
+ previewBackground: this.props.theme.previewBackgrounds
+ ? {
+ label: this.props.bgTheme,
+ value: this.props.theme.previewBackgrounds[this.props.bgTheme]
+ }
: {}
};
@@ -80,11 +98,13 @@ export default class Preview extends Component {
code,
codeJSXOptions,
bgTheme,
+ bgThemeExcludedColors,
isIframe,
iframeHead,
iframeScripts,
hasCodePreview,
html,
+ theme,
...other
} = this.props;
@@ -111,44 +131,53 @@ export default class Preview extends Component {
const actions = [];
- if (bgTheme) {
- actions.push(
-