gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Bundled ComponentSets for InspectorControls

Open caseymilne opened this issue 5 years ago • 2 comments

What problem does this address?

To provide consistent design controls for most major design concerns. In other words to ensure that all elements can be spaced with padding and margin, all elements can have backgrounds, all elements can have font controls.

What is your proposed solution?

Individual controls such as box controls used for padding and margin are bundled into ComponentSets. For example SpacingComponentSet provide margin and padding combined under 1 panel with a common heading "Spacing". This then fits into a standardized tab "Layout" which sits next to 1-2 other standardized tabs.

All aspects of ComponentSet usage would still be filterable and configurable. But instead of blocks building up controls, instead their controls would be setup by default to include the mapping from standard ComponentSets to attribute on a per element basis.

The model to picture for this is a single div tag that we'll call our design box. It's only purpose is to house InnerBlocks. Our goal is to provide complete design control for the box. What do we need to provide to mirror the essentials of CSS styling for a single div?

  1. Spacing - padding and margin applied to the box.
  2. Typography - option to inherit or customize font-family, font-size.
  3. Color settings for text and background.
  4. Position override (to set box to relative or other CSS position)
  5. Width control (preset width defined e.g. Full Width or defined width and/or max-width)
  6. Height control (inherit, preset defined or set in pixels)
  7. Border controls (border type, border width, border radius etc.)
  8. Background controls ( background type [ color | image | video ], conditional settings that appear based on background type )
  9. Background overlay controls (similar control set as background)
  10. Animation controls (list of available animations, settings appear on after selection).

This level of ComponentSet would tend to be suited to placement in tabs.

Developers would have the following options in usage of ComponentSets:

  1. Use them directly as they are by import and placement inside InspectorControls
  2. Create an adapted version by importing and altering settings. A key setting would be an array of "include" or "remove" components which would allow developers to specific that they want specific components to be added or removed from the ControlSet. This adaption helps in a situation where certain controls are not relevant to a given element.
  3. ComponentSets would be nature be mapped to element(s) rendered, allowing these attributes to be automatically or semi-automatically applied with little or no configuration by developers. A demo of this for instance would be using the design box concept where we map these controls to a single div and then we test if we have full design control over that single div.
  4. Developers can define their own ComponentSets by extending an existing one so that they can then reuse their own customized approach which might be specific to the type of markup their blocks create.

Perhaps ComponentSets could also become an NPM package enabling the use of import like:

import { SpacingComponentSet, BackgroundComponentSet, BackgroundOverlayComponentSet } from '@wordpress/components-sets';

Typography ComponentSet

A typography ComponentSet would include up to 8 components providing a full range of typography controls.

  1. Font Family | <Select [ Inherit, Global, List of Available Fonts ... ] />
  2. Font Size |
  3. Font Weight | <Select [ CSS Font Weights, 400, 500, 600... ] />
  4. Five additional lesser used typography selectors: Transform (uppercase/lowercase), Style (italic/default), Decoration (underlined, strikethrough), Line Height (default, numeric), Line Spacing (inherit, default, numeric).

Example Usage Typography ComponentSet

import { TypographyComponentSet } from '@wordpress/components-sets';

render (
  <InspectorControls>
    <TypographyComponentSet 
      title="Header Typography"
      includeComponents="all" 
      container="standard" <<< This flag enables automatic wrapping into a <PanelBody>     
     />
  </InspectorControls>
)

Attribute Mapping

A standardized form of attribute mapping might enable developers to make only 1 line reference in the "attributes" property of the block definition object passed into registerBlockType(). This would rely on each component in the component set using the same methodology for calling setAttributes. Effectively the goal is that all attributes for a single component set would be stored under a single attribute object. This would enable configuration such as:


registerBlockType( 'block-namespace/block-title'
  attributes: {
    typography: {
      type: 'object'
    }
  }
);

Accessing ComponentSet Attributes

Each component set will have a consistent set of keys used to stored attributes and as all attributes are grouped under a single object per component set, accessing them is handled in a uniform manner:

save( { attributes } ) {

  attributes.typography.fontSize
  attributes.typography.fontWeight
  ...

}

caseymilne avatar Aug 12 '21 17:08 caseymilne

Please mention in comments if you know of existing tickets that propose a similar bundling of components or standardization of inspector control component usage.

caseymilne avatar Aug 12 '21 17:08 caseymilne

These controls are now pretty much all implemented in either @wordpress/components itself, or in @wordpress/block-editor 🎉 Let us know if that's not the case! It might be better to open a new issue if you still want a specific high-level "component set" that doesn't currently exist.

mirka avatar Aug 02 '23 12:08 mirka