Skip to content

Commit

Permalink
Merge pull request #361 from newfold-labs/add/sitegen-sitelogo
Browse files Browse the repository at this point in the history
SiteGen Site Logo Step
  • Loading branch information
officiallygod authored Nov 18, 2023
2 parents 1a95b57 + d9f9a18 commit 5b375ed
Show file tree
Hide file tree
Showing 23 changed files with 575 additions and 33 deletions.
29 changes: 26 additions & 3 deletions src/OnboardingSPA/components/Animate/stylesheet.scss
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,32 @@
}
}

@-webkit-keyframes spin {

0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}

100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}

@keyframes spin {

0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}

100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}

.animate {

&__blank {
Expand Down Expand Up @@ -141,7 +167,6 @@

@media (prefers-reduced-motion) {
animation: none !important;
translation: none !important;
}
}

Expand All @@ -150,7 +175,6 @@

@media (prefers-reduced-motion) {
animation: none !important;
translation: none !important;
}
}

Expand All @@ -159,7 +183,6 @@

@media (prefers-reduced-motion) {
animation: none !important;
translation: none !important;
}
}
}
Expand Down
43 changes: 43 additions & 0 deletions src/OnboardingSPA/components/Button/ButtonNext/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { useNavigate } from 'react-router-dom';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { Button } from '@wordpress/components';
import { Icon, chevronRight } from '@wordpress/icons';

import { store as nfdOnboardingStore } from '../../../store';
import classNames from 'classnames';

const ButtonNext = ( { disabled = false } ) => {
const { nextStep } = useSelect( ( select ) => {
return {
nextStep: select( nfdOnboardingStore ).getNextStep(),
};
} );
/* [TODO]: some sense of isStepComplete to enable/disable */
const navigate = useNavigate();
const navigateNext = () => {
if ( disabled ) {
return;
}

navigate( nextStep.path, { state: { origin: 'header' } } );
};
return (
<Button
onClick={ () => navigateNext() }
className={ classNames( 'nfd-onboarding-button--next', {
'nfd-onboarding-button--next--disabled': disabled,
} ) }
>
<span className="nfd-onboarding-button--next__text">
{ __( 'Next', 'wp-module-onboarding' ) }
</span>
<Icon
className="nfd-onboarding-button--next__icon"
icon={ chevronRight }
/>
</Button>
);
};

export default ButtonNext;
21 changes: 21 additions & 0 deletions src/OnboardingSPA/components/Button/ButtonNext/stylesheet.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.nfd-onboarding-button {

&--next {
background-color: var(--nfd-onboarding-primary);
color: var(--nfd-onboarding-secondary);
width: 80px;
height: 50px;
font-size: 15px;
border-radius: 8px;
padding: 16px;

&--disabled {
background-color: rgba(var(--nfd-onboarding-primary-rgb), 0.4);

&:hover {
cursor: not-allowed;
color: var(--nfd-onboarding-secondary);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { __ } from '@wordpress/i18n';
import { memo, useRef, useState } from '@wordpress/element';

import { ImageUploadLoader } from '../Loaders';
import { uploadImage } from '../../utils/api/uploader';
import { ImageUploadLoader } from '../../../Loaders';
import { uploadImage } from '../../../../utils/api/uploader';

/*
* Image Uploader
*
*/
const ImageUploader = ( { icon, iconSetter } ) => {
const ImageUploaderWithIcon = ( { icon, iconSetter } ) => {
const inputRef = useRef( null );
const [ isUploading, setIsUploading ] = useState( false );
const [ onDragActive, setOnDragActive ] = useState( false );
Expand Down Expand Up @@ -151,4 +151,4 @@ const ImageUploader = ( { icon, iconSetter } ) => {
);
};

export default memo( ImageUploader );
export default memo( ImageUploaderWithIcon );
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
import { __ } from '@wordpress/i18n';

import { memo, useContext, useRef, useState } from '@wordpress/element';
import { uploadImage } from '../../../../utils/api/uploader';
import Spinner from '../../../Loaders/Spinner';
import { ThemeContext } from '../../../ThemeContextProvider';
import classNames from 'classnames';
import { THEME_LIGHT } from '../../../../../constants';

const ImageUploaderWithText = ( { image, imageSetter } ) => {
const inputRef = useRef( null );
const { theme } = useContext( ThemeContext );
const [ isUploading, setIsUploading ] = useState( false );
const [ onDragActive, setOnDragActive ] = useState( false );

async function updateItem( fileData ) {
if ( fileData ) {
setIsUploading( true );
const res = await uploadImage( fileData );
if ( res ) {
const id = res?.body?.id;
const url = res?.body?.source_url;
imageSetter( {
id,
url,
} );
}
}

setIsUploading( false );
}

const handleClick = () => {
inputRef?.current.click();
};

const handleDragEnter = ( e ) => {
e.preventDefault();
e.stopPropagation();
setOnDragActive( true );
};

const handleDragLeave = ( e ) => {
e.preventDefault();
e.stopPropagation();
setOnDragActive( false );
};

const handleDragOver = ( e ) => {
e.preventDefault();
e.stopPropagation();
setOnDragActive( true );
};

const removeSelectedImage = () => {
imageSetter( {
id: 0,
url: '',
} );
if ( inputRef?.current?.files.length > 0 ) {
inputRef.current.value = '';
}
};

const imageChange = ( e ) => {
if ( e?.target?.files && e?.target?.files.length > 0 ) {
updateItem( e?.target?.files[ 0 ] );
}
};

const handleDrop = ( e ) => {
e.preventDefault();
e.stopPropagation();
setOnDragActive( false );
if ( e?.dataTransfer?.files && e?.dataTransfer?.files.length > 0 ) {
if (
e?.dataTransfer?.files[ 0 ]?.type.split( '/' )[ 0 ] === 'image'
) {
updateItem( e?.dataTransfer?.files[ 0 ] );
}
}
};

return (
<div
className={ `nfd-onboarding-image-uploader--with-text ${
onDragActive &&
'nfd-onboarding-image-uploader--with-text--on-drag'
}` }
onDrop={ ( e ) => handleDrop( e ) }
onDragOver={ ( e ) => handleDragOver( e ) }
onDragEnter={ ( e ) => handleDragEnter( e ) }
onDragLeave={ ( e ) => handleDragLeave( e ) }
>
{ isUploading ? (
<Spinner />
) : (
<>
{ ( image === undefined || image?.id === 0 ) && (
<>
<div className="nfd-onboarding-image-uploader--with-text__heading">
<div
className={ classNames(
'nfd-onboarding-image-uploader--with-text__heading__icon',
theme === THEME_LIGHT
? 'nfd-onboarding-image-uploader--with-text__heading__icon--light'
: null
) }
></div>
<p className="nfd-onboarding-image-uploader--with-text__heading__text">
<span className="nfd-onboarding-image-uploader--with-text__heading__text__drop">
{ __(
'Drop your logo here, or ',
'wp-module-onboarding'
) }
</span>
<button
onClick={ handleClick }
className="nfd-onboarding-image-uploader--with-text__heading__text__modal"
>
{ __(
'browse',
'wp-module-onboarding'
) }
</button>
<input
className="nfd-onboarding-image-uploader--with-text__heading__text__input"
accept="image/*"
type="file"
ref={ inputRef }
onChange={ imageChange }
/>
</p>
</div>
<div className="nfd-onboarding-image-uploader--with-text__subheading">
<p className="nfd-onboarding-image-uploader--with-text__subheading__text">
{ __(
'supports .jpg, .png, .gif',
'wp-module-onboarding'
) }
</p>
</div>
</>
) }
{ image?.id !== 0 && image?.id !== undefined && (
<>
<img
className="nfd-onboarding-image-uploader--with-text__site_logo"
src={ image?.url }
alt="Thumb"
/>
<div className="nfd-onboarding-image-uploader--with-text__site_logo-reset">
<button
className="nfd-onboarding-image-uploader--with-text__site_logo-reset__button"
onClick={ removeSelectedImage }
>
{ __( 'Reset', 'wp-module-onboarding' ) }
</button>
</div>
</>
) }
</>
) }
</div>
);
};

export default memo( ImageUploaderWithText );
Loading

0 comments on commit 5b375ed

Please sign in to comment.