Skip to content

Latest commit

 

History

History
108 lines (80 loc) · 3.26 KB

README.md

File metadata and controls

108 lines (80 loc) · 3.26 KB

Color Picker Editor for Neos CMS

Latest Stable Version Total Downloads License

Introduction

This package provides a Color Picker Editor which can be used in Neos CMS with the Neos.Ui 2+.

This editor is based on the example in https://github.com/neos/neos-ui-extensibility-examples but has some modifications in regards to styling, supports the alpha channel and has a reset button to unset a value.

Example

See it in action.

Colorpicker in Neos CMS sidebar

Installation

Run this in your site package

composer require --no-update shel/neos-colorpicker

Then run composer update in your project directory.

How to use

Add a property of type string and configure the editor as seen in this example:

Your NodeType:

"My.Site:Content.Text":
  superTypes:
    "Neos.Neos:Content": true
  ui:
    label: 'My text content'
  properties:
    textColor:
      type: string
      ui:
        label: 'Text color'
        reloadIfChanged: true
        inspector:
          group: 'text'
          editor: 'Shel.Neos.ColorPicker/ColorPickerEditor'
          editorOptions:
            # `mode` can be one of "rgba", "hsla", "hex", default: rgba
            mode: 'rgba'
            # Show saturation/hue/alpha (optional), boolean, default: false
            picker: true
            # Show hex/rgba fields (optional), boolean, default: false
            fields: true
            # Show preset colors (optional), array of colors or boolean (to disable)
            presetColors: ['#ff0000', '#0000ff', '#ffff00', ...]
            # Hides the reset button if set to false
            allowEmpty: true

Your Fusion:

prototype(My.Site:Content.Text) < prototype(Neos.Neos:ContentComponent) {

  textColor = ${q(node).property('textColor')}

  renderer = afx`
    <div class="container" style={'color:' + props.textColor + ';'} [email protected]={props.textColor}>
        <h1>Hello World</h1>
        <p>Euismod massa quam arcu et mi arcu tincidunt maximus tortor lacus interdum vivamus cursus aliquam eget amet amet eget gravida et vivamus eget diam tortor.</p>
    </div>
  `
}

Customization

The editor allows some customization options via your Settings.yaml file:

Neos:
 Neos:
  Ui:
   frontendConfiguration:
    "Shel.Neos:ColorPickerEditor":
     # `mode` can be one of "rgba", "hsla", "hex"
     mode: "rgba"
     # Colors which are available for quick selection
     presetColors: ["#D0021B", "#F5A623", ...]

mode allows you to store the selected color values in a different format if needed. This can be helpful, when the hsl format is needed to get the individual components.

presetColors lets you customize the list of color squares that are available for quick selection.

Contributions

Contributions are very welcome!

Please create detailed issues and PRs.