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.
- Loading branch information
1 parent
f406a06
commit f3aab65
Showing
8 changed files
with
163 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/** | ||
* The ConditionalGroup block class. | ||
* | ||
* @package OmniForm | ||
*/ | ||
|
||
namespace OmniForm\BlockLibrary\Blocks; | ||
|
||
use OmniForm\Traits\CallbackSupport; | ||
|
||
/** | ||
* The ConditionalGroup block class. | ||
*/ | ||
class ConditionalGroup extends BaseBlock { | ||
use CallbackSupport; | ||
|
||
/** | ||
* Renders the block on the server. | ||
* | ||
* @return string | ||
*/ | ||
public function render() { | ||
if ( ! $this->has_callback( $this->get_block_attribute( 'callback' ) ?? '' ) ) { | ||
return $this->content; | ||
} | ||
|
||
return empty( $this->process_callbacks( $this->get_block_attribute( 'callback' ) ) ) === $this->get_block_attribute( 'reverseCondition' ) | ||
? $this->content : ''; | ||
} | ||
} |
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,26 @@ | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/WordPress/gutenberg/wp/6.3/schemas/json/block.json", | ||
"apiVersion": 3, | ||
"name": "omniform/conditional-group", | ||
"category": "omniform", | ||
"title": "Conditional Group", | ||
"description": "Controls the visibility of a group of blocks based on specified conditions.", | ||
"textdomain": "omniform", | ||
"attributes": { | ||
"callback": { | ||
"type": "string" | ||
}, | ||
"reverseCondition": { | ||
"type": "boolean", | ||
"default": false | ||
} | ||
}, | ||
"supports": { | ||
"html": false, | ||
"layout": { | ||
"allowEditing": false | ||
} | ||
}, | ||
"editorScript": "file:index.js", | ||
"editorStyle": "file:index.css" | ||
} |
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,51 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
BlockControls, | ||
useBlockProps, | ||
useInnerBlocksProps, | ||
} from '@wordpress/block-editor'; | ||
import { | ||
ToolbarGroup, | ||
ToolbarButton, | ||
} from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { iconReverseCondition } from '../shared/icons'; | ||
|
||
const Edit = ( { | ||
attributes: { callback, reverseCondition }, | ||
setAttributes, | ||
} ) => { | ||
const blockProps = useBlockProps(); | ||
const innerBlockProps = useInnerBlocksProps(); | ||
|
||
const conditionLabel = reverseCondition | ||
? __( 'Show when not', 'omniform' ) | ||
: __( 'Show when', 'omniform' ); | ||
|
||
return ( | ||
<> | ||
<BlockControls> | ||
<ToolbarGroup> | ||
<ToolbarButton | ||
icon={ iconReverseCondition } | ||
isActive={ reverseCondition } | ||
label={ __( 'Reverse condition', 'omniform' ) } | ||
onClick={ () => setAttributes( { reverseCondition: ! reverseCondition } ) } | ||
/> | ||
</ToolbarGroup> | ||
</BlockControls> | ||
<div { ...blockProps }> | ||
<div className="condition-label">{ conditionLabel } { callback || '' }</div> | ||
<div { ...innerBlockProps } /> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default Edit; |
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,22 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { registerBlockType } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import json from './block.json'; | ||
import Edit from './edit'; | ||
import Save from './save'; | ||
import { label as iconLabel } from '../shared/icons'; | ||
|
||
import './index.scss'; | ||
|
||
const { name } = json; | ||
|
||
registerBlockType( name, { | ||
edit: Edit, | ||
save: Save, | ||
icon: { foreground: '#D92E83', src: iconLabel }, | ||
} ); |
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,17 @@ | ||
.wp-block-omniform-conditional-group { | ||
|
||
outline-color: var(--wp-admin-theme-color); | ||
outline-offset: -1px; | ||
outline-style: dashed; | ||
outline-width: 1px; | ||
padding-left: 1rem; | ||
|
||
.condition-label { | ||
display: block; | ||
padding: 0.5rem 0; | ||
font-size: 0.8em; | ||
font-style: italic; | ||
pointer-events: none; | ||
color: var(--wp-admin-theme-color); | ||
} | ||
} |
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,9 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useInnerBlocksProps, useBlockProps } from '@wordpress/block-editor'; | ||
|
||
const Save = () => { | ||
return useInnerBlocksProps.save( useBlockProps.save() ).children; | ||
}; | ||
export default Save; |
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