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

Fix Dynamic BG #394

Merged
merged 10 commits into from
Jan 1, 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
37 changes: 24 additions & 13 deletions src/OnboardingSPA/components/NewfoldInterfaceSkeleton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,31 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { forwardRef, useEffect } from '@wordpress/element';
import { forwardRef, useEffect, useContext } from '@wordpress/element';
// eslint-disable-next-line @wordpress/no-unsafe-wp-apis
import { __unstableUseNavigateRegions as useNavigateRegions } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useMergeRefs } from '@wordpress/compose';
// import bgAiImg from '../../static/images/ai_bg.png';
// Needs to explicitly imported to be added dynamically
import aiBg from '../../static/images/sitegen/ai_bg.png';
import { ThemeContext } from '../ThemeContextProvider';
import { THEME_DARK } from '../../../constants';

function useHTMLClass( className ) {
function useHTMLClass( className, isDarkMode ) {
useEffect( () => {
const lightBg = '#ededed';
// eslint-disable-next-line no-undef
// const mainImage = new Image();
// mainImage.src = bgAiImg;
// mainImage.onload = () => {
// document.querySelector(
// '.nfd-onboarding-skeleton--sitegen'
// ).style.backgroundImage = `url('${ bgAiImg }')`;
// };
const mainImage = new Image();
mainImage.src = aiBg;
mainImage.onload = () => {
if (
document.querySelector( '.nfd-onboarding-skeleton--sitegen' )
) {
document.querySelector(
'.nfd-onboarding-skeleton--sitegen'
).style.background = isDarkMode ? `url('${ aiBg }')` : lightBg;
}
};

const element =
document && document.querySelector( `html:not(.${ className })` );
Expand All @@ -36,7 +44,7 @@ function useHTMLClass( className ) {
return () => {
element.classList.toggle( className );
};
}, [ className ] );
}, [ className, isDarkMode ] );
}

function NewfoldInterfaceSkeleton(
Expand All @@ -56,8 +64,11 @@ function NewfoldInterfaceSkeleton(
ref
) {
const navigateRegionsProps = useNavigateRegions( shortcuts );

useHTMLClass( 'nfd-interface-interface-skeleton__html-container' );
const { theme } = useContext( ThemeContext );
useHTMLClass(
'nfd-interface-interface-skeleton__html-container',
theme === THEME_DARK
);

const defaultLabels = {
/* translators: accessibility text for the nav bar landmark region. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ html.nfd-interface-interface-skeleton__html-container {
.nfd-onboarding-skeleton {

&--sitegen {
background: var(--sitegen-background);
background-repeat: no-repeat;
background-size: cover;
background: var(--sitegen-background-low);
background-repeat: no-repeat !important;
background-size: cover !important;

.nfd-interface-interface-skeleton__footer {
display: flex;
Expand Down
4 changes: 2 additions & 2 deletions src/OnboardingSPA/styles/_branding.scss
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ body {

.nfd-onboarding-sitegen-light {

--sitegen-background: #ededed;
--sitegen-background-low: #ededed;
--nfd-onboarding-primary: #000;
--nfd-onboarding-primary-rgb: 0, 0, 0;
--nfd-onboarding-hover: #c3c4c7;
Expand Down Expand Up @@ -345,6 +345,6 @@ body {
--nfd-onboarding-editor-header-background: var(--nfd-onboarding-preview-favorite-background);
--nfd-onboarding-favorite-fill: #ef4a71;
--nfd-onboarding-button-background: #363e4459;
--sitegen-background: url(../static/images/ai_bg.png);
--sitegen-background-low: url(../static/images/sitegen/ai_bg_low.png);
}
}
2 changes: 0 additions & 2 deletions src/OnboardingSPA/styles/_icons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ body {
--site-features-wishlist: url(../static/icons/site-features/wishlist.svg);
--site-features-comingsoon: url(../static/icons/site-features/comingsoon.svg);

--sitegen-background: url(../static/images/ai_bg.png);
--sitegen-background-high-res: url(../static/images/ai_bg.png);
--sitegen-ai-icon: url(../static/icons/sitegen/sitegen-ai-icon.svg);
--sitegen-image-upload-icon: url(../static/icons/sitegen/image-upload.svg);
--sitegen-ai-animation: url(../static/images/sitegen/sitegen-ai-animation.gif);
Expand Down