Search by

sunnysideup / selected-colour-picker

sunnysideup

Silverstrpe Module that sets a list of colours that the CMS Editor can choose from.

Package info

github.com/sunnysideup/silverstripe-selected-colour-picker

Type:silverstripe-vendormodule

pkg:composer/sunnysideup/selected-colour-picker

Statistics

Installs: 619

Dependents: 2

Suggesters: 0

Stars: 0

Open Issues: 0

2.0.0 2023-08-14 19:03 UTC

This package is auto-updated.

Last update: 2026-12-05 01:14:02 UTC


README

Build Status Scrutinizer Code Quality codecov.io

Latest Stable Version License Monthly Downloads

TL;DR

add colour to DataObject

Here is how to add a colour to a DataObject:

    private static $db = [
        'MyColour' => 'Colour',
        'MyColour2' => 'BackgroundColour',
        'MyColour3' => 'FontColour',
        'MyColour4' => 'DifferentDBColourSchema',
    ]

Settings in yml

Sunnysideup\SelectedColourPicker\Model\Fields\DBColour:
  # REQUIRED
  colours:
    '#ff2233': 'Brand Colour 1'
    '#88aadd': 'Brand Colour 2'

  # OPTIONAL!
  linked_colours:
    '#ff2233': 
      'font': '#123312'
      'background': '#775544'
      'somethingelse': '#000000'
  # OPTIONAL!
  colour_picker_field_class_name: MyColourSelectionField

Usage in SilverStripe template

<div style="background-color: $MyColour; color: $MyColour.ReadableColour" style="$MyColour.CssClass">

<br /><% if $MyColour.IsDarkColour %>Is Dark Colour <% end_if %>
<br /><% if $MyColour.IsLightColour %>Is Light Colour <% end_if %>
<br />Related font colour: $MyColour.RelatedColourByName(font) - as set in private static
<br />Related background colour: $MyColour.RelatedColourByName(background) - as set in private static
<br />Related something else colour: $MyColour.RelatedColourByName(somethingelse) - as set in private static
<br />Inverted colour: $MyColour.Inverted
<style>
MyColour.CssVariableDefinition
</style>

customisation

SilverStripe\Core\Injector\Injector:
  MyColour:
    class: MyName\MyApp\Model\Fields\DifferentDBColourSchema

In PHP you can then add different approaches.

class DifferentDBColourSchema extends DBColour
{
    private static $colour_picker_field_class_name = MyFormField::class;

    /**
     * please set.
     *
     * @var bool
     */
    protected const IS_BG_COLOUR = true;
}

Requirements

See composer.json for details

Suggested Modules

See composer.json for details

Installation

composer require sunnysideup/selected-colour-picker

Configuration

In the _config folder you will find the selected-colour-picker.yml.example file that shows options for the configuration of this module.

We recommend that you:

  1. copy these selected-colour-picker.yml.example files into your app/_config folder (where available - otherwise search for private static $ in the module to see what can be configured)
  2. remove the .example extension,
  3. delete the lines you do not care about, and
  4. adjust the configurations that you would like to use.

Contributing

We welcome any contributions. See CONTRIBUTING.md for more details.

Paid assistance

You can pay us to create an improved / adapted version of this module for your own projects. Please contact us if you like to find out more: www.sunnysideup.co.nz. For exmaple, we can write tests for this module.

Author

Sunny Side Up Ltd.

Care to see more modules?

To find other modules, please visit ssmods.com.