Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SITES-10934: Color alone is used to convey information. #319

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions coral-component-colorinput/src/scripts/ColorInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,8 @@ const ColorInput = Decorator(class extends BaseFormField(BaseComponent(HTMLEleme
this._elements.colorPreview.style.backgroundColor = currentColor ? currentColor.rgbaValue : '';
this.classList.toggle('_coral-ColorInput--novalue', isValueEmpty);

this._elements.colorPreviewLabel.textContent = currentColor ? this._color.value : '';

// Update preview in overlay
const preview = this._elements.overlay.querySelector('._coral-ColorInput-preview');
if (preview) {
Expand Down
10 changes: 10 additions & 0 deletions coral-component-colorinput/src/scripts/ColorInputSwatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import BaseColorInputAbstractSubview from './BaseColorInputAbstractSubview';
import Color from './Color';
import '../../../coral-component-button';
import colorButton from '../templates/colorButton';
import colorLabel from '../templates/colorLabel';
import {commons, i18n, transform} from '../../../coral-utils';
import {Decorator} from '../../../coral-decorator';

Expand All @@ -39,6 +40,7 @@ const ColorInputSwatch = Decorator(class extends BaseColorInputAbstractSubview(B
// Templates
this._elements = {};
colorButton.call(this._elements);
colorLabel.call(this._elements);
}

/**
Expand Down Expand Up @@ -107,10 +109,12 @@ const ColorInputSwatch = Decorator(class extends BaseColorInputAbstractSubview(B
if (cssColorValue) {
this._elements.colorButton.style.backgroundColor = cssColorValue;
this._elements.colorButton.label.textContent = hexColorValue;
this._elements.colorLabel.textContent = hexColorValue;
this.setAttribute('data-value', hexColorValue);
} else {
this._elements.colorButton.classList.add('_coral-ColorInput-swatch-novalue');
this._elements.colorButton.label.textContent = i18n.get('unset');
this._elements.colorLabel.textContent = i18n.get('unset');;
this.setAttribute('data-value', '');
}
}
Expand Down Expand Up @@ -192,7 +196,13 @@ const ColorInputSwatch = Decorator(class extends BaseColorInputAbstractSubview(B
button.remove();
}

const label = this.querySelector('[handle="colorLabel"]');
if (label) {
label.remove();
}

this.appendChild(this._elements.colorButton);
this.appendChild(this._elements.colorLabel);
}
});

Expand Down
15 changes: 12 additions & 3 deletions coral-component-colorinput/src/styles/index.styl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ $colorinput-button-size = 28px;

$colorinput-input-swatch-size = 38px;

$colorinput-swatch-preview-width = 44px;
$colorinput-swatch-preview-height = 57px;

$colorinput-slider-width = 160px;
$colorinput-slider-margin = 5px 16px 0 16px;

Expand Down Expand Up @@ -141,6 +144,7 @@ coral-colorinput-item {
._coral-ColorInput-swatch {
display: block;
float: left;
text-align: center;
padding: $colorinput-swatch-top-padding $colorinput-swatch-left-right-padding 0;

/* All buttons inside the colorinput are square */
Expand Down Expand Up @@ -185,12 +189,17 @@ coral-colorinput-item {
}
}
}

label {
display block;
}
}

._coral-ColorInput-buttonWrapper {
position: absolute;
right: $colorinput-button-wrapper-offset;
top: $colorinput-button-wrapper-offset;
text-align: center;

// set opacity < 1 to create new stacking context (for checker image to work)
opacity: .999;
Expand Down Expand Up @@ -233,11 +242,11 @@ coral-colorinput-item {

// Swatch variant
._coral-ColorInput--swatch {
width: $colorinput-input-swatch-size;
height: $colorinput-input-swatch-size;
width: $colorinput-swatch-preview-width;
height: $colorinput-swatch-preview-height;

// makes sure the width stays no matter the parent's configuration
max-width: $colorinput-input-swatch-size;
max-width: $colorinput-swatch-preview-width;

._coral-ColorInput-input {
position: absolute;
Expand Down
3 changes: 2 additions & 1 deletion coral-component-colorinput/src/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
<input handle="input" is="coral-textfield" class="_coral-ColorInput-input" type="text" value="" role="combobox" aria-autocomplete="none" aria-haspopup="dialog" aria-expanded="false" aria-controls="{{uid}}" />
<div class="_coral-ColorInput-buttonWrapper" handle="buttonWrapper" role="presentation">
<button handle="colorPreview" is="coral-button" variant="_custom" class="_coral-FieldButton _coral-ColorInput-button _coral-ColorInput-preview" type="button" aria-haspopup="dialog" aria-expanded="false" aria-controls="{{uid}}"></button>
<label handle="colorPreviewLabel" type="label"></label>
<js>
// Since we don't have a mutation observer anymore to replace content zones magically, we have to do it manually.
this.colorPreview.label.classList.add('u-coral-screenReaderOnly');
this.colorPreview.label.innerText = data.i18n.get('Color Picker');
this.colorPreview.label.id = uid + '-coral-button-label';
</js>
</div>
<coral-popover smart class="_coral-ColorInput-overlay" role="dialog" focusonshow="on" trapfocus="on" handle="overlay" breadthoffset="50%r - 50%p" placement="bottom" id="{{uid}}" aria-label="{{data.i18n.get('Color Picker')}}">
<coral-popover smart class="_coral-ColorInput-overlay" role="dialog" focusonshow="on" trapfocus="on" handle="overlay" breadthoffset="50%r - 50%p" lengthoffset="20" placement="bottom" id="{{uid}}" aria-label="{{data.i18n.get('Color Picker')}}">
<coral-colorinput-colorproperties handle="propertiesView"></coral-colorinput-colorproperties>
<coral-colorinput-swatches handle="swatchesView"></coral-colorinput-swatches>
</coral-popover>
1 change: 1 addition & 0 deletions coral-component-colorinput/src/templates/colorLabel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<label handle="colorLabel" type="label"></label>
Loading