diff --git a/blocks/duotone-filter/duotone.php b/blocks/duotone-filter/duotone.php
new file mode 100644
index 00000000..47f5e785
--- /dev/null
+++ b/blocks/duotone-filter/duotone.php
@@ -0,0 +1,24 @@
+
diff --git a/blocks/duotone-filter/filter.svg b/blocks/duotone-filter/filter.svg
deleted file mode 100644
index 85fa10f8..00000000
--- a/blocks/duotone-filter/filter.svg
+++ /dev/null
@@ -1,18 +0,0 @@
-
diff --git a/blocks/duotone-filter/index.php b/blocks/duotone-filter/index.php
index 47a3e9d4..de4f9dd2 100644
--- a/blocks/duotone-filter/index.php
+++ b/blocks/duotone-filter/index.php
@@ -40,32 +40,11 @@ function hex2rgb( $color ) {
$duotone_id = $block['attrs']['duotoneId'];
$duotone_dark = hex2rgb( $block['attrs']['duotoneDark'] );
$duotone_light = hex2rgb( $block['attrs']['duotoneLight'] );
- $duotone = <<
-
-
-
-
-
-
-
-
-
-
-
-EOT;
+
+ ob_start();
+ include 'duotone.php';
+ $duotone = ob_get_clean();
+
return $block_content . $duotone;
}, 10, 2 );
} );
diff --git a/blocks/duotone-filter/src/duotone.js b/blocks/duotone-filter/src/duotone.js
new file mode 100644
index 00000000..b39e9edc
--- /dev/null
+++ b/blocks/duotone-filter/src/duotone.js
@@ -0,0 +1,80 @@
+/**
+ * WordPress dependencies
+ */
+import { SVG } from '@wordpress/components';
+
+const parseColor = ( color ) => {
+ if ( ! color ) return {};
+
+ let r = '0';
+ let g = '0';
+ let b = '0';
+
+ if ( color.length === 7 ) {
+ r = '0x' + color[ 1 ] + color[ 2 ];
+ g = '0x' + color[ 3 ] + color[ 4 ];
+ b = '0x' + color[ 5 ] + color[ 6 ];
+ } else if ( color.length === 4 ) {
+ r = '0x' + color[ 1 ] + color[ 1 ];
+ g = '0x' + color[ 2 ] + color[ 2 ];
+ b = '0x' + color[ 3 ] + color[ 3 ];
+ }
+
+ return {
+ r: r / 0xff,
+ g: g / 0xff,
+ b: b / 0xff,
+ };
+};
+
+function Duotone( { id: duotoneId, darkColor, lightColor } ) {
+ const duotoneDark = parseColor( darkColor );
+ const duotoneLight = parseColor( lightColor );
+
+ return (
+
+ );
+}
+
+export default Duotone;
diff --git a/blocks/duotone-filter/src/index.js b/blocks/duotone-filter/src/index.js
index 22d09b0e..70a9976f 100644
--- a/blocks/duotone-filter/src/index.js
+++ b/blocks/duotone-filter/src/index.js
@@ -7,35 +7,16 @@ import { useEffect } from '@wordpress/element';
import { addFilter } from '@wordpress/hooks';
import { __ } from '@wordpress/i18n';
+/**
+ * Internal dependencies
+ */
+import Duotone from './duotone';
+
const SUPPORTED_BLOCKS = [ 'core/image', 'core/cover' ];
export const isSupportedBlock = ( blockName ) =>
SUPPORTED_BLOCKS.includes( blockName );
-const parseColor = ( color ) => {
- if ( ! color ) return {};
-
- let r = '0';
- let g = '0';
- let b = '0';
-
- if ( color.length === 7 ) {
- r = '0x' + color[ 1 ] + color[ 2 ];
- g = '0x' + color[ 3 ] + color[ 4 ];
- b = '0x' + color[ 5 ] + color[ 6 ];
- } else if ( color.length === 4 ) {
- r = '0x' + color[ 1 ] + color[ 1 ];
- g = '0x' + color[ 2 ] + color[ 2 ];
- b = '0x' + color[ 3 ] + color[ 3 ];
- }
-
- return {
- r: r / 0xff,
- g: g / 0xff,
- b: b / 0xff,
- };
-};
-
const withDuotoneAttributes = ( settings, blockName ) => {
if ( isSupportedBlock( blockName ) ) {
Object.assign( settings.attributes, {
@@ -62,8 +43,6 @@ const withDuotoneEditorControls = createHigherOrderComponent(
}
const instanceId = useInstanceId( BlockEdit );
- const duotoneDark = parseColor( attributes.duotoneDark );
- const duotoneLight = parseColor( attributes.duotoneLight );
useEffect( () => {
setAttributes( {
@@ -93,48 +72,11 @@ const withDuotoneEditorControls = createHigherOrderComponent(
] }
/>
-
+