Skip to content

Commit

Permalink
add background color
Browse files Browse the repository at this point in the history
  • Loading branch information
cahdeemer committed Jun 5, 2024
1 parent d6b05e8 commit a0cc731
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 5 additions & 1 deletion blocks/divider/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
"elHeight": {
"type": "number",
"default": 8
}
},
"elColor": {
"type": "string",
"default": "#000"
}
}
}
10 changes: 9 additions & 1 deletion blocks/divider/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
import { __ } from '@wordpress/i18n';
import {
ColorPicker,
PanelBody,
RangeControl,
} from '@wordpress/components';
Expand All @@ -29,6 +30,7 @@ import { useBlockProps, InspectorControls } from '@wordpress/block-editor';
interface EditProps {
attributes: {
elHeight: number;
elColor: string;
},
setAttributes: (attributes: {}) => void;
}
Expand All @@ -44,13 +46,14 @@ interface EditProps {
export default function Edit({
attributes: {
elHeight = 8,
elColor = '#000',
},
setAttributes,
}: EditProps) {
return (
<>
<div {...useBlockProps()}>
<div style={{ backgroundColor: '#000', height: `${elHeight}px` }} />
<div style={{ backgroundColor: elColor, height: `${elHeight}px` }} />
</div>
<InspectorControls>
{/* @ts-ignore */}
Expand All @@ -68,6 +71,11 @@ export default function Edit({
resetFallbackValue={8}
allowReset
/>
<h3>{__('Divider color', 'wp-newsletter-builder')}</h3>
<ColorPicker
color={elColor}
onChange={(color) => setAttributes({ elColor: color })}
/>
</PanelBody>
</InspectorControls>
</>
Expand Down
3 changes: 2 additions & 1 deletion blocks/divider/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
*/

$wp_newsletter_builder_divider_height = $attributes['elHeight'] ?? null;
$wp_newsletter_builder_divider_color = $attributes['elColor'] ?? null;
?>
<div style="height: <?php echo esc_attr( $wp_newsletter_builder_divider_height ); ?>px;background-color: #000;"></div>
<div style="height: <?php echo esc_attr( $wp_newsletter_builder_divider_height ); ?>px;background-color: <?php echo esc_attr( $wp_newsletter_builder_divider_color ); ?>;"></div>

0 comments on commit a0cc731

Please sign in to comment.