Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 771eb44

Browse files
albarinimanish003
andauthored
Mini-cart: add the option to change the style between 'Outline' and 'Fill' in all the buttons (#8835)
* Render inner buttons on the frontend * Add deprecation to the buttons * Fix lint and inline save * Remove commented out code and fix condition * Change migrate condition * Add styles outline and fill styles to cart and checkout buttons * Add fill and outline styles to the start shopping button * Refactor variants * Remove imports * Add classname default value --------- Co-authored-by: Manish Menaria <[email protected]>
1 parent 322a671 commit 771eb44

File tree

10 files changed

+69
-4
lines changed

10 files changed

+69
-4
lines changed

assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-cart-button-block/block.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@
2424
}
2525
}
2626
},
27+
"styles": [
28+
{
29+
"name": "fill",
30+
"label": "Fill"
31+
},
32+
{
33+
"name": "outline",
34+
"label": "Outline",
35+
"isDefault": true
36+
}
37+
],
2738
"parent": [ "woocommerce/mini-cart-footer-block" ],
2839
"textdomain": "woo-gutenberg-products-block",
2940
"apiVersion": 2

assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-cart-button-block/block.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { useColorProps } from '@woocommerce/base-hooks';
1010
* Internal dependencies
1111
*/
1212
import { defaultCartButtonLabel } from './constants';
13+
import { getVariant } from '../utils';
1314

1415
type MiniCartCartButtonBlockProps = {
1516
cartButtonLabel?: string;
@@ -37,7 +38,7 @@ const Block = ( {
3738
) }
3839
style={ { ...colorProps.style } }
3940
href={ CART_URL }
40-
variant="outlined"
41+
variant={ getVariant( className, 'outlined' ) }
4142
>
4243
{ cartButtonLabel || defaultCartButtonLabel }
4344
</Button>

assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-cart-button-block/edit.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import EditableButton from '@woocommerce/editor-components/editable-button';
88
* Internal dependencies
99
*/
1010
import { defaultCartButtonLabel } from './constants';
11+
import { getVariant } from '../utils';
1112

1213
export const Edit = ( {
1314
attributes,
@@ -25,7 +26,7 @@ export const Edit = ( {
2526
<EditableButton
2627
{ ...blockProps }
2728
className="wc-block-mini-cart__footer-cart"
28-
variant="outlined"
29+
variant={ getVariant( blockProps.className, 'outlined' ) }
2930
value={ cartButtonLabel }
3031
placeholder={ defaultCartButtonLabel }
3132
onChange={ ( content ) => {

assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-checkout-button-block/block.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,20 @@
2424
}
2525
}
2626
},
27-
"parent": [ "woocommerce/mini-cart-footer-block" ],
27+
"styles": [
28+
{
29+
"name": "fill",
30+
"label": "Fill",
31+
"isDefault": true
32+
},
33+
{
34+
"name": "outline",
35+
"label": "Outline"
36+
}
37+
],
38+
"parent": [
39+
"woocommerce/mini-cart-footer-block"
40+
],
2841
"textdomain": "woo-gutenberg-products-block",
2942
"apiVersion": 2
3043
}

assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-checkout-button-block/block.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { useColorProps } from '@woocommerce/base-hooks';
1010
* Internal dependencies
1111
*/
1212
import { defaultCheckoutButtonLabel } from './constants';
13+
import { getVariant } from '../utils';
1314

1415
type MiniCartCheckoutButtonBlockProps = {
1516
checkoutButtonLabel?: string;
@@ -35,6 +36,7 @@ const Block = ( {
3536
colorProps.className,
3637
'wc-block-mini-cart__footer-checkout'
3738
) }
39+
variant={ getVariant( className, 'contained' ) }
3840
style={ { ...colorProps.style } }
3941
href={ CHECKOUT_URL }
4042
>

assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-checkout-button-block/edit.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
*/
44
import { useBlockProps } from '@wordpress/block-editor';
55
import EditableButton from '@woocommerce/editor-components/editable-button';
6+
import classNames from 'classnames';
67

78
/**
89
* Internal dependencies
910
*/
1011
import { defaultCheckoutButtonLabel } from './constants';
12+
import { getVariant } from '../utils';
1113

1214
export const Edit = ( {
1315
attributes,
@@ -24,7 +26,11 @@ export const Edit = ( {
2426
return (
2527
<EditableButton
2628
{ ...blockProps }
27-
className="wc-block-mini-cart__footer-checkout"
29+
className={ classNames(
30+
'wc-block-mini-cart__footer-checkout',
31+
blockProps.className
32+
) }
33+
variant={ getVariant( blockProps.className, 'contained' ) }
2834
value={ checkoutButtonLabel }
2935
placeholder={ defaultCheckoutButtonLabel }
3036
onChange={ ( content ) => {

assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-shopping-button-block/block.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@
2424
}
2525
}
2626
},
27+
"styles": [
28+
{
29+
"name": "fill",
30+
"label": "Fill",
31+
"isDefault": true
32+
},
33+
{
34+
"name": "outline",
35+
"label": "Outline"
36+
}
37+
],
2738
"parent": [ "woocommerce/empty-mini-cart-contents-block" ],
2839
"textdomain": "woo-gutenberg-products-block",
2940
"apiVersion": 2

assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-shopping-button-block/block.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import classNames from 'classnames';
99
* Internal dependencies
1010
*/
1111
import { defaultStartShoppingButtonLabel } from './constants';
12+
import { getVariant } from '../utils';
1213

1314
type MiniCartShoppingButtonBlockProps = {
1415
className: string;
@@ -30,6 +31,7 @@ const Block = ( {
3031
className,
3132
'wc-block-mini-cart__shopping-button'
3233
) }
34+
variant={ getVariant( className, 'contained' ) }
3335
href={ SHOP_URL }
3436
>
3537
{ startShoppingButtonLabel || defaultStartShoppingButtonLabel }

assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-shopping-button-block/edit.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import EditableButton from '@woocommerce/editor-components/editable-button';
88
* Internal dependencies
99
*/
1010
import { defaultStartShoppingButtonLabel } from './constants';
11+
import { getVariant } from '../utils';
1112

1213
export const Edit = ( {
1314
attributes,
@@ -33,6 +34,7 @@ export const Edit = ( {
3334
startShoppingButtonLabel: content,
3435
} );
3536
} }
37+
variant={ getVariant( blockProps.className, 'contained' ) }
3638
/>
3739
</div>
3840
);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
type Variant = 'text' | 'contained' | 'outlined';
2+
3+
export const getVariant = (
4+
className = '',
5+
defaultVariant: Variant
6+
): Variant => {
7+
if ( className.includes( 'is-style-outline' ) ) {
8+
return 'outlined';
9+
}
10+
11+
if ( className.includes( 'is-style-fill' ) ) {
12+
return 'contained';
13+
}
14+
15+
return defaultVariant;
16+
};

0 commit comments

Comments
 (0)