Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
open-source
hacklab-blocks
Commits
741b7558
Commit
741b7558
authored
3 years ago
by
everaldomatias
Browse files
Options
Download
Email Patches
Plain Diff
Add block featured-color
parent
8a77bb1e
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
179 additions
and
0 deletions
+179
-0
blocks/featured-color/block.json
blocks/featured-color/block.json
+25
-0
blocks/featured-color/edit.js
blocks/featured-color/edit.js
+43
-0
blocks/featured-color/editor.scss
blocks/featured-color/editor.scss
+21
-0
blocks/featured-color/featured-color.php
blocks/featured-color/featured-color.php
+17
-0
blocks/featured-color/index.js
blocks/featured-color/index.js
+39
-0
blocks/featured-color/save.js
blocks/featured-color/save.js
+24
-0
blocks/featured-color/script.js
blocks/featured-color/script.js
+0
-0
blocks/featured-color/style.scss
blocks/featured-color/style.scss
+7
-0
hacklab-blocks.php
hacklab-blocks.php
+3
-0
No files found.
blocks/featured-color/block.json
0 → 100644
View file @
741b7558
{
"$schema"
:
"https://schemas.wp.org/trunk/block.json"
,
"apiVersion"
:
2
,
"name"
:
"hacklab-blocks/featured-color"
,
"version"
:
"1.0.0"
,
"title"
:
"Cor de destaque"
,
"category"
:
"media"
,
"icon"
:
"admin-customizer"
,
"description"
:
"Exibe a cor de destaque do post (a partir do metadado 'featured_color')."
,
"keywords"
:
[
"color"
,
"post"
,
"destaque"
],
"textdomain"
:
"hacklab-blocks"
,
"editorScript"
:
"file:../../build/js/featured-color-index/featured-color-index.js"
,
"script"
:
"file:../../build/js/featured-color-script/featured-color-script.js"
,
"editorStyle"
:
"file:../../build/css/featured-color-index.css"
,
"style"
:
"file:../../build/css/style-featured-color-index.css"
,
"supports"
:
{
"align"
:
false
},
"attributes"
:
{
"postId"
:
{
"type"
:
"string"
}
},
"usesContext"
:
[
"postId"
,
"postType"
,
"queryId"
]
}
This diff is collapsed.
Click to expand it.
blocks/featured-color/edit.js
0 → 100644
View file @
741b7558
/**
* WordPress components that create the necessary UI elements for the block
*
* @see https://developer.wordpress.org/block-editor/packages/packages-components/
*/
import
{
TextControl
,
SelectControl
,
__experimentalNumberControl
as
NumberControl
}
from
'
@wordpress/components
'
;
import
{
__
}
from
"
@wordpress/i18n
"
;
import
React
,
{
useCallback
,
useSelect
,
useState
,
useEffect
}
from
'
react
'
;
/**
* React hook that is used to mark the block wrapper element.
* It provides all the necessary props like the class name.
*
* @see https://developer.wordpress.org/block-editor/packages/packages-block-editor/#useBlockProps
*/
import
{
useBlockProps
}
from
'
@wordpress/block-editor
'
;
/**
* The edit function describes the structure of your block in the context of the
* editor. This represents what the editor will render when the block is used.
*
* @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#edit
*
* @param {Object} props Properties passed to the function.
* @param {Object} props.attributes Available block attributes.
* @param {Function} props.setAttributes Function that updates individual attributes.
*
* @return {WPElement} Element to render.
*/
export
default
function
Edit
(
{
attributes
:
{},
setAttributes
}
)
{
return
(
<>
<
div
className
=
"
wp-block-hacklab-featured-color-wrapper
"
>
<
div
className
=
"
color
"
><
/div
>
<
span
>
Cor
de
destaque
<
/span
>
<
/div
>
<
/
>
);
}
This diff is collapsed.
Click to expand it.
blocks/featured-color/editor.scss
0 → 100644
View file @
741b7558
.wp-block-hacklab-featured-color-wrapper
{
align-items
:
center
;
background-color
:
#bebebe
81
;
border-radius
:
16px
;
display
:
flex
;
margin-bottom
:
15px
;
margin-top
:
15px
;
padding
:
10px
;
.color
{
background-color
:
#BEBEBE
;
border-radius
:
16px
;
display
:
inline-block
;
height
:
50px
;
width
:
50px
;
}
span
{
padding
:
10px
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
blocks/featured-color/featured-color.php
0 → 100644
View file @
741b7558
<?php
namespace
hacklabBlocks
;
/**
* Featured color render_callback
*/
function
featured_color_callback
(
$attributes
,
$content
,
$block
)
{
if
(
!
isset
(
$block
->
context
[
'postId'
]
)
)
{
return
''
;
}
$featured_color
=
get_post_meta
(
$block
->
context
[
'postId'
],
'featured_color'
,
true
);
return
'<div class="wp-block-hacklab-featured-color" style="background-color:'
.
esc_attr
(
$featured_color
)
.
'"></div>'
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
blocks/featured-color/index.js
0 → 100644
View file @
741b7558
/**
* Registers a new block provided a unique name and an object defining its behavior.
*
* @see https://developer.wordpress.org/block-editor/developers/block-api/#registering-a-block
*/
import
{
registerBlockType
}
from
'
@wordpress/blocks
'
;
/**
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files.
* All files containing `style` keyword are bundled together. The code used
* gets applied both to the front of your site and to the editor. All other files
* get applied to the editor only.
*
* @see https://www.npmjs.com/package/@wordpress/scripts#using-css
*/
import
'
./style.scss
'
;
import
'
./editor.scss
'
;
/**
* Internal dependencies
*/
import
Edit
from
'
./edit
'
;
import
save
from
'
./save
'
;
/**
* Every block starts by registering a new block type definition.
*
* @see https://developer.wordpress.org/block-editor/developers/block-api/#registering-a-block
*/
registerBlockType
(
'
hacklab-blocks/featured-color
'
,
{
/**
* @see ./edit.js
*/
edit
:
Edit
,
/**
* @see ./save.js
*/
save
,
}
);
This diff is collapsed.
Click to expand it.
blocks/featured-color/save.js
0 → 100644
View file @
741b7558
/**
* React hook that is used to mark the block wrapper element.
* It provides all the necessary props like the class name.
*
* @see https://developer.wordpress.org/block-editor/packages/packages-block-editor/#useBlockProps
*/
import
{
useBlockProps
}
from
'
@wordpress/block-editor
'
;
/**
* The save function defines the way in which the different attributes should
* be combined into the final markup, which is then serialized by the block
* editor into `post_content`.
*
* @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#save
*
* @param {Object} props Properties passed to the function.
* @param {Object} props.attributes Available block attributes.
* @return {WPElement} Element to render.
*/
export
default
function
save
(
{
attributes
}
)
{
const
blockProps
=
useBlockProps
.
save
();
return
<
div
{
...
blockProps
}
>
{
attributes
.
message
}
<
/div>
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
blocks/featured-color/script.js
0 → 100644
View file @
741b7558
This diff is collapsed.
Click to expand it.
blocks/featured-color/style.scss
0 → 100644
View file @
741b7558
.wp-block-hacklab-featured-color
{
background-color
:
#BEBEBE
;
border-radius
:
16px
;
display
:
inline-block
;
height
:
50px
;
width
:
50px
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
hacklab-blocks.php
View file @
741b7558
...
...
@@ -30,6 +30,9 @@ function hacklab_blocks_init() {
'sample-block'
=>
null
,
'hacklab-video-playlist'
=>
array
(
'render_callback'
=>
'hacklabBlocks\\hacklab_video_playlist_callback'
),
'featured-color'
=>
array
(
'render_callback'
=>
'hacklabBlocks\\featured_color_callback'
)
);
foreach
(
$active_blocks
as
$block_name
=>
$block_args
)
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment