Code Monkey home page Code Monkey logo

craft-colour-swatches's People

Contributors

ammannbe avatar benface avatar chasegiunta avatar cookie10codes avatar craftedsystems avatar engram-design avatar markmiddleton avatar michtio avatar pixelmachine avatar timeverts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

craft-colour-swatches's Issues

Use custom properties in colours config

I'm using the colour-swatches config with only custom colours (no palettes).
I'm using Tailwind CSS and I noticed that you can add custom properties to the palettes such as 'teal-500'.
Is it possible to use this inside the colours array too? Can't seem to get the data out when dumping fieldName.

craft-colour-drops

Hi man,

Great plugin!
Any chance for a craft-colour-drops plugin ? ;)
colorme
Perhaps using checkboxes instead of radiobuttons, to let user select one or more colors..
Best regards /

Fredrik

Global variables in color swatches?

What about accepting global varibales in the color values column?
Or is it supposed to work already, and it's just me doing something wrong?
Would be very nice and practical, feeding those fields with global color sets!

Selected color not highlighted in entry page

Hi guys, this is a great and helpful plugin, thank you for making it real!

We are currently running on Craft CMS 3.7.18 and Craft Colour Swatches 1.4.2. It is working great, however when we select a color in the entry page, the selected color seems like losing its focus. The selected ring/shadow around the color is missing.

Screenshot 2021-11-09 at 11 14 17

Migration Issue

Thanks for taking over the plugin!

Unfortunately I upgraded and it seems that we've lost the data. Is there anyway to keep compatibility with previously created fields?

image

Default colour not set into the array when saving entry

So I have set a default colour on a general config for a palette setup.
In the CMS this shows up as selected. However, when coding for this in twig, the value is show as null and not saved.

The only way for this to work, is to set a different colour, save the entry then go back and change back to the default colour.
If you save the entry without setting a colour the default appears to be selected in the CM, but when trying to access the array /output is null.
Impossible to access a key ("0") on a string variable ("")

It might also be linked to this issue #32 , I see on another setup where there is no default set, but there is no error trapping on the 'required' setting for the field. The two might be interlinked?

here is my config:

return [


  'palettes' => [
    'Circles' => [  // custom label
                    [
                      'label'   => 'Yellow', // custom label
                      'default' => true,
                      'color'   => [
                        [
                          'color' => '#FDF20C',  // the color shown in the fieldtype (required)
                          'class' => 'bg-yellow-500', // custom attribute
                        ],
                      ]
                    ],
                    [
                      'label'   => 'Cyan', // custom label
                      'default' => false,
                      'color'   => [
                        [
                          'color' => '#4BC3D5',   // the color shown in the fieldtype (required)
                          'class' => 'bg-cyan-500',  // custom attribute
                        ],
                      ]
                    ],
                    [
                      'label'   => 'Lime', // custom label
                      'default' => false,
                      'color'   => [
                        [
                          'color' => '#BED72F',   // the color shown in the fieldtype (required)
                          'class' => 'bg-lime-500',  // custom attribute
                        ],
                      ]
                    ],
                    [
                      'label'   => 'Pink', // custom label
                      'default' => false,
                      'color'   => [
                        [
                          'color' => '#E7729A',   // the color shown in the fieldtype (required)
                          'class' => 'bg-pink-400',  // custom attribute
                        ],
                      ]
                    ],
                    [
                      'label'   => 'Navy', // custom label
                      'default' => false,
                      'color'   => [
                        [
                          'color' => '#CACED9',   // the color shown in the fieldtype (required)
                          'class' => 'bg-navy-200',  // custom attribute
                        ],
                      ]
                    ],
    ],
    'Boxes'   => [  // custom label
                    [
                      'label'   => 'Navy', // custom label
                      'default' => true,
                      'color'   => [
                        [
                          'color' => '#293A66',   // the color shown in the fieldtype (required)
                          'class' => 'bg-navy-500',  // custom attribute
                        ],
                      ]
                    ],
                    [
                      'label'   => 'Gray', // custom label
                      'default' => false,
                      'color'   => [
                        [
                          'color' => '#6A6D77',   // the color shown in the fieldtype (required)
                          'class' => 'bg-gray-600',  // custom attribute
                        ],
                      ]
                    ],
                    [
                      'label'   => 'Pink', // custom label
                      'default' => false,
                      'color'   => [
                        [
                          'color' => '#DC356F',   // the color shown in the fieldtype (required)
                          'class' => 'bg-pink-500',  // custom attribute
                        ],
                      ]
                    ],
                    [
                      'label'   => 'Lime', // custom label
                      'default' => false,
                      'color'   => [
                        [
                          'color' => '#ABC22A',   // the color shown in the fieldtype (required)
                          'class' => 'bg-lime-600',  // custom attribute
                        ],
                      ]
                    ],
                    [
                      'label'   => 'Cyan', // custom label
                      'default' => false,
                      'color'   => [
                        [
                          'color' => '#44B0C0',   // the color shown in the fieldtype (required)
                          'class' => 'bg-cyan-600',  // custom attribute
                        ],
                      ]
                    ],
                    [
                      'label'   => 'Orange', // custom label
                      'default' => false,
                      'color'   => [
                        [
                          'color' => '#E35E26',   // the color shown in the fieldtype (required)
                          'class' => 'bg-orange-500',  // custom attribute
                        ],
                      ]
                    ],
    ],
  ],
];

Selecting colorField to be shown in entries list gives 400 bad request error

So I am trying to display the color the user select for a specific entry in the Entries list in the CP.

Steps to reproduce:

  • Create a colorField and add it to an Entry
  • Select the colorField to be displayed in the Entries list

Good to know that my colorField has its options defined in the colour-swatches.php config file.

Error message displayed in debug toolbar:
CleanShot 2020-08-06 at 09 28 27@2x

Size of color

Hello.

Thanks for a very usefull plugin. Maybe its just me, but I think the colors are a little bit to big. Could there be an option for a smaller size.

I've just some testing in the browser and did this by changing the css.

.color-swatches li { display: inline-block; margin: 0 10px 10px 0; padding: 5px; }

I removed the original css for color-swatches input:checked + label and added this instead
.color-swatches input:checked + label { box-shadow: 0 0 0 3px orange; }

.color-swatches label { border: 3px solid white; border-radius: 50%; cursor: pointer; display: block; height: 30px; position: relative; transition: box-shadow 200ms ease 0s; width: 30px; }

Thanks!

Color definition in config file occurs an error => not countable()

Create config/colour-swatches.php and set custom color occurs a in CraftCMS Backend while editing the field settings again.

Error
count(): Parameter must be an array or an object that implements Countable

Reproduce

  1. Create config file like in the example,
  2. Create new field in CraftCMS Backend (activate lightswitch => Use config options)
  3. Save and go back to edit the field again occurs the error like in the title

=> Can someone confirm that?

Naming convention of config file
You use

config/colour-swatches.php (use in Tutorial)
and
config/color-swatches.php (this might be wrong but written as comment in the example config file)

Which is correct or even better?

Vizy Support

Hey All,

I'm test driving Vizy from Verbb and it looks like the Colour Swatch plugin is not saving the color selected inside of the Vizy field. On save the field selected just reverts to the first one in the list. I realize that Vizy is super new, but I thought I'd call that out here.

I'm on the latest version of Craft and your plugin.

Thanks gang!

Dashboard error with 1.2.5 update

I've just updated to 1.2.5 (thanks for being so quick at getting back to me today ๐Ÿ™Œ๐Ÿป) and I'm getting a Variable "value" does not exist. error at the root level of my admin view (/admin/dashboard).

See below for more:

Twig\Error\RuntimeError: Variable "value" does not exist. in /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/rias/craft-colour-swatches/src/templates/input.twig:29
Stack trace:
#0 /Users/jaycollett/Sites/jaycollett/project-name/build/storage/runtime/compiled_templates/78/78d3264ed9e7d671ddd08acce375d70fc13b05899ac65adb26bb1eff206f24de.php(84): __TwigTemplate_a4d73b6ecc9488d2205d4146a0a48ad5e10bee0383a66686b4e392fc01c13b4e->{closure}()
#1 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/twig/twig/src/Template.php(407): __TwigTemplate_a4d73b6ecc9488d2205d4146a0a48ad5e10bee0383a66686b4e392fc01c13b4e->doDisplay(Array, Array)
#2 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#3 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/twig/twig/src/Template.php(392): Twig\Template->display(Array)
#4 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/twig/twig/src/TemplateWrapper.php(45): Twig\Template->render(Array, Array)
#5 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/twig/twig/src/Environment.php(318): Twig\TemplateWrapper->render(Array)
#6 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/craftcms/cms/src/web/View.php(400): Twig\Environment->render('colour-swatches...', Array)
#7 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/rias/craft-colour-swatches/src/fields/ColourSwatches.php(205): craft\web\View->renderTemplate('colour-swatches...', Array)
#8 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/twig/twig/src/Extension/CoreExtension.php(1495): rias\colourswatches\fields\ColourSwatches->getInputHtml(Object(rias\colourswatches\models\ColourSwatches), Object(craft\elements\MatrixBlock))
#9 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/craftcms/cms/src/helpers/Template.php(105): twig_get_attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(rias\colourswatches\fields\ColourSwatches), 'getInputHtml', Array, 'method', false, false)
#10 /Users/jaycollett/Sites/jaycollett/project-name/build/storage/runtime/compiled_templates/31/31b9c922b134031893aed3d18850ebb21106eed6bd0988c1418525f062b94216.php(78): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(rias\colourswatches\fields\ColourSwatches), 'getInputHtml', Array, 'method')
#11 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/twig/twig/src/Template.php(407): __TwigTemplate_325d47befe23fcb8c0737038f2a4d2d17501159ec9613fbcdd1913df28e624a2->doDisplay(Array, Array)
#12 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#13 /Users/jaycollett/Sites/jaycollett/project-name/build/storage/runtime/compiled_templates/01/01c043e455977953969ef2f83396173db38eb8c62d67770a564c0dcd460a8dbd.php(86): Twig\Template->display(Array)
#14 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/twig/twig/src/Template.php(407): __TwigTemplate_9a037541dd0bf928cb87edbf20e8fedb65d3a22bc5ee47c05fc28df8a5021042->doDisplay(Array, Array)
#15 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#16 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/twig/twig/src/Template.php(392): Twig\Template->display(Array)
#17 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/twig/twig/src/TemplateWrapper.php(45): Twig\Template->render(Array, Array)
#18 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/twig/twig/src/Environment.php(318): Twig\TemplateWrapper->render(Array)
#19 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/craftcms/cms/src/web/View.php(400): Twig\Environment->render('_includes/field...', Array)
#20 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/craftcms/cms/src/fields/Matrix.php(1107): craft\web\View->renderTemplate('_includes/field...', Array)
#21 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/craftcms/cms/src/fields/Matrix.php(647): craft\fields\Matrix->_getBlockTypeInfoForInput(NULL, Array)
#22 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/twig/twig/src/Extension/CoreExtension.php(1495): craft\fields\Matrix->getInputHtml(Array, NULL)
#23 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/craftcms/cms/src/helpers/Template.php(105): twig_get_attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(craft\fields\Matrix), 'getInputHtml', Array, 'method', false, false)
#24 /Users/jaycollett/Sites/jaycollett/project-name/build/storage/runtime/compiled_templates/31/31b9c922b134031893aed3d18850ebb21106eed6bd0988c1418525f062b94216.php(78): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(craft\fields\Matrix), 'getInputHtml', Array, 'method')
#25 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/twig/twig/src/Template.php(407): __TwigTemplate_325d47befe23fcb8c0737038f2a4d2d17501159ec9613fbcdd1913df28e624a2->doDisplay(Array, Array)
#26 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#27 /Users/jaycollett/Sites/jaycollett/project-name/build/storage/runtime/compiled_templates/07/078714ee4a9cb9d0a9575b2a834c5749af5ef76d8d9ee96c02449942fabb5e99.php(86): Twig\Template->display(Array)
#28 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/twig/twig/src/Template.php(407): __TwigTemplate_b17d6750c1fece166e262fb06bc5bad86bcf4175b27b347493a1c20c6219d8ca->doDisplay(Array, Array)
#29 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#30 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/twig/twig/src/Template.php(392): Twig\Template->display(Array)
#31 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/twig/twig/src/TemplateWrapper.php(45): Twig\Template->render(Array, Array)
#32 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/twig/twig/src/Environment.php(318): Twig\TemplateWrapper->render(Array)
#33 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/craftcms/cms/src/web/View.php(400): Twig\Environment->render('_components/wid...', Array)
#34 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/craftcms/cms/src/widgets/QuickPost.php(177): craft\web\View->renderTemplate('_components/wid...', Array)
#35 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/craftcms/cms/src/controllers/DashboardController.php(514): craft\widgets\QuickPost->getBodyHtml()
#36 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/craftcms/cms/src/controllers/DashboardController.php(99): craft\controllers\DashboardController->_getWidgetInfo(Object(craft\widgets\QuickPost))
#37 [internal function]: craft\controllers\DashboardController->actionIndex()
#38 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#39 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#40 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/craftcms/cms/src/web/Controller.php(187): yii\base\Controller->runAction('index', Array)
#41 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('index', Array)
#42 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/craftcms/cms/src/web/Application.php(299): yii\base\Module->runAction('dashboard/index', Array)
#43 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction('dashboard/index', Array)
#44 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/craftcms/cms/src/web/Application.php(284): yii\web\Application->handleRequest(Object(craft\web\Request))
#45 /Users/jaycollett/Sites/jaycollett/project-name/build/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#46 /Users/jaycollett/Sites/jaycollett/project-name/build/public/index.php(21): yii\base\Application->run()
#47 {main}

Here's an easier screenshot of the markup it's failing on:

Screenshot 2019-12-18 at 15 22 48

Thanks!

Default Values not respected within a Super Table field

Hey Gang,

When using a Colour Swatch field within a SuperTable field the default selection does not save.

Screen Shot 2021-06-08 at 2 34 34 PM

I selected it above, but no matter how many times I select the second color it never gets the red ring. (Plus the red ring isn't all that clear that the color is selected even inside a CS field) and when the field settings are saved it reverts back to the first option:

Screen Shot 2021-06-08 at 2 39 42 PM

I hope that helps

Clicking too many colours to quickly crashes the plugin

After selecting a few colours in quick succession, the plugin stops working entirely and gives this javascript error in the console:

ColourSwatches.js?v=1528375172:30 Uncaught TypeError: Cannot read property 'removeClass' of null
    at s.constructor.onOptionSelect (ColourSwatches.js?v=1528375172:30)
    at s.constructor.i (jquery.js:496)
    at s.constructor.<anonymous> (garnish.js:893)
    at HTMLButtonElement.i (jquery.js:496)
    at HTMLButtonElement.dispatch (jquery.js:5206)
    at HTMLButtonElement.v.handle (jquery.js:5014)

colour-swatches.php

Well, as a Brit this is the first time I've ever been caught out in reverse for pre-emptively assuming the file name would be the American English version, and not the British.

Could I suggest aliasing both spellings?

Selected active state not showing on entry admin load.

Selected colour 'active' state not being shown after I save an entry. Please see below. I have chosen one of these colours for my slide, then when the admin refreshes to store this change, the active indicator is gone.

Craft Version: 3.5.4

image

Trying to access hex in plugin

Hi - I'm trying to access the value of the colour swatch in a custom plugin but everything in the ColorData Object seems to be private so I can't get the value. Is there any way I can do this?

Swatches displaying with checkerboard pattern in Control Panel

After updating from plugin version 1.2.3 to 1.2.7, the swatches on the fields in the Control Panel are displaying a checkerboard pattern rather than as a solid colour.

checkerboard-pattern-swatches

Craft Version: 3.3.19
Plugin Version: 1.2.7

Here is my colour-swatches.php config file:

<?php
return [
	'colours' => [
		[
			'label'   => 'Coal Dark',
			'color'   => '#141A1E',
			'default' => true
		],
		[
			'label'   => 'Coal Light',
			'color'   => '#1D252D',
			'default' => false
		],
		[
			'label'   => 'Coal Grey',
			'color'   => '#5A5E61',
			'default' => false
		],
		[
			'label'   => 'Plum',
			'color'   => '#5A2D58',
			'default' => false
		],
		[
			'label'   => 'Wine',
			'color'   => '#A12242',
			'default' => false
		]
	]
];

Default colour not working

If you create a colour swatched field and select one of the colours to be "Default", it doesn't actually get selected as the default colour. It appears to in the CMS, but the front end outputs nothing.

Latest update breaks "migrate/all" over Craft console

The schemaVersion in composer.json was updated even though the newest update to this plugin doesn't actually have/need any migrations. This is causing Craft to be confused and think that it has missed a migration, and require a manual visit to the CP in order to bring the site up.

The schemaVersion should only change if/when a new migration is also present on the plugin (furthermore, schemaVersion does not need to match the plugin version - Craft itself has a schemaVersion that is behind / not-in-sync with their Craft veron due to many Craft versions that do not require table migrations).

[Feature Request] Selectable swatch shape, size, and style

First off: This plugin is invaluable; thank you so much!

I'm working on a site where I'm needing two colors per swatch, a foreground/text color, and the background color. The current way of displaying multiple colors as a diagonal linear-gradient is great for general use, but it falls a bit short at conveying which color is FG and which is the BG:

image

This can be solved by adding a few simple per-field settings to control the appearance of the swatches in the backend:

  • Swatch Shape: circular / square / wide / tall (wide and tall could be something like 2:1 ratio rectangles)
  • Swatch Size: small / medium / large

And for multi-color swatches only, you could add:

  • Swatch Type: linear / radial / conic (equal to the CSS gradient types; with a disclaimer about the conic mode only working in Webkit browsers)
  • Swatch Direction (linear-only): Horizontal / Vertical / Angled forwards (like this: /) / Angled backwards (like this: \)

Ok, so not all of those are necessary to solve the issue I'm specifically dealing with, but they're all pretty closely related as they simply change the CSS styles being applied to the swatches. ;)

In my use case, and given the options above, I'd probably choose Wide, Medium, & Radial, to convey FG color as a smallish circle inside a colored rectangle:

image

Thanks for your time!

Value being reverted to default value

issue-with-default-color-swatch

Upon editing a previously saved entry with the Colour swatches field, the color is reverted to the default color.

this can be repeated by:

  1. open a previously saved entry using a colour swatches field (make sure the colour swatches field has a default value different from the currently selected value).
  2. make no changes to the entry
  3. save the entry
  4. the colour is updated to the default colour.

How to migrate/upgrade from v.1.2.8 without breaking Craft?

I have an old version of craft colour swatches installed - "marbles/craft-colour-swatches": "1.2.8" and would like to upgrade to the latest version - "percipioglobal/craft-colour-swatches": "1.4.0"

The CraftCMS CP shows me the upgrade option - so I presume it is the same plugin, despite the different repositories. (I may have switched to marbles' version sometime in the past because of the need to save defaults...)

But, when I do upgrade, both the CP and existing twig code break.

I have hundreds of entries using the colour swatches to set colors for different elements - I would need to preserve all of these.

Any suggestions?

With "marbles/craft-colour-swatches": "1.2.8":

Screen Shot 2020-09-29 at 1 10 51 PM

With "percipioglobal/craft-colour-swatches": "1.4.0"

Screen Shot 2020-09-29 at 1 09 20 PM

Screen Shot 2020-09-29 at 1 09 39 PM

Screen Shot 2020-09-29 at 1 09 34 PM

Option to unselect user selection

Hi there!

Wonderful plugin of yours! Thank you!

But I think it would be crucial to have a field option to unset any selection, e.g. by simply clicking a selected color once again... Would be usefull, don't you think?

Regards, Hendrik

Inconsistent use of "colour" and "color"

Further to #50 (I'm sure this will get tackled in fixing that), I'd like to raise the inconsistency of where the word is used. Personally, I'm a Brit, but I still would rather use the Americanism for consistency across my code.

But there are some instances where "Colour" and "Color" are used in the same place. See below:
image

If they could all be "color" that'd be lovely. ๐Ÿ™Œ๐Ÿป

Twig template error when fieldValue is set to null

The new code sets the value of fieldValue to null if it is undefined, which breaks the template.

The template tries to ensure fieldValue is defined before accessing it, but Twig treats null as defined. This lead to the following:

  • fieldValue is defined -> true
  • fieldValue is not null -> false

So the checks for fieldValue should probably be updated to null checks, instead of defined checks.

Configurable option for client to add custom hex?

I've used this in two places now and I've had to combine it with the P&T colour field for an instance where there's a custom option.

Any possibility for this to be built into the plugin so when I'm setting up my field I have the option of allowing the client to add a custom colour if required?

Cheers

Importing colours via Feedme?

Has anyone had any luck importing colours into Colour Swatches via FeedMe?

I've tried with different values e.g. using the label of red, or the Hex Value, but just get the following in FeedMe Logs?

Trying to get property 'label' of non-object - ColourSwatches.php: 25

Is it to do with the field values or does this need it's own field importer building for Feedme?

Thanks

graphql support

Any chance the full model can be exposed for graphql queries? Currently returns a string corresponding to the Label field

Twig Runtime Error โ€“ Twig\Error\RuntimeError When Using Config File

When I use the config file provided in the readme, I am receiving the following error when I try to create a swatches field. I'm using the latest version of Craft.

Twig\Error\RuntimeError: Impossible to access an attribute ("color") on a null variable. in /Users/@username/Projects/@Client/@Client-www/vendor/percipioglobal/craft-colour-swatches/src/templates/colourOption.twig:32
Stack trace:
#0 /Users/@username/Projects/@Client/@Client-www/vendor/craftcms/cms/src/helpers/Template.php(90): twig_get_attribute(Object(craft\web\twig\Environment), Object(Twig\Source), NULL, 'color', Array, 'any', false, false)
#1 /Users/@username/Projects/@Client/@Client-www/storage/runtime/compiled_templates/98/988e760d3744f98cc265daf168b4090ebfff8ba83776ad7b74af5fc5f12af33b.php(160): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), NULL, 'color', Array)
#2 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Template.php(407): __TwigTemplate_a9bdff91721db457c1def9f93ea04a9c89c4bc095bb4cfad626f7ab503fa6322->doDisplay(Array, Array)
#3 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#4 /Users/@username/Projects/@Client/@Client-www/storage/runtime/compiled_templates/fc/fcead86f63cda8b1601f623772e594cc40dc8ce88d9194c4be7992b46c8f4d68.php(123): Twig\Template->display(Array)
#5 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Template.php(407): __TwigTemplate_830fac83030a160162cccf85f1ba01b12d66c384d3548b2bf723eba15f0f0149->doDisplay(Array, Array)
#6 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#7 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Template.php(392): Twig\Template->display(Array)
#8 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/TemplateWrapper.php(45): Twig\Template->render(Array, Array)
#9 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Environment.php(318): Twig\TemplateWrapper->render(Array)
#10 /Users/@username/Projects/@Client/@Client-www/vendor/craftcms/cms/src/web/View.php(391): Twig\Environment->render('colour-swatches...', Array)
#11 /Users/@username/Projects/@Client/@Client-www/vendor/percipioglobal/craft-colour-swatches/src/fields/ColourSwatches.php(177): craft\web\View->renderTemplate('colour-swatches...', Array)
#12 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Extension/CoreExtension.php(1499): percipioglobal\colourswatches\fields\ColourSwatches->getSettingsHtml()
#13 /Users/@username/Projects/@Client/@Client-www/vendor/craftcms/cms/src/helpers/Template.php(90): twig_get_attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(percipioglobal\colourswatches\fields\ColourSwatches), 'getSettingsHtml', Array, 'method', false, false)
#14 /Users/@username/Projects/@Client/@Client-www/storage/runtime/compiled_templates/89/8981e7bd542db6027db4a519f681666e3b8fce0851e4b4846bd9ccc43477d3ba.php(493): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(percipioglobal\colourswatches\fields\ColourSwatches), 'getSettingsHtml', Array, 'method')
#15 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Template.php(407): __TwigTemplate_44d43af88f5a97be8f5af234567d3f06a9dc2ea1e43f8e32faa22f734bf99cfe->doDisplay(Array, Array)
#16 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#17 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Template.php(392): Twig\Template->display(Array)
#18 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/TemplateWrapper.php(45): Twig\Template->render(Array, Array)
#19 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Environment.php(318): Twig\TemplateWrapper->render(Array)
#20 /Users/@username/Projects/@Client/@Client-www/vendor/craftcms/cms/src/web/View.php(391): Twig\Environment->render('_components/fie...', Array)
#21 /Users/@username/Projects/@Client/@Client-www/vendor/craftcms/cms/src/fields/Matrix.php(480): craft\web\View->renderTemplate('_components/fie...', Array)
#22 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Extension/CoreExtension.php(1499): craft\fields\Matrix->getSettingsHtml()
#23 /Users/@username/Projects/@Client/@Client-www/vendor/craftcms/cms/src/helpers/Template.php(90): twig_get_attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(craft\fields\Matrix), 'getSettingsHtml', Array, 'method', false, false)
#24 /Users/@username/Projects/@Client/@Client-www/storage/runtime/compiled_templates/b0/b001cafe7fcde89c43d6f30fc3a1b072b34784d4f266adf805b772ad4948168a.php(46): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(craft\fields\Matrix), 'getSettingsHtml', Array, 'method')
#25 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Template.php(407): __TwigTemplate_d15fa2816bfbd4efb4cbb2de0c8d6c90206c5da81829c2d97718dd44ac9e85e7->doDisplay(Array, Array)
#26 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#27 /Users/@username/Projects/@Client/@Client-www/storage/runtime/compiled_templates/fa/fa2252bbb0d116adfbaa1cf595833a65d3c0b1ed609f0ffa1c5feccaf203afe9.php(252): Twig\Template->display(Array)
#28 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Template.php(184): __TwigTemplate_fea505635b6743399d3305c49f679a6d576f8428abed1b40987500d97af6a059->block_content(Array, Array)
#29 /Users/@username/Projects/@Client/@Client-www/storage/runtime/compiled_templates/de/de929b49b891150853d81291c1496963e0001e6e862d29429a35f2e8668af30b.php(439): Twig\Template->displayBlock('content', Array, Array)
#30 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Template.php(184): __TwigTemplate_bcdf16f6ea79446579e0f1f6314350a6a4ff3427001b78acd025a1728da6ae5e->block_main(Array, Array)
#31 /Users/@username/Projects/@Client/@Client-www/storage/runtime/compiled_templates/de/de929b49b891150853d81291c1496963e0001e6e862d29429a35f2e8668af30b.php(304): Twig\Template->displayBlock('main', Array, Array)
#32 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Template.php(184): __TwigTemplate_bcdf16f6ea79446579e0f1f6314350a6a4ff3427001b78acd025a1728da6ae5e->block_body(Array, Array)
#33 /Users/@username/Projects/@Client/@Client-www/storage/runtime/compiled_templates/80/80d436834e2be9780ab6ada4e971208f2652bb4a9663963e64897c78c807d673.php(85): Twig\Template->displayBlock('body', Array, Array)
#34 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Template.php(407): __TwigTemplate_b482ca96a64171d151407ea8b9d955b8f9568d26e48faa44bcc51f142b0b4c77->doDisplay(Array, Array)
#35 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#36 /Users/@username/Projects/@Client/@Client-www/storage/runtime/compiled_templates/05/0505bff6efc7f42f963300b6ee1b914237862ea83836a31cb3465a1c69194e41.php(56): Twig\Template->display(Array, Array)
#37 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Template.php(407): __TwigTemplate_78b2cacba6b4403bd89068577db25a3de6557cc077c8bd55c0a46b744af36612->doDisplay(Array, Array)
#38 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#39 /Users/@username/Projects/@Client/@Client-www/storage/runtime/compiled_templates/de/de929b49b891150853d81291c1496963e0001e6e862d29429a35f2e8668af30b.php(154): Twig\Template->display(Array, Array)
#40 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Template.php(407): __TwigTemplate_bcdf16f6ea79446579e0f1f6314350a6a4ff3427001b78acd025a1728da6ae5e->doDisplay(Array, Array)
#41 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#42 /Users/@username/Projects/@Client/@Client-www/storage/runtime/compiled_templates/fa/fa2252bbb0d116adfbaa1cf595833a65d3c0b1ed609f0ffa1c5feccaf203afe9.php(110): Twig\Template->display(Array, Array)
#43 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Template.php(407): __TwigTemplate_fea505635b6743399d3305c49f679a6d576f8428abed1b40987500d97af6a059->doDisplay(Array, Array)
#44 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#45 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Template.php(392): Twig\Template->display(Array)
#46 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/TemplateWrapper.php(45): Twig\Template->render(Array, Array)
#47 /Users/@username/Projects/@Client/@Client-www/vendor/twig/twig/src/Environment.php(318): Twig\TemplateWrapper->render(Array)
#48 /Users/@username/Projects/@Client/@Client-www/vendor/craftcms/cms/src/web/View.php(391): Twig\Environment->render('settings/fields...', Array)
#49 /Users/@username/Projects/@Client/@Client-www/vendor/craftcms/cms/src/web/View.php(452): craft\web\View->renderTemplate('settings/fields...', Array)
#50 /Users/@username/Projects/@Client/@Client-www/vendor/craftcms/cms/src/web/Controller.php(243): craft\web\View->renderPageTemplate('settings/fields...', Array, 'cp')
#51 /Users/@username/Projects/@Client/@Client-www/vendor/craftcms/cms/src/controllers/FieldsController.php(260): craft\web\Controller->renderTemplate('settings/fields...', Array)
#52 [internal function]: craft\controllers\FieldsController->actionEditField(26, Object(craft\fields\Matrix), 5)
#53 /Users/@username/Projects/@Client/@Client-www/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#54 /Users/@username/Projects/@Client/@Client-www/vendor/yiisoft/yii2/base/Controller.php(180): yii\base\InlineAction->runWithParams(Array)
#55 /Users/@username/Projects/@Client/@Client-www/vendor/craftcms/cms/src/web/Controller.php(181): yii\base\Controller->runAction('edit-field', Array)
#56 /Users/@username/Projects/@Client/@Client-www/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('edit-field', Array)
#57 /Users/@username/Projects/@Client/@Client-www/vendor/craftcms/cms/src/web/Application.php(294): yii\base\Module->runAction('fields/edit-fie...', Array)
#58 /Users/@username/Projects/@Client/@Client-www/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction('fields/edit-fie...', Array)
#59 /Users/@username/Projects/@Client/@Client-www/vendor/craftcms/cms/src/web/Application.php(279): yii\web\Application->handleRequest(Object(craft\web\Request))
#60 /Users/@username/Projects/@Client/@Client-www/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#61 /Users/@username/Projects/@Client/@Client-www/web/index.php(21): yii\base\Application->run()
#62 /Users/@username/.composer/vendor/laravel/valet/server.php(191): require('/Users/@username...')
#63 {main}

If I omit:

    'colours' => [ ... ],

it seems to work as expected.

Color Swatches not rendering in Craft 3.4.5 CP

image

Here is my config/colour-swatches.php:

<?php
/**
 * color-swatches plugin for Craft.x,  CMS.
 *
 * Let clients choose from a predefined set of colours.
 *
 * @link      https://rias.be
 *
 * @copyright Copyright (c) 2018 Rias
 */

/**
 * color-swatches.php,  conf.
 *
 * This file exists only as a template for theswatches settings,  colo.
 * It does nothing on its own.
 *
 * Don't edit this file, instead copy it to 'craft/config' as 'color.php, -swatch'
 * and make your changes there to override default settings.
 *
 * Once copied to 'craft/config', this file will be multi-environment aware as
 * well, so you can have different settings groups for each environment, just as
 * you do for 'general.php'
 */

return
[
	'palettes' =>
	[
		'Button Colors' =>
		[
			[
				'label'   => 'white',
				'color'   => '#fff',
				'default' => false
			],
                        // ETC....
		],
	],
];

PHP error when saving as a draft

Repro: I have an entry with a matrix field that includes a Colour Swatch block. When I try saving an entry as a draft, I get an error.

PHP Warning โ€“ yii\base\ErrorException
json_decode() expects parameter 1 to be string, array given

The stack trace tells me that it's related to line 20 in /src/models/ColourSwatches.php

Config file

Is there any plan for a config file? Being able to configure preset colour lists would be an absolute lifesaver and much more DRY.

Must use {{ fieldName.value.value.color }} to access property

I believe this is because the JSON the model constructor gets already contains a value key. I believe accessing this key when you store it on the public class property will fix this so the magic method can access the properties in $this->value properly.

public function __construct($value) { $this->value = json_decode($value).value; }

RGBA instead of Hex

I would love to see an option to have colors with RGBA instead of hex. This way the client could choose from different levels of transparency on a single color.

i.e.

rgb(147, 147, 147)
rgba(147, 147, 147, 0.8)
rgba(147, 147, 147, 0.6)
rgba(147, 147, 147, 0.4)

So 4 different grey's where they can choose the transparency as needed.

Breaks craft when changing existing fields to colour swatch field type

Hello,

I'm currently using radio buttons to select a colour option, but when I change that field type to the colour swatch field type it breaks the admin side and the front end of any page that contains that field. Here's the error:

PHP Notice โ€“ yii\base\ErrorException
Trying to get property of non-object

The plug in also doesn't warn you there will be data loss in this case even though all data is lost when changing the field type.

The plug in works if I delete the field and completely recreate it from new.

Swatches no longer in the admin and editable

We have been using this plugin on a project for about three months and it's worked great, but we've recently updated our plugins and now we can no longer see our themes we've added in our config file and we can't even manually add them for now.

No console warnings either. See below:
swatches-bug

image

Config is: (and hasn't changed since initial setup)

return [

    // Predefined colours
    'colours' => [
        [
            'label'   => 'White', 
            'color'   => '#FFFFFF',
            'default' => false,
        ],
        [
            'label'   => 'Gray', 
            'color'   => '#F8F9F4',
            'default' => true,
        ],
        [
            'label'   => 'Chartreuse', 
            'color'   => '#cfdc4a',
            'default' => false,
        ],
    ],
];

This was originally a required field, but as the user cannot select a theme, this was breaking all content blocks that used it (90% of them).

Versions:
CraftCMS: 3.5.17.1
Colour Swatches: 1.4.1.1

Unable to save colour selection if swatches have no "Labels"

Problem:
If I configure some swatches, but don't assign any value to the "Label" for each (admittedly I was lazy and didn't want to have labels...), then in the entry form, make a swatch selection and save that entry, the selection isn't saved.

Workaround/Solution:
Adding labels for each colour allows the swatch field to behave normally.

ps. Thank you for an amazing plugin!

"Getting unknown property" error in control panel since upgrade to 1.4.1

When trying to view a Color Swatches field in the control panel, this error appears:
Getting unknown property: percipioglobal\colourswatches\models\Settings::colours

It appears that this error is being thrown from line 161 of /src/fields/ColourSwatches.php, and is due to the fact that the $colours property was removed from /src/models/Settings.php in version 1.4.1 of the plugin.

Documentation still using American "color" for config file

I couldn't get the colour-swatches.php file to work.
I'd followed the instruction inside the config.php file which says:

 * Don't edit this file, instead copy it to 'craft/config' as 'color-swatches.php'
 * and make your changes there to override default settings.

That spelling is wrong, it has to be the UK colour-swatches.php

Required field not being honored

Marking a color swatch field as required doesn't prevent an entry with no swatch selected from being saved...

Craft CMS 3.3.18
Colour Swatches 1.2.3

colour vs color

The British version was working at some point, but checking 1.4.1.1 the swatches stopped appearing in the CMS when using the config file as...

return [
    // Predefined colors, fixed options [label, color, default (boolean)]
    'colours' => [

and I've had to switch back to the American

return [
    // Predefined colors, fixed options [label, color, default (boolean)]
    'colors' => [

Display labels when rendering & add Optgroups

Hello, first of all, this plugin is amazing. Thank you for it :)

Id like to know if there's planned support to add the option to show the label on the admin panel as well as the colour swatch, as it will help with accessibility and easier for the user to decide which colour to choose.

In this case, I have ice cream flavours and some of them have a similar colour palette so the tooltips are not enough to help the user

Also, I have suggestions for the colours grouped like in the image below.
For example, for the scoop flavours, I want to suggest those colours marked in red, and for the 2L presentation then suggest other colours, and so on. But at this point is not possible to add the optgroups.

Screen Shot 2021-10-01 at 1 25 33 PM

Screen Shot 2021-10-01 at 1 24 10 PM

)

Updating class strings in the config file don't take effect immediately or even on just a resave of the entry.

I have found that if I need to update a class string in the config file, that this is no immediately available in the template/out-put. Instead, I have to manually force this to change. However, just resaving the entry doesn't seem to trigger this either. Instead I have to edit the entry and remove the colour, then save. I then have to edit then entry again and re-applying the colour -> saving again.

I am not sure how this gets parsed and passed into the twig templates, but at the minimum, it would be super handy if just resaving the entries would trigger the classes to be updated.

I can see this being a huge problem down the line if I need to update a classname or colour style. If I had to manually save each entry to trigger this.

Here is a shorted example of my 'palettes' array:

palettes' => [
    'Services' => [
      [
        'label'   => 'green',
        'default' => false,
        'color'   => [
          [
            'color'          => '#65942d',
            'classA'         => 'green',
            'classB'         => 'blue',
            'textClassA'     => 'text-green-500',
            'bgClassA'       => 'bg-green-500',
            'bordegClassA'   => 'border-green-500',
            'textClassB'     => 'text-blue-500',
            'bgClassB'       => 'bg-blue-500',
            'borderClassB'   => 'border-blue-600',
            'gradientFull'   => 'from-green-500 to-blue-600',
            'gradientClassA' => 'from-green-200 to-green-600',
            'bgBanner'       => 'bg-green-900',
            'arrow'          => 'text-blue-600',
            'barBanner'      => 'bg-green-300',
          ],
        ],
      ],
  ],
];

I hope the above is clear, but happy to try and explain better or produce a screencast if not.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.