Skip to content

Commit

Permalink
Move the theme setting into a plugin sidebar.
Browse files Browse the repository at this point in the history
  • Loading branch information
bradyvercher committed Aug 2, 2018
1 parent 5971302 commit f9e15ab
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 18 deletions.
20 changes: 2 additions & 18 deletions blocks/code/edit.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import classnames from 'classnames';
import { components, data, editor, element, i18n } from 'wp';
import CodeEditor from './code-editor';
import { languageChoices, themeChoices } from './settings';
import { languageChoices } from './settings';

const { PanelBody, SelectControl, ToggleControl } = components;
const { dispatch, select, withSelect } = data;
const { select, withSelect } = data;
const { InspectorControls } = editor;
const { Component, Fragment } = element;
const { __ } = i18n;
Expand All @@ -13,14 +13,9 @@ export class CodeBlockEdit extends Component {
constructor() {
super( ...arguments );

this.onChangeTheme = this.onChangeTheme.bind( this );
this.toggleLineHighlight = this.toggleLineHighlight.bind( this );
}

onChangeTheme( value ) {
dispatch( 'cedaro/code' ).updateTheme( value )
}

toggleLineHighlight( value ) {
let lines = this.props.attributes.highlightLines;

Expand Down Expand Up @@ -54,17 +49,6 @@ export class CodeBlockEdit extends Component {
onChange={ () => setAttributes( { showLineNumbers: ! showLineNumbers } ) }
/>
</PanelBody>
<PanelBody title={ __( 'Settings' ) } initialOpen={ false }>
<p>
{ __( 'Settings that apply to all Shiny Code blocks.' ) }
</p>
<SelectControl
label={ __( 'Theme' ) }
value={ theme }
options={ themeChoices }
onChange={ this.onChangeTheme }
/>
</PanelBody>
</InspectorControls>
<div className={ className }>
<CodeEditor
Expand Down
1 change: 1 addition & 0 deletions blocks/code/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import classnames from 'classnames';
import { blocks, i18n } from 'wp';
import CodeBlockEdit from './edit';
import './data';
import './sidebar';

const { createBlock, registerBlockType } = blocks;
const { __ } = i18n;
Expand Down
55 changes: 55 additions & 0 deletions blocks/code/sidebar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { components, data, editPost, element, i18n, plugins } from 'wp';
import { themeChoices } from './settings';

const { PanelBody, SelectControl } = components;
const { Component, Fragment } = element;
const { dispatch, select, withSelect } = data;
const { PluginSidebar, PluginSidebarMoreMenuItem } = editPost;
const { __ } = i18n;
const { registerPlugin } = plugins;

class Sidebar extends Component {
constructor() {
super( ...arguments );

this.onChangeTheme = this.onChangeTheme.bind( this );
}

onChangeTheme( value ) {
dispatch( 'cedaro/code' ).updateTheme( value )
}

render() {
const { theme } = this.props;

return (
<Fragment>
<PluginSidebarMoreMenuItem target="shiny-code">
{ __( 'Shiny Code' ) }
</PluginSidebarMoreMenuItem>
<PluginSidebar
name="shiny-code"
title={ __( 'Shiny Code' ) }
>
<PanelBody>
<SelectControl
label={ __( 'Theme' ) }
value={ theme }
options={ themeChoices }
onChange={ value => dispatch( 'cedaro/code' ).updateTheme( value ) }
/>
</PanelBody>
</PluginSidebar>
</Fragment>
);
}
}

registerPlugin( 'plugin-name', {
icon: 'editor-code',
render: withSelect( function( select ) {
return {
theme: select( 'cedaro/code' ).getTheme()
};
} )( Sidebar ),
} );

0 comments on commit f9e15ab

Please sign in to comment.