Skip to content

Commit

Permalink
Add theme selector to sidenav.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcenizal committed Dec 4, 2017
1 parent 810d9b7 commit fae0978
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 24 deletions.
5 changes: 4 additions & 1 deletion src-docs/src/actions/theme_actions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import ActionTypes from './action_types';

export const toggleTheme = () => ({
export const toggleTheme = theme => ({
type: ActionTypes.TOGGLE_THEME,
data: {
theme,
},
});
62 changes: 53 additions & 9 deletions src-docs/src/components/guide_page/guide_page_chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ import {

import {
EuiButtonEmpty,
EuiContextMenuItem,
EuiContextMenuPanel,
EuiFieldSearch,
EuiFlexGroup,
EuiFlexItem,
EuiIcon,
EuiPopover,
EuiSideNav,
EuiSpacer,
} from '../../../../src/components';
Expand All @@ -23,6 +26,7 @@ export class GuidePageChrome extends Component {
this.state = {
search: '',
isSideNavOpenOnMobile: false,
isThemePopoverOpen: false,
};
}

Expand All @@ -49,6 +53,18 @@ export class GuidePageChrome extends Component {
this.scrollTo($(`#${id}`).offset().top - 20);
};

onThemeButtonClick = () => {
this.setState({
isThemePopoverOpen: !this.state.isThemePopoverOpen,
});
};

closeThemePopover = () => {
this.setState({
isThemePopoverOpen: false,
});
};

renderIdentity() {
const homeLink = (
<Link
Expand All @@ -59,23 +75,48 @@ export class GuidePageChrome extends Component {
</Link>
);

const themeButton = (
<EuiButtonEmpty
size="s"
color="text"
iconType="arrowDown"
iconSide="right"
onClick={this.onThemeButtonClick}
>
Theme
</EuiButtonEmpty>
);

const themeOptions = ['Light', 'Dark', 'K6'].map(option => (
<EuiContextMenuItem
key={option}
icon={option.toLowerCase() === this.props.selectedTheme ? 'check' : 'empty'}
onClick={() => { this.closeThemePopover(); this.props.onToggleTheme(option.toLowerCase()); }}
>
{`${option}`}
</EuiContextMenuItem>
));

return (
<EuiFlexGroup alignItems="center" gutterSize="s" responsive={false}>
<EuiFlexItem grow={false}>
{homeLink}
</EuiFlexItem>

<EuiFlexItem grow={false}>
<EuiButtonEmpty
size="xs"
onClick={this.props.onToggleTheme}
className="euiLink"
iconSide="right"
color="text"
iconType="invert"
<EuiPopover
id="pageChromeThemePopover"
button={themeButton}
isOpen={this.state.isThemePopoverOpen}
closePopover={this.closeThemePopover}
panelPaddingSize="none"
withTitle
anchorPosition="downRight"
>
Flip theme
</EuiButtonEmpty>
<EuiContextMenuPanel
items={themeOptions}
/>
</EuiPopover>
</EuiFlexItem>
</EuiFlexGroup>
);
Expand Down Expand Up @@ -203,6 +244,9 @@ export class GuidePageChrome extends Component {

GuidePageChrome.propTypes = {
currentRouteName: PropTypes.string.isRequired,
onToggleTheme: PropTypes.func.isRequired,
selectedTheme: PropTypes.string.isRequired,
guidelines: PropTypes.array.isRequired,
components: PropTypes.array.isRequired,
sandboxes: PropTypes.array.isRequired,
};
5 changes: 5 additions & 0 deletions src-docs/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {

import themeLight from './theme_light.scss';
import themeDark from './theme_dark.scss';
import themeK6 from './theme_k6.scss';

registerTheme('light', [
themeLight
Expand All @@ -29,6 +30,10 @@ registerTheme('dark', [
themeDark
]);

registerTheme('k6', [
themeK6
]);

// Set up app

const store = configureStore();
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/store/reducers/theme_reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function sectionsReducer(state = defaultState, action) {
switch (action.type) {
case ActionTypes.TOGGLE_THEME: {
return {
theme: (state.theme === 'light') ? 'dark' : 'light',
theme: action.data.theme,
};
}

Expand Down
3 changes: 3 additions & 0 deletions src-docs/src/theme_k6.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@import "../../src/theme_k6";
@import "./components/guide_components";

25 changes: 15 additions & 10 deletions src-docs/src/views/app_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,18 @@ export class AppView extends Component {
}

renderContent() {
if (this.props.isSandbox) {
const {
children,
currentRoute,
isSandbox,
toggleTheme,
theme,
} = this.props;

if (isSandbox) {
return (
<div className="guideSandbox">
{this.props.children}
{children}
</div>
);
} else {
Expand All @@ -69,9 +77,9 @@ export class AppView extends Component {
<EuiPageBody>
<EuiPageSideBar>
<GuidePageChrome
currentRouteName={this.props.currentRoute.name}
onToggleTheme={this.props.toggleTheme}
routes={this.props.routes}
currentRouteName={currentRoute.name}
onToggleTheme={toggleTheme}
selectedTheme={theme}
guidelines={Routes.guidelines}
components={Routes.components}
sandboxes={Routes.sandboxes}
Expand All @@ -80,7 +88,7 @@ export class AppView extends Component {

<EuiPageContent>
<EuiPageContentBody>
{this.props.children}
{children}
</EuiPageContentBody>
</EuiPageContent>
</EuiPageBody>
Expand All @@ -101,14 +109,11 @@ export class AppView extends Component {
AppView.propTypes = {
children: PropTypes.any,
currentRoute: PropTypes.object.isRequired,
sections: PropTypes.array,
isSandbox: PropTypes.bool,
toggleTheme: PropTypes.func.isRequired,
theme: PropTypes.string.isRequired,
sections: PropTypes.array.isRequired,
toggleTheme: PropTypes.func.isRequired,
};

AppView.defaultProps = {
currentRoute: {},
sections: [],
};
5 changes: 5 additions & 0 deletions src/global_styling/theme_k6_variables.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// K6 custom values
@import 'k6/index';

// Configuration
@import 'variables/index';
3 changes: 0 additions & 3 deletions src/global_styling/theme_light_variables.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
// K6 custom values
@import 'k6/index';

// Configuration
@import 'variables/index';
8 changes: 8 additions & 0 deletions src/theme_k6.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Variables
@import 'global_styling/theme_k6_variables';

// Global styling
@import 'global_styling/core';

// Components
@import 'components/index';

0 comments on commit fae0978

Please sign in to comment.