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 1233 merge components aionboarding #362

Merged
35 changes: 34 additions & 1 deletion src/OnboardingSPA/components/AdminBar/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,40 @@
import { __ } from '@wordpress/i18n';
import { Icon, wordpress } from '@wordpress/icons';
import { useSelect } from '@wordpress/data';
import { store as nfdOnboardingStore } from '../../../OnboardingSPA/store';

const AdminBar = () => {
const { currentUserInfo } = useSelect( ( select ) => {
return {
currentUserInfo:
select( nfdOnboardingStore ).getCurrentUserDetails(),
};
}, [] );

if ( ! currentUserInfo ) {
return null;
}

return (
<div className="nfd-onboarding-header__admin-bar">
Admin Bar Goes Here
<div className="nfd-onboarding-header__admin-bar__wplogo">
<Icon icon={ wordpress } />
<span>{ __( 'WordPress', 'wp-module-onboarding' ) }</span>
</div>
<div className="nfd-onboarding-header__admin-bar__profile">
<span className="nfd-onboarding-header__admin-bar__profile__greeting">
<span>
{ __( 'Howdy!', 'wp-module-onboarding' ) },{ ' ' }
ajayadav09 marked this conversation as resolved.
Show resolved Hide resolved
{ currentUserInfo.displayName }
</span>
</span>
<div className="nfd-onboarding-header__admin-bar__profile__avatar">
<img
src={ currentUserInfo.avatarUrl }
alt={ currentUserInfo.displayName }
/>
</div>
</div>
</div>
);
};
Expand Down
48 changes: 46 additions & 2 deletions src/OnboardingSPA/components/AdminBar/stylesheet.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
$light-grey : #a0a5aa;

.nfd-onboarding-header {

&__admin-bar {
Expand All @@ -6,7 +8,49 @@
width: 100%;
color: var(--nfd-onboarding-admin-bar-color);
margin: 0;
padding-left: 10px;
padding-top: 7px;
padding: 5px;
display: flex;
justify-content: space-between;
align-items: center;
box-sizing: border-box;

&__wplogo {
color: var(--nfd-onboarding-white);
font-size: 16px;
display: flex;
align-items: center;

svg {
color: $light-grey;
fill: $light-grey;
}

span {
margin-left: 15px;
}
}

&__profile {
display: flex;
align-items: center;

&__greeting {
color: $light-grey;
font-size: 16px;
margin-right: 5px;
}

&__avatar {
height: 20px;
width: 20px;
display: inline-block;

img {
width: 100%;
height: 100%;
object-fit: contain;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import Content from '../../Content';
import Drawer from '../../Drawer';
import Sidebar from '../../Sidebar';
import ToggleDarkMode from '../../ToggleDarkMode';
import classNames from 'classnames';
import { useLocation } from 'react-router-dom';
import { setFlow } from '../../../utils/api/flow';
Expand Down Expand Up @@ -52,6 +53,8 @@
import { init as initializeThemes } from '../../../utils/api/themes';
import { trigger as cronTrigger } from '../../../utils/api/cronTrigger';
import { stepTheFork } from '../../../steps/TheFork/step';
import { ThemeProvider } from '../../ThemeContextProvider';
import themeToggleHOC from '../themeToggleHOC';

const SiteBuild = () => {
const location = useLocation();
Expand Down Expand Up @@ -98,7 +101,7 @@
select( nfdOnboardingStore ).getPluginInstallHash(),
};
},
[ location.pathname ]

Check warning on line 104 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteBuild/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useSelect has an unnecessary dependency: 'location.pathname'. Either exclude it or remove the dependency array

Check warning on line 104 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteBuild/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useSelect has an unnecessary dependency: 'location.pathname'. Either exclude it or remove the dependency array
);

const [ isRequestPlaced, setIsRequestPlaced ] = useState( false );
Expand Down Expand Up @@ -361,7 +364,7 @@

useEffect( () => {
trackChapters();
}, [ currentStep ] );

Check warning on line 367 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteBuild/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has a missing dependency: 'trackChapters'. Either include it or remove the dependency array

Check warning on line 367 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteBuild/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has a missing dependency: 'trackChapters'. Either include it or remove the dependency array

const prioritizeFlow = () => {
const currentFlow = window.nfdOnboarding.currentFlow;
Expand Down Expand Up @@ -402,13 +405,13 @@
initializeSettings();
setInterval( cronTrigger, 45000 );
}
}, [ initialize ] );

Check warning on line 408 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteBuild/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has a missing dependency: 'pluginInstallHash'. Either include it or remove the dependency array

Check warning on line 408 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteBuild/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has a missing dependency: 'pluginInstallHash'. Either include it or remove the dependency array

useEffect( () => {
if ( false !== brandConfig?.prioritization ) {
return prioritizeFlow();
}
}, [ experienceLevel, topPriority ] );

Check warning on line 414 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteBuild/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'brandConfig?.prioritization' and 'prioritizeFlow'. Either include them or remove the dependency array

Check warning on line 414 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteBuild/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'brandConfig?.prioritization' and 'prioritizeFlow'. Either include them or remove the dependency array

useEffect( () => {
document.body.classList.add( `nfd-brand-${ newfoldBrand }` );
Expand All @@ -418,29 +421,39 @@
syncStoreToDB();
handlePreviousStepTracking();
handleConditionalDesignStepsRoutes();
}, [ location.pathname, onboardingFlow ] );

Check warning on line 424 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteBuild/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'handleConditionalDesignStepsRoutes', 'handlePreviousStepTracking', and 'syncStoreToDB'. Either include them or remove the dependency array

Check warning on line 424 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteBuild/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'handleConditionalDesignStepsRoutes', 'handlePreviousStepTracking', and 'syncStoreToDB'. Either include them or remove the dependency array

// wrapping the NewfoldInterfaceSkeleton with the HOC to make 'theme' available
const ThemedNewfoldInterfaceSkeleton = themeToggleHOC(
NewfoldInterfaceSkeleton,
'nfd-onboarding-sitegen-dark',
'nfd-onboarding-sitegen-light'
);

return (
<NewfoldInterfaceSkeleton
className={ classNames(
'nfd-onboarding-skeleton',
`brand-${ newfoldBrand }`,
`path-${ pathname }`,
{ 'is-drawer-open': isDrawerOpen },
{ 'is-large-viewport': isLargeViewport },
{ 'is-small-viewport': ! isLargeViewport },
{
'nfd-onboarding-skeleton--sitegen':
currentStep === stepTheFork,
},
{
'nfd-onboarding-sitegen-dark': currentStep === stepTheFork,
<ThemeProvider>
<ThemedNewfoldInterfaceSkeleton
className={ classNames(
'nfd-onboarding-skeleton',
`brand-${ newfoldBrand }`,
`path-${ pathname }`,
{ 'is-drawer-open': isDrawerOpen },
{ 'is-large-viewport': isLargeViewport },
{ 'is-small-viewport': ! isLargeViewport },
{
'nfd-onboarding-skeleton--sitegen':
currentStep === stepTheFork,
}
) }
header={ <Header /> }
drawer={ <Drawer /> }
content={ <Content /> }
sidebar={ <Sidebar /> }
footer={
currentStep === stepTheFork ? <ToggleDarkMode /> : null
}
) }
header={ <Header /> }
drawer={ <Drawer /> }
content={ <Content /> }
sidebar={ <Sidebar /> }
/>
/>
</ThemeProvider>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,29 @@ import NewfoldInterfaceSkeleton from '../index';
import Header from '../../Header';
import Content from '../../Content';
import Sidebar from '../../Sidebar';
import ToggleDarkMode from '../../ToggleDarkMode';
import { ThemeProvider } from '../../ThemeContextProvider';
import classNames from 'classnames';
import themeToggleHOC from '../themeToggleHOC';

// Wrapping the NewfoldInterfaceSkeleton with the HOC to make theme available
const ThemedNewfoldInterfaceSkeleton = themeToggleHOC(
NewfoldInterfaceSkeleton,
'nfd-onboarding-sitegen-dark',
'nfd-onboarding-sitegen-light'
);

const SiteGen = () => {
return (
<NewfoldInterfaceSkeleton
className={ classNames(
'nfd-onboarding-skeleton--sitegen',
'nfd-onboarding-sitegen-dark'
) }
header={ <Header /> }
content={ <Content /> }
sidebar={ <Sidebar /> }
/>
<ThemeProvider>
<ThemedNewfoldInterfaceSkeleton
className={ classNames( 'nfd-onboarding-skeleton--sitegen' ) }
ajayadav09 marked this conversation as resolved.
Show resolved Hide resolved
header={ <Header /> }
content={ <Content /> }
sidebar={ <Sidebar /> }
footer={ <ToggleDarkMode /> }
/>
</ThemeProvider>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,9 @@ html.nfd-interface-interface-skeleton__html-container {

&--sitegen {
background-image: var(--sitegen-background);

.nfd-interface-interface-skeleton__footer {
display: flex;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useContext } from '@wordpress/element';
import { ThemeContext } from '../ThemeContextProvider';
import classNames from 'classnames';

const themeToggleHOC = ( WrappedComponent, darkClass, lightClass ) => {
return ( props ) => {
const { theme } = useContext( ThemeContext );
const isDarkMode = theme === 'dark';
const className = classNames( props.className, {
[ darkClass ]: isDarkMode,
[ lightClass ]: ! isDarkMode,
} );

return <WrappedComponent { ...props } className={ className } />;
};
};

export default themeToggleHOC;
21 changes: 21 additions & 0 deletions src/OnboardingSPA/components/ThemeContextProvider/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useState, createContext } from '@wordpress/element';

const ThemeContext = createContext();

const ThemeProvider = ( { children } ) => {
const [ theme, setTheme ] = useState( 'dark' );

const toggleTheme = () => {
setTheme( ( prevTheme ) =>
prevTheme === 'dark' ? 'light' : 'dark'
ajayadav09 marked this conversation as resolved.
Show resolved Hide resolved
);
};

return (
<ThemeContext.Provider value={ { theme, toggleTheme } }>
{ children }
</ThemeContext.Provider>
);
};

export { ThemeContext, ThemeProvider };
9 changes: 9 additions & 0 deletions src/OnboardingSPA/components/ToggleDarkMode/contents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { __ } from '@wordpress/i18n';

const getContents = () => {
return {
label: __( 'Dark Mode', 'wp-module-onboarding' ),
};
};

export default getContents;
25 changes: 25 additions & 0 deletions src/OnboardingSPA/components/ToggleDarkMode/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ToggleControl } from '@wordpress/components';
import { useContext } from '@wordpress/element';
import { ThemeContext } from '../ThemeContextProvider';
import getContents from './contents';

const ToggleDarkMode = () => {
const { theme, toggleTheme } = useContext( ThemeContext );
const isChecked = theme === 'dark';
const content = getContents();
const onChange = () => {
toggleTheme();
};

return (
<div className="nfd-onboarding-toggle__darkmode">
<ToggleControl
label={ content.label }
checked={ isChecked }
onChange={ onChange }
/>
</div>
);
};

export default ToggleDarkMode;
24 changes: 24 additions & 0 deletions src/OnboardingSPA/components/ToggleDarkMode/stylesheet.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.nfd-onboarding-toggle__darkmode {
position: absolute;
bottom: 15px;
left: 50%;
transform: translateX(-50%);
z-index: 999;
color: #fff;

.components-toggle-control {

.components-form-toggle {

&.is-checked {

.components-form-toggle__track {
background-color: transparent;
outline: 2px solid #fff;
outline-offset: 0;
}
}

}
}
}
11 changes: 11 additions & 0 deletions src/OnboardingSPA/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,14 @@ export function getExperienceLevel( state ) {
export function getTopPriority( state ) {
return state.data.flowData.data.topPriority.priority1;
}

/**
* Gets Current User Details like Display name and avatar URL
*
* @param {*} state
* @return {string} currentUserInfo
*/
export function getCurrentUserDetails( state ) {
const currentUserInfo = state.runtime.currentUserDetails;
return currentUserInfo;
}
10 changes: 10 additions & 0 deletions src/OnboardingSPA/styles/_branding.scss
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,14 @@ body {
--nfd-onboarding-progress-bar-background: #353a40;
--nfd-onboarding-progress-bar-fill: #0060f0;
}

.nfd-onboarding-sitegen-light {
--nfd-onboarding-admin-bar-background: #1d2327;
--nfd-onboarding-admin-bar-color: #c3c4c7;
--nfd-onboarding-navigation-back-background: rgba(54, 62, 68, 0.35);
--nfd-onboarding-primary: #000;
--nfd-onboarding-secondary: #fff;
--nfd-onboarding-progress-bar-background: #353a40;
--nfd-onboarding-progress-bar-fill: #0060f0;
}
}
1 change: 1 addition & 0 deletions src/OnboardingSPA/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
@import "../components/ProgressBar/stylesheet";
@import "../components/Button/ButtonDark/stylesheet";
@import "../components//SiteGenPlaceholder/stylesheet.scss";
@import "../components/ToggleDarkMode/stylesheet";

// CSS for Pages
@import "../steps/BasicInfo/stylesheet";
Expand Down