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,32 +21,35 @@ 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 }
> >
<p> <div className="wc-block-editor-container">
{ __( <Skeleton numberOfLines={ 3 } />
'Customers will see product add-to-cart options displayed here, dependent on the product type.', <Disabled>
'woo-gutenberg-products-block'
) }
</p>
</Notice>
<input <input
type={ 'number' } type={ 'number' }
value={ '1' } value={ '1' }
className={ 'wc-block-add-to-cart-form__quantity' } className={
'wc-block-editor-add-to-cart-form__quantity'
}
/> />
<Button <Button
variant={ 'primary' } variant={ 'primary' }
className={ 'wc-block-add-to-cart-form__button' } className={
'wc-block-editor-add-to-cart-form__button'
}
> >
{ __( 'Add to cart', 'woo-gutenberg-products-block' ) } { __(
'Add to cart',
'woo-gutenberg-products-block'
) }
</Button> </Button>
</Disabled> </Disabled>
</div> </div>
</Tooltip>
</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%;
}
}