From 7d71b3a6c7e1947cc342d0b10585e6d4d5682bf6 Mon Sep 17 00:00:00 2001 From: Takashi Kitajima Date: Tue, 21 Aug 2018 20:47:23 +0900 Subject: [PATCH] Fix #5 --- block/faq/_block.scss | 42 +++++++ block/faq/block.js | 113 ++++++++++++++++++ block/faq/block.php | 17 +++ .../snow-monkey-awesome-custom-blocks-ja.mo | Bin 3782 -> 4016 bytes .../snow-monkey-awesome-custom-blocks-ja.po | 30 +++-- src/css/blocks.scss | 1 + src/js/blocks.js | 1 + 7 files changed, 197 insertions(+), 7 deletions(-) create mode 100644 block/faq/_block.scss create mode 100644 block/faq/block.js create mode 100644 block/faq/block.php diff --git a/block/faq/_block.scss b/block/faq/_block.scss new file mode 100644 index 00000000..bd4297c7 --- /dev/null +++ b/block/faq/_block.scss @@ -0,0 +1,42 @@ +.smacb-faq { + &__item { + border-bottom: 1px solid _lighter($_color-gray); + @include _padding(1, 0); + + &:first-child { + border-top: 1px solid _lighter($_color-gray); + } + + &__question, + &__answer { + position: relative; + @include _padding-left(1.25); + + &::before { + position: absolute; + top: 0; + left: 0; + display: block; + @include _font-size($_base-font-size-px * 1.5); + line-height: 1; + font-weight: normal; + color: $color-accent; + } + } + + &__question { + @include _margin(0, 0, 1); + font-weight: bold; + + &::before { + content: 'Q'; + } + } + + &__answer { + &::before { + content: 'A'; + } + } + } +} diff --git a/block/faq/block.js b/block/faq/block.js new file mode 100644 index 00000000..7b08974f --- /dev/null +++ b/block/faq/block.js @@ -0,0 +1,113 @@ +'use strict'; + +const { get, times } = lodash; +const { registerBlockType } = wp.blocks; +const { RichText, InspectorControls } = wp.editor; +const { PanelBody, RangeControl } = wp.components; +const { Fragment } = wp.element; +const { __, sprintf } = wp.i18n; + +registerBlockType('snow-monkey-awesome-custom-blocks/faq', { + title: __('FAQ', 'snow-monkey-awesome-custom-blocks'), + icon: 'businessman', + category: 'smacb', + attributes: { + content: { + type: 'array', + default: [ + { + question: [], + answer: [], + } + ], + }, + rows: { + type: 'number', + default: 1, + }, + }, + + edit({ attributes, setAttributes, isSelected }) { + const { rows, content } = attributes; + + const generateUpdatedAttribute = (parent, index, attribute, value) => { + let newParent = [...parent]; + newParent[ index ] = get(newParent, index, {}); + newParent[ index ][ attribute ] = value; + return newParent; + } + + return ( + + + + setAttributes({ rows: value }) } + min="1" + max="50" + /> + + + +
+
+ { times(rows, (index) => { + const question = get(content, [index, 'question'], []); + const answer = get(content, [index, 'answer'], []); + + return ( +
+ setAttributes({ content: generateUpdatedAttribute(content, index, 'question', value) }) } + /> + + setAttributes({ content: generateUpdatedAttribute(content, index, 'answer', value) }) } + /> +
+ ); + } ) } +
+
+
+ ); + }, + + save({ attributes }) { + const { rows, content } = attributes; + + return ( +
+
+ { times(rows, (index) => { + const question = get(content, [index, 'question'], []); + const answer = get(content, [index, 'answer'], []); + + return ( +
+
+ { question } +
+
+ { answer } +
+
+ ); + } ) } +
+
+ ); + }, +} ); diff --git a/block/faq/block.php b/block/faq/block.php new file mode 100644 index 00000000..da80c866 --- /dev/null +++ b/block/faq/block.php @@ -0,0 +1,17 @@ +register( + [ '.smacb-faq__item__question::before', '.smacb-faq__item__answer::before' ], + 'color: ' . $accent_color +); diff --git a/languages/snow-monkey-awesome-custom-blocks-ja.mo b/languages/snow-monkey-awesome-custom-blocks-ja.mo index 692ac9be1d392214079a73d725ec8e22715f820b..15d498064d2546d96fd7ad0412ace1dfb0cb5b28 100644 GIT binary patch delta 1558 zcmXxkOGs2v9LMpaj^miq_?X`LEKM!VQcLrd(hG_b6&Efn!Xzv(Z7hSJ$rjN==rOq{ z!A&G07}6{XEL=!|AYpAPiYUc0T8ImGE&Beh$HV>K&pF3?&*Oj3_%3BME%-gj)n_O* zL^6>XX-pI5xwuj8M;o&SA6N%5iuRaw9J$N{Hy=)70)ECA{A1gT=%pR$UN#;XCuovw zM>=wud~WerjH~b<`mq+dOba*0GUreebf6}@f~j~LlW+)~g`y@Nx9us6qdkpo<~QG{ zB+@a9+QAaWqKna$1RrVuKkD!4xEc$rmB=gR7;3@ws0BBpHqvSPdr;%`BA0oL|xp5=)$P!r{#1}sADv=sGRh3!9zT0kvoyi@k?9oB0Y)Q)!YZY#weF!zcNz}s5qZZJE+WB47!~>X#Z*2bzYP==uzaSM& z6h+>%(U1D(<<@4@1o}?u??Wx%C2F8))Wn~xKT$jVi`vKn>bW>3(ZZ6fS*US>rM9Ea zddAvqAGm`W;3?`X3}Xc55^01Mr&2}icWTD$MUIQ}o)%Y3=v}3r{hD$@g)_AL{R?Sm zb=wL36DlEevh@vB_yIV-5M@Z|%qMCH70#rSYSp*sM%lBBb681$lR0&z6Us^%p`!EW zq+vY`{Q^pf-NZ^MqLO19d8lu`lc*-v5i4aIl`LW_q4e({Dv1JO7g0g1luauYOwj68 zHii;i{%}roUPOFNojF`nm)_9Y)z#L1HV~?J-wc0nyCPyww+FggFV0*a484yz;OV^7 z8t7`f&>o8MjJgVUl@*7^Jef`eGs!Sia?Pzu4-c-!4OnXF%Z05 z)FNt=EeeDeWgm-*Y7t3I(4w+vRl6WsNe2D?Z;lHO@7&+L=iPhHx#ynuW}9Cpa^LDo zryVkgZbX+t&Sl|3mlH~xaUk|kp_Qrx!@DuYRw zn=ElIO-FZp18)iFLpdrKKSE{X6I5z{KxJ&v>|ydNdmL(B3sgqBZ9HV}4?wLOwf7TI z^1lYd6ow7(3e?H(LIvPMEqDmE;d8hf7NAlZ#hV;<&}e-h)cUNAk3y}RH2Vc(9PmoBbx#{6|oC{0#C%2SF$>)rrqhnMYhgbs*;d4gRsl#dMXYG$Ob3y)q3h5d4Uj!(2g;!XX`$62`RC+mj=uF}(N(6\n" "Language-Team: Takashi Kitajima \n" "Language: ja_JP\n" @@ -152,6 +152,26 @@ msgstr "ノーマルボタン" msgid "Full button" msgstr "フルサイズのボタン" +#: block/faq/block.js:11 +msgid "FAQ" +msgstr "FAQ" + +#: block/faq/block.js:43 +msgid "FAQ Settings" +msgstr "FAQ 設定" + +#: block/faq/block.js:45 block/rating-box/block.js:46 +msgid "Rows" +msgstr "行数" + +#: block/faq/block.js:64 +msgid "Write question…" +msgstr "質問を書く…" + +#: block/faq/block.js:73 +msgid "Write answer…" +msgstr "回答を書く…" + #: block/pricing-table/block.js:11 msgid "Pricing table" msgstr "価格表" @@ -188,10 +208,6 @@ msgstr "レーティングボックス" msgid "Rating box Settings" msgstr "レーティングボックス設定" -#: block/rating-box/block.js:46 -msgid "Rows" -msgstr "行数" - #: block/rating-box/block.js:61 #, javascript-format msgid "(%d) Rating Settings" @@ -199,7 +215,7 @@ msgstr "(%d) レーティング設定" #: block/rating-box/block.js:65 msgid "Rating" -msgstr "" +msgstr "レーティング" #: block/rating-box/block.js:72 msgid "Color" diff --git a/src/css/blocks.scss b/src/css/blocks.scss index 69f7feda..1f4847e4 100644 --- a/src/css/blocks.scss +++ b/src/css/blocks.scss @@ -25,3 +25,4 @@ $_font-path: '../../../../themes/snow-monkey/vendor/inc2734/wp-basis/src/assets/ @import '../../block/section-has-items/block'; @import '../../block/btn-box/block'; @import '../../block/rating-box/block'; +@import '../../block/faq/block'; diff --git a/src/js/blocks.js b/src/js/blocks.js index 848bd334..2ea23936 100644 --- a/src/js/blocks.js +++ b/src/js/blocks.js @@ -11,3 +11,4 @@ import '../../block/section-has-bgimage/block.js'; import '../../block/section-has-items/block.js'; import '../../block/btn-box/block.js'; import '../../block/rating-box/block.js'; +import '../../block/faq/block.js';