Skip to content

Commit

Permalink
Release version 0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ptesei committed Jun 1, 2024
1 parent 1774c46 commit 59e8b8c
Show file tree
Hide file tree
Showing 123 changed files with 4,792 additions and 18 deletions.
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
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.js

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

114 changes: 114 additions & 0 deletions build/render.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?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 wp-block-navigation-submenu';

sprintf(
'<li %s><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"
%s>',
get_block_wrapper_attributes( [ 'class' => $additional_classes ] ),
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.

1 change: 1 addition & 0 deletions build/view.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array('@wordpress/interactivity'), 'version' => '356e48b6b59d979b57c5', 'type' => 'module');
1 change: 1 addition & 0 deletions build/view.js

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

25 changes: 25 additions & 0 deletions vendor/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

// autoload.php @generated by Composer

if (PHP_VERSION_ID < 50600) {
if (!headers_sent()) {
header('HTTP/1.1 500 Internal Server Error');
}
$err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
if (!ini_get('display_errors')) {
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
fwrite(STDERR, $err);
} elseif (!headers_sent()) {
echo $err;
}
}
trigger_error(
$err,
E_USER_ERROR
);
}

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit7503855339f65cc2fabad2ffaf851e98::getLoader();
Loading

0 comments on commit 59e8b8c

Please sign in to comment.