Skip to content

Commit

Permalink
feat: template picker initial selection improvements
Browse files Browse the repository at this point in the history
Initial state has no template selected.
If no selection is made, disable the insertion button.
  • Loading branch information
jeffersonrabb committed Apr 24, 2020
1 parent 0b28524 commit af1bd2e
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { BlockPreview } from '@wordpress/block-editor';
import { ENTER, SPACE } from '@wordpress/keycodes';

export default ( { onInsertTemplate, templates } ) => {
const [ selectedTemplate, setSelectedTemplate ] = useState( 1 );
const [ selectedTemplate, setSelectedTemplate ] = useState( null );
const generateBlockPreview = () => {
return templates && templates[ selectedTemplate ]
? parse( templates[ selectedTemplate ].content )
Expand Down Expand Up @@ -65,7 +65,11 @@ export default ( { onInsertTemplate, templates } ) => {
{ __( 'Start From Scratch', 'newspack-newsletters' ) }
</Button>
<span className="separator">{ __( 'or', 'newspack-newsletters' ) }</span>
<Button isPrimary onClick={ () => onInsertTemplate( selectedTemplate ) }>
<Button
isPrimary
disabled={ selectedTemplate < 1 }
onClick={ () => onInsertTemplate( selectedTemplate ) }
>
{ __( 'Use Selected Layout', 'newspack-newsletters' ) }
</Button>
</div>
Expand Down

0 comments on commit af1bd2e

Please sign in to comment.