woocommerce/plugins/woocommerce-admin/client/marketing/coupons/recommended-extensions/index.js

128 lines
3.0 KiB
JavaScript
Raw Normal View History

/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { compose } from '@wordpress/compose';
import clsx from 'clsx';
import { withDispatch, withSelect } from '@wordpress/data';
import PropTypes from 'prop-types';
/**
* Internal dependencies
*/
import './style.scss';
import RecommendedExtensionsItem from './item';
import RecommendedExtensionsPlaceholder from './placeholder';
import { STORE_KEY } from '~/marketing/data/constants';
import Card from '../card';
const RecommendedExtensions = ( {
extensions,
isLoading,
title,
description,
category,
} ) => {
if ( extensions.length === 0 && ! isLoading ) {
return null;
}
const categoryClass = category
? `woocommerce-marketing-recommended-extensions-card__category-${ category }`
: '';
const placholdersCount = 5;
return (
<Card
title={ title }
description={ description }
className={ clsx(
'woocommerce-marketing-recommended-extensions-card',
categoryClass
) }
>
Convert the marketing tab cards to use the new @wordpress/components Card component. (https://github.com/woocommerce/woocommerce-admin/pull/5428) * Change WooCommerce Card to WordPress Card in the WelcomeCard component. Use isElevated and margin-bottom to make the Card look close to previous UI. * Use WordPress Card in KnowledgeBase. For the description in Card header, it will be rendered as a p element instead of h2, which should be more semantically correct. Test is updated to reflect this. * Add Card component wrapper that supports title and description props. * Use WordPress Card component wrapper in recommended extensions. * Code refactor to use WordPress Card wrapper. * Use WordPress Card wrapper in installed extension. * Use margin-bottom for children layout at the parent CSS level. * Add test for Card. * Fix no margin between cards in Coupons page, and remove previous css for WooCommerce Card. * Remove old WooCommerce Card css. * Don't use isElevated in Card, to match the style in WooCommerce Home screen. * Make item border color consistent with WordPress Card in Installed Extension card. Use WordPress Card without CardBody here because we don't want the padding from CardBody. * Make the card description look similar to previous WooCommerce Card description. * Fix spelling in CSS class names. * Fix WooCommerce spelling in comment. * Change the Marketing Card style to match with WooCommerce Home style. Also change the text gray color to use CSS variable instead of hardcoded gray value. Also remove the usage of h2 in the Card header to follow WooCommerce Home style. * Use $gray-200 as light borders between items in card. * Remove unneeded CSS code based on TODO in comment.
2020-10-23 06:41:45 +00:00
{ isLoading ? (
<div
className={ clsx(
'woocommerce-marketing-recommended-extensions-card__items',
`woocommerce-marketing-recommended-extensions-card__items--count-${ placholdersCount }`
) }
>
{ [ ...Array( placholdersCount ).keys() ].map( ( key ) => (
<RecommendedExtensionsPlaceholder key={ key } />
) ) }
</div>
Convert the marketing tab cards to use the new @wordpress/components Card component. (https://github.com/woocommerce/woocommerce-admin/pull/5428) * Change WooCommerce Card to WordPress Card in the WelcomeCard component. Use isElevated and margin-bottom to make the Card look close to previous UI. * Use WordPress Card in KnowledgeBase. For the description in Card header, it will be rendered as a p element instead of h2, which should be more semantically correct. Test is updated to reflect this. * Add Card component wrapper that supports title and description props. * Use WordPress Card component wrapper in recommended extensions. * Code refactor to use WordPress Card wrapper. * Use WordPress Card wrapper in installed extension. * Use margin-bottom for children layout at the parent CSS level. * Add test for Card. * Fix no margin between cards in Coupons page, and remove previous css for WooCommerce Card. * Remove old WooCommerce Card css. * Don't use isElevated in Card, to match the style in WooCommerce Home screen. * Make item border color consistent with WordPress Card in Installed Extension card. Use WordPress Card without CardBody here because we don't want the padding from CardBody. * Make the card description look similar to previous WooCommerce Card description. * Fix spelling in CSS class names. * Fix WooCommerce spelling in comment. * Change the Marketing Card style to match with WooCommerce Home style. Also change the text gray color to use CSS variable instead of hardcoded gray value. Also remove the usage of h2 in the Card header to follow WooCommerce Home style. * Use $gray-200 as light borders between items in card. * Remove unneeded CSS code based on TODO in comment.
2020-10-23 06:41:45 +00:00
) : (
<div
className={ clsx(
Convert the marketing tab cards to use the new @wordpress/components Card component. (https://github.com/woocommerce/woocommerce-admin/pull/5428) * Change WooCommerce Card to WordPress Card in the WelcomeCard component. Use isElevated and margin-bottom to make the Card look close to previous UI. * Use WordPress Card in KnowledgeBase. For the description in Card header, it will be rendered as a p element instead of h2, which should be more semantically correct. Test is updated to reflect this. * Add Card component wrapper that supports title and description props. * Use WordPress Card component wrapper in recommended extensions. * Code refactor to use WordPress Card wrapper. * Use WordPress Card wrapper in installed extension. * Use margin-bottom for children layout at the parent CSS level. * Add test for Card. * Fix no margin between cards in Coupons page, and remove previous css for WooCommerce Card. * Remove old WooCommerce Card css. * Don't use isElevated in Card, to match the style in WooCommerce Home screen. * Make item border color consistent with WordPress Card in Installed Extension card. Use WordPress Card without CardBody here because we don't want the padding from CardBody. * Make the card description look similar to previous WooCommerce Card description. * Fix spelling in CSS class names. * Fix WooCommerce spelling in comment. * Change the Marketing Card style to match with WooCommerce Home style. Also change the text gray color to use CSS variable instead of hardcoded gray value. Also remove the usage of h2 in the Card header to follow WooCommerce Home style. * Use $gray-200 as light borders between items in card. * Remove unneeded CSS code based on TODO in comment.
2020-10-23 06:41:45 +00:00
'woocommerce-marketing-recommended-extensions-card__items',
`woocommerce-marketing-recommended-extensions-card__items--count-${ extensions.length }`
) }
>
{ extensions.map( ( extension ) => (
<RecommendedExtensionsItem
key={ extension.product }
category={ category }
{ ...extension }
/>
) ) }
</div>
) }
</Card>
);
};
RecommendedExtensions.propTypes = {
/**
* Array of recommended extensions.
*/
extensions: PropTypes.arrayOf( PropTypes.object ).isRequired,
/**
* Whether the card is loading.
*/
isLoading: PropTypes.bool.isRequired,
/**
* Cart title.
*/
title: PropTypes.string,
/**
* Card description.
*/
description: PropTypes.string,
/**
* Category of extensions to display.
*/
category: PropTypes.string,
};
RecommendedExtensions.defaultProps = {
title: __( 'Recommended extensions', 'woocommerce' ),
description: __(
'Great marketing requires the right tools. Take your marketing to the next level with our recommended marketing extensions.',
'woocommerce'
),
};
export { RecommendedExtensions };
export { default as RecommendedExtensionsPlaceholder } from './placeholder';
export default compose(
withSelect( ( select, props ) => {
const { getRecommendedPlugins, isResolving } = select( STORE_KEY );
return {
extensions: getRecommendedPlugins( props.category ),
isLoading: isResolving( 'getRecommendedPlugins', [
props.category,
] ),
};
} ),
withDispatch( ( dispatch ) => {
const { createNotice } = dispatch( 'core/notices' );
return {
createNotice,
};
} )
)( RecommendedExtensions );