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
Merged
Show file tree
Hide file tree
Changes from 8 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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' ) }
{ 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
);

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

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

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

useEffect( () => {
document.body.classList.add( `nfd-brand-${ newfoldBrand }` );
Expand All @@ -418,29 +421,40 @@
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

const shouldApplyTheme =
currentStep === stepTheFork ||
window.nfdOnboarding.currentFlow === 'sitegen';
// wrapping the NewfoldInterfaceSkeleton with the HOC to make 'theme' available
const ThemedNewfoldInterfaceSkeleton = themeToggleHOC(
NewfoldInterfaceSkeleton,
'nfd-onboarding-sitegen-dark',
'nfd-onboarding-sitegen-light',
shouldApplyTheme
);

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,
}
) }
header={ <Header /> }
drawer={ <Drawer /> }
content={ <Content /> }
sidebar={ <Sidebar /> }
/>
<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': shouldApplyTheme,
}
) }
header={ <Header /> }
drawer={ <Drawer /> }
content={ <Content /> }
sidebar={ <Sidebar /> }
footer={ shouldApplyTheme ? <ToggleDarkMode /> : null }
/>
</ThemeProvider>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,28 @@ import NewfoldInterfaceSkeleton from '../index';
import Header from '../../Header';
import Content from '../../Content';
import Sidebar from '../../Sidebar';
import classNames from 'classnames';
import ToggleDarkMode from '../../ToggleDarkMode';
import { ThemeProvider } from '../../ThemeContextProvider';
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={ 'nfd-onboarding-skeleton--sitegen' }
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,26 @@
import { useContext } from '@wordpress/element';
import { ThemeContext } from '../ThemeContextProvider';
import classNames from 'classnames';
import { THEME_DARK } from '../../../constants';

const themeToggleHOC = (
WrappedComponent,
darkClass,
lightClass,
shouldApplyTheme = true
) => {
return ( props ) => {
const { theme } = useContext( ThemeContext );
const isDarkMode = theme === THEME_DARK;
const shouldApply =
shouldApplyTheme !== undefined ? shouldApplyTheme : true;
const className = classNames( props.className, {
[ darkClass ]: isDarkMode && shouldApply,
[ lightClass ]: ! isDarkMode && shouldApply,
} );

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

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

const ThemeContext = createContext();

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

const toggleTheme = () => {
setTheme( ( prevTheme ) =>
prevTheme === THEME_DARK ? THEME_LIGHT : THEME_DARK
);
};

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;
38 changes: 38 additions & 0 deletions src/OnboardingSPA/components/ToggleDarkMode/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { useContext } from '@wordpress/element';
import { ThemeContext } from '../ThemeContextProvider';
import classNames from 'classnames';
import { THEME_DARK } from '../../../constants';

const ToggleDarkMode = () => {
const { theme, toggleTheme } = useContext( ThemeContext );
const isDarkMode = theme === THEME_DARK;
const onChange = () => {
toggleTheme();
};

return (
<div className="nfd-onboarding-toggle__theme">
<div
className={ classNames(
'nfd-onboarding-toggle__theme__button',
{
'nfd-onboarding-toggle__theme__button__light':
! isDarkMode,
'nfd-onboarding-toggle__theme__button__dark':
isDarkMode,
}
) }
onClick={ () => onChange() }
role="button"
onKeyDown={ ( event ) => {
if ( event.key === 'Enter' ) {
onChange();
}
} }
tabIndex="0"
></div>
</div>
);
};

export default ToggleDarkMode;
21 changes: 21 additions & 0 deletions src/OnboardingSPA/components/ToggleDarkMode/stylesheet.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.nfd-onboarding-toggle__theme {
position: absolute;
bottom: 25px;
left: 25px;
z-index: 1;

&__button {
width: 60px;
height: 60px;
cursor: pointer;

&__light {
animation: fadeIn 600ms ease-in-out;
background: var(--sitegen-toggle-theme-icon-light);
}

&__dark {
background: var(--sitegen-toggle-theme-icon-dark);
}
}
}
11 changes: 11 additions & 0 deletions src/OnboardingSPA/static/icons/toggle-dark-mode.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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;
}
}
2 changes: 2 additions & 0 deletions src/OnboardingSPA/styles/_icons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ body {
--site-features-comingsoon: url(../static/icons/site-features/comingsoon.svg);

--sitegen-background: url(../static/images/sitegen-bg.png);
--sitegen-toggle-theme-icon-dark: url(../static/icons/toggle-dark-mode.svg);
--sitegen-toggle-theme-icon-light: url(../static/icons/toggle-light-mode.png);
}
Loading