-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from bangank36/feat/register-custom-block
Gitenberg: Add sample block
- Loading branch information
Showing
20 changed files
with
62,571 additions
and
12,063 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Binary file not shown.
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,18 @@ | ||
/** | ||
* Input types that supports the range, along with the type to handle their values. | ||
*/ | ||
export const CF7BLOCKS_RANGE_SUPPORTED_INPUT_TYPES = { | ||
number: 'number', | ||
date: 'date', | ||
range: 'number', | ||
}; | ||
|
||
export const CF7BLOCKS_PLACEHOLDER_SUPPORTED_TYPES = [ | ||
'text', | ||
'email', | ||
'url', | ||
'tel', | ||
'number', | ||
'date', | ||
'textarea', | ||
]; |
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,21 @@ | ||
/** Custom Styles **/ | ||
@import "./selection-base/editor.scss"; | ||
@import "./form-template/editor.scss"; | ||
@import "./acceptance/editor.scss"; | ||
@import "./input-base/editor.scss"; | ||
|
||
.cf7-block-field { | ||
width: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
|
||
& > input, | ||
& > textarea { | ||
width: 100%; | ||
padding: 5px; | ||
} | ||
|
||
textarea { | ||
min-height: 300px; | ||
} | ||
} |
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,4 @@ | ||
/** | ||
* Blocks | ||
*/ | ||
import './shields-badge'; |
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,61 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/block.json", | ||
"apiVersion": 2, | ||
"name": "gitenberg/shields-badge", | ||
"title": "Shields Badge", | ||
"category": "text", | ||
"description": "Badge", | ||
"keywords": [ | ||
"badge" | ||
], | ||
"version": "1.0.0", | ||
"textdomain": "gitenberg", | ||
"attributes": { | ||
"style": { | ||
"type": "string", | ||
"default": "flat-square" | ||
}, | ||
"label": { | ||
"type": "string", | ||
"default": "healthinesses" | ||
}, | ||
"logo": { | ||
"type": "string", | ||
"default": "appveyor" | ||
}, | ||
"logoColor": { | ||
"type": "string", | ||
"default": "violet" | ||
}, | ||
"logoWidth": { | ||
"type": "number", | ||
"default": 40 | ||
}, | ||
"link": { | ||
"type": "array", | ||
"default": ["http://left", "http://right"] | ||
}, | ||
"labelColor": { | ||
"type": "string", | ||
"default": "abcdef" | ||
}, | ||
"color": { | ||
"type": "string", | ||
"default": "fedcba" | ||
}, | ||
"cacheSeconds": { | ||
"type": "number", | ||
"default": 3600 | ||
} | ||
}, | ||
"supports": { | ||
"multiple": false, | ||
"spacing": { | ||
"margin": true | ||
}, | ||
"customClassName": false, | ||
"anchor": false, | ||
"html": false | ||
}, | ||
"styles": [] | ||
} |
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,38 @@ | ||
/** | ||
* WordPress Dependencies | ||
*/ | ||
import { isEmpty } from 'lodash'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
import { addQueryArgs } from '@wordpress/url'; | ||
/** | ||
* Custom Dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
import Inspector from './inspector'; | ||
|
||
export default function edit( props ) { | ||
const blockProps = useBlockProps( { | ||
className: classnames( 'cf7-submit-field' ), | ||
} ); | ||
|
||
const { label, logo, logoColor, logoWidth, labelColor, color, style } = props.attributes; | ||
const shieldsUrl = addQueryArgs( 'https://shields.io/badge/style-flat--square-green', { | ||
label, | ||
logo, | ||
logoColor, | ||
logoWidth, | ||
labelColor, | ||
color, | ||
style | ||
}) | ||
|
||
return ( | ||
<> | ||
<div { ...blockProps }> | ||
<img src={shieldsUrl}/> | ||
</div> | ||
<Inspector { ...props } /> | ||
</> | ||
); | ||
} |
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,16 @@ | ||
import { registerBlockType } from '@wordpress/blocks'; | ||
import metadata from './block.json'; | ||
|
||
import edit from './edit'; | ||
import save from './save'; | ||
|
||
import { button } from '@wordpress/icons'; | ||
|
||
console.log('import'); | ||
|
||
registerBlockType( metadata, { | ||
apiVersion: 2, | ||
edit, | ||
save, | ||
icon: button, | ||
} ); |
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,83 @@ | ||
/** | ||
* WordPress Dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
InspectorControls, | ||
} from '@wordpress/block-editor'; | ||
import { | ||
TextControl, | ||
SelectControl, | ||
PanelBody } from '@wordpress/components'; | ||
|
||
function Inspector( props ) { | ||
const { label, logo, logoColor, logoWidth, labelColor, color, style } = props.attributes; | ||
|
||
return ( | ||
<InspectorControls> | ||
<PanelBody title={ __( 'Parameters', 'gitenberg' ) }> | ||
<SelectControl | ||
label={__('Badge Style', 'gitenberg')} | ||
value={ style } | ||
options={ [ | ||
{ label: 'Plastic', value: 'plastic' }, | ||
{ label: 'Square', value: 'flat' }, | ||
{ label: 'Flat square', value: 'flat-square' }, | ||
{ label: 'For the badge', value: 'for-the-badge' }, | ||
{ label: 'Social', value: 'social' } | ||
] } | ||
onChange={(newValue) => props.setAttributes({ style: newValue })} | ||
/> | ||
<TextControl | ||
style={ { maxWidth: '100%' } } | ||
value={label} | ||
label={__('Label', 'gitenberg')} | ||
help={__('Left-hand-side text', 'gitenberg')} | ||
onChange={(newValue) => props.setAttributes({ label: newValue })} | ||
/> | ||
<TextControl | ||
style={ { maxWidth: '100%' } } | ||
value={logo} | ||
label={__('Logo', 'gitenberg')} | ||
help={__('Insert the logo name or custom logo image.', 'gitenberg')} | ||
onChange={(newValue) => props.setAttributes({ logo: newValue })} | ||
/> | ||
<TextControl | ||
style={ { maxWidth: '100%' } } | ||
value={ logoColor } | ||
label={__('Logo Color', 'gitenberg')} | ||
onChange={ ( newValue ) => | ||
props.setAttributes( { logoColor: newValue } ) | ||
} | ||
/> | ||
<TextControl | ||
style={ { maxWidth: '100%' } } | ||
value={ logoWidth } | ||
label={__('Logo Width', 'gitenberg')} | ||
onChange={ ( newValue ) => | ||
props.setAttributes( { logoWidth: newValue } ) | ||
} | ||
/> | ||
<TextControl | ||
style={ { maxWidth: '100%' } } | ||
value={ labelColor } | ||
label={__('Label Color', 'gitenberg')} | ||
onChange={ ( newValue ) => | ||
props.setAttributes( { labelColor: newValue } ) | ||
} | ||
/> | ||
<TextControl | ||
style={ { maxWidth: '100%' } } | ||
value={ color } | ||
label={__('Badge Color', 'gitenberg')} | ||
help={__('Background color for the right part.', 'gitenberg')} | ||
onChange={ ( newValue ) => | ||
props.setAttributes( { color: newValue } ) | ||
} | ||
/> | ||
</PanelBody> | ||
</InspectorControls> | ||
); | ||
} | ||
|
||
export default Inspector; |
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,24 @@ | ||
/** | ||
* WordPress Dependencies | ||
*/ | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
import { addQueryArgs } from '@wordpress/url'; | ||
|
||
export default function save( props ) { | ||
const { label, logo, logoColor, logoWidth, labelColor, color, style } = props.attributes; | ||
const shieldsUrl = addQueryArgs( 'https://shields.io/badge/style-flat--square-green', { | ||
label, | ||
logo, | ||
logoColor, | ||
logoWidth, | ||
labelColor, | ||
color, | ||
style | ||
}) | ||
|
||
return ( | ||
<div { ...useBlockProps.save() }> | ||
<img src={shieldsUrl}/> | ||
</div> | ||
); | ||
} |
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-cf7-blocks-input-base { | ||
|
||
label { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
input, | ||
textarea { | ||
width: 100%; | ||
padding: 5px; | ||
min-height: 30px; | ||
} | ||
|
||
} |
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,10 @@ | ||
@import "./input-base/style.scss"; | ||
@import "./selection-base//style.scss"; | ||
|
||
.wpcf7-form > p { | ||
display: none; | ||
} | ||
|
||
.wpcf7-form > p br { | ||
display: none; | ||
} |
Oops, something went wrong.