From 8f0c832d851598ff82d3cc257097efb88accde2c Mon Sep 17 00:00:00 2001 From: Jorge Date: Thu, 1 Feb 2018 22:38:04 +0000 Subject: [PATCH] Move components in wp.blocks.InspectorControls.* to wp.components.*. The components were not inspector controls specific, they were just generic input elements. This move will allow other parts of the Gutenberg besides blocks, e.g: document sidebar to take advantage of this reusable components. --- blocks/hooks/anchor.js | 3 +- blocks/hooks/custom-class-name.js | 3 +- blocks/inspector-controls/index.js | 65 +++++++++++----- blocks/library/button/index.js | 3 +- blocks/library/categories/block.js | 3 +- blocks/library/columns/index.js | 2 +- blocks/library/cover-image/index.js | 4 +- blocks/library/gallery/block.js | 12 ++- blocks/library/image/block.js | 4 +- blocks/library/latest-posts/block.js | 11 ++- blocks/library/more/index.js | 2 +- blocks/library/paragraph/index.js | 11 ++- blocks/library/text-columns/index.js | 2 +- blocks/query-panel/index.js | 3 +- blocks/term-tree-select/index.js | 4 +- components/base-control/README.md | 63 ++++++++++++++++ .../base-control/index.js | 0 .../base-control/style.scss | 0 components/checkbox-control/README.md | 62 ++++++++++++++++ .../checkbox-control/index.js | 10 +-- .../checkbox-control/style.scss | 0 components/index.js | 8 ++ components/radio-control/README.md | 62 ++++++++++++++++ .../radio-control/index.js | 10 +-- .../radio-control/style.scss | 0 components/range-control/README.md | 74 +++++++++++++++++++ .../range-control/index.js | 6 +- .../range-control/style.scss | 0 .../range-control/test/index.js | 0 components/select-control/README.md | 55 ++++++++++++++ .../select-control/index.js | 10 +-- .../select-control/style.scss | 0 components/text-control/README.md | 57 ++++++++++++++ .../text-control/index.js | 10 +-- .../text-control/style.scss | 0 components/textarea-control/README.md | 58 +++++++++++++++ .../textarea-control/index.js | 10 +-- .../textarea-control/style.scss | 0 components/toggle-control/README.md | 50 +++++++++++++ .../toggle-control/index.js | 5 +- .../toggle-control/style.scss | 0 .../toggle-control/test/index.js | 0 42 files changed, 595 insertions(+), 87 deletions(-) create mode 100644 components/base-control/README.md rename {blocks/inspector-controls => components}/base-control/index.js (100%) rename {blocks/inspector-controls => components}/base-control/style.scss (100%) create mode 100644 components/checkbox-control/README.md rename {blocks/inspector-controls => components}/checkbox-control/index.js (78%) rename {blocks/inspector-controls => components}/checkbox-control/style.scss (100%) create mode 100644 components/radio-control/README.md rename {blocks/inspector-controls => components}/radio-control/index.js (84%) rename {blocks/inspector-controls => components}/radio-control/style.scss (100%) create mode 100644 components/range-control/README.md rename {blocks/inspector-controls => components}/range-control/index.js (86%) rename {blocks/inspector-controls => components}/range-control/style.scss (100%) rename {blocks/inspector-controls => components}/range-control/test/index.js (100%) create mode 100644 components/select-control/README.md rename {blocks/inspector-controls => components}/select-control/index.js (83%) rename {blocks/inspector-controls => components}/select-control/style.scss (100%) create mode 100644 components/text-control/README.md rename {blocks/inspector-controls => components}/text-control/index.js (75%) rename {blocks/inspector-controls => components}/text-control/style.scss (100%) create mode 100644 components/textarea-control/README.md rename {blocks/inspector-controls => components}/textarea-control/index.js (75%) rename {blocks/inspector-controls => components}/textarea-control/style.scss (100%) create mode 100644 components/toggle-control/README.md rename {blocks/inspector-controls => components}/toggle-control/index.js (84%) rename {blocks/inspector-controls => components}/toggle-control/style.scss (100%) rename {blocks/inspector-controls => components}/toggle-control/test/index.js (100%) diff --git a/blocks/hooks/anchor.js b/blocks/hooks/anchor.js index e27094c66bbda..c4e14cc0193ba 100644 --- a/blocks/hooks/anchor.js +++ b/blocks/hooks/anchor.js @@ -8,6 +8,7 @@ import { assign } from 'lodash'; */ import { getWrapperDisplayName } from '@wordpress/element'; import { addFilter } from '@wordpress/hooks'; +import { TextControl } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; /** @@ -62,7 +63,7 @@ export function withInspectorControl( BlockEdit ) { return [ , hasAnchor && - , hasCustomClassName && - { diff --git a/blocks/inspector-controls/index.js b/blocks/inspector-controls/index.js index f5db4830647ca..9276d08aa94f3 100644 --- a/blocks/inspector-controls/index.js +++ b/blocks/inspector-controls/index.js @@ -1,19 +1,23 @@ /** - * WordPress dependencies + * External dependencies */ -import { Fill } from '@wordpress/components'; +import { forEach } from 'lodash'; /** - * Internal dependencies + * WordPress dependencies */ -import BaseControl from './base-control'; -import CheckboxControl from './checkbox-control'; -import RadioControl from './radio-control'; -import RangeControl from './range-control'; -import SelectControl from './select-control'; -import TextControl from './text-control'; -import TextareaControl from './textarea-control'; -import ToggleControl from './toggle-control'; +import { + BaseControl, + CheckboxControl, + Fill, + RadioControl, + RangeControl, + SelectControl, + TextControl, + TextareaControl, + ToggleControl, +} from '@wordpress/components'; +import { Component } from '@wordpress/element'; export default function InspectorControls( { children } ) { return ( @@ -23,11 +27,34 @@ export default function InspectorControls( { children } ) { ); } -InspectorControls.BaseControl = BaseControl; -InspectorControls.CheckboxControl = CheckboxControl; -InspectorControls.RadioControl = RadioControl; -InspectorControls.RangeControl = RangeControl; -InspectorControls.SelectControl = SelectControl; -InspectorControls.TextControl = TextControl; -InspectorControls.TextareaControl = TextareaControl; -InspectorControls.ToggleControl = ToggleControl; +const withDeprecation = ( componentName ) => ( OriginalComponent ) => { + class WrappedComponent extends Component { + componentDidMount() { + // eslint-disable-next-line no-console + console.warn( `wp.blocks.InspectorControls.${ componentName } is deprecated, use wp.components.${ componentName }.` ); + } + + render() { + return ( + + ); + } + } + return WrappedComponent; +}; + +forEach( + { + BaseControl, + CheckboxControl, + RadioControl, + RangeControl, + SelectControl, + TextControl, + TextareaControl, + ToggleControl, + }, + ( component, componentName ) => { + InspectorControls[ componentName ] = withDeprecation( componentName )( component ); + } +); diff --git a/blocks/library/button/index.js b/blocks/library/button/index.js index c91e4e1f77022..1d272f2d6ff43 100644 --- a/blocks/library/button/index.js +++ b/blocks/library/button/index.js @@ -3,7 +3,7 @@ */ import { __ } from '@wordpress/i18n'; import { Component } from '@wordpress/element'; -import { Dashicon, IconButton, PanelColor, withFallbackStyles } from '@wordpress/components'; +import { Dashicon, IconButton, PanelColor, ToggleControl, withFallbackStyles } from '@wordpress/components'; /** * Internal dependencies @@ -13,7 +13,6 @@ import './style.scss'; import RichText from '../../rich-text'; import UrlInput from '../../url-input'; import BlockControls from '../../block-controls'; -import ToggleControl from '../../inspector-controls/toggle-control'; import BlockAlignmentToolbar from '../../block-alignment-toolbar'; import ColorPalette from '../../color-palette'; import ContrastChecker from '../../contrast-checker'; diff --git a/blocks/library/categories/block.js b/blocks/library/categories/block.js index 751455a02a60c..5a9faaa621a5c 100644 --- a/blocks/library/categories/block.js +++ b/blocks/library/categories/block.js @@ -2,7 +2,7 @@ * WordPress dependencies */ import { Component } from '@wordpress/element'; -import { Placeholder, Spinner, withAPIData } from '@wordpress/components'; +import { Placeholder, Spinner, ToggleControl, withAPIData } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { times, unescape } from 'lodash'; @@ -12,7 +12,6 @@ import { times, unescape } from 'lodash'; import './editor.scss'; import './style.scss'; import InspectorControls from '../../inspector-controls'; -import ToggleControl from '../../inspector-controls/toggle-control'; import BlockControls from '../../block-controls'; import BlockAlignmentToolbar from '../../block-alignment-toolbar'; diff --git a/blocks/library/columns/index.js b/blocks/library/columns/index.js index 5331df92262a9..9f4a88e491ecd 100644 --- a/blocks/library/columns/index.js +++ b/blocks/library/columns/index.js @@ -8,12 +8,12 @@ import classnames from 'classnames'; * WordPress dependencies */ import { __, sprintf } from '@wordpress/i18n'; +import { RangeControl } from '@wordpress/components'; /** * Internal dependencies */ import './style.scss'; -import RangeControl from '../../inspector-controls/range-control'; import InspectorControls from '../../inspector-controls'; import BlockControls from '../../block-controls'; import BlockAlignmentToolbar from '../../block-alignment-toolbar'; diff --git a/blocks/library/cover-image/index.js b/blocks/library/cover-image/index.js index 8999277552afc..ee26f0b4dd626 100644 --- a/blocks/library/cover-image/index.js +++ b/blocks/library/cover-image/index.js @@ -6,7 +6,7 @@ import { isEmpty } from 'lodash'; /** * WordPress dependencies */ -import { IconButton, PanelBody, Toolbar } from '@wordpress/components'; +import { IconButton, PanelBody, RangeControl, ToggleControl, Toolbar } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import classnames from 'classnames'; @@ -23,8 +23,6 @@ import ImagePlaceHolder from '../../image-placeholder'; import BlockControls from '../../block-controls'; import BlockAlignmentToolbar from '../../block-alignment-toolbar'; import InspectorControls from '../../inspector-controls'; -import ToggleControl from '../../inspector-controls/toggle-control'; -import RangeControl from '../../inspector-controls/range-control'; const validAlignments = [ 'left', 'center', 'right', 'wide', 'full' ]; diff --git a/blocks/library/gallery/block.js b/blocks/library/gallery/block.js index 36b87499381b2..b6bdd911b34bc 100644 --- a/blocks/library/gallery/block.js +++ b/blocks/library/gallery/block.js @@ -9,7 +9,14 @@ import { filter } from 'lodash'; import { Component } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { mediaUpload } from '@wordpress/utils'; -import { IconButton, DropZone, Toolbar } from '@wordpress/components'; +import { + IconButton, + DropZone, + RangeControl, + SelectControl, + ToggleControl, + Toolbar, +} from '@wordpress/components'; /** * Internal dependencies @@ -17,9 +24,6 @@ import { IconButton, DropZone, Toolbar } from '@wordpress/components'; import MediaUpload from '../../media-upload'; import ImagePlaceHolder from '../../image-placeholder'; import InspectorControls from '../../inspector-controls'; -import RangeControl from '../../inspector-controls/range-control'; -import ToggleControl from '../../inspector-controls/toggle-control'; -import SelectControl from '../../inspector-controls/select-control'; import BlockControls from '../../block-controls'; import BlockAlignmentToolbar from '../../block-alignment-toolbar'; import GalleryImage from './gallery-image'; diff --git a/blocks/library/image/block.js b/blocks/library/image/block.js index 7c92349864ce1..fd46be4535145 100644 --- a/blocks/library/image/block.js +++ b/blocks/library/image/block.js @@ -18,6 +18,8 @@ import { Component, compose } from '@wordpress/element'; import { createMediaFromFile, getBlobByURL, revokeBlobURL, viewPort } from '@wordpress/utils'; import { IconButton, + SelectControl, + TextControl, Toolbar, withAPIData, withContext, @@ -30,8 +32,6 @@ import RichText from '../../rich-text'; import ImagePlaceHolder from '../../image-placeholder'; import MediaUpload from '../../media-upload'; import InspectorControls from '../../inspector-controls'; -import TextControl from '../../inspector-controls/text-control'; -import SelectControl from '../../inspector-controls/select-control'; import BlockControls from '../../block-controls'; import BlockAlignmentToolbar from '../../block-alignment-toolbar'; import UrlInputButton from '../../url-input/button'; diff --git a/blocks/library/latest-posts/block.js b/blocks/library/latest-posts/block.js index 08e4a17d43a50..0ca30c391bd82 100644 --- a/blocks/library/latest-posts/block.js +++ b/blocks/library/latest-posts/block.js @@ -10,7 +10,14 @@ import { stringify } from 'querystringify'; * WordPress dependencies */ import { Component } from '@wordpress/element'; -import { Placeholder, Toolbar, Spinner, withAPIData } from '@wordpress/components'; +import { + Placeholder, + RangeControl, + Spinner, + ToggleControl, + Toolbar, + withAPIData, +} from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { decodeEntities } from '@wordpress/utils'; @@ -21,8 +28,6 @@ import './editor.scss'; import './style.scss'; import QueryPanel from '../../query-panel'; import InspectorControls from '../../inspector-controls'; -import ToggleControl from '../../inspector-controls/toggle-control'; -import RangeControl from '../../inspector-controls/range-control'; import BlockControls from '../../block-controls'; import BlockAlignmentToolbar from '../../block-alignment-toolbar'; diff --git a/blocks/library/more/index.js b/blocks/library/more/index.js index 8e95f4866d51a..1e63af6ab6b6c 100644 --- a/blocks/library/more/index.js +++ b/blocks/library/more/index.js @@ -2,13 +2,13 @@ * WordPress dependencies */ import { __ } from '@wordpress/i18n'; +import { ToggleControl } from '@wordpress/components'; /** * Internal dependencies */ import './editor.scss'; import InspectorControls from '../../inspector-controls'; -import ToggleControl from '../../inspector-controls/toggle-control'; export const name = 'core/more'; diff --git a/blocks/library/paragraph/index.js b/blocks/library/paragraph/index.js index 3c6be708ba1c5..37ccc4188d41b 100644 --- a/blocks/library/paragraph/index.js +++ b/blocks/library/paragraph/index.js @@ -8,7 +8,14 @@ import classnames from 'classnames'; */ import { __ } from '@wordpress/i18n'; import { concatChildren, Component } from '@wordpress/element'; -import { Autocomplete, PanelBody, PanelColor, withFallbackStyles } from '@wordpress/components'; +import { + Autocomplete, + PanelBody, + PanelColor, + RangeControl, + ToggleControl, + withFallbackStyles, +} from '@wordpress/components'; /** * Internal dependencies @@ -22,8 +29,6 @@ import BlockAlignmentToolbar from '../../block-alignment-toolbar'; import BlockControls from '../../block-controls'; import RichText from '../../rich-text'; import InspectorControls from '../../inspector-controls'; -import ToggleControl from '../../inspector-controls/toggle-control'; -import RangeControl from '../../inspector-controls/range-control'; import ColorPalette from '../../color-palette'; import ContrastChecker from '../../contrast-checker'; diff --git a/blocks/library/text-columns/index.js b/blocks/library/text-columns/index.js index b8c2b7a05a6da..c0ad471fe68f7 100644 --- a/blocks/library/text-columns/index.js +++ b/blocks/library/text-columns/index.js @@ -7,6 +7,7 @@ import { times } from 'lodash'; * WordPress dependencies */ import { __ } from '@wordpress/i18n'; +import { RangeControl } from '@wordpress/components'; /** * Internal dependencies @@ -15,7 +16,6 @@ import './style.scss'; import './editor.scss'; import BlockControls from '../../block-controls'; import BlockAlignmentToolbar from '../../block-alignment-toolbar'; -import RangeControl from '../../inspector-controls/range-control'; import RichText from '../../rich-text'; import InspectorControls from '../../inspector-controls'; diff --git a/blocks/query-panel/index.js b/blocks/query-panel/index.js index 3b36a0f5cd94e..667409a3b23a6 100644 --- a/blocks/query-panel/index.js +++ b/blocks/query-panel/index.js @@ -7,13 +7,12 @@ import { noop } from 'lodash'; * WordPress dependencies */ import { __ } from '@wordpress/i18n'; +import { RangeControl, SelectControl } from '@wordpress/components'; /** * Internal dependencies */ import CategorySelect from './category-select'; -import RangeControl from '../inspector-controls/range-control'; -import SelectControl from '../inspector-controls/select-control'; const DEFAULT_MIN_ITEMS = 1; const DEFAULT_MAX_ITEMS = 100; diff --git a/blocks/term-tree-select/index.js b/blocks/term-tree-select/index.js index 78efb90e270e2..d78006f442eee 100644 --- a/blocks/term-tree-select/index.js +++ b/blocks/term-tree-select/index.js @@ -4,9 +4,9 @@ import { unescape as unescapeString, repeat, flatMap, compact } from 'lodash'; /** - * Internal dependencies + * WordPress dependencies */ -import SelectControl from '../inspector-controls/select-control'; +import { SelectControl } from '@wordpress/components'; function getSelectOptions( terms, level = 0 ) { return flatMap( terms, ( term ) => [ diff --git a/components/base-control/README.md b/components/base-control/README.md new file mode 100644 index 0000000000000..acc23a9cf82a0 --- /dev/null +++ b/components/base-control/README.md @@ -0,0 +1,63 @@ +BaseControl +======= + +BaseControl component is used to generate labels and help text for components handling user inputs. + + +## Usage + +Render a BaseControl for a textarea input: +```jsx + +