Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ver/0.1.3 #12

Merged
merged 2 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
# Directories/files that may be generated by this project
/build/
/vendor/
/node_modules/
.nvmrc
package-lock.json

# Directories/files that may appear in your environment
*.log
.cache
/.git
/.github
/.wordpress-org
/node_modules
/src

# Operating system specific files
.DS_Store
Thumbs.db

# Local overrides
.wp-env.override.json
phpcs.xml
psalm.xml
.distignore
.editorconfig
.gitattributes
.gitignore
.plugin-data
.wp-env.json
CHANGELOG.md
composer.json
composer.lock
grumphp.yml
LICENSE.md
package.json
package-lock.json
phpcs.xml.dist
phpunit.xml.dist
psalm.xml.dist
README.md
webpack.config.js
yarn.lock
2 changes: 1 addition & 1 deletion .plugin-data
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "0.1.2",
"version": "0.1.3",
"slug": "mosne-dark-palette"
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ You can change the icons using CSS in your theme or in the customizer.
![screenshot-3](https://github.com/mosne/mosne-dark-palette/blob/main/_wordpress-org/screenshot-3.gif)

## Changelog
### 0.1.3 - 2023-06-09

* Fix escaping via wp_kses_data and changelogs

### 0.1.2 - 2023-06-01

Expand Down
50 changes: 50 additions & 0 deletions build/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "mosne/dark-palette",
"version": "0.1.0",
"title": "Dark Palette Switcher",
"category": "widgets",
"description": "Create and apply your dark palette in an accessibility-friendly manner using the new Interactivity API.",
"parent": [
"core/navigation"
],
"example": {},
"supports": {
"html": false,
"multiple": false,
"interactivity": true
},
"attributes": {
"classOptions": {
"type": "string",
"default": "has-icon has-label"
},
"defaultLabel": {
"type": "string",
"default": "Theme"
},
"autoLabel": {
"type": "string",
"default": "OS auto"
},
"darkLabel": {
"type": "string",
"default": "Dark"
},
"lightLabel": {
"type": "string",
"default": "Light"
},
"darkColorsPalette": {
"type": "array",
"default": []
}
},
"textdomain": "mosne-dark-palette",
"render": "file:./render.php",
"editorScript": "file:./index.js",
"editorStyle": "file:./index.css",
"style": "file:./style-index.css",
"viewScriptModule": "file:./view.js"
}
1 change: 1 addition & 0 deletions build/index.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'b6ea52e85f11b35842ac');
1 change: 1 addition & 0 deletions build/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.wp-block-mosne-dark-palette__parlette{display:flex;flex-wrap:wrap}.wp-block-mosne-dark-palette__parlette-item{flex:1 1 50%}
1 change: 1 addition & 0 deletions build/index.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/index.js.map

Large diffs are not rendered by default.

116 changes: 116 additions & 0 deletions build/render.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php
/**
* PHP file to use when rendering the block type on the server to show on the front end.
*
* The following variables are exposed to the file:
* $attributes (array): The block attributes.
* $content (string): The block default content.
* $block (WP_Block): The block instance.
*
* @see https://github.com/WordPress/gutenberg/blob/trunk/docs/reference-guides/block-api/block-metadata.md#render
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
} // Exit if access directly

/** @var array $attributes */

$dark_colors = '';
$colors = '';

// Generate the CSS variables for the dark palette
if ( ! empty( $attributes['darkColorsPalette'] ) ) {
foreach ( $attributes['darkColorsPalette'] as $color ) {
$dark_colors .= sprintf(
'--mosne-dark-palette-%s: %s;',
esc_attr( $color['slug'] ),
esc_attr( $color['color'] )
);
$colors .= sprintf(
'--wp--preset--color--%s: var(--mosne-dark-palette-%s, %s);',
esc_attr( $color['slug'] ),
esc_attr( $color['slug'] ),
esc_attr( $color['color'] )
);
}
}
// Generate the CSS for the dark palette.
$palette_styles = sprintf(
'body[data-theme="dark"] { %s %s prefers-color-scheme: dark;}',
$dark_colors,
$colors
);

/**
* Add the dark palette styles to the page.
*/
wp_add_inline_style(
'mosne-dark-palette-style',
$palette_styles
);

$unique_id = wp_unique_id( 'p-' );
$class_options = $attributes['classOptions'] ?? '';
$additional_classes = $class_options . ' wp-block-navigation-item open-on-hover-click toto wp-block-navigation-submenu';

?>
<li <?php echo wp_kses_data( get_block_wrapper_attributes( [ 'class' => $additional_classes ] ) ); ?>>
<div class="navigaiton-item__wrapper has-child"
tabindex="-1"
data-wp-interactive="mosne/dark-palette"
data-wp-init="callbacks.colorInit"
data-wp-on--mouseenter="actions.showSubmenu"
data-wp-on--mouseleave="actions.hideSubmenu"
data-wp-on--click="actions.showSubmenu"
data-wp-on--keydown="actions.showSubmenu"
data-wp-on--focusin="actions.showSubmenu"
data-wp-on--focusout="actions.hideSubmenu"
<?php
echo wp_kses_data(
wp_interactivity_data_wp_context(
[
'mode' => 'auto',
'current' => 'has-icon--auto wp-block-navigation-submenu__toggle',
'submenu' => false,
]
)
);
?>
>
<button
type="button"
aria-haspopup="menu"
data-wp-bind--class="context.current"
data-wp-bind--aria-expanded="context.submenu"
class="wp-block-navigation-submenu__toggle">
<span data-wp-bind--aria-label="context.mode">
<?php echo esc_html( $attributes['defaultLabel'] ); ?>
</span>
</button>
<ul aria-labelledby="themes-menu-button"
class="wp-block-navigation__submenu-container wp-block-navigation-submenu">
<li class="wp-block-navigation-item">
<button type="button" data-wp-on--click="actions.makeAuto">
<span>
<?php echo esc_html( $attributes['autoLabel'] ); ?>
</span>
</button>
</li>
<li class="wp-block-navigation-item">
<button type="button" class="has-icon--light" data-wp-on--click="actions.makeLight">
<span>
<?php echo esc_html( $attributes['lightLabel'] ); ?>
</span>
</button>
</li>
<li class="wp-block-navigation-item">
<button type="button" class="has-icon--dark" data-wp-on--click="actions.makeDark">
<span>
<?php echo esc_html( $attributes['darkLabel'] ); ?>
</span>
</button>
</li>
</ul>
</div>
</li>
1 change: 1 addition & 0 deletions build/style-index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading