From 3daa6d29e2b0dcbb2e3bc106b371928114ecad4e Mon Sep 17 00:00:00 2001 From: ajayadav09 Date: Wed, 6 Mar 2024 12:24:23 +0530 Subject: [PATCH 1/2] sitegen logo container background for png images --- .../components/ImageUploaderWithText/index.js | 34 +++++++++++-------- .../ImageUploaderWithText/stylesheet.scss | 22 ++++++++++++ 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/OnboardingSPA/components/ImageUploader/components/ImageUploaderWithText/index.js b/src/OnboardingSPA/components/ImageUploader/components/ImageUploaderWithText/index.js index 491fc2595..79a18ec51 100644 --- a/src/OnboardingSPA/components/ImageUploader/components/ImageUploaderWithText/index.js +++ b/src/OnboardingSPA/components/ImageUploader/components/ImageUploaderWithText/index.js @@ -5,7 +5,7 @@ import { uploadImage } from '../../../../utils/api/uploader'; import Spinner from '../../../Loaders/Spinner'; import { ThemeContext } from '../../../ThemeContextProvider'; import classNames from 'classnames'; -import { THEME_LIGHT } from '../../../../../constants'; +import { THEME_LIGHT, THEME_DARK } from '../../../../../constants'; import bytes from 'bytes'; import { Icon, closeSmall } from '@wordpress/icons'; import { store as nfdOnboardingStore } from '../../../../store'; @@ -16,7 +16,7 @@ const ImageUploaderWithText = ( { image, imageSetter } ) => { const { theme } = useContext( ThemeContext ); const [ isUploading, setIsUploading ] = useState( false ); const [ onDragActive, setOnDragActive ] = useState( false ); - const [ pngLogoBgColor, setPngLogoBgColor ] = useState( 'transparent' ); + const [ pngLogoBgTheme, setPngLogoBgTheme ] = useState( 'transparent' ); const { updateSiteGenErrorStatus } = useDispatch( nfdOnboardingStore ); @@ -72,7 +72,7 @@ const ImageUploaderWithText = ( { image, imageSetter } ) => { /* if the contrast value more than 150 it should have black bg, otherwise white */ const [ r, g, b ] = color.match( /\d+/g ).map( Number ); const contrastValue = 0.2126 * r + 0.7152 * g + 0.0722 * b; - return contrastValue > 160 ? 'black' : 'white'; + return contrastValue > 160 ? THEME_DARK : THEME_LIGHT; }; async function updateItem( fileData ) { @@ -91,7 +91,7 @@ const ImageUploaderWithText = ( { image, imageSetter } ) => { getDominantColor( url, ( dominantColor ) => { const contrastingColor = getContrastingColor( dominantColor ); - setPngLogoBgColor( contrastingColor ); + setPngLogoBgTheme( contrastingColor ); } ); } imageSetter( { @@ -160,15 +160,22 @@ const ImageUploaderWithText = ( { image, imageSetter } ) => { const isImageUploaded = ! isUploading && image?.id !== 0 && image?.id !== undefined; + const logoContainerClassnames = classNames( + 'nfd-onboarding-image-uploader--with-text', + { + 'nfd-onboarding-image-uploader--with-text--on-drag': onDragActive, + 'nfd-onboarding-image-uploader--with-text--not-dashed': + isImageUploaded, + 'nfd-onboarding-image-uploader--with-text--not-dashed__dark': + pngLogoBgTheme === THEME_DARK, + 'nfd-onboarding-image-uploader--with-text--not-dashed__light': + pngLogoBgTheme === THEME_LIGHT, + } + ); + return (
handleDrop( e ) } onDragOver={ ( e ) => handleDragOver( e ) } onDragEnter={ ( e ) => handleDragEnter( e ) } @@ -226,10 +233,7 @@ const ImageUploaderWithText = ( { image, imageSetter } ) => { ) } { isImageUploaded && (
-
+
Date: Wed, 6 Mar 2024 12:36:57 +0530 Subject: [PATCH 2/2] state update --- .../ImageUploader/components/ImageUploaderWithText/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/OnboardingSPA/components/ImageUploader/components/ImageUploaderWithText/index.js b/src/OnboardingSPA/components/ImageUploader/components/ImageUploaderWithText/index.js index 79a18ec51..0ddfe016e 100644 --- a/src/OnboardingSPA/components/ImageUploader/components/ImageUploaderWithText/index.js +++ b/src/OnboardingSPA/components/ImageUploader/components/ImageUploaderWithText/index.js @@ -16,7 +16,7 @@ const ImageUploaderWithText = ( { image, imageSetter } ) => { const { theme } = useContext( ThemeContext ); const [ isUploading, setIsUploading ] = useState( false ); const [ onDragActive, setOnDragActive ] = useState( false ); - const [ pngLogoBgTheme, setPngLogoBgTheme ] = useState( 'transparent' ); + const [ pngLogoBgTheme, setPngLogoBgTheme ] = useState( '' ); const { updateSiteGenErrorStatus } = useDispatch( nfdOnboardingStore ); @@ -127,6 +127,7 @@ const ImageUploaderWithText = ( { image, imageSetter } ) => { }; const removeSelectedImage = () => { + setPngLogoBgTheme( '' ); imageSetter( { id: 0, url: '',