Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Press2 1821 logo container background #511

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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( '' );

const { updateSiteGenErrorStatus } = useDispatch( nfdOnboardingStore );

Expand Down Expand Up @@ -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 ) {
Expand All @@ -91,7 +91,7 @@ const ImageUploaderWithText = ( { image, imageSetter } ) => {
getDominantColor( url, ( dominantColor ) => {
const contrastingColor =
getContrastingColor( dominantColor );
setPngLogoBgColor( contrastingColor );
setPngLogoBgTheme( contrastingColor );
} );
}
imageSetter( {
Expand Down Expand Up @@ -127,6 +127,7 @@ const ImageUploaderWithText = ( { image, imageSetter } ) => {
};

const removeSelectedImage = () => {
setPngLogoBgTheme( '' );
imageSetter( {
id: 0,
url: '',
Expand Down Expand Up @@ -160,15 +161,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 (
<div
className={ `nfd-onboarding-image-uploader--with-text ${
onDragActive &&
'nfd-onboarding-image-uploader--with-text--on-drag'
} ${
isImageUploaded &&
'nfd-onboarding-image-uploader--with-text--not-dashed'
}` }
className={ logoContainerClassnames }
onDrop={ ( e ) => handleDrop( e ) }
onDragOver={ ( e ) => handleDragOver( e ) }
onDragEnter={ ( e ) => handleDragEnter( e ) }
Expand Down Expand Up @@ -226,10 +234,7 @@ const ImageUploaderWithText = ( { image, imageSetter } ) => {
) }
{ isImageUploaded && (
<div className="nfd-onboarding-image-uploader--with-text__site_logo__preview">
<div
className="nfd-onboarding-image-uploader--with-text__site_logo__preview__wrapper"
style={ { backgroundColor: pngLogoBgColor } }
>
<div className="nfd-onboarding-image-uploader--with-text__site_logo__preview__wrapper">
<img
className="nfd-onboarding-image-uploader--with-text__site_logo__preview__image"
src={ image.url }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,28 @@
&--not-dashed {
border: 1.25px solid rgba(var(--nfd-onboarding-primary-rgb), 0.5);
align-items: stretch;

&__dark{
background-color: rgba(0,0,0,0.7);

.nfd-onboarding-image-uploader--with-text__site_logo__preview__details{
color: white;
}
.nfd-onboarding-image-uploader--with-text__site_logo__preview__reset__button__icon{
fill: white;
}
}

&__light{
background-color: rgba(255,255,255,0.7);

.nfd-onboarding-image-uploader--with-text__site_logo__preview__details{
color: black;
}
.nfd-onboarding-image-uploader--with-text__site_logo__preview__reset__button__icon{
fill:black;
}
}
}
border-radius: 8px;
padding: 30px;
Expand Down
Loading