Skip to content

Commit

Permalink
new option to hide rating text && addition panel opened by default
Browse files Browse the repository at this point in the history
  • Loading branch information
farhan-shafi committed Jan 23, 2024
1 parent f09a45e commit 338b20d
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 83 deletions.
2 changes: 1 addition & 1 deletion dist/blocks.build.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('lodash', 'moment', 'react', 'react-dom', 'wp-api', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-keycodes', 'wp-notices', 'wp-primitives', 'wp-url'), 'version' => '5d70d1db87e58c288a15');
<?php return array('dependencies' => array('lodash', 'moment', 'react', 'react-dom', 'wp-api', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-keycodes', 'wp-notices', 'wp-primitives', 'wp-url'), 'version' => '91710aab9379134097bf');
20 changes: 15 additions & 5 deletions dist/blocks.build.js
Original file line number Diff line number Diff line change
Expand Up @@ -53188,7 +53188,8 @@ var inspectorControls = function inspectorControls(props) {
starSize = attributes.starSize,
starColor = attributes.starColor,
selectedStars = attributes.selectedStars,
reviewTextColor = attributes.reviewTextColor;
reviewTextColor = attributes.reviewTextColor,
isShowReviewText = attributes.isShowReviewText;
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__.InspectorControls, {
group: "settings"
}, /*#__PURE__*/React.createElement(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.PanelBody, {
Expand Down Expand Up @@ -53218,6 +53219,14 @@ var inspectorControls = function inspectorControls(props) {
max: starCount,
step: 0.1,
beforeIcon: "star-half"
}), /*#__PURE__*/React.createElement(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.ToggleControl, {
label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.__)("Show Review Text", "ultimate-blocks"),
checked: isShowReviewText,
onChange: function onChange() {
return setAttributes({
isShowReviewText: !isShowReviewText
});
}
}))), /*#__PURE__*/React.createElement(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__.InspectorControls, {
group: "typography"
}, /*#__PURE__*/React.createElement(_components__WEBPACK_IMPORTED_MODULE_1__.CustomFontSizePicker, {
Expand Down Expand Up @@ -53295,7 +53304,8 @@ var editorDisplay = function editorDisplay(props) {
reviewText = _props$attributes.reviewText,
reviewTextColor = _props$attributes.reviewTextColor,
reviewTextAlign = _props$attributes.reviewTextAlign,
starAlign = _props$attributes.starAlign;
starAlign = _props$attributes.starAlign,
isShowReviewText = _props$attributes.isShowReviewText;
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
className: "ub-star-outer-container",
style: {
Expand Down Expand Up @@ -53330,7 +53340,7 @@ var editorDisplay = function editorDisplay(props) {
value: (highlightedStars - (highlightedStars === selectedStars ? 0.5 : 0) || selectedStars) - i,
displayColor: starColor
}));
}))), /*#__PURE__*/React.createElement(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__.RichText, {
}))), isShowReviewText && /*#__PURE__*/React.createElement(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__.RichText, {
tagName: "div",
className: "ub-review-text",
placeholder: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.__)("The text of the review goes here"),
Expand Down Expand Up @@ -55397,7 +55407,7 @@ function EditorComponent(props) {
max: 10
})), /*#__PURE__*/React.createElement(_wordpress_components__WEBPACK_IMPORTED_MODULE_6__.PanelBody, {
title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)("Additional"),
initialOpen: false
initialOpen: true
}, /*#__PURE__*/React.createElement("p", null, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)("Number of columns")), /*#__PURE__*/React.createElement(_wordpress_components__WEBPACK_IMPORTED_MODULE_6__.RangeControl, {
value: columns,
onChange: function onChange(columns) {
Expand Down Expand Up @@ -102201,7 +102211,7 @@ module.exports = JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json
/***/ ((module) => {

"use strict";
module.exports = JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"ub/star-rating-block","title":"Star Rating","category":"ultimateblocks","description":"Add Star ratings in your posts/pages. You can customize size, color, numbers of stars.","keywords":["star rating","review","Ultimate Blocks"],"attributes":{"blockID":{"type":"string","default":""},"starCount":{"type":"number","default":5},"textFontSize":{"type":"string","default":""},"starSize":{"type":"number","default":20},"starColor":{"type":"string","default":"#FFB901"},"selectedStars":{"type":"number","default":0},"reviewText":{"type":"string","default":""},"reviewTextAlign":{"type":"string","default":"text"},"reviewTextColor":{"type":"string","default":""},"starAlign":{"type":"string","default":"left"},"padding":{"type":"object","default":{}},"margin":{"type":"object","default":{}}},"supports":{}}');
module.exports = JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"ub/star-rating-block","title":"Star Rating","category":"ultimateblocks","description":"Add Star ratings in your posts/pages. You can customize size, color, numbers of stars.","keywords":["star rating","review","Ultimate Blocks"],"attributes":{"blockID":{"type":"string","default":""},"starCount":{"type":"number","default":5},"textFontSize":{"type":"string","default":""},"starSize":{"type":"number","default":20},"starColor":{"type":"string","default":"#FFB901"},"selectedStars":{"type":"number","default":0},"reviewText":{"type":"string","default":""},"reviewTextAlign":{"type":"string","default":"text"},"reviewTextColor":{"type":"string","default":""},"starAlign":{"type":"string","default":"left"},"padding":{"type":"object","default":{}},"margin":{"type":"object","default":{}},"isShowReviewText":{"type":"boolean","default":true}},"supports":{}}');

/***/ }),

Expand Down
2 changes: 1 addition & 1 deletion dist/blocks.build.js.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions dist/blocks/star-rating/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
"margin": {
"type": "object",
"default": {}
},
"isShowReviewText": {
"type": "boolean",
"default": true
}
},
"supports": {}
Expand Down
2 changes: 2 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ That's it. You're done!
* IMPROVE: Add upsell for post grid pagination.
* IMPROVE: Color component in button (improved) block.
* IMPROVE: Icon control in all blocks.
* IMPROVE: Styled List additional panel opened by default.
* NEW: Option to hide review text in the star rating block.
* NEW: Border and Radius option in icon block.

= 3.1.1 =
Expand Down
4 changes: 4 additions & 0 deletions src/blocks/star-rating/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
"margin": {
"type": "object",
"default": {}
},
"isShowReviewText": {
"type": "boolean",
"default": true
}
},
"supports": {}
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/star-rating/block.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function ub_render_star_rating_block($attributes){
('flex-' . $starAlign === 'left' ? 'start' : 'end')) . ';"' : '').'>
<div class="ub-star-inner-container">'.$stars.'</div>
</div>'.
($reviewText === '' ? '' : '<div class="ub-review-text"' . ($blockID === '' ? ' style="text-align:' . $reviewTextAlign . ';"' : '') . '>' .
($reviewText === '' || false === $isShowReviewText ? '' : '<div class="ub-review-text"' . ($blockID === '' ? ' style="text-align:' . $reviewTextAlign . ';"' : '') . '>' .
$reviewText
. '</div>') .
'</div>';
Expand Down
59 changes: 38 additions & 21 deletions src/blocks/star-rating/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
RangeControl,
ToolbarGroup,
ToolbarButton,
ToggleControl,
} from "@wordpress/components";

export const blockControls = (props) => {
Expand All @@ -37,7 +38,7 @@ export const blockControls = (props) => {
label={__(
(a !== "justify" ? "Align " : "") +
a[0].toUpperCase() +
a.slice(1)
a.slice(1),
)}
isActive={reviewTextAlign === a}
onClick={() => setAttributes({ reviewTextAlign: a })}
Expand All @@ -51,8 +52,14 @@ export const blockControls = (props) => {
export const inspectorControls = (props) => {
const { attributes, setAttributes } = props;

const { starCount, starSize, starColor, selectedStars, reviewTextColor } =
attributes;
const {
starCount,
starSize,
starColor,
selectedStars,
reviewTextColor,
isShowReviewText,
} = attributes;
return (
<>
<InspectorControls group="settings">
Expand All @@ -79,6 +86,13 @@ export const inspectorControls = (props) => {
step={0.1}
beforeIcon="star-half"
/>
<ToggleControl
label={__("Show Review Text", "ultimate-blocks")}
checked={isShowReviewText}
onChange={() =>
setAttributes({ isShowReviewText: !isShowReviewText })
}
/>
</PanelBody>
</InspectorControls>
<InspectorControls group="typography">
Expand Down Expand Up @@ -161,6 +175,7 @@ export const editorDisplay = (props) => {
reviewTextColor,
reviewTextAlign,
starAlign,
isShowReviewText,
} = props.attributes;
return (
<>
Expand Down Expand Up @@ -208,24 +223,26 @@ export const editorDisplay = (props) => {
))}
</div>
</div>
<RichText
tagName="div"
className="ub-review-text"
placeholder={__("The text of the review goes here")}
value={reviewText}
style={{
textAlign: reviewTextAlign,
color: reviewTextColor || "inherit",
}}
onChange={(text) => setAttributes({ reviewText: text })}
keepPlaceholderOnFocus={true}
allowedFormats={[
"core/bold",
"core/italic",
"core/strikethrough",
"core/link",
]}
/>
{isShowReviewText && (
<RichText
tagName="div"
className="ub-review-text"
placeholder={__("The text of the review goes here")}
value={reviewText}
style={{
textAlign: reviewTextAlign,
color: reviewTextColor || "inherit",
}}
onChange={(text) => setAttributes({ reviewText: text })}
keepPlaceholderOnFocus={true}
allowedFormats={[
"core/bold",
"core/italic",
"core/strikethrough",
"core/link",
]}
/>
)}
</>
);
};
Loading

0 comments on commit 338b20d

Please sign in to comment.