Skip to content

Commit

Permalink
Fix #7
Browse files Browse the repository at this point in the history
  • Loading branch information
inc2734 committed Aug 21, 2018
1 parent 575333e commit b44a717
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 32 deletions.
8 changes: 3 additions & 5 deletions block/pricing-table/block.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

import classnames from 'classnames';

const { get, times } = lodash;
const { registerBlockType } = wp.blocks;
const { RichText, InspectorControls, ColorPalette } = wp.editor;
Expand Down Expand Up @@ -67,7 +65,7 @@ registerBlockType('snow-monkey-awesome-custom-blocks/pricing-table', {

return (
<PanelBody
title={ sprintf( __('(%s) Button Settings', 'snow-monkey-awesome-custom-blocks'), index + 1) }
title={ sprintf( __('(%d) Button Settings', 'snow-monkey-awesome-custom-blocks'), index + 1) }
initialOpen={ false }
>
<TextControl
Expand Down Expand Up @@ -110,7 +108,7 @@ registerBlockType('snow-monkey-awesome-custom-blocks/pricing-table', {
} ) }
</InspectorControls>

<div className={ classnames('smacb-pricing-table', [`smacb-pricing-table--${columns}`]) }>
<div className={ `smacb-pricing-table smacb-pricing-table--${columns}` }>
<div className="smacb-pricing-table__row">
{ times(columns, (index) => {
const title = get(content, [index, 'title'], []);
Expand Down Expand Up @@ -193,7 +191,7 @@ registerBlockType('snow-monkey-awesome-custom-blocks/pricing-table', {
const { content, columns } = attributes;

return (
<div className={ classnames('smacb-pricing-table', [`smacb-pricing-table--${columns}`]) }>
<div className={ `smacb-pricing-table smacb-pricing-table--${columns}` }>
<div className="smacb-pricing-table__row">
{ times(columns, (index) => {
const title = get(content, [index, 'title'], []);
Expand Down
42 changes: 42 additions & 0 deletions block/rating-box/_block.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.smacb-rating-box {
&__body {}

&__item {
&:not(:first-child) {
@include _padding-top(.5);
}

&__title {
font-weight: bold;
}

&__evaluation {
&__bar,
&__rating {
height: 10px;
border-radius: 3px;
}

&__bar {
position: relative;
background-color: _lighter($_color-gray);
}

&__rating {
position: absolute;
top: 0;
left: 0;
background-color: #f9bb2d;
}

&__numeric {
position: absolute;
top: $_base-font-size-px * -1;
right: 0;
@include _font-size($_base-font-size-px - 4);
line-height: 1;
color: $_color-gray;
}
}
}
}
150 changes: 150 additions & 0 deletions block/rating-box/block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
'use strict';

const { get, times } = lodash;
const { registerBlockType } = wp.blocks;
const { RichText, InspectorControls, ColorPalette } = wp.editor;
const { PanelBody, RangeControl, BaseControl } = wp.components;
const { Fragment } = wp.element;
const { __, sprintf } = wp.i18n;

registerBlockType('snow-monkey-awesome-custom-blocks/rating-box', {
title: __('Rating box', 'snow-monkey-awesome-custom-blocks'),
icon: 'editor-alignleft',
category: 'smacb',
attributes: {
ratings: {
type: 'array',
default: [
{
title: [],
rating: 0,
color: '',
}
],
},
rows: {
type: 'number',
default: 1,
},
},

edit({ attributes, setAttributes, isSelected }) {
const { rows, ratings } = attributes;

const generateUpdatedAttribute = (parent, index, attribute, value) => {
let newParent = [...parent];
newParent[ index ] = get(newParent, index, {});
newParent[ index ][ attribute ] = value;
return newParent;
}

return (
<Fragment>
<InspectorControls>
<PanelBody title={ __('Rating box Settings', 'snow-monkey-awesome-custom-blocks') }>
<RangeControl
label={ __('Rows', 'snow-monkey-awesome-custom-blocks') }
value={ rows }
onChange={ value => setAttributes({ rows: value }) }
min="1"
max="10"
/>
</PanelBody>

{ times(rows, (index) => {
const title = get(ratings, [index, 'title'], []);
const rating = get(ratings, [index, 'rating'], 0);
const color = get(ratings, [index, 'color'], '');

return (
<PanelBody
title={ sprintf( __('(%d) Rating Settings', 'snow-monkey-awesome-custom-blocks'), index + 1) }
initialOpen={ false }
>
<RangeControl
label={ __('Rating', 'snow-monkey-awesome-custom-blocks') }
value={ rating }
onChange={ value => setAttributes({ ratings: generateUpdatedAttribute(ratings, index, 'rating', value) }) }
min="1"
max="10"
/>

<BaseControl label={ __('Color', 'snow-monkey-awesome-custom-blocks') }>
<ColorPalette
value={ color }
onChange={ value => setAttributes({ ratings: generateUpdatedAttribute(ratings, index, 'color', value) }) }
/>
</BaseControl>
</PanelBody>
);
} ) }
</InspectorControls>

<div className="smacb-rating-box">
<div className="smacb-rating-box__body">
{ times(rows, (index) => {
const title = get(ratings, [index, 'title'], []);
const rating = get(ratings, [index, 'rating'], 0);
const color = get(ratings, [index, 'color'], '');

return (
<div className="smacb-rating-box__item">
<RichText
className="smacb-rating-box__item__title"
placeholder={ __('Write title…', 'snow-monkey-awesome-custom-blocks') }
value={ title }
formattingControls={ [] }
multiline={ false }
onChange={ value => setAttributes({ ratings: generateUpdatedAttribute(ratings, index, 'title', value) }) }
/>

<div className="smacb-rating-box__item__evaluation">
<div className="smacb-rating-box__item__evaluation__bar">
<div className="smacb-rating-box__item__evaluation__numeric">
{rating}
</div>
<div className="smacb-rating-box__item__evaluation__rating" style={{ width: `${rating * 10}%`, backgroundColor: color }}></div>
</div>
</div>
</div>
);
} ) }
</div>
</div>
</Fragment>
);
},

save({ attributes }) {
const { rows, ratings } = attributes;

return (
<div className="smacb-rating-box">
<div className="smacb-rating-box__body">
{ times(rows, (index) => {
const title = get(ratings, [index, 'title'], []);
const rating = get(ratings, [index, 'rating'], 0);
const color = get(ratings, [index, 'color'], '');

return (
<div className="smacb-rating-box__item">
<div className="smacb-rating-box__item__title" >
{ title }
</div>

<div className="smacb-rating-box__item__evaluation">
<div className="smacb-rating-box__item__evaluation__bar">
<div className="smacb-rating-box__item__evaluation__numeric">
{rating}
</div>
<div className="smacb-rating-box__item__evaluation__rating" style={{ width: `${rating * 10}%`, backgroundColor: color }}></div>
</div>
</div>
</div>
);
} ) }
</div>
</div>
);
},
} );
2 changes: 1 addition & 1 deletion block/section-has-items/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ registerBlockType('snow-monkey-awesome-custom-blocks/section-has-items', {

return (
<PanelBody
title={ sprintf( __('(%s) Button Settings', 'snow-monkey-awesome-custom-blocks'), index + 1) }
title={ sprintf( __('(%d) Button Settings', 'snow-monkey-awesome-custom-blocks'), index + 1) }
initialOpen={ false }
>
<TextControl
Expand Down
Binary file modified languages/snow-monkey-awesome-custom-blocks-ja.mo
Binary file not shown.
Loading

0 comments on commit b44a717

Please sign in to comment.