( function ( wp ) {

const { registerBlockType } = wp.blocks;
const { createElement: el } = wp.element;
const { useBlockProps, InspectorControls } = wp.blockEditor;
const { PanelBody, SelectControl, TextareaControl } = wp.components;

registerBlockType( 'web-soul/code', {

	edit: function ( props ) {

		const { attributes, setAttributes } = props;

		const blockProps = useBlockProps();

		return el(
			'div',
			blockProps,

			el(
				InspectorControls,
				{},
				el(
					PanelBody,
					{
						title: 'Web-Soul Code',
						initialOpen: true
					},

					el( SelectControl, {
						label: 'Langage',
						value: attributes.language,
						options: [
							{ label: 'Bash', value: 'bash' },
							{ label: 'YAML', value: 'yaml' },
							{ label: 'JSON', value: 'json' },
							{ label: 'PHP', value: 'php' },
							{ label: 'JavaScript', value: 'javascript' },
							{ label: 'HTML', value: 'html' },
							{ label: 'CSS', value: 'css' },
							{ label: 'Texte', value: 'text' }
						],
						onChange: function ( value ) {
							setAttributes( { language: value } );
						}
					} )
				)
			),

			el( TextareaControl, {
				label: 'Code',
				value: attributes.content,
				onChange: function ( value ) {
					setAttributes( { content: value } );
				},
				rows: 12
			} )
		);
	},

	save: function () {
		return null;
	}
} );

} )( window.wp );

Table des matières

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Retour en haut