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>
74 lines
3.1 KiB
PHP
74 lines
3.1 KiB
PHP
<?php
|
|
/**
|
|
* Render the theme preference controls.
|
|
*
|
|
* @package CHRNX
|
|
*/
|
|
|
|
$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
|
|
type="button"
|
|
hidden
|
|
data-chrnx-theme-button
|
|
aria-controls="<?php echo esc_attr( $chrnx_panel_id ); ?>"
|
|
aria-expanded="false"
|
|
aria-label="<?php echo esc_attr( $chrnx_button_label ); ?>"
|
|
>
|
|
<?php echo chrnx_get_icon_markup( 'theme' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns a fixed literal SVG. ?>
|
|
</button>
|
|
<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
|
|
echo get_block_wrapper_attributes(
|
|
array(
|
|
'class' => 'chrnx-theme-toggle',
|
|
'data-chrnx-theme-toggle' => '',
|
|
)
|
|
);
|
|
?>
|
|
data-chrnx-theme-panel
|
|
data-status-light="<?php esc_attr_e( 'Light theme active', 'chrnx' ); ?>"
|
|
data-status-dark="<?php esc_attr_e( 'Dark theme active', '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' ); ?>"
|
|
>
|
|
<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>
|
|
</div>
|
|
<noscript><p class="chrnx-theme-noscript"><?php esc_html_e( 'Enable JavaScript to choose a color theme.', 'chrnx' ); ?></p></noscript>
|
|
</div>
|