feat: rebuild the header controls as icon buttons
The theme switch was three labelled radios that wrapped the header onto a second line with long translations. It is three SVG buttons now, with search and menu sharing the same language: no resting outline, a filled chip for the active choice. Radios gave arrow-key roving for free, so the group reimplements it rather than losing it. The first chip colour put accent on accent and failed WCAG AA; the label carries full contrast instead. Mobile targets sit at 45px because a floor of exactly 44 rounds to 43.99997 in Firefox. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
16 files changed
+316
-156
No files matched your search
@@ -5,9 +5,23 @@
|
||||
* @package CHRNX
|
||||
*/
|
||||
|
||||
$chrnx_control_name = wp_unique_id( 'chrnx-theme-' );
|
||||
$chrnx_panel_id = wp_unique_id( 'chrnx-theme-panel-' );
|
||||
$chrnx_legend_id = wp_unique_id( 'chrnx-theme-legend-' );
|
||||
$chrnx_button_label = __( 'Choose color theme', 'chrnx' );
|
||||
$chrnx_choices = array(
|
||||
'light' => array(
|
||||
'label' => __( 'Light', 'chrnx' ),
|
||||
'icon' => '<circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/>',
|
||||
),
|
||||
'dark' => array(
|
||||
'label' => __( 'Dark', 'chrnx' ),
|
||||
'icon' => '<path d="M20 14.5A8.5 8.5 0 0 1 9.5 4a8.5 8.5 0 1 0 10.5 10.5Z"/>',
|
||||
),
|
||||
'system' => array(
|
||||
'label' => __( 'System', 'chrnx' ),
|
||||
'icon' => '<rect x="3" y="4" width="18" height="12" rx="2"/><path d="M8 20h8M12 16v4"/>',
|
||||
),
|
||||
);
|
||||
?>
|
||||
<div class="chrnx-theme-control">
|
||||
<button
|
||||
@@ -18,10 +32,12 @@ $chrnx_button_label = __( 'Choose color theme', 'chrnx' );
|
||||
aria-expanded="false"
|
||||
aria-label="<?php echo esc_attr( $chrnx_button_label ); ?>"
|
||||
>
|
||||
<span aria-hidden="true">◐</span>
|
||||
<?php echo chrnx_get_icon_markup( 'theme' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns a fixed literal SVG. ?>
|
||||
</button>
|
||||
<fieldset
|
||||
<div
|
||||
id="<?php echo esc_attr( $chrnx_panel_id ); ?>"
|
||||
role="group"
|
||||
aria-labelledby="<?php echo esc_attr( $chrnx_legend_id ); ?>"
|
||||
<?php
|
||||
// WordPress escapes each generated wrapper attribute.
|
||||
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
@@ -38,11 +54,20 @@ $chrnx_button_label = __( 'Choose color theme', 'chrnx' );
|
||||
data-status-system-light="<?php esc_attr_e( 'Light theme active, following system preference', 'chrnx' ); ?>"
|
||||
data-status-system-dark="<?php esc_attr_e( 'Dark theme active, following system preference', 'chrnx' ); ?>"
|
||||
>
|
||||
<legend><?php esc_html_e( 'Color theme', 'chrnx' ); ?></legend>
|
||||
<label><input type="radio" name="<?php echo esc_attr( $chrnx_control_name ); ?>" value="light"> <?php esc_html_e( 'Light', 'chrnx' ); ?></label>
|
||||
<label><input type="radio" name="<?php echo esc_attr( $chrnx_control_name ); ?>" value="dark"> <?php esc_html_e( 'Dark', 'chrnx' ); ?></label>
|
||||
<label><input type="radio" name="<?php echo esc_attr( $chrnx_control_name ); ?>" value="system" checked> <?php esc_html_e( 'System', 'chrnx' ); ?></label>
|
||||
<span class="chrnx-theme-toggle__legend" id="<?php echo esc_attr( $chrnx_legend_id ); ?>"><?php esc_html_e( 'Color theme', 'chrnx' ); ?></span>
|
||||
<?php
|
||||
foreach ( $chrnx_choices as $chrnx_value => $chrnx_choice ) {
|
||||
printf(
|
||||
// The icon geometry is a fixed literal above, never user input.
|
||||
'<button type="button" data-chrnx-theme-value="%1$s" aria-pressed="%2$s" title="%3$s"><svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">%4$s</svg><span class="chrnx-screen-reader-text">%3$s</span></button>',
|
||||
esc_attr( $chrnx_value ),
|
||||
'system' === $chrnx_value ? 'true' : 'false',
|
||||
esc_html( $chrnx_choice['label'] ),
|
||||
$chrnx_choice['icon'] // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
);
|
||||
}
|
||||
?>
|
||||
<output data-chrnx-theme-status aria-live="polite"><?php esc_html_e( 'Following system theme', 'chrnx' ); ?></output>
|
||||
</fieldset>
|
||||
</div>
|
||||
<noscript><p class="chrnx-theme-noscript"><?php esc_html_e( 'Enable JavaScript to choose a color theme.', 'chrnx' ); ?></p></noscript>
|
||||
</div>
|
||||
Reference in new issue
Block a user