Add to Cart Form: Replace Notice with Skeleton component (https://github.com/woocommerce/woocommerce-blocks/pull/8842)

* Add Skeleton component

* Replace notice with skeleton on Add to Cart Form block

* Fix css lint error

* add tooltip

* fix css linter

* add css for change cursor

---------

Co-authored-by: Luigi <gigitux@gmail.com>
This commit is contained in:
Alexandre Lara 2023-04-05 09:38:58 -03:00 committed by GitHub
parent d27d4d3a2e
commit 2f98513cd8
4 changed files with 83 additions and 35 deletions

View File

@ -3,7 +3,9 @@
*/ */
import { useBlockProps } from '@wordpress/block-editor'; import { useBlockProps } from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n'; import { __ } from '@wordpress/i18n';
import { Button, Disabled, Notice } from '@wordpress/components'; import { Button, Disabled, Tooltip } from '@wordpress/components';
import { Skeleton } from '@woocommerce/base-components/skeleton';
/** /**
* Internal dependencies * Internal dependencies
*/ */
@ -19,31 +21,34 @@ const Edit = () => {
return ( return (
<div { ...blockProps }> <div { ...blockProps }>
<Disabled> <Tooltip
<Notice text="Customer will see product add-to-cart options in this space, dependend on the product type. "
className={ 'wc-block-add-to-cart-form__notice' } position="bottom right"
status={ 'warning' } >
isDismissible={ false } <div className="wc-block-editor-container">
> <Skeleton numberOfLines={ 3 } />
<p> <Disabled>
{ __( <input
'Customers will see product add-to-cart options displayed here, dependent on the product type.', type={ 'number' }
'woo-gutenberg-products-block' value={ '1' }
) } className={
</p> 'wc-block-editor-add-to-cart-form__quantity'
</Notice> }
<input />
type={ 'number' } <Button
value={ '1' } variant={ 'primary' }
className={ 'wc-block-add-to-cart-form__quantity' } className={
/> 'wc-block-editor-add-to-cart-form__button'
<Button }
variant={ 'primary' } >
className={ 'wc-block-add-to-cart-form__button' } { __(
> 'Add to cart',
{ __( 'Add to cart', 'woo-gutenberg-products-block' ) } 'woo-gutenberg-products-block'
</Button> ) }
</Disabled> </Button>
</Disabled>
</div>
</Tooltip>
</div> </div>
); );
}; };

View File

@ -1,15 +1,10 @@
.wc-block-add-to-cart-form { .wc-block-editor-add-to-cart-form {
display: flex; display: flex;
flex-direction: row; flex-direction: column;
row-gap: $default-block-margin;
} }
.wc-block-add-to-cart-form__notice.components-notice { input.wc-block-editor-add-to-cart-form__quantity[type="number"] {
margin: 10px 0;
color: $black;
max-width: 60%;
}
input.wc-block-add-to-cart-form__quantity[type="number"] {
max-width: 50px; max-width: 50px;
min-height: 23px; min-height: 23px;
float: left; float: left;
@ -28,3 +23,10 @@ button.components-button.wc-block-add-to-cart-form__button {
padding: 20px 30px; padding: 20px 30px;
border-radius: 0; border-radius: 0;
} }
.wc-block-editor-container {
cursor: help;
gap: 10px;
display: flex;
flex-direction: column;
}

View File

@ -0,0 +1,22 @@
/**
* Internal dependencies
*/
import './style.scss';
export interface SkeletonProps {
numberOfLines?: number;
}
export const Skeleton = ( {
numberOfLines = 1,
}: SkeletonProps ): JSX.Element => {
const skeletonLines = Array( numberOfLines ).fill(
<span
className="wc-block-components-skeleton-text-line"
aria-hidden="true"
/>
);
return (
<div className="wc-block-components-skeleton">{ skeletonLines }</div>
);
};

View File

@ -0,0 +1,19 @@
.wc-block-components-skeleton {
display: flex;
flex-direction: column;
gap: 1rem;
width: 100%;
}
.wc-block-components-skeleton-text-line {
height: 0.8em;
width: 100%;
position: relative;
background: $gray-200;
border-radius: 2em;
&:last-child {
width: 80%;
}
}