Browse Source

Add customizer options for dark (hover) colours (#125)

* Add dark variants for primary/accent colours in customizer.
* Expand contrast checks to handle dark variants.
pull/126/head
Ned Zimmerman 7 years ago committed by GitHub
parent
commit
abd4314b36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      inc/actions/namespace.php
  2. 20
      inc/customizer/namespace.php

7
inc/actions/namespace.php

@ -243,15 +243,8 @@ function add_color_variants( $option, $old_value, $value ) {
$color = Hex::fromString( $value ); $color = Hex::fromString( $value );
$color = $color->toRgb(); $color = $color->toRgb();
$color_alpha = $color->toRgba( 0.25 ); $color_alpha = $color->toRgba( 0.25 );
$color_dark = new Rgb(
$color->red() * 0.9,
$color->green() * 0.9,
$color->blue() * 0.9
);
$color_alpha = (string) $color_alpha; $color_alpha = (string) $color_alpha;
$color_dark = (string) $color_dark;
update_option( $option . '_dark', $color_dark );
update_option( $option . '_alpha', $color_alpha ); update_option( $option . '_alpha', $color_alpha );
} }

20
inc/customizer/namespace.php

@ -61,12 +61,24 @@ function customize_register( \WP_Customize_Manager $wp_customize ) {
'label' => __( 'Primary Color', 'pressbooks-aldine' ), 'label' => __( 'Primary Color', 'pressbooks-aldine' ),
'description' => __( 'Primary color, used for links and other primary elements.', 'pressbooks-aldine' ), 'description' => __( 'Primary color, used for links and other primary elements.', 'pressbooks-aldine' ),
], ],
[
'slug' => 'primary_dark',
'hex' => '#7f0c07',
'label' => __( 'Primary Color (Dark)', 'pressbooks-aldine' ),
'description' => __( 'Darkened variant of the primary color, used for primary element hover states.', 'pressbooks-aldine' ),
],
[ [
'slug' => 'accent', 'slug' => 'accent',
'hex' => '#015d75', 'hex' => '#015d75',
'label' => __( 'Accent Color', 'pressbooks-aldine' ), 'label' => __( 'Accent Color', 'pressbooks-aldine' ),
'description' => __( 'Accent color, used for flourishes and secondary elements.', 'pressbooks-aldine' ), 'description' => __( 'Accent color, used for flourishes and secondary elements.', 'pressbooks-aldine' ),
], ],
[
'slug' => 'accent_dark',
'hex' => '#013542',
'label' => __( 'Accent Color (Dark)', 'pressbooks-aldine' ),
'description' => __( 'Darkened variant of the accent color, used for secondary element hover states.', 'pressbooks-aldine' ),
],
[ [
'slug' => 'primary_fg', 'slug' => 'primary_fg',
'hex' => '#ffffff', 'hex' => '#ffffff',
@ -203,8 +215,12 @@ function enqueue_color_contrast_validator() {
$exports = [ $exports = [
'validate_color_contrast' => [ 'validate_color_contrast' => [
'pb_network_color_primary_fg' => [ 'pb_network_color_primary' ], 'pb_network_color_primary_fg' => [ 'pb_network_color_primary', 'pb_network_color_primary_dark' ],
'pb_network_color_accent_fg' => [ 'pb_network_color_accent' ], 'pb_network_color_accent_fg' => [ 'pb_network_color_accent', 'pb_network_color_accent_dark' ],
'pb_network_color_primary' => [ 'pb_network_color_primary_fg' ],
'pb_network_color_primary_dark' => [ 'pb_network_color_primary_fg' ],
'pb_network_color_accent' => [ 'pb_network_color_accent_fg' ],
'pb_network_color_accent_dark' => [ 'pb_network_color_accent_fg' ],
], ],
]; ];

Loading…
Cancel
Save