generated from jrtashjian/pluginwp
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Block Transform to Convert Core Search Block (#36)
* Add transforms for label/no-label * Support no-button style and placeholder attribute when transforming * Change "required" toolbar icon to asterisk * php and css lint fixes * Fix applied button classes * apply styles during transform * fix style application on button * Don't show label if empty * Set buttonLabel if empty
- Loading branch information
1 parent
38cd69f
commit ea028b5
Showing
4 changed files
with
133 additions
and
10 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
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,125 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { createBlock } from '@wordpress/blocks'; | ||
|
||
const transforms = { | ||
from: [ | ||
{ | ||
type: 'block', | ||
blocks: [ 'core/search' ], | ||
transform: ( { | ||
label, | ||
showLabel, | ||
buttonText, | ||
placeholder, | ||
buttonPosition, | ||
...attributes | ||
} ) => { | ||
const fieldInnerBlocks = [ | ||
createBlock( 'omniform/input', { | ||
fieldType: 'search', | ||
fieldPlaceholder: placeholder, | ||
style: { | ||
layout: { | ||
selfStretch: 'fill', | ||
flexSize: null, | ||
}, | ||
border: attributes?.style?.border, | ||
}, | ||
borderColor: attributes?.borderColor, | ||
}, [] ), | ||
]; | ||
|
||
if ( showLabel && label ) { | ||
fieldInnerBlocks.unshift( createBlock( 'omniform/label', {}, [] ) ); | ||
} | ||
|
||
const innerBlocks = [ | ||
createBlock( 'omniform/field', | ||
{ | ||
fieldLabel: label || __( 'Search', 'omniform' ), | ||
fieldName: 's', | ||
style: { | ||
layout: { | ||
selfStretch: 'fill', | ||
flexSize: null, | ||
}, | ||
}, | ||
layout: showLabel ? { | ||
type: 'flex', | ||
orientation: 'vertical', | ||
justifyContent: 'stretch', | ||
} : { | ||
type: 'flex', | ||
orientation: 'horizontal', | ||
justifyContent: 'space-between', | ||
}, | ||
}, | ||
fieldInnerBlocks | ||
), | ||
]; | ||
|
||
if ( buttonPosition !== 'no-button' ) { | ||
innerBlocks.push( | ||
createBlock( 'omniform/button', | ||
{ | ||
buttonType: 'submit', | ||
buttonLabel: buttonText || __( 'Search', 'omniform' ), | ||
style: { | ||
layout: { | ||
selfStretch: 'fit', | ||
flexSize: null, | ||
}, | ||
border: attributes?.style?.border, | ||
typography: attributes?.style?.typography, | ||
}, | ||
textColor: attributes?.textColor, | ||
backgroundColor: attributes?.backgroundColor, | ||
borderColor: attributes?.borderColor, | ||
} | ||
), | ||
); | ||
} | ||
|
||
return createBlock( 'omniform/form', | ||
{ | ||
form_type: 'custom', | ||
submit_action: '{{get_site_url}}', | ||
submit_method: 'GET', | ||
required_label: '*', | ||
}, | ||
[ | ||
createBlock( 'core/group', | ||
{ | ||
tagName: 'div', | ||
style: { | ||
spacing: { | ||
margin: { | ||
top: 0, | ||
bottom: 0, | ||
}, | ||
}, | ||
typography: attributes?.style?.typography, | ||
}, | ||
layout: { | ||
type: 'flex', | ||
flexWrap: 'nowrap', | ||
justifyContent: 'space-between', | ||
orientation: 'horizontal', | ||
verticalAlignment: showLabel ? 'bottom' : undefined, | ||
}, | ||
fontFamily: attributes?.fontFamily, | ||
fontSize: attributes?.fontSize, | ||
}, | ||
innerBlocks | ||
), | ||
] | ||
); | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
export default transforms; |