From d13cf2650e0adf3afa5c39bec829e94a7045c4cc Mon Sep 17 00:00:00 2001 From: JF-Cozy Date: Tue, 24 Oct 2023 16:00:59 +0200 Subject: [PATCH] feat(Empty): Accept now , and as icon prop value fix https://github.com/cozy/cozy-ui/issues/1465 --- react/Empty/Readme.md | 38 ++++++++++++++++++++++ react/Empty/index.jsx | 37 +++++++++++++++------ react/__snapshots__/examples.spec.jsx.snap | 31 ++++++++++++++++++ 3 files changed, 96 insertions(+), 10 deletions(-) diff --git a/react/Empty/Readme.md b/react/Empty/Readme.md index e6441d697c..09785c91fa 100644 --- a/react/Empty/Readme.md +++ b/react/Empty/Readme.md @@ -28,3 +28,41 @@ const initialVariants = [ )} ``` + +### With custom image + +```jsx +import CozyIcon from 'cozy-ui/transpiled/react/Icons/Cozy' +import PeopleSVGIcon from '../../assets/icons/ui/people.svg' +import Empty from 'cozy-ui/transpiled/react/Empty' +import Icon from 'cozy-ui/transpiled/react/Icon' + +; + +<> + + } + title="With IMG" + text="Try adding some content to this list" + /> + + + + } + title="With SVG" + text="Try adding some content to this list" + /> + } + title="With Icon component" + text="Try adding some content to this list" + /> + +``` \ No newline at end of file diff --git a/react/Empty/index.jsx b/react/Empty/index.jsx index 7f35d200bc..fc0cd0d198 100644 --- a/react/Empty/index.jsx +++ b/react/Empty/index.jsx @@ -1,10 +1,12 @@ import React from 'react' import cx from 'classnames' import PropTypes from 'prop-types' + import Icon, { iconPropType } from '../Icon' -import styles from './styles.styl' import Typography from '../Typography' +import styles from './styles.styl' + export const Empty = ({ icon, iconSize, @@ -15,6 +17,8 @@ export const Empty = ({ centered, ...restProps }) => { + const isReactIconElement = typeof icon === 'object' && !!icon.props + return (
- {icon && ( - - )} + {icon && + (isReactIconElement ? ( + React.cloneElement(icon, { + className: cx( + styles['c-empty-img'], + { + [styles[`c-empty-img--${iconSize}`]]: iconSize !== 'normal' + }, + icon.props?.className + ), + size: icon.props?.size || (icon.type === Icon ? '100%' : undefined) + }) + ) : ( + + ))} {title && ( {title} @@ -51,6 +67,7 @@ Empty.propTypes = { text: PropTypes.node, /** Sets horizontal and vertical centring. The reference element is that of a fixed position */ centered: PropTypes.bool, + children: PropTypes.node, className: PropTypes.string } diff --git a/react/__snapshots__/examples.spec.jsx.snap b/react/__snapshots__/examples.spec.jsx.snap index 7479074d52..e593b19a27 100644 --- a/react/__snapshots__/examples.spec.jsx.snap +++ b/react/__snapshots__/examples.spec.jsx.snap @@ -2498,6 +2498,37 @@ exports[`Empty should render examples: Empty 1`] = `
" `; +exports[`Empty should render examples: Empty 2`] = ` +"
+
+ + +

With functional SVG

+

Try adding some content to this list

+
+
+
+

With IMG

+

Try adding some content to this list

+
+
+
+ + +

With SVG

+

Try adding some content to this list

+
+
+
+ + +

With Icon component

+

Try adding some content to this list

+
+
+
" +`; + exports[`Hero should render examples: Hero 1`] = ` "