HEX
Server: Microsoft-IIS/10.0
System: Windows NT HMW8635 10.0 build 14393 (Windows Server 2016) i586
User: ibratele2 (0)
PHP: 8.0.11
Disabled: escapeshellarg, escapeshellcmd, exec, passthru, proc_close, proc_open, shell_exec, system, dl, popen, php_check_syntax, php_strip_whitespace, symlink, link, openlog, apache_child_terminate
Upload Files
File: E:/Home/ibratele2/Web/wp-content/themes/astra/inc/metabox/extend-metabox/src/ast-selector.js
import { Button } from '@wordpress/components';

const AstSelectorControl = props => {

	const {
		label,
		description,
		id,
		metavalue,
		choices,
	} = props;

	const onValueChange = (value) => {
		props.onChange( value );
	};

	if ( ! choices ) {
		return;
	}

	let labelHtml = null;
	let descriptionHtml = null;

	if ( label ) {
		labelHtml = <span className="ast-meta-sortable-title">{label}</span>;
	}

	if ( description ) {
		descriptionHtml = <span className="ast-meta-sortable-description">{description}</span>;
	}

	let optionsHtml = Object.entries( choices ).map( ( [key, data] ) => {

		let value = data.value;

		var html = (
			<div className="ast-selector-inner-wrap" key={ key }>
				<Button
					key={ key }
					onClick={ () => onValueChange( value ) }
					aria-pressed = { value === metavalue }
					isPrimary = { value === metavalue }
					label = { data.label }
				>
					{ data.label }
				</Button>
			</div>
		);

		return html;
	} );

	return <div id={id} className='ast-meta-selector-controller'>
		{ ( labelHtml || descriptionHtml ) &&
			<label>
				{labelHtml}
				{descriptionHtml}
			</label>
		}
		<div className="ast-meta-selector-wrapper">
			{optionsHtml}
		</div>
	</div>;

};

export default AstSelectorControl;