Skip to content

Commit

Permalink
Add box block
Browse files Browse the repository at this point in the history
  • Loading branch information
inc2734 committed Aug 9, 2018
1 parent 3091aa1 commit cdd4616
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Alert
* Balloon
* Button
* Box

## How to use

Expand Down
1 change: 1 addition & 0 deletions block/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
import './alert/block.js';
import './balloon/block.js';
import './btn/block.js';
import './box/block.js';
1 change: 1 addition & 0 deletions block/blocks.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ $color-accent: #bd3c4f !default;
@import 'alert/block';
@import 'balloon/block';
@import 'btn/block';
@import 'box/block';
15 changes: 15 additions & 0 deletions block/box/_block.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.smacb-box {
@include _alert();
border: 1px solid _lighter($_color-gray);
border-radius: $_border-radius;
@include _padding(.5);

&__body {
@include content(.75);

// Gutenberg
> .editor-rich-text .editor-rich-text__tinymce {
@include content(.75); // = wpac-box__body
}
}
}
89 changes: 89 additions & 0 deletions block/box/block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
'use strict';

const { registerBlockType } = wp.blocks;
const { InnerBlocks, InspectorControls, PanelColorSettings, ContrastChecker } = wp.editor;
const { Button, PanelBody, SelectControl, TextControl } = wp.components;
const { Fragment } = wp.element;
const { __ } = wp.i18n;

registerBlockType('snow-monkey-awesome-custom-blocks/box', {
title: __('Box', 'snow-monkey-awesome-custom-blocks'),
icon: 'admin-comments',
category: 'smacb',
attributes: {
backgroundColor: {
type: 'string'
},
borderColor: {
type: 'string'
},
textColor: {
type: 'string'
}
},

edit({ attributes, setAttributes }) {
const { backgroundColor, borderColor, textColor } = attributes;

const onChangeBackgroundColor = (value) => {
setAttributes({ backgroundColor: value });
};

const onChangeBorderColor = (value) => {
setAttributes({ borderColor: value });
};

const onChangeTextColor = (value) => {
setAttributes({ textColor: value });
};

return (
<Fragment>
<InspectorControls>
<PanelColorSettings
title={ __('Color Settings', 'snow-monkey-awesome-custom-blocks') }
initialOpen={ false }
colorSettings={ [
{
value: backgroundColor,
onChange: onChangeBackgroundColor,
label: __('Background Color', 'snow-monkey-awesome-custom-blocks'),
},
{
value: borderColor,
onChange: onChangeBorderColor,
label: __('Border Color', 'snow-monkey-awesome-custom-blocks'),
},
{
value: textColor,
onChange: onChangeTextColor,
label: __('Text Color', 'snow-monkey-awesome-custom-blocks'),
},
] }
>
</PanelColorSettings>
</InspectorControls>

<div className="smacb-box" style={ { backgroundColor: backgroundColor, borderColor: borderColor, color: textColor } }>
<div className="smacb-box__body">
<InnerBlocks
allowedBlocks={ [ 'core/image', 'core/paragraph', 'core/list' ] }
/>
</div>
</div>
</Fragment>
);
},

save({ attributes }) {
const { backgroundColor, borderColor, textColor } = attributes;

return (
<div className="smacb-box" style={ { backgroundColor: backgroundColor, borderColor: borderColor, color: textColor } }>
<div className="smacb-box__body">
<InnerBlocks.Content />
</div>
</div>
);
},
} );
Binary file modified languages/snow-monkey-awesome-custom-blocks-ja.mo
Binary file not shown.
44 changes: 32 additions & 12 deletions languages/snow-monkey-awesome-custom-blocks-ja.po
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Snow Monkey Awesome Custom Blocks\n"
"Report-Msgid-Bugs-To: https://make.wordpress.org/polyglots/\n"
"POT-Creation-Date: 2018-08-08 13:24+0900\n"
"PO-Revision-Date: 2018-08-08 13:24+0900\n"
"POT-Creation-Date: 2018-08-09 21:37+0900\n"
"PO-Revision-Date: 2018-08-09 21:37+0900\n"
"Last-Translator: inc2734 <inc@2inc.org>\n"
"Language-Team: Takashi Kitajima <inc@2inc.org>\n"
"Language: ja_JP\n"
Expand All @@ -20,7 +20,7 @@ msgstr ""
"X-Poedit-SearchPathExcluded-0: vendor\n"
"X-Poedit-SearchPathExcluded-1: node_modules\n"

#: snow-monkey-awesome-custom-blocks.php:43
#: snow-monkey-awesome-custom-blocks.php:40
msgid "Snow Monkey Awesome Custom Blocks"
msgstr "Snow Monkey Awesome Custom Blocks"

Expand All @@ -44,7 +44,7 @@ msgstr "サクセスアラート"
msgid "Alert Settings"
msgstr "アラート設定"

#: block/alert/block.js:58 block/balloon/block.js:86 block/btn/block.js:92
#: block/alert/block.js:58 block/balloon/block.js:86 block/btn/block.js:106
msgid "Type"
msgstr "タイプ"

Expand All @@ -68,35 +68,55 @@ msgstr "吹き出し設定"
msgid "Name"
msgstr "名前"

#: block/btn/block.js:12 block/btn/block.js:18 block/btn/block.js:60
#: block/box/block.js:10
msgid "Box"
msgstr "ボックス"

#: block/box/block.js:44 block/btn/block.js:113
msgid "Color Settings"
msgstr "色設定"

#: block/box/block.js:50 block/btn/block.js:119
msgid "Background Color"
msgstr "背景色"

#: block/box/block.js:55
msgid "Border Color"
msgstr "枠線の色"

#: block/box/block.js:60 block/btn/block.js:124
msgid "Text Color"
msgstr "文字色"

#: block/btn/block.js:12 block/btn/block.js:18 block/btn/block.js:66
msgid "Button"
msgstr "ボタン"

#: block/btn/block.js:40
#: block/btn/block.js:46
msgid "_self"
msgstr "_self"

#: block/btn/block.js:44
#: block/btn/block.js:50
msgid "_blank"
msgstr "_blank"

#: block/btn/block.js:51
#: block/btn/block.js:57
msgid "Normal button"
msgstr "ノーマルボタン"

#: block/btn/block.js:55
#: block/btn/block.js:61
msgid "Full button"
msgstr "フルサイズのボタン"

#: block/btn/block.js:79
#: block/btn/block.js:93
msgid "Button Settings"
msgstr "ボタン設定"

#: block/btn/block.js:81
#: block/btn/block.js:95
msgid "URL"
msgstr "URL"

#: block/btn/block.js:86
#: block/btn/block.js:100
msgid "Target"
msgstr "Target"

Expand Down

0 comments on commit cdd4616

Please sign in to comment.