First inside the edit function declare a variable with your dropdown option -
const linkOptions = [
{ value: 'small', label: __( 'Small' ) },
{ value: 'normal', label: __( 'Normal' ) },
{ value: 'medium', label: __( 'Medium' ) },
{ value: 'large', label: __( 'Large' ) },
];
I'm assuming you will be showing the dropdown option in the Sidebar panel. Here's the code for panelbody and how to get the dropdown value -
<PanelBody>
<SelectControl
label={ __( 'Size' ) }
value={ size }
options={ linkOptions.map( ({ value, label }) => ( {
value: value,
label: label,
} ) ) }
onChange={ ( newSize ) => { setAttributes( { size: newSize } ) } }
/>
</PanelBody>
This will show a dropdown panel in the Inspector area, notice I'm using (ES6)Map function to iterate over the values and corresponding labels. Now, comes the RichText Component where you call the HTML nodes -
<RichText
tagName={ 'span' }
placeholder={ __( 'Enter Text' ) }
value={ text }
onChange={ (text) => setAttributes( { text: text } ) }
formattingControls={ [ 'bold', 'italic', 'strikethrough' ] }
className={`button-${size}`} /*ES6 Template Literals*/
isSelected={ isSelected }
keepPlaceholderOnFocus
/>
Notice, Depending upon the dropdown option. Button size gets attached to the HTML node classname. Now in the editor stylesheet, Add couple of css class and properties -
button-small
button-normal
button-medium
button-large
For the save function -
const save = ( props ) => {
const { size } = props.attributes;
return (
<div className={ `ubutton-${size}` }>
</div>
);
}