client/tags: use new color input (#119)

This commit is contained in:
rr- 2017-02-07 21:33:44 +01:00
parent a3b3532ca4
commit ba7ca0cd87
3 changed files with 48 additions and 16 deletions

View file

@ -170,13 +170,25 @@ input:disabled
cursor: not-allowed cursor: not-allowed
label.color label.color
white-space: nowrap
position: relative position: relative
display: flex
input[type=text] input[type=text]
margin-right: 0.25em
width: auto
.preview
display: inline-block
text-align: center text-align: center
pointer-events: none padding: 0 0.5em
input[type=color] border: 2px solid black
position: absolute &:after
opacity: 0 content: 'A'
.background-preview
border-right: 0
color: transparent
.text-preview
border-left: 0
form.show-validation .input form.show-validation .input
input:invalid input:invalid

View file

@ -2,7 +2,7 @@
.content-wrapper.tag-categories .content-wrapper.tag-categories
width: 100% width: 100%
max-width: 40em max-width: 45em
table table
border-spacing: 0 border-spacing: 0
width: 100% width: 100%
@ -11,7 +11,8 @@
td, th td, th
padding: .4em padding: .4em
&.color &.color
text-align: center input[type=text]
width: 8em
&.usages &.usages
text-align: center text-align: center
&.remove, &.set-default &.remove, &.set-default

View file

@ -139,12 +139,29 @@ function makeColorInput(options) {
type: 'text', type: 'text',
value: options.value || '', value: options.value || '',
required: options.required, required: options.required,
style: 'color: ' + options.value, class: 'color',
disabled: true,
}); });
const colorInput = makeElement( const backgroundPreviewNode = makeElement(
'input', {type: 'color', value: options.value || ''}); 'div',
return makeElement('label', {class: 'color'}, colorInput, textInput); {
class: 'preview background-preview',
style:
`border-color: ${options.value};
background-color: ${options.value}`,
});
const textPreviewNode = makeElement(
'div',
{
class: 'preview text-preview',
style:
`border-color: ${options.value};
color: ${options.value}`,
});
return makeElement(
'label', {class: 'color'},
textInput,
backgroundPreviewNode,
textPreviewNode);
} }
function makeNumericInput(options) { function makeNumericInput(options) {
@ -478,11 +495,13 @@ function monitorNodeRemoval(monitoredNode, callback) {
} }
document.addEventListener('input', e => { document.addEventListener('input', e => {
const type = e.target.getAttribute('type'); if (e.target.classList.contains('color')) {
if (type && type.toLowerCase() === 'color') { let bkNode = e.target.parentNode.querySelector('.background-preview');
const textInput = e.target.parentNode.querySelector('input[type=text]'); let textNode = e.target.parentNode.querySelector('.text-preview');
textInput.style.color = e.target.value; bkNode.style.backgroundColor = e.target.value;
textInput.value = e.target.value; bkNode.style.borderColor = e.target.value;
textNode.style.color = e.target.value;
textNode.style.borderColor = e.target.value;
} }
}); });