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

UI bug fixes reported #436

Merged
merged 15 commits into from
Feb 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@
justify-content: center;
flex-wrap: wrap;

@media (min-width: #{ ($break-mobile) }) and (max-width: #{ ($break-wide) }) {
width: 340px;
padding: 15px;
}

@media (max-width: #{ ($break-mobile) }) {
width: 300px;
padding: 10px;
padding: 20px 0;
}

&__live-preview-container {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { forwardRef, useImperativeHandle } from 'react';
import { useState, useEffect } from '@wordpress/element';
import { useSelect, useDispatch } from '@wordpress/data';
import { PanelBody, PanelRow, Button, Dashicon } from '@wordpress/components';
import { PanelBody, PanelRow, Button } from '@wordpress/components';
import './stylesheet.scss';
import { store as nfdOnboardingStore } from '../../../../../store';
import { __ } from '@wordpress/i18n';
Expand Down Expand Up @@ -154,17 +154,11 @@ const CustomFontsDisplay = ( {
role="presentation"
onClick={ () => handleGroupSelect( 'custom' ) }
>
<Dashicon
className={ `${ baseClassName }__font-group__container__button__icon` }
icon={ 'yes-alt' }
size={ 30 }
style={ {
color:
selectedGroup === 'custom'
? 'var(--nfd-onboarding-sitegen-customize-icon-selected)'
: 'var(--nfd-onboarding-sitegen-customize-grey-1)',
} }
/>
<span
className={ `${ baseClassName }__font-group__container__button__icon${
selectedGroup === 'custom' ? ` selected` : ``
}` }
></span>
<div
className={ `${ baseClassName }__font-group__container__button__font-name__container` }
>
Expand Down
201 changes: 131 additions & 70 deletions src/OnboardingSPA/steps/SiteGen/Editor/Header/center.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,19 @@
import { Icon, chevronDown, reusableBlock } from '@wordpress/icons';
import { __ } from '@wordpress/i18n';
import { useViewportMatch } from '@wordpress/compose';
import { useRef } from '@wordpress/element';
import { useRef, useState, useEffect, memo } from '@wordpress/element';
import { ReactComponent as FavoriteIconStroked } from '../../../../static/icons/sitegen/heart-stroked.svg';
import { ReactComponent as FavoriteFilled } from '../../../../static/icons/sitegen/heart-filled.svg';
import { Dropdown, MenuGroup, MenuItem } from '@wordpress/components';

const StepEditorHeaderCenter = ( {
handleFavorite,
handleRename,
handleViewAll,
handleRegenerate,
handleCustomize,
handleIsRenaming,
isRenaming,
homepageTitle,
isFavorite,
} ) => {
const isLargeViewport = useViewportMatch( 'medium' );
const inputRef = useRef( null );

const onRegenerate = () => {
if ( typeof handleRegenerate === 'function' ) {
return handleRegenerate();
}
};

const onFavorite = () => {
if ( typeof onFavorite === 'function' ) {
return handleFavorite();
}
};

const onCustomize = () => {
if ( typeof handleCustomize === 'function' ) {
return handleCustomize();
}
};

const onViewAll = () => {
if ( typeof handleViewAll === 'function' ) {
return handleViewAll();
}
};

const onRenameItemSelect = () => {
if ( typeof handleIsRenaming === 'function' ) {
handleIsRenaming( true );
return inputRef.current.focus();
}
};

const onRename = () => {
if ( typeof handleRename === 'function' ) {
handleRename( inputRef.current.value );
}
};

const onTitleInputBlur = () => {
if ( typeof handleIsRenaming === 'function' ) {
return handleIsRenaming( false );
}
};

if ( isRenaming ) {
inputRef.current.focus();
}

const DropDownMenu = () => {
const DropDownMenu = memo(
( {
onRegenerate,
onCustomize,
onRenameItemSelect,
onViewAll,
isLargeViewport,
} ) => {
return (
<MenuGroup className="nfd-onboarding-header__version_dropdown-menu">
{ ! isLargeViewport && (
Expand All @@ -91,9 +37,49 @@ const StepEditorHeaderCenter = ( {
</MenuItem>
</MenuGroup>
);
};
}
);

const TitleContent = memo(
( {
isFavorite,
homepageTitle,
onFavorite,
onRename,
inputRef,
onRegenerate,
onCustomize,
onRenameItemSelect,
onViewAll,
isLargeViewport,
isInputEnabled,
enableInput,
} ) => {
const [ renameInputValue, setRenameInputValue ] =
useState( homepageTitle );

const handleOnChange = () => {
setRenameInputValue( inputRef.current.value );
};

const onTitleInputBlur = () => {
const newTitleValue = inputRef.current.value.trim();
if ( newTitleValue && newTitleValue !== homepageTitle ) {
onRename( newTitleValue );
}
enableInput( false );
};

useEffect( () => {
if ( isInputEnabled ) {
inputRef.current?.focus();
}
}, [ isInputEnabled, inputRef ] );

useEffect( () => {
setRenameInputValue( homepageTitle );
}, [ homepageTitle ] );

const TitleContent = () => {
return (
<Dropdown
renderToggle={ ( { isOpen, onToggle } ) => (
Expand Down Expand Up @@ -122,12 +108,12 @@ const StepEditorHeaderCenter = ( {
</div>
<input
ref={ inputRef }
disabled={ ! isInputEnabled }
className="nfd-onboarding-header__center-input"
disabled={ ! isRenaming }
type="text"
value={ homepageTitle }
value={ renameInputValue }
onBlur={ onTitleInputBlur }
onChange={ onRename }
onChange={ handleOnChange }
/>
<Icon
icon={ chevronDown }
Expand All @@ -140,14 +126,89 @@ const StepEditorHeaderCenter = ( {
/>
</div>
) }
renderContent={ DropDownMenu }
renderContent={ () => (
<DropDownMenu
onRegenerate={ onRegenerate }
onCustomize={ onCustomize }
onRenameItemSelect={ onRenameItemSelect }
onViewAll={ onViewAll }
isLargeViewport={ isLargeViewport }
/>
) }
/>
);
}
);

const StepEditorHeaderCenter = ( {
handleFavorite,
handleRename,
handleViewAll,
handleRegenerate,
handleCustomize,
homepageTitle,
isFavorite,
} ) => {
const isLargeViewport = useViewportMatch( 'medium' );
const inputRef = useRef( null );
const [ isInputEnabled, setInputEnabled ] = useState( false );
const enableInput = ( isEnabled ) => {
setInputEnabled( isEnabled );
if ( isEnabled ) {
inputRef.current?.focus();
}
};

const onRegenerate = () => {
if ( typeof handleRegenerate === 'function' ) {
return handleRegenerate();
}
};

const onFavorite = () => {
if ( typeof onFavorite === 'function' ) {
return handleFavorite();
}
};

const onCustomize = () => {
if ( typeof handleCustomize === 'function' ) {
return handleCustomize();
}
};

const onViewAll = () => {
if ( typeof handleViewAll === 'function' ) {
return handleViewAll();
}
};

const onRenameItemSelect = () => {
enableInput( true );
};

const onRename = ( newTitleValue ) => {
if ( typeof handleRename === 'function' ) {
handleRename( newTitleValue );
}
};

return (
<div className="nfd-onboarding-header__step-navigation">
<TitleContent />
<TitleContent
isFavorite={ isFavorite }
homepageTitle={ homepageTitle }
onFavorite={ onFavorite }
onRename={ onRename }
inputRef={ inputRef }
onRegenerate={ onRegenerate }
onCustomize={ onCustomize }
onRenameItemSelect={ onRenameItemSelect }
onViewAll={ onViewAll }
isLargeViewport={ isLargeViewport }
isInputEnabled={ isInputEnabled }
enableInput={ enableInput }
/>
</div>
);
};
Expand Down
5 changes: 0 additions & 5 deletions src/OnboardingSPA/steps/SiteGen/Editor/Header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
const [ homepage, setHomepage ] = useState();
const [ isSaving, setIsSaving ] = useState( false );
const [ isRegenerating, setIsRegenerating ] = useState( false );
const [ isEditingTitle, setIsEditingTitle ] = useState( false );

const isLargeViewport = useViewportMatch( 'medium' );

Expand Down Expand Up @@ -126,7 +125,7 @@

useEffect( () => {
handleCustomize();
}, [] );

Check warning on line 128 in src/OnboardingSPA/steps/SiteGen/Editor/Header/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

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

useEffect( () => {
if ( currentData?.sitegen?.homepages?.active ) {
Expand Down Expand Up @@ -176,13 +175,9 @@
handleViewAll={ handleViewAll }
handleCustomize={ handleCustomize }
handleRegenerate={ handleRegenerate }
handleIsRenaming={ ( isRenaming ) =>
setIsEditingTitle( isRenaming )
}
handleRename={ handleRename }
homepageTitle={ homepage.title }
isFavorite={ homepage.isFavorite }
isRenaming={ isEditingTitle }
/>
</div>
) }
Expand Down
9 changes: 9 additions & 0 deletions src/OnboardingSPA/steps/SiteGen/Editor/stylesheet.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@
color: var(--nfd-onboarding-header-contrast);
background-color: var(--nfd-onboarding-header-base);
width: 150px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;

@media (max-width: #{ ($break-small) }) {
width: 80px;
}

&:focus {
overflow: visible;
white-space: normal;
text-overflow: clip;
}
}
}

Expand Down
Loading
Loading