-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathglobal-style-sidebar-notice.tsx
71 lines (62 loc) · 2.42 KB
/
global-style-sidebar-notice.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
declare const wpcomGlobalStyles: { upgradeUrl: string; blogId: string };
import { ExternalLink, Fill, Notice } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { createInterpolateElement, useEffect } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { recordUpgradeNoticeSidebarShow, recordUpgradeSidebarNoticeClick } from './tracks-events';
import { useGlobalStylesConfig } from './use-global-styles-config';
const GLOBAL_STYLES_SIDEBAR = 'edit-site/global-styles';
type CoreInterfacePlaceholder = {
getActiveComplementaryArea: ( area: string ) => string;
};
export default function GlobalStylesSidebarNotice(): JSX.Element {
const area = useSelect(
( select ) =>
( select( 'core/interface' ) as CoreInterfacePlaceholder ).getActiveComplementaryArea(
'core/edit-site'
),
[]
);
const isGlobalStylesSidebar = GLOBAL_STYLES_SIDEBAR === area;
const globalStylesInUse = useGlobalStylesConfig().globalStylesInUse;
useEffect( () => {
if ( globalStylesInUse && isGlobalStylesSidebar ) {
recordUpgradeNoticeSidebarShow();
}
}, [ globalStylesInUse, isGlobalStylesSidebar ] );
return (
<Fill name="ComplementaryArea/core/edit-site">
{ /*
The fragment is needed in order to avoid a forceUpdate done by the slot-fill library.
When a forceUpdate is done, the local state of the components is cleared, which means that when the nudge is displayed/removed,
the state of GS is cleared, disrupting the UX, since the user will be redirected to the main GS root screen.
*/ }
<>
{ /*
We'll need to do the condition here because if we are doing an early return, the fill will be introduced at the bottom of the page, which means some additional CSS magic needs to be done.
*/ }
{ globalStylesInUse && isGlobalStylesSidebar && (
<div className="interface-complementary-area">
<Notice status="warning" isDismissible={ false } className="wpcom-global-styles-notice">
{ createInterpolateElement(
__(
'Your changes include customized styles that will only be visible once you <a>upgrade to a Premium plan</a>.',
'full-site-editing'
),
{
a: (
<ExternalLink
href={ wpcomGlobalStyles.upgradeUrl }
target="_blank"
onClick={ recordUpgradeSidebarNoticeClick }
/>
),
}
) }
</Notice>
</div>
) }
</>
</Fill>
);
}