Skip to content

Commit

Permalink
feat(example): Add dark theme toggle button & change background colort
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 committed Jan 17, 2019
1 parent d32d52a commit a87f288
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { LiveProvider, LiveEditor, LiveError, LivePreview, withLive } from 'reac
import { transform } from 'babel-standalone';
import Section from '../section';
import copy from 'clipboard-copy';
import classNames from 'classnames';

const propTypes = {
className: PropTypes.string,
Expand Down Expand Up @@ -56,7 +57,14 @@ const transformCode = code => {
class LiveDemo extends React.Component {
state = {
codeOpen: false,
showCopyMessage: false
showCopyMessage: false,
isDarkTheme: false
};

handleToggleDarkTheme = () => {
this.setState({
isDarkTheme: !this.state.isDarkTheme
});
};

handleClickCodeOpen = () => {
Expand All @@ -79,7 +87,7 @@ class LiveDemo extends React.Component {

render() {
const { className, raw, images, live, liveScope, path } = this.props;
const { codeOpen, showCopyMessage } = this.state;
const { codeOpen, showCopyMessage, isDarkTheme } = this.state;

const GITHUB_BASE = 'https://github.com/patternfly/patternfly-react/blob/master/packages/patternfly-4';
const examplePath = `${GITHUB_BASE}${path.substr(5)}`;
Expand All @@ -96,11 +104,15 @@ class LiveDemo extends React.Component {
scope[importName] = image.file;
}
}
const darkThemeClasses =
classNames({
'pf-t-dark pf-m-opaque-200': isDarkTheme,
})

return (
<Section>
<LiveProvider code={raw} scope={scope} transformCode={transformCode}>
{live && <LivePreview className={css(className, exampleStyles.example)} />}
{live && <LivePreview className={css(className, exampleStyles.example, darkThemeClasses)} />}
<div className={css(styles.toolbar)}>
<CoreComponents.Button
onClick={this.handleClickCodeOpen}
Expand Down Expand Up @@ -128,6 +140,15 @@ class LiveDemo extends React.Component {
<i className={css('fab fa-github')} />
</CoreComponents.Button>
</a>
<CoreComponents.Button
onClick={this.handleToggleDarkTheme}
variant="plain"
title="Toggle Dark Theme"
aria-label="Toggle Dark Theme"
>
<CoreIcons.AsleepIcon />
</CoreComponents.Button>

<CoreComponents.TextContent className={css(styles.message, showCopyMessage && styles.messageShow)}>
<CoreComponents.Text component="pre" className={css(styles.messageText)}>
Copied to clipboard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export default StyleSheet.create({
},
nav: {
position: 'relative',
flexShrink: 0
flexShrink: 0,
borderRight: 'solid 1px #cecece'
},
main: {
position: 'relative',
Expand Down
4 changes: 0 additions & 4 deletions packages/patternfly-4/react-docs/src/layouts/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ body {
height: 100%;
}

body {
background-color: #ececec;
}

#___gatsby {
position: relative;
width: 100%;
Expand Down

0 comments on commit a87f288

Please sign in to comment.