Skip to content

Commit

Permalink
Support electronic device power supply icon preview in block editor. …
Browse files Browse the repository at this point in the history
…Replace doc links. Version bump to 3.18.7.
  • Loading branch information
dennisnissle committed Jan 23, 2025
1 parent 52c1e03 commit 7c3dec0
Show file tree
Hide file tree
Showing 39 changed files with 3,551 additions and 2,949 deletions.
27 changes: 27 additions & 0 deletions assets/js/blocks/product-elements/shared/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,31 @@
display: block;
text-indent: -9999px;
}
}

.wc-gzd-block-components-product-power-supply {
.wc-gzd-block-components-product-power-supply__value {
display: flex;
flex-wrap: wrap;
height: 70px;
margin: 1em 0;

svg {
display: flex;
align-items: center;
width: 70px;
height: 70px;

text {
text-anchor: middle;
dominant-baseline: middle;
font-size: 1.8rem;
font-weight: 600;

&.power-supply-usb-pd {
font-size: 1.5rem;
}
}
}
}
}
66 changes: 44 additions & 22 deletions assets/js/blocks/product-elements/shared/price-label-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,28 @@ const getPreviewData = ( labelType, productData, isDescendentOfSingleProductTemp
</p>
</>
);
} else if ( 'power_supply' === labelTypeData ) {
formattedPreview = (
<>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 150 188"
>
<line className="power-supply-excluded-line" x1="20" y1="1" x2="200" y2="270" stroke="black" strokeWidth="3"></line>
<path d="m 49.026981,2.6593224 a 0.80511101,0.78626814 0 0 0 -0.533384,0.4874861 l -0.05535,0.1454597 V 32.754718 l -7.922292,0.004 -7.920279,0.0068 -0.153977,0.05798 a 0.87555821,0.85506659 0 0 0 -0.459919,0.452103 l -0.05535,0.142511 v 29.488987 l -8.129609,0.0078 c -8.849177,0.0118 -8.180933,0 -8.774703,0.146444 a 4.9715604,4.8552058 0 0 0 -3.70653,4.0768 c -0.05132,0.376426 -0.05132,113.336627 0,113.714027 0.274745,1.94994 1.686707,3.53526 3.612936,4.04928 0.372365,0.0964 0.600815,0.13466 1.026517,0.16118 0.266692,0.0158 19.121385,0.0236 58.361489,0.0158 53.90923,-0.008 57.98612,-0.008 58.20953,-0.0492 1.10501,-0.19657 1.96548,-0.61526 2.73234,-1.33274 a 4.9514326,4.835549 0 0 0 1.4784,-3.00256 c 0.0352,-0.37642 0.0352,-113.014245 -0.005,-113.406396 a 4.9514326,4.835549 0 0 0 -3.66326,-4.211449 c -0.64107,-0.169048 0.10063,-0.153322 -8.84615,-0.161185 l -8.12157,-0.0078 V 33.37291 l -0.0785,-0.154305 a 0.80511101,0.78626814 0 0 0 -0.62898,-0.441293 c -0.11473,-0.01572 -2.73234,-0.0226 -7.98469,-0.0226 h -7.81461 l -0.008,-14.781842 -0.009,-14.7710286 -0.0594,-0.1159746 a 0.94600542,0.92386506 0 0 0 -0.4086,-0.387237 L 98.9752,2.6367118 h -8.63683 l -0.144919,0.068799 a 0.78498322,0.76661143 0 0 0 -0.468739,0.595605 c -0.02043,0.1081118 -0.02748,4.3303718 -0.02748,14.8034622 V 32.755701 H 58.333064 l -0.008,-14.754322 -0.009,-14.7523555 -0.06642,-0.1415284 A 0.82523878,0.80592484 0 0 0 57.836909,2.7045328 l -0.150958,-0.068799 -4.277153,-0.00492 c -3.397568,-0.00294 -4.298286,0.00492 -4.381817,0.028502 M 56.677549,18.491811 V 32.753735 H 50.06155 V 4.2318587 h 6.615999 z m 41.289109,0 V 32.753735 H 91.350661 V 4.2318587 h 6.615997 z m 16.511832,30.14552 V 62.9081 H 33.554762 V 34.361653 h 80.923728 z m 18.0828,15.951414 c 0.67628,0.176911 1.17143,0.453088 1.63134,0.917969 0.41765,0.425568 0.67228,0.874723 0.84134,1.488995 l 0.0594,0.219173 0.008,56.682078 c 0.008,50.04793 0,56.70467 -0.0312,56.90123 -0.0594,0.31845 -0.16102,0.60937 -0.31902,0.917 -0.46295,0.8865 -1.28113,1.48996 -2.30362,1.70422 -0.20431,0.0422 -3.18421,0.0422 -58.420876,0.0422 -49.35733,0 -58.233678,-0.003 -58.38665,-0.0344 -1.435111,-0.27225 -2.519997,-1.3858 -2.689071,-2.76374 -0.02416,-0.18085 -0.02818,-14.48502 -0.02416,-56.83146 l 0.008,-56.59362 0.07045,-0.253571 c 0.08664,-0.318439 0.169173,-0.518938 0.322144,-0.791183 a 3.2908911,3.213871 0 0 1 1.734007,-1.478184 4.5287494,4.4227582 0 0 1 0.708498,-0.179859 c 0.04629,-0.004 26.286874,-0.0078 58.323246,-0.0078 l 58.244752,0.004 z m 0,0"></path>
</svg>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 150 188"
className="power-supply-icon power-supply-charge-icon"
>
<text x="50%" y="100" className="power-supply-min-max-watt">50 - 90</text>
<text x="50%" y="130" className="power-supply-watt-abbr">W</text>
<text x="50%" y="160" className="power-supply-usb-pd">USB-PD</text>
<path d="m 49.026981,2.6593224 a 0.80511101,0.78626814 0 0 0 -0.533384,0.4874861 l -0.05535,0.1454597 V 32.754718 l -7.922292,0.004 -7.920279,0.0068 -0.153977,0.05798 a 0.87555821,0.85506659 0 0 0 -0.459919,0.452103 l -0.05535,0.142511 v 29.488987 l -8.129609,0.0078 c -8.849177,0.0118 -8.180933,0 -8.774703,0.146444 a 4.9715604,4.8552058 0 0 0 -3.70653,4.0768 c -0.05132,0.376426 -0.05132,113.336627 0,113.714027 0.274745,1.94994 1.686707,3.53526 3.612936,4.04928 0.372365,0.0964 0.600815,0.13466 1.026517,0.16118 0.266692,0.0158 19.121385,0.0236 58.361489,0.0158 53.90923,-0.008 57.98612,-0.008 58.20953,-0.0492 1.10501,-0.19657 1.96548,-0.61526 2.73234,-1.33274 a 4.9514326,4.835549 0 0 0 1.4784,-3.00256 c 0.0352,-0.37642 0.0352,-113.014245 -0.005,-113.406396 a 4.9514326,4.835549 0 0 0 -3.66326,-4.211449 c -0.64107,-0.169048 0.10063,-0.153322 -8.84615,-0.161185 l -8.12157,-0.0078 V 33.37291 l -0.0785,-0.154305 a 0.80511101,0.78626814 0 0 0 -0.62898,-0.441293 c -0.11473,-0.01572 -2.73234,-0.0226 -7.98469,-0.0226 h -7.81461 l -0.008,-14.781842 -0.009,-14.7710286 -0.0594,-0.1159746 a 0.94600542,0.92386506 0 0 0 -0.4086,-0.387237 L 98.9752,2.6367118 h -8.63683 l -0.144919,0.068799 a 0.78498322,0.76661143 0 0 0 -0.468739,0.595605 c -0.02043,0.1081118 -0.02748,4.3303718 -0.02748,14.8034622 V 32.755701 H 58.333064 l -0.008,-14.754322 -0.009,-14.7523555 -0.06642,-0.1415284 A 0.82523878,0.80592484 0 0 0 57.836909,2.7045328 l -0.150958,-0.068799 -4.277153,-0.00492 c -3.397568,-0.00294 -4.298286,0.00492 -4.381817,0.028502 M 56.677549,18.491811 V 32.753735 H 50.06155 V 4.2318587 h 6.615999 z m 41.289109,0 V 32.753735 H 91.350661 V 4.2318587 h 6.615997 z m 16.511832,30.14552 V 62.9081 H 33.554762 V 34.361653 h 80.923728 z m 18.0828,15.951414 c 0.67628,0.176911 1.17143,0.453088 1.63134,0.917969 0.41765,0.425568 0.67228,0.874723 0.84134,1.488995 l 0.0594,0.219173 0.008,56.682078 c 0.008,50.04793 0,56.70467 -0.0312,56.90123 -0.0594,0.31845 -0.16102,0.60937 -0.31902,0.917 -0.46295,0.8865 -1.28113,1.48996 -2.30362,1.70422 -0.20431,0.0422 -3.18421,0.0422 -58.420876,0.0422 -49.35733,0 -58.233678,-0.003 -58.38665,-0.0344 -1.435111,-0.27225 -2.519997,-1.3858 -2.689071,-2.76374 -0.02416,-0.18085 -0.02818,-14.48502 -0.02416,-56.83146 l 0.008,-56.59362 0.07045,-0.253571 c 0.08664,-0.318439 0.169173,-0.518938 0.322144,-0.791183 a 3.2908911,3.213871 0 0 1 1.734007,-1.478184 4.5287494,4.4227582 0 0 1 0.708498,-0.179859 c 0.04629,-0.004 26.286874,-0.0078 58.323246,-0.0078 l 58.244752,0.004 z m 0,0"></path>
</svg>
</>
);
}

return {
Expand All @@ -129,11 +151,11 @@ const getPreviewData = ( labelType, productData, isDescendentOfSingleProductTemp
}
};

const PriceLabelBlock = ( props ) => {
const { className, textAlign, isDescendentOfSingleProductTemplate, labelType } = props;
const { parentName, parentClassName } = useInnerBlockLayoutContext();
const { product } = useProductDataContext();
const styleProps = useStyleProps( props );
const PriceLabelBlock = (props) => {
const {className, textAlign, isDescendentOfSingleProductTemplate, labelType} = props;
const {parentName, parentClassName} = useInnerBlockLayoutContext();
const {product} = useProductDataContext();
const styleProps = useStyleProps(props);

const isDescendentOfAllProductsBlock = parentName === 'woocommerce/all-products';

Expand All @@ -142,37 +164,37 @@ const PriceLabelBlock = ( props ) => {
className,
styleProps.className,
{
[ `${ parentClassName }__product-${ labelType }` ]: parentClassName,
[`${parentClassName}__product-${labelType}`]: parentClassName,
}
);

if ( ! product.id && ! isDescendentOfSingleProductTemplate ) {
if (!product.id && !isDescendentOfSingleProductTemplate) {
const productComponent = (
<FormattedPriceLabel align={ textAlign } className={ wrapperClassName } labelType={ labelType } />
<FormattedPriceLabel align={textAlign} className={wrapperClassName} labelType={labelType}/>
);

if ( isDescendentOfAllProductsBlock ) {
const allProductsClassName = `wp-block-woocommerce-gzd-product-${ labelType }`;
if (isDescendentOfAllProductsBlock) {
const allProductsClassName = `wp-block-woocommerce-gzd-product-${labelType}`;

return (
<div className={ allProductsClassName }>
{ productComponent }
<div className={allProductsClassName}>
{productComponent}
</div>
);
}

return productComponent;
}

const previewData = getPreviewData( labelType, product, isDescendentOfSingleProductTemplate );
const previewData = getPreviewData(labelType, product, isDescendentOfSingleProductTemplate);

const productComponent = (
<FormattedPriceLabel
align={ textAlign }
className={ wrapperClassName }
labelType={ labelType }
style={ styleProps.style }
labelStyle={ styleProps.style }
align={textAlign}
className={wrapperClassName}
labelType={labelType}
style={styleProps.style}
labelStyle={styleProps.style}
formattedLabel={
isDescendentOfSingleProductTemplate
? previewData['preview']
Expand All @@ -181,12 +203,12 @@ const PriceLabelBlock = ( props ) => {
/>
);

if ( isDescendentOfAllProductsBlock ) {
const allProductsClassName = `wp-block-woocommerce-gzd-product-${ labelType }`;
if (isDescendentOfAllProductsBlock) {
const allProductsClassName = `wp-block-woocommerce-gzd-product-${labelType}`;

return (
<div className={ allProductsClassName }>
{ productComponent }
<div className={allProductsClassName}>
{productComponent}
</div>
);
}
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"defuse/php-encryption": "^2.0.0",
"globalcitizen/php-iban": "^4.0.0",
"vendidero/woocommerce-germanized-dhl": "3.5.0",
"vendidero/woocommerce-germanized-shipments": "4.2.0",
"vendidero/woocommerce-eu-tax-helper": "2.0.5"
"vendidero/woocommerce-germanized-shipments": "4.2.1",
"vendidero/woocommerce-eu-tax-helper": "2.0.6"
},
"require-dev": {
"myclabs/deep-copy": "^1.7.0",
Expand Down
46 changes: 23 additions & 23 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified i18n/languages/woocommerce-germanized-de_DE.mo
Binary file not shown.
Loading

0 comments on commit 7c3dec0

Please sign in to comment.