-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fields UI Cleanup - Better approach to post meta management by separa…
…ting "Fields" from "Blocks" (#87) * remove visibility toggle and makes fields ui panel more intuitive * remove inline comments * separate tabs for blocks and fields * split fields and blocks into distinct data * combine item list * cleans up icons with hardcoded references * updates tab name * remove unnecessary disableds
- Loading branch information
Showing
6 changed files
with
327 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import { | ||
Button, | ||
ButtonGroup, | ||
TextControl, | ||
__experimentalGrid as Grid, | ||
CardBody, | ||
Card, | ||
__experimentalItemGroup as ItemGroup, | ||
__experimentalItem as Item, | ||
Flex, | ||
FlexBlock, | ||
FlexItem, | ||
} from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useState, useEffect } from '@wordpress/element'; | ||
import { | ||
blockDefault, | ||
paragraph, | ||
image, | ||
heading, | ||
group, | ||
button, | ||
} from '@wordpress/icons'; | ||
|
||
import { SUPPORTED_BLOCK_ATTRIBUTES } from '../constants'; | ||
|
||
const EditBlockForm = ( { | ||
block = { | ||
label: '', | ||
slug: '', | ||
description: '', | ||
type: 'text', | ||
visible: false, | ||
}, | ||
onChange = () => {}, | ||
} ) => { | ||
const [ formData, setFormData ] = useState( block ); | ||
|
||
useEffect( () => { | ||
onChange( formData ); | ||
}, [ formData ] ); | ||
|
||
return ( | ||
<> | ||
<Card> | ||
<CardBody> | ||
<ButtonGroup | ||
style={ { | ||
marginBottom: '1rem', | ||
} } | ||
> | ||
<Button | ||
icon={ blockIcon( formData.type ) } | ||
title={ formData.type } | ||
> | ||
{ __( 'Block Binding' ) } | ||
</Button> | ||
</ButtonGroup> | ||
|
||
<Grid columns={ 3 }> | ||
<TextControl | ||
label={ __( 'Name' ) } | ||
value={ formData.label } | ||
disabled={ true } | ||
/> | ||
<TextControl | ||
label={ __( 'Key' ) } | ||
value={ formData.slug } | ||
disabled={ true } | ||
/> | ||
<TextControl | ||
label={ __( 'Description (optional)' ) } | ||
value={ formData.description } | ||
onChange={ ( value ) => | ||
setFormData( { | ||
...formData, | ||
description: value, | ||
} ) | ||
} | ||
/> | ||
</Grid> | ||
|
||
<BlockAttributes | ||
slug={ formData.slug } | ||
type={ formData.type } | ||
/> | ||
</CardBody> | ||
</Card> | ||
</> | ||
); | ||
}; | ||
|
||
const BlockAttributes = ( { slug, type } ) => { | ||
const supportedAttributes = SUPPORTED_BLOCK_ATTRIBUTES[ type ]; | ||
return ( | ||
<ItemGroup isBordered isSeparated> | ||
{ supportedAttributes.map( ( attribute ) => ( | ||
<Item key={ attribute }> | ||
<Flex> | ||
<FlexBlock>{ attribute }</FlexBlock> | ||
<FlexItem> | ||
<span> | ||
{ 'post_content' === slug ? ( | ||
<code>{ slug }</code> | ||
) : ( | ||
<code>{ `${ slug }__${ attribute }` }</code> | ||
) } | ||
</span> | ||
</FlexItem> | ||
</Flex> | ||
</Item> | ||
) ) } | ||
</ItemGroup> | ||
); | ||
}; | ||
|
||
const blockIcon = ( type ) => { | ||
switch ( type ) { | ||
case 'core/paragraph': | ||
return paragraph; | ||
case 'core/image': | ||
return image; | ||
case 'core/heading': | ||
return heading; | ||
case 'core/group': | ||
return group; | ||
case 'core/button': | ||
return button; | ||
default: | ||
return blockDefault; | ||
} | ||
}; | ||
|
||
export default EditBlockForm; |
Oops, something went wrong.