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

Add SiteGen Customize Sidebar #417

Merged
merged 4 commits into from
Jan 17, 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
20 changes: 20 additions & 0 deletions includes/RestApi/SiteGenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ public function register_routes() {
'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ),
)
);
\register_rest_route(
$this->namespace,
$this->rest_base . '/customize-data',
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array( $this, 'get_customize_sidebar_data' ),
'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ),
)
);
}

/**
Expand Down Expand Up @@ -326,4 +335,15 @@ public function toggle_favourite_homepage( \WP_REST_Request $request ) {
public function get_site_details_meta( \WP_REST_Request $request ) {
return SiteGenData::get_site_details_questionnaire();
}

/**
* Get Sitegen Customize sidebar data.
*
* @param \WP_REST_Request $request Request model.
*
* @return array|WP_Error
*/
public function get_customize_sidebar_data( \WP_REST_Request $request ) {
return SiteGenService::get_customize_sidebar_data();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,10 @@ const SiteGenHeader = () => {
</>
</Fill>

{ currentStep?.header?.component
? isHeaderNavigationEnabled && <currentStep.header.component />
: isHeaderNavigationEnabled && (
<Fill name={ `${ HEADER_SITEGEN }/${ HEADER_START }` }>
<StepNavigation />
</Fill>
) }
<Fill name={ `${ HEADER_SITEGEN }/${ HEADER_START }` }>
<>{ isHeaderNavigationEnabled && <StepNavigation /> }</>
</Fill>
{ currentStep?.header && <currentStep.header /> }
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
if ( setIsLoadingParent ) {
setIsLoadingParent( false );
}
}, [ skeletonLoadingTime ] );

Check warning on line 37 in src/OnboardingSPA/components/LivePreview/BlockPreview/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has a missing dependency: 'setIsLoadingParent'. Either include it or remove the dependency array. If 'setIsLoadingParent' changes too often, find the parent component that defines it and wrap that definition in useCallback

const { currentData, storedPreviewSettings } = useSelect( ( select ) => {
return {
Expand All @@ -54,7 +54,7 @@
} else {
setSettings( storedPreviewSettings );
}
}, [] );
}, [ previewSettings, storedPreviewSettings ] );

useEffect( () => {
if ( blockGrammer ) {
Expand All @@ -66,7 +66,7 @@
if ( ! previewSettings ) {
setSettings( storedPreviewSettings );
}
}, [ storedPreviewSettings, currentData ] );

Check warning on line 69 in src/OnboardingSPA/components/LivePreview/BlockPreview/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

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

const SkeletonLivePreview = memo( () => {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import './stylesheet.scss';

const ColorPaletteIcon = ( {
idx,
label,
selectedPalette,
setSelectedPalette,
setSelectedColor,
colors,
setShowCustomColors = null,
} ) => {
const conicGradient = `conic-gradient(${ colors[ idx ].primary } 90deg, ${ colors[ idx ].secondary } 90deg 150deg, ${ colors[ idx ].tertiary } 150deg 330deg, ${ colors[ idx ].primary } 330deg 360deg)`;
const baseClassName =
'nfd-onboarding-sidebar--customize__color-palette-icon';
const handleClick = () => {
setSelectedPalette( idx );
setSelectedColor( colors[ idx ] );
if ( setShowCustomColors ) {
setShowCustomColors( false );
}
};
return (
<div className={ `${ baseClassName }__container` }>
<div
role="presentation"
className={ `${
selectedPalette === idx
? `${ baseClassName }__container__icon__selected`
: `${ baseClassName }__container__icon`
}` }
style={ {
background: conicGradient,
} }
onClick={ handleClick }
></div>
<p>{ label }</p>
</div>
);
};

export default ColorPaletteIcon;
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.nfd-onboarding-sidebar--customize__color-palette-icon {

&__container {
text-align: center;

&__icon {
box-sizing: border-box;
width: 45px;
height: 45px;
border-radius: 50%;
cursor: pointer;
box-shadow: "none";
}

&__icon__selected {
box-sizing: border-box;
width: 45px;
height: 45px;
border-radius: 50%;
cursor: pointer;
box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--nfd-onboarding-sitegen-customize-icon-selected);
}

p {
margin-top: 8px;
color: var(--nfd-onboarding-sitegen-customize-default-text-color);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { useState } from '@wordpress/element';
import { ColorPalette, Popover } from '@wordpress/components';
import './stylesheet.scss';
import { __ } from '@wordpress/i18n';

const CustomColorPalette = ( {
onChange,
paletteSecondaryColors,
palettePrimaryColors,
} ) => {
const [ color, setColor ] = useState( palettePrimaryColors[ 0 ].color );
const baseClassName =
'nfd-onboarding-sidebar--customize__custom-color-palette';
const colors = [
{
colors: palettePrimaryColors,
name: __( 'Primary colors', 'wp-module-onboarding' ),
},
{
colors: paletteSecondaryColors,
name: __( 'Secondary colors', 'wp-module-onboarding' ),
},
];
const handleColorChange = ( newColor ) => {
setColor( newColor );
onChange( newColor );
};
return (
<Popover placement="left">
<div className={ `${ baseClassName }__container` }>
<ColorPalette
colors={ colors }
value={ color }
onChange={ handleColorChange }
/>
</div>
</Popover>
);
};

export default CustomColorPalette;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.nfd-onboarding-sidebar {

&--customize {

&__custom-color-palette {

&__container {
padding: 16px;
width: 260px;
}
}
}

}
Loading