-
Notifications
You must be signed in to change notification settings - Fork 34
Add Modal Block #2270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add Modal Block #2270
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 @@ | ||
<?php | ||
/** | ||
* Css handling logic for blocks. | ||
* | ||
* @package ThemeIsle\OtterPro\CSS\Blocks | ||
*/ | ||
|
||
namespace ThemeIsle\OtterPro\CSS\Blocks; | ||
|
||
use ThemeIsle\GutenbergBlocks\CSS\Blocks\Popup_CSS; | ||
|
||
/** | ||
* Class Modal_CSS | ||
*/ | ||
class Modal_CSS extends Popup_CSS { | ||
/** | ||
* The namespace under which the blocks are registered. | ||
* | ||
* @var string | ||
*/ | ||
public $block_prefix = 'modal'; | ||
} |
This file contains hidden or 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,114 @@ | ||
<?php | ||
/** | ||
* Class Modal_CSS. | ||
* | ||
* @package ThemeIsle\GutenbergBlocks\Render | ||
*/ | ||
|
||
namespace ThemeIsle\OtterPro\Render; | ||
|
||
use ThemeIsle\OtterPro\Plugins\License; | ||
|
||
/** | ||
* Class Modal_CSS. | ||
* | ||
* This class handles the CSS for the modal block. | ||
*/ | ||
class Modal_Block { | ||
|
||
/** | ||
* Block render function for server-side. | ||
* | ||
* This method will pe passed to the render_callback parameter and it will output | ||
* the server side output of the block. | ||
* | ||
* @param array $attributes The block attributes. | ||
* @param array $content The saved content. | ||
* @param \WP_Block $block The parsed block. | ||
* | ||
* @return mixed|string | ||
*/ | ||
public function render( $attributes, $content, $block ) { | ||
|
||
if ( ! License::has_active_license() ) { | ||
return ''; | ||
} | ||
|
||
if ( empty( $attributes['trigger'] ) ) { | ||
$attributes['trigger'] = 'onClick'; | ||
} | ||
|
||
$container_tag = '<div '; | ||
if ( ! empty( $attributes['id'] ) ) { | ||
$container_tag .= 'id="' . esc_attr( $attributes['id'] ) . '" '; | ||
} | ||
|
||
$classes = array( 'wp-block-themeisle-blocks-modal', 'is-active', 'is-front' ); | ||
|
||
if ( ! empty( $attributes['className'] ) ) { | ||
$classes[] = esc_attr( $attributes['className'] ); | ||
} | ||
|
||
if ( ! empty( $attributes['closeButtonType'] ) && 'outside' === $attributes['closeButtonType'] ) { | ||
$classes[] = 'with-outside-button'; | ||
} | ||
|
||
$container_tag .= 'class="' . ( implode( ' ', $classes ) ) . '" '; | ||
$container_tag .= 'data-open="' . esc_attr( $attributes['trigger'] ) . '" '; | ||
|
||
if ( 'onClick' === $attributes['trigger'] ) { | ||
$container_tag .= 'data-anchor="' . ( ! empty( $attributes['anchor'] ) ? esc_attr( $attributes['anchor'] ) : '' ) . '" '; | ||
} | ||
|
||
if ( ! empty( $attributes['recurringClose'] ) ) { | ||
$container_tag .= 'data-dismiss="' . ( ! empty( $attributes['recurringTime'] ) ? esc_attr( $attributes['recurringTime'] ) : '' ) . '" '; | ||
} | ||
|
||
if ( ! empty( $attributes['outsideClose'] ) ) { | ||
$container_tag .= 'data-outside="' . esc_attr( $attributes['outsideClose'] ) . '" '; | ||
} | ||
|
||
if ( ! empty( $attributes['anchorClose'] ) ) { | ||
$container_tag .= 'data-anchorclose="' . esc_attr( $attributes['closeAnchor'] ) . '" '; | ||
} | ||
|
||
if ( ! empty( $attributes['lockScrolling'] ) ) { | ||
$container_tag .= 'data-lock-scrolling="1" '; | ||
} | ||
|
||
if ( ! empty( $attributes['disableOn'] ) ) { | ||
$container_tag .= 'data-disable-on="' . esc_attr( $attributes['disableOn'] ) . '" '; | ||
} | ||
|
||
$container_tag .= '>'; | ||
|
||
$modal_wrap = '<div class="otter-popup__modal_wrap">'; | ||
$modal_wrap .= '<div role="presentation" class="otter-popup__modal_wrap_overlay"></div>'; | ||
|
||
$modal_content = '<div class="otter-popup__modal_content">'; | ||
if ( ! empty( $attributes['showClose'] ) ) { | ||
$modal_content .= '<div class="otter-popup__modal_header">'; | ||
$modal_content .= '<button type="button" class="components-button has-icon">'; | ||
$modal_content .= '<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" role="img" aria-hidden="true">'; | ||
$modal_content .= '<path d="M12 13.06l3.712 3.713 1.061-1.06L13.061 12l3.712-3.712-1.06-1.06L12 10.938 8.288 7.227l-1.061 1.06L10.939 12l-3.712 3.712 1.06 1.061L12 13.061z"></path>'; | ||
$modal_content .= '</svg>'; | ||
$modal_content .= '</button>'; | ||
$modal_content .= '</div>'; | ||
} | ||
|
||
$modal_content .= '<div class="otter-popup__modal_body">'; | ||
foreach ( $block->inner_blocks as $inner_block ) { | ||
$modal_content .= $inner_block->render(); | ||
} | ||
$modal_content .= '</div>'; // Close otter-popup__modal_body. | ||
$modal_content .= '</div>'; // Close otter-popup__modal_content. | ||
|
||
$modal_wrap .= $modal_content; | ||
$modal_wrap .= '</div>'; // Close otter-popup__modal_wrap. | ||
|
||
$container_tag .= $modal_wrap; | ||
$container_tag .= '</div>'; // Close container tag. | ||
|
||
return $container_tag; | ||
} | ||
} |
This file contains hidden or 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 hidden or 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,131 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "themeisle-blocks/modal", | ||
"title": "Modal", | ||
"category": "themeisle-blocks", | ||
"description": "Display your content in beautiful Modal with many customization options. Powered by Otter.", | ||
"keywords": [ "modal", "lightbox" ], | ||
"textdomain": "otter-blocks", | ||
"attributes": { | ||
"id": { | ||
"type": "string" | ||
}, | ||
"minWidth": { | ||
"type": ["number", "string"] | ||
}, | ||
"maxWidth": { | ||
"type": ["number", "string"] | ||
}, | ||
"anchor": { | ||
"type": "string" | ||
}, | ||
"showClose": { | ||
"type": "boolean", | ||
"default": true | ||
}, | ||
"outsideClose": { | ||
"type": "boolean", | ||
"default": true | ||
}, | ||
"anchorClose": { | ||
"type": "boolean", | ||
"default": false | ||
}, | ||
"closeAnchor": { | ||
"type": "string" | ||
}, | ||
"backgroundColor": { | ||
"type": "string" | ||
}, | ||
"closeColor": { | ||
"type": "string" | ||
}, | ||
"overlayColor": { | ||
"type": "string" | ||
}, | ||
"overlayOpacity": { | ||
"type": "number" | ||
}, | ||
"padding": { | ||
"type": "object" | ||
}, | ||
"paddingTablet": { | ||
"type": "object" | ||
}, | ||
"paddingMobile": { | ||
"type": "object" | ||
}, | ||
"borderWidth": { | ||
"type": "object" | ||
}, | ||
"borderRadius": { | ||
"type": "object" | ||
}, | ||
"borderColor": { | ||
"type": "string" | ||
}, | ||
"borderStyle": { | ||
"type": "string" | ||
}, | ||
"width": { | ||
"type": "string" | ||
}, | ||
"widthTablet": { | ||
"type": "string" | ||
}, | ||
"widthMobile": { | ||
"type": "string" | ||
}, | ||
"heightMode": { | ||
"type": "string" | ||
}, | ||
"height":{ | ||
"type": "string" | ||
}, | ||
"heightTablet":{ | ||
"type": "string" | ||
}, | ||
"heightMobile":{ | ||
"type": "string" | ||
}, | ||
"verticalPosition": { | ||
"type": "string" | ||
}, | ||
"horizontalPosition": { | ||
"type": "string" | ||
}, | ||
"verticalPositionTablet": { | ||
"type": "string" | ||
}, | ||
"horizontalPositionTablet": { | ||
"type": "string" | ||
}, | ||
"verticalPositionMobile": { | ||
"type": "string" | ||
}, | ||
"horizontalPositionMobile": { | ||
"type": "string" | ||
}, | ||
"closeButtonType": { | ||
"type": "string" | ||
}, | ||
"boxShadow": { | ||
"type": "object", | ||
"default": { | ||
"active": false, | ||
"colorOpacity": 50, | ||
"blur": 5, | ||
"spread": 1, | ||
"horizontal": 0, | ||
"vertical": 0 | ||
} | ||
}, | ||
"disableOn": { | ||
"type": "string" | ||
} | ||
}, | ||
"editorStyle": "otter-popup-editor", | ||
"style": "otter-popup-style", | ||
"script": "otter-popup" | ||
} |
This file contains hidden or 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,53 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
|
||
import { registerBlockType } from '@wordpress/blocks'; | ||
|
||
import { useBlockProps, InnerBlocks } from '@wordpress/block-editor'; | ||
|
||
import { Placeholder } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import metadata from './block.json'; | ||
import save from './save.js'; | ||
import { popupIcon as icon } from '../../helpers/icons'; | ||
|
||
const { name } = metadata; | ||
|
||
if ( ! Boolean( window.themeisleGutenberg.hasPro ) ) { | ||
registerBlockType( name, { | ||
...metadata, | ||
title: __( 'Modal (PRO)', 'otter-blocks' ), | ||
description: __( 'Display your content in beautiful Modal with many customization options. Powered by Otter.', 'otter-blocks' ), | ||
icon, | ||
keywords: [ | ||
'modal', | ||
'lightbox' | ||
], | ||
edit: () => { | ||
const instructions = sprintf( | ||
__( 'You need to activate your Otter Pro to use %1$s block.', 'otter-blocks' ), | ||
metadata.title | ||
); | ||
|
||
return ( | ||
<div { ...useBlockProps() }> | ||
<Placeholder | ||
icon={ icon } | ||
label={ metadata.title } | ||
instructions={ instructions } | ||
className="o-license-warning" | ||
/> | ||
</div> | ||
); | ||
}, | ||
save, | ||
example: { | ||
attributes: {} | ||
} | ||
}); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.