Files
chrnx-dev-wp/blocks/theme-toggle/render.php
T

49 lines
2.0 KiB
PHP

<?php
/**
* Render the theme preference controls.
*
* @package CHRNX
*/
$chrnx_control_name = wp_unique_id( 'chrnx-theme-' );
$chrnx_panel_id = wp_unique_id( 'chrnx-theme-panel-' );
$chrnx_button_label = __( 'Choose color theme', 'chrnx' );
?>
<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 ); ?>"
>
<span aria-hidden="true">◐</span>
</button>
<fieldset
id="<?php echo esc_attr( $chrnx_panel_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' ); ?>"
>
<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>
<output data-chrnx-theme-status aria-live="polite"><?php esc_html_e( 'Following system theme', 'chrnx' ); ?></output>
</fieldset>
<noscript><p class="chrnx-theme-noscript"><?php esc_html_e( 'Enable JavaScript to choose a color theme.', 'chrnx' ); ?></p></noscript>
</div>