@@ -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