2023-08-28 01:28:05 +00:00
|
|
|
// Reference: https://github.com/WordPress/gutenberg/blob/v16.4.0/packages/edit-site/src/components/site-hub/index.js
|
|
|
|
/* eslint-disable @woocommerce/dependency-group */
|
|
|
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2024-05-31 03:49:36 +00:00
|
|
|
import clsx from 'clsx';
|
2023-08-28 01:28:05 +00:00
|
|
|
import { useSelect } from '@wordpress/data';
|
|
|
|
import {
|
|
|
|
// @ts-ignore No types for this exist yet.
|
|
|
|
__unstableMotion as motion,
|
|
|
|
// @ts-ignore No types for this exist yet.
|
|
|
|
__unstableAnimatePresence as AnimatePresence,
|
|
|
|
// @ts-ignore No types for this exist yet.
|
|
|
|
__experimentalHStack as HStack,
|
|
|
|
} from '@wordpress/components';
|
|
|
|
import { useReducedMotion } from '@wordpress/compose';
|
|
|
|
// @ts-ignore No types for this exist yet.
|
|
|
|
import { store as coreStore } from '@wordpress/core-data';
|
|
|
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
|
|
import { forwardRef } from '@wordpress/element';
|
|
|
|
// @ts-ignore No types for this exist yet.
|
|
|
|
import SiteIcon from '@wordpress/edit-site/build-module/components/site-icon';
|
2024-04-23 15:52:29 +00:00
|
|
|
import { getNewPath, getPersistedQuery } from '@woocommerce/navigation';
|
2023-10-25 05:09:05 +00:00
|
|
|
import { Link } from '@woocommerce/components';
|
2024-05-20 13:43:24 +00:00
|
|
|
import WordPressLogo from '~/lib/wordpress-logo';
|
|
|
|
|
2023-08-28 01:28:05 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2024-05-20 11:04:13 +00:00
|
|
|
import { isEntrepreneurFlow } from '~/customize-store/design-with-ai/entrepreneur-flow';
|
2023-08-28 01:28:05 +00:00
|
|
|
|
|
|
|
const HUB_ANIMATION_DURATION = 0.3;
|
|
|
|
|
|
|
|
export const SiteHub = forwardRef(
|
|
|
|
(
|
|
|
|
{
|
|
|
|
isTransparent,
|
|
|
|
...restProps
|
|
|
|
}: {
|
|
|
|
isTransparent: boolean;
|
|
|
|
className: string;
|
|
|
|
as: string;
|
|
|
|
variants: motion.Variants;
|
|
|
|
},
|
|
|
|
ref
|
|
|
|
) => {
|
|
|
|
const { siteTitle } = useSelect( ( select ) => {
|
|
|
|
// @ts-ignore No types for this exist yet.
|
|
|
|
const { getSite } = select( coreStore );
|
|
|
|
|
|
|
|
return {
|
|
|
|
siteTitle: getSite()?.title,
|
|
|
|
};
|
|
|
|
}, [] );
|
|
|
|
|
|
|
|
const disableMotion = useReducedMotion();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<motion.div
|
|
|
|
ref={ ref }
|
|
|
|
{ ...restProps }
|
2024-05-31 03:49:36 +00:00
|
|
|
className={ clsx( 'edit-site-site-hub', restProps.className ) }
|
2023-08-28 01:28:05 +00:00
|
|
|
initial={ false }
|
|
|
|
transition={ {
|
|
|
|
type: 'tween',
|
|
|
|
duration: disableMotion ? 0 : HUB_ANIMATION_DURATION,
|
|
|
|
ease: 'easeOut',
|
|
|
|
} }
|
|
|
|
>
|
|
|
|
<HStack
|
|
|
|
justify="space-between"
|
|
|
|
alignment="center"
|
|
|
|
className="edit-site-site-hub__container"
|
|
|
|
>
|
|
|
|
<HStack
|
|
|
|
justify="flex-start"
|
|
|
|
className="edit-site-site-hub__text-content"
|
|
|
|
spacing="0"
|
|
|
|
>
|
2024-03-04 11:34:47 +00:00
|
|
|
<div
|
2024-05-31 03:49:36 +00:00
|
|
|
className={ clsx(
|
2023-08-28 01:28:05 +00:00
|
|
|
'edit-site-site-hub__view-mode-toggle-container',
|
|
|
|
{
|
|
|
|
'has-transparent-background': isTransparent,
|
|
|
|
}
|
|
|
|
) }
|
|
|
|
>
|
2023-10-25 05:09:05 +00:00
|
|
|
<Link
|
2024-04-23 15:52:29 +00:00
|
|
|
href={ getNewPath(
|
|
|
|
getPersistedQuery(),
|
|
|
|
'/',
|
|
|
|
{}
|
|
|
|
) }
|
2023-10-25 05:09:05 +00:00
|
|
|
type="wp-admin"
|
|
|
|
>
|
2024-05-20 13:43:24 +00:00
|
|
|
{ isEntrepreneurFlow() ? (
|
|
|
|
<WordPressLogo
|
|
|
|
size={ 24 }
|
|
|
|
className="woocommerce-cys-wordpress-header-logo"
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<SiteIcon className="edit-site-layout__view-mode-toggle-icon" />
|
|
|
|
) }
|
2023-10-25 05:09:05 +00:00
|
|
|
</Link>
|
2024-03-04 11:34:47 +00:00
|
|
|
</div>
|
2023-08-28 01:28:05 +00:00
|
|
|
|
2024-05-20 11:04:13 +00:00
|
|
|
{ ! isEntrepreneurFlow() && (
|
|
|
|
<AnimatePresence>
|
|
|
|
<motion.div
|
|
|
|
layout={ false }
|
|
|
|
animate={ {
|
|
|
|
opacity: 1,
|
|
|
|
} }
|
|
|
|
exit={ {
|
|
|
|
opacity: 0,
|
|
|
|
} }
|
2024-05-31 03:49:36 +00:00
|
|
|
className={ clsx(
|
2024-05-20 11:04:13 +00:00
|
|
|
'edit-site-site-hub__site-title',
|
|
|
|
{ 'is-transparent': isTransparent }
|
|
|
|
) }
|
|
|
|
transition={ {
|
|
|
|
type: 'tween',
|
|
|
|
duration: disableMotion ? 0 : 0.2,
|
|
|
|
ease: 'easeOut',
|
|
|
|
delay: 0.1,
|
|
|
|
} }
|
|
|
|
>
|
|
|
|
{ decodeEntities( siteTitle ) }
|
|
|
|
</motion.div>
|
|
|
|
</AnimatePresence>
|
|
|
|
) }
|
2023-08-28 01:28:05 +00:00
|
|
|
</HStack>
|
|
|
|
</HStack>
|
|
|
|
</motion.div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|