diff --git a/app/assets/javascripts/colourPreview.js b/app/assets/javascripts/colourPreview.js new file mode 100644 index 000000000..da9546ba7 --- /dev/null +++ b/app/assets/javascripts/colourPreview.js @@ -0,0 +1,26 @@ +(function(Modules) { + "use strict"; + + let isSixDigitHex = value => value.match(/^#[0-9A-F]{6}$/i); + let colourOrWhite = value => isSixDigitHex(value) ? value : '#FFFFFF'; + + Modules.ColourPreview = function() { + + this.start = component => { + + this.$input = $('input', component); + this.$preview = $('.textbox-colour-preview', component); + + this.$input + .on('change keyup', this.update) + .trigger('change'); + + }; + + this.update = () => this.$preview.css( + 'background', colourOrWhite(this.$input.val()) + ); + + }; + +})(window.GOVUK.Modules); diff --git a/app/assets/stylesheets/components/textbox.scss b/app/assets/stylesheets/components/textbox.scss index 0555c0586..c675b016e 100644 --- a/app/assets/stylesheets/components/textbox.scss +++ b/app/assets/stylesheets/components/textbox.scss @@ -62,11 +62,13 @@ .textbox-colour-preview { @include media(desktop) { - width: 34px; - height: 34px; + width: 38px; + height: 38px; margin-left: 5px; - border: 2px solid #0B0C0C; + border-radius: 50%; + box-shadow: inset 0 0 0 1px rgba($black, 0.2); display: inline-block; vertical-align: top; + transition: background 0.3s ease-out; } } diff --git a/app/main/forms.py b/app/main/forms.py index b3678f75d..fbc856b3b 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -734,21 +734,18 @@ class ServiceUpdateEmailBranding(StripWhitespaceForm): domain = StringField('Domain') colour = StringField( 'Colour', - render_kw={'onchange': 'update_colour(this)'}, validators=[ Regexp(regex="^$|^#(?:[0-9a-fA-F]{3}){1,2}$", message='Must be a valid color hex code') ] ) banner_colour = StringField( 'Banner colour', - render_kw={'onchange': 'update_colour(this)'}, validators=[ Regexp(regex="^$|^#(?:[0-9a-fA-F]{3}){1,2}$", message='Must be a valid color hex code') ] ) single_id_colour = StringField( 'Single identity colour', - render_kw={'onchange': 'update_colour(this)'}, validators=[ Regexp(regex="^$|^#(?:[0-9a-fA-F]{3}){1,2}$", message='Must be a valid color hex code') ] diff --git a/app/templates/components/textbox.html b/app/templates/components/textbox.html index 955ffb7d5..e723b9a41 100644 --- a/app/templates/components/textbox.html +++ b/app/templates/components/textbox.html @@ -60,10 +60,9 @@ {% macro colour_textbox( field, - width='2-3', - colour='#FFFFFF' + width='2-3' ) %} -