Skip to content

Commit 3580f43

Browse files
committed
add preview for colour input
1 parent 3e7fd6e commit 3580f43

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

css/80_app.css

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,15 @@ a.hide-toggle {
15051505
fill: #333;
15061506
opacity: .5;
15071507
}
1508+
.form-field-button.colour-preview {
1509+
background-color: #fff;
1510+
border-radius: 0 0 4px 0;
1511+
}
1512+
.form-field-button.colour-preview > div {
1513+
border: 3px solid #fff;
1514+
height: 100%;
1515+
border-radius: 8px;
1516+
}
15081517

15091518

15101519
/* round corners of first/last child elements */
@@ -1703,12 +1712,13 @@ a.hide-toggle {
17031712

17041713
/* Field - Text / Numeric
17051714
------------------------------------------------------- */
1706-
.form-field-input-text > input:only-of-type,
1715+
.form-field-input-text > input:only-child,
17071716
.form-field-input-tel > input:only-of-type,
17081717
.form-field-input-email > input:only-of-type,
17091718
.form-field-input-url > input:only-child {
17101719
border-radius: 0 0 4px 4px;
17111720
}
1721+
.form-field-input-text > input:not(:only-child),
17121722
.form-field-input-url > input:not(:only-child) {
17131723
border-radius: 0 0 0 4px;
17141724
}

modules/ui/fields/address.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ export function uiFieldAddress(field, context) {
288288
})
289289
.attr('title', function(subfield) {
290290
var val = tags[field.key + ':' + subfield.id];
291-
return val && Array.isArray(val) && val.filter(Boolean).join('\n');
291+
return (val && Array.isArray(val)) ? val.filter(Boolean).join('\n') : undefined;
292292
})
293293
.classed('mixed', function(subfield) {
294294
return Array.isArray(tags[field.key + ':' + subfield.id]);

modules/ui/fields/input.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export function uiFieldText(field, context) {
2121
var dispatch = d3_dispatch('change');
2222
var input = d3_select(null);
2323
var outlinkButton = d3_select(null);
24+
var wrap = d3_select(null);
2425
var _entityIDs = [];
2526
var _tags;
2627
var _phoneFormats = {};
@@ -62,7 +63,7 @@ export function uiFieldText(field, context) {
6263
calcLocked();
6364
var isLocked = field.locked();
6465

65-
var wrap = selection.selectAll('.form-field-input-wrap')
66+
wrap = selection.selectAll('.form-field-input-wrap')
6667
.data([0]);
6768

6869
wrap = wrap.enter()
@@ -167,9 +168,29 @@ export function uiFieldText(field, context) {
167168
if (value) window.open(value, '_blank');
168169
})
169170
.merge(outlinkButton);
171+
} else if (field.key.includes('colour')) {
172+
input.attr('type', 'text');
173+
174+
updateColourPreview();
170175
}
171176
}
172177

178+
function updateColourPreview() {
179+
wrap.selectAll('.foreign-id-permalink')
180+
.remove();
181+
182+
outlinkButton = wrap.selectAll('.foreign-id-permalink')
183+
.data([utilGetSetValue(input)], d => d);
184+
185+
outlinkButton
186+
.enter()
187+
.append('div')
188+
.attr('class', 'form-field-button foreign-id-permalink colour-preview')
189+
.append('div')
190+
.style('background-color', d => d)
191+
.merge(outlinkButton);
192+
}
193+
173194

174195
function updatePhonePlaceholder() {
175196
if (input.empty() || !Object.keys(_phoneFormats).length) return;
@@ -247,6 +268,8 @@ export function uiFieldText(field, context) {
247268
.attr('placeholder', isMixed ? t('inspector.multiple_values') : (field.placeholder() || t('inspector.unknown')))
248269
.classed('mixed', isMixed);
249270

271+
if (field.key.includes('colour')) updateColourPreview();
272+
250273
if (outlinkButton && !outlinkButton.empty()) {
251274
var disabled = !validIdentifierValueForLink();
252275
outlinkButton.classed('disabled', disabled);

0 commit comments

Comments
 (0)