From f9e15abdd36c76947b622b7c5bbf6945ead72900 Mon Sep 17 00:00:00 2001 From: Brady Vercher Date: Thu, 2 Aug 2018 10:50:51 -0700 Subject: [PATCH] Move the theme setting into a plugin sidebar. --- blocks/code/edit.js | 20 ++------------- blocks/code/index.js | 1 + blocks/code/sidebar.js | 55 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 18 deletions(-) create mode 100644 blocks/code/sidebar.js diff --git a/blocks/code/edit.js b/blocks/code/edit.js index 2676479..0edce8f 100644 --- a/blocks/code/edit.js +++ b/blocks/code/edit.js @@ -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; @@ -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; @@ -54,17 +49,6 @@ export class CodeBlockEdit extends Component { onChange={ () => setAttributes( { showLineNumbers: ! showLineNumbers } ) } /> - -

- { __( 'Settings that apply to all Shiny Code blocks.' ) } -

- -
+ + { __( 'Shiny Code' ) } + + + + dispatch( 'cedaro/code' ).updateTheme( value ) } + /> + + + + ); + } +} + +registerPlugin( 'plugin-name', { + icon: 'editor-code', + render: withSelect( function( select ) { + return { + theme: select( 'cedaro/code' ).getTheme() + }; + } )( Sidebar ), +} );