First pass, buttons not rendering

This commit is contained in:
Justin Foell
2020-11-27 14:29:57 -06:00
parent 3f5dcb409f
commit fb5160b6cb
3 changed files with 65 additions and 1 deletions
+4
View File
@@ -1,6 +1,7 @@
/* global wp, wpStrava */
import EmbedPlaceholder from './embed-placeholder';
import EmbedControls from './embed-controls';
import SOMOverride from './som-override';
const { __ } = wp.i18n;
const { Component } = wp.element;
@@ -98,6 +99,9 @@ class Edit extends Component {
checked={ displayMarkers }
onChange={ (checked ) => this.toggleDisplayMarkers( checked ) }
/>
<SOMOverride
onChange={ ( value ) => this.props.setAttributes( { som: value } ) }
/>
</PanelBody>
</InspectorControls>
</>
+5 -1
View File
@@ -18,7 +18,11 @@ registerBlockType( 'wp-strava/activity', {
displayMarkers: {
type: 'boolean',
default: false,
}
},
som: {
type: 'string',
default: null,
},
},
edit,
save: () => null,
+56
View File
@@ -0,0 +1,56 @@
/**
* External dependencies
*/
import mapValues from 'lodash';
/**
* WordPress dependencies
*/
import {
Button,
ButtonGroup,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
const SOM_PRESETS = {
'english': __( 'English', 'wp-strava' ),
'metric': __( 'Metric', 'wp-strava' ),
};
export default function SOMOverride( {
onChange,
} ) {
function updateSOM( newSOM ) {
return () => {
onChange( { som: newSOM } );
};
}
return (
<>
<div className="block-editor-som-control">
<ButtonGroup aria-label={ __( 'System of Measure (override from Settings)' ) }>
{ mapValues( SOM_PRESETS, ( key, label ) => {
return (
<Button
key={ key }
isSmall
isPrimary={ true }
isPressed={ true }
onClick={ updateSOM(
key
) }
>
{ label }
</Button>
);
} ) }
</ButtonGroup>
<Button isSmall onClick={ updateSOM() }>
{ __( 'Reset' ) }
</Button>
</div>
</>
);
}