Skip to content

Commit 7ce319a

Browse files
committed
Typography preview background color automatically shifts to black for lighter font colors.
1 parent 55da0a6 commit 7ce319a

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

redux-core/assets/css/redux-fields.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

redux-core/assets/css/redux-fields.min.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

redux-core/inc/fields/typography/redux-typography.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,16 @@
492492
return retVal;
493493
};
494494

495+
redux.field_objects.typography.hexToInt = function ( hexColor ) {
496+
// Remove the '#' if present.
497+
if ( hexColor.indexOf( '#' ) === 0 ) {
498+
hexColor = hexColor.slice( 1 );
499+
}
500+
// Convert hex to integer.
501+
return parseInt( hexColor, 16 );
502+
};
503+
504+
495505
// Sync up font options.
496506
redux.field_objects.typography.select = function( selector, skipCheck, destroy, fontName, active ) {
497507
var mainID;
@@ -928,6 +938,19 @@
928938

929939
if ( color ) {
930940
that.find( '.typography-preview' ).css( 'color', color );
941+
942+
// Convert the color and range values to integers.
943+
var colorInt = redux.field_objects.typography.hexToInt( color );
944+
var whiteInt = redux.field_objects.typography.hexToInt( 'ffffff' );
945+
var lightGreyInt = redux.field_objects.typography.hexToInt( 'dddddd' );
946+
947+
// Check if the color is within the specified range.
948+
if (colorInt >= lightGreyInt && colorInt <= whiteInt) {
949+
that.find( '.typography-preview' ).css( 'background-color', 'black' );
950+
} else {
951+
// Optionally reset the background color if the text color is not within the range.
952+
that.find( '.typography-preview' ).css( 'background-color', '' ); // Or set to a default color.
953+
}
931954
}
932955

933956
if ( ! proLoaded ) {

redux-core/inc/fields/typography/redux-typography.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)