Skip to content

Commit

Permalink
Add color settings example block
Browse files Browse the repository at this point in the history
Signed-off-by: Souptik Datta <[email protected]>
  • Loading branch information
Souptik2001 committed May 11, 2024
1 parent ee97861 commit 9c9d05c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
18 changes: 18 additions & 0 deletions example/src/blocks/color-settings-example/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "example/color-settings-example",
"title": "Color Settings Component Example",
"description": "Example Block to show the Color settings component",
"icon": "smiley",
"category": "common",
"example": {},
"supports": {
"html": false
},
"attributes": {
"color": {
"type": "string"
}
},
"variations": [],
"editorScript": "file:./index.js"
}
40 changes: 40 additions & 0 deletions example/src/blocks/color-settings-example/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { __ } from '@wordpress/i18n';
import { InspectorControls } from '@wordpress/block-editor';
import { PanelBody } from '@wordpress/components';

import { ColorSetting } from '@10up/block-components';

export const BlockEdit = (props) => {
const {
attributes: { color },
setAttributes
} = props;

const colors = [
{ name: 'red', color: '#f00' },
{ name: 'white', color: '#fff' },
{ name: 'blue', color: '#00f' },
];
return (
<>
<InspectorControls>
<PanelBody title={ __( 'Post Picker', 'example' ) }>
<ColorSetting
label={ __( 'Color Setting - Label', 'example' ) }
help={ __( 'Color Setting - Help Text', 'example' ) }
colors={ colors }
value={ color }
onChange={ ( val ) => setAttributes( { color: val } ) }
/>
</PanelBody>
</InspectorControls>
<ColorSetting
label={ __( 'Color Setting - Label', 'example' ) }
help={ __( 'Color Setting - Help Text', 'example' ) }
colors={ colors }
value={ color }
onChange={ ( val ) => setAttributes( { color: val } ) }
/>
</>
)
}
8 changes: 8 additions & 0 deletions example/src/blocks/color-settings-example/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { registerBlockType } from '@wordpress/blocks';
import metadata from './block.json';
import { BlockEdit } from './edit';

registerBlockType( metadata, {
edit: BlockEdit,
save: () => null
} );

0 comments on commit 9c9d05c

Please sign in to comment.