@wordpress/edit-site 4.2.0 → 4.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/block-editor/index.js +53 -4
  3. package/build/components/block-editor/index.js.map +1 -1
  4. package/build/components/editor/index.js +9 -5
  5. package/build/components/editor/index.js.map +1 -1
  6. package/build/components/global-styles/color-indicator-wrapper.js +37 -0
  7. package/build/components/global-styles/color-indicator-wrapper.js.map +1 -0
  8. package/build/components/global-styles/dimensions-panel.js +32 -1
  9. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  10. package/build/components/global-styles/header.js +1 -4
  11. package/build/components/global-styles/header.js.map +1 -1
  12. package/build/components/global-styles/icon-with-current-color.js +34 -0
  13. package/build/components/global-styles/icon-with-current-color.js.map +1 -0
  14. package/build/components/global-styles/navigation-button.js +7 -3
  15. package/build/components/global-styles/navigation-button.js.map +1 -1
  16. package/build/components/global-styles/palette.js +8 -5
  17. package/build/components/global-styles/palette.js.map +1 -1
  18. package/build/components/global-styles/preview.js +142 -26
  19. package/build/components/global-styles/preview.js.map +1 -1
  20. package/build/components/global-styles/screen-block-list.js +50 -6
  21. package/build/components/global-styles/screen-block-list.js.map +1 -1
  22. package/build/components/global-styles/screen-colors.js +11 -3
  23. package/build/components/global-styles/screen-colors.js.map +1 -1
  24. package/build/components/global-styles/screen-root.js +7 -5
  25. package/build/components/global-styles/screen-root.js.map +1 -1
  26. package/build/components/global-styles/screen-style-variations.js +12 -5
  27. package/build/components/global-styles/screen-style-variations.js.map +1 -1
  28. package/build/components/sidebar/index.js +12 -1
  29. package/build/components/sidebar/index.js.map +1 -1
  30. package/build/components/sidebar/navigation-menu-sidebar/index.js +40 -0
  31. package/build/components/sidebar/navigation-menu-sidebar/index.js.map +1 -0
  32. package/build/components/sidebar/navigation-menu-sidebar/navigation-inspector.js +185 -0
  33. package/build/components/sidebar/navigation-menu-sidebar/navigation-inspector.js.map +1 -0
  34. package/build/components/sidebar/navigation-menu-sidebar/navigation-menu.js +54 -0
  35. package/build/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +1 -0
  36. package/build/components/template-part-converter/convert-to-regular.js +6 -0
  37. package/build/components/template-part-converter/convert-to-regular.js.map +1 -1
  38. package/build-module/components/block-editor/index.js +51 -6
  39. package/build-module/components/block-editor/index.js.map +1 -1
  40. package/build-module/components/editor/index.js +10 -6
  41. package/build-module/components/editor/index.js.map +1 -1
  42. package/build-module/components/global-styles/color-indicator-wrapper.js +25 -0
  43. package/build-module/components/global-styles/color-indicator-wrapper.js.map +1 -0
  44. package/build-module/components/global-styles/dimensions-panel.js +33 -2
  45. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  46. package/build-module/components/global-styles/header.js +2 -5
  47. package/build-module/components/global-styles/header.js.map +1 -1
  48. package/build-module/components/global-styles/icon-with-current-color.js +22 -0
  49. package/build-module/components/global-styles/icon-with-current-color.js.map +1 -0
  50. package/build-module/components/global-styles/navigation-button.js +7 -3
  51. package/build-module/components/global-styles/navigation-button.js.map +1 -1
  52. package/build-module/components/global-styles/palette.js +8 -6
  53. package/build-module/components/global-styles/palette.js.map +1 -1
  54. package/build-module/components/global-styles/preview.js +141 -27
  55. package/build-module/components/global-styles/preview.js.map +1 -1
  56. package/build-module/components/global-styles/screen-block-list.js +49 -6
  57. package/build-module/components/global-styles/screen-block-list.js.map +1 -1
  58. package/build-module/components/global-styles/screen-colors.js +10 -3
  59. package/build-module/components/global-styles/screen-colors.js.map +1 -1
  60. package/build-module/components/global-styles/screen-root.js +8 -7
  61. package/build-module/components/global-styles/screen-root.js.map +1 -1
  62. package/build-module/components/global-styles/screen-style-variations.js +13 -6
  63. package/build-module/components/global-styles/screen-style-variations.js.map +1 -1
  64. package/build-module/components/sidebar/index.js +11 -1
  65. package/build-module/components/sidebar/index.js.map +1 -1
  66. package/build-module/components/sidebar/navigation-menu-sidebar/index.js +26 -0
  67. package/build-module/components/sidebar/navigation-menu-sidebar/index.js.map +1 -0
  68. package/build-module/components/sidebar/navigation-menu-sidebar/navigation-inspector.js +168 -0
  69. package/build-module/components/sidebar/navigation-menu-sidebar/navigation-inspector.js.map +1 -0
  70. package/build-module/components/sidebar/navigation-menu-sidebar/navigation-menu.js +45 -0
  71. package/build-module/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +1 -0
  72. package/build-module/components/template-part-converter/convert-to-regular.js +6 -0
  73. package/build-module/components/template-part-converter/convert-to-regular.js.map +1 -1
  74. package/build-style/style-rtl.css +53 -5
  75. package/build-style/style.css +53 -5
  76. package/package.json +29 -29
  77. package/src/components/block-editor/index.js +79 -9
  78. package/src/components/editor/index.js +16 -5
  79. package/src/components/global-styles/color-indicator-wrapper.js +23 -0
  80. package/src/components/global-styles/dimensions-panel.js +39 -1
  81. package/src/components/global-styles/header.js +2 -7
  82. package/src/components/global-styles/icon-with-current-color.js +21 -0
  83. package/src/components/global-styles/navigation-button.js +6 -4
  84. package/src/components/global-styles/palette.js +8 -11
  85. package/src/components/global-styles/preview.js +186 -29
  86. package/src/components/global-styles/screen-block-list.js +64 -11
  87. package/src/components/global-styles/screen-colors.js +7 -6
  88. package/src/components/global-styles/screen-root.js +15 -17
  89. package/src/components/global-styles/screen-style-variations.js +13 -4
  90. package/src/components/global-styles/style.scss +20 -7
  91. package/src/components/sidebar/index.js +12 -0
  92. package/src/components/sidebar/navigation-menu-sidebar/index.js +34 -0
  93. package/src/components/sidebar/navigation-menu-sidebar/navigation-inspector.js +224 -0
  94. package/src/components/sidebar/navigation-menu-sidebar/navigation-menu.js +62 -0
  95. package/src/components/sidebar/navigation-menu-sidebar/style.scss +42 -0
  96. package/src/components/sidebar/style.scss +1 -1
  97. package/src/components/template-part-converter/convert-to-regular.js +9 -0
  98. package/src/style.scss +1 -0
@@ -8,20 +8,26 @@ import classnames from 'classnames';
8
8
  */
9
9
  import { useSelect, useDispatch } from '@wordpress/data';
10
10
  import { useCallback, useRef } from '@wordpress/element';
11
- import { useEntityBlockEditor } from '@wordpress/core-data';
11
+ import { useEntityBlockEditor, store as coreStore } from '@wordpress/core-data';
12
12
  import {
13
13
  BlockList,
14
14
  BlockEditorProvider,
15
15
  __experimentalLinkControl,
16
16
  BlockInspector,
17
17
  BlockTools,
18
+ __unstableBlockToolbarLastItem,
18
19
  __unstableBlockSettingsMenuFirstItem,
19
20
  __unstableUseTypingObserver as useTypingObserver,
20
21
  BlockEditorKeyboardShortcuts,
21
22
  store as blockEditorStore,
23
+ __unstableBlockNameContext,
22
24
  } from '@wordpress/block-editor';
23
25
  import { useMergeRefs, useViewportMatch } from '@wordpress/compose';
24
26
  import { ReusableBlocksMenuItems } from '@wordpress/reusable-blocks';
27
+ import { listView } from '@wordpress/icons';
28
+ import { ToolbarButton, ToolbarGroup } from '@wordpress/components';
29
+ import { __ } from '@wordpress/i18n';
30
+ import { store as interfaceStore } from '@wordpress/interface';
25
31
 
26
32
  /**
27
33
  * Internal dependencies
@@ -42,17 +48,44 @@ const LAYOUT = {
42
48
  };
43
49
 
44
50
  export default function BlockEditor( { setIsInserterOpen } ) {
45
- const { settings, templateType, templateId, page } = useSelect(
51
+ const { settings } = useSelect(
46
52
  ( select ) => {
47
- const {
48
- getSettings,
49
- getEditedPostType,
50
- getEditedPostId,
51
- getPage,
52
- } = select( editSiteStore );
53
+ let storedSettings = select( editSiteStore ).getSettings(
54
+ setIsInserterOpen
55
+ );
56
+
57
+ if ( ! storedSettings.__experimentalBlockPatterns ) {
58
+ storedSettings = {
59
+ ...storedSettings,
60
+ __experimentalBlockPatterns: select(
61
+ coreStore
62
+ ).getBlockPatterns(),
63
+ };
64
+ }
65
+
66
+ if ( ! storedSettings.__experimentalBlockPatternCategories ) {
67
+ storedSettings = {
68
+ ...storedSettings,
69
+ __experimentalBlockPatternCategories: select(
70
+ coreStore
71
+ ).getBlockPatternCategories(),
72
+ };
73
+ }
74
+
75
+ return {
76
+ settings: storedSettings,
77
+ };
78
+ },
79
+ [ setIsInserterOpen ]
80
+ );
81
+
82
+ const { templateType, templateId, page } = useSelect(
83
+ ( select ) => {
84
+ const { getEditedPostType, getEditedPostId, getPage } = select(
85
+ editSiteStore
86
+ );
53
87
 
54
88
  return {
55
- settings: getSettings( setIsInserterOpen ),
56
89
  templateType: getEditedPostType(),
57
90
  templateId: getEditedPostId(),
58
91
  page: getPage(),
@@ -60,11 +93,19 @@ export default function BlockEditor( { setIsInserterOpen } ) {
60
93
  },
61
94
  [ setIsInserterOpen ]
62
95
  );
96
+
63
97
  const [ blocks, onInput, onChange ] = useEntityBlockEditor(
64
98
  'postType',
65
99
  templateType
66
100
  );
67
101
  const { setPage } = useDispatch( editSiteStore );
102
+ const { enableComplementaryArea } = useDispatch( interfaceStore );
103
+ const openNavigationSidebar = useCallback( () => {
104
+ enableComplementaryArea(
105
+ 'core/edit-site',
106
+ 'edit-site/navigation-menu'
107
+ );
108
+ }, [ enableComplementaryArea ] );
68
109
  const contentRef = useRef();
69
110
  const mergedRefs = useMergeRefs( [ contentRef, useTypingObserver() ] );
70
111
  const isMobileViewport = useViewportMatch( 'small', '<' );
@@ -72,6 +113,26 @@ export default function BlockEditor( { setIsInserterOpen } ) {
72
113
 
73
114
  const isTemplatePart = templateType === 'wp_template_part';
74
115
 
116
+ const NavMenuSidebarToggle = () => (
117
+ <ToolbarGroup>
118
+ <ToolbarButton
119
+ className="components-toolbar__control"
120
+ label={ __( 'Open list view' ) }
121
+ onClick={ openNavigationSidebar }
122
+ icon={ listView }
123
+ />
124
+ </ToolbarGroup>
125
+ );
126
+
127
+ // Conditionally include NavMenu sidebar in Plugin only.
128
+ // Optimise for dead code elimination.
129
+ // See https://github.com/WordPress/gutenberg/blob/trunk/docs/how-to-guides/feature-flags.md#dead-code-elimination.
130
+ let MaybeNavMenuSidebarToggle = 'Fragment';
131
+
132
+ if ( process.env.IS_GUTENBERG_PLUGIN ) {
133
+ MaybeNavMenuSidebarToggle = NavMenuSidebarToggle;
134
+ }
135
+
75
136
  return (
76
137
  <BlockEditorProvider
77
138
  settings={ settings }
@@ -133,6 +194,15 @@ export default function BlockEditor( { setIsInserterOpen } ) {
133
194
  <BlockInspectorButton onClick={ onClose } />
134
195
  ) }
135
196
  </__unstableBlockSettingsMenuFirstItem>
197
+ <__unstableBlockToolbarLastItem>
198
+ <__unstableBlockNameContext.Consumer>
199
+ { ( blockName ) =>
200
+ blockName === 'core/navigation' && (
201
+ <MaybeNavMenuSidebarToggle />
202
+ )
203
+ }
204
+ </__unstableBlockNameContext.Consumer>
205
+ </__unstableBlockToolbarLastItem>
136
206
  </BlockTools>
137
207
  <ReusableBlocksMenuItems />
138
208
  </BlockEditorProvider>
@@ -5,7 +5,11 @@ import { useEffect, useState, useMemo, useCallback } from '@wordpress/element';
5
5
  import { useSelect, useDispatch } from '@wordpress/data';
6
6
  import { Popover, Button, Notice } from '@wordpress/components';
7
7
  import { EntityProvider, store as coreStore } from '@wordpress/core-data';
8
- import { BlockContextProvider, BlockBreadcrumb } from '@wordpress/block-editor';
8
+ import {
9
+ BlockContextProvider,
10
+ BlockBreadcrumb,
11
+ BlockStyles,
12
+ } from '@wordpress/block-editor';
9
13
  import {
10
14
  InterfaceSkeleton,
11
15
  ComplementaryArea,
@@ -43,7 +47,6 @@ import { GlobalStylesProvider } from '../global-styles/global-styles-provider';
43
47
  import useTitle from '../routes/use-title';
44
48
 
45
49
  const interfaceLabels = {
46
- secondarySidebar: __( 'Block Library' ),
47
50
  drawer: __( 'Navigation Sidebar' ),
48
51
  };
49
52
 
@@ -176,11 +179,15 @@ function Editor( { onError } ) {
176
179
  templateType !== undefined &&
177
180
  entityId !== undefined;
178
181
 
182
+ const secondarySidebarLabel = isListViewOpen
183
+ ? __( 'List View' )
184
+ : __( 'Block Library' );
185
+
179
186
  const secondarySidebar = () => {
180
- if ( isInserterOpen ) {
187
+ if ( editorMode === 'visual' && isInserterOpen ) {
181
188
  return <InserterSidebar />;
182
189
  }
183
- if ( isListViewOpen ) {
190
+ if ( editorMode === 'visual' && isListViewOpen ) {
184
191
  return <ListViewSidebar />;
185
192
  }
186
193
  return null;
@@ -208,7 +215,10 @@ function Editor( { onError } ) {
208
215
  <KeyboardShortcuts.Register />
209
216
  <SidebarComplementaryAreaFills />
210
217
  <InterfaceSkeleton
211
- labels={ interfaceLabels }
218
+ labels={ {
219
+ ...interfaceLabels,
220
+ secondarySidebar: secondarySidebarLabel,
221
+ } }
212
222
  className={
213
223
  showIconLabels &&
214
224
  'show-icon-labels'
@@ -236,6 +246,7 @@ function Editor( { onError } ) {
236
246
  content={
237
247
  <>
238
248
  <EditorNotices />
249
+ <BlockStyles.Slot scope="core/block-inspector" />
239
250
  { editorMode === 'visual' &&
240
251
  template && (
241
252
  <BlockEditor
@@ -0,0 +1,23 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import classnames from 'classnames';
5
+
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import { Flex } from '@wordpress/components';
10
+
11
+ function ColorIndicatorWrapper( { className, ...props } ) {
12
+ return (
13
+ <Flex
14
+ className={ classnames(
15
+ 'edit-site-global-styles__color-indicator-wrapper',
16
+ className
17
+ ) }
18
+ { ...props }
19
+ />
20
+ );
21
+ }
22
+
23
+ export default ColorIndicatorWrapper;
@@ -6,6 +6,7 @@ import {
6
6
  __experimentalToolsPanel as ToolsPanel,
7
7
  __experimentalToolsPanelItem as ToolsPanelItem,
8
8
  __experimentalBoxControl as BoxControl,
9
+ __experimentalUnitControl as UnitControl,
9
10
  __experimentalUseCustomUnits as useCustomUnits,
10
11
  } from '@wordpress/components';
11
12
  import { __experimentalUseCustomSides as useCustomSides } from '@wordpress/block-editor';
@@ -20,8 +21,9 @@ const AXIAL_SIDES = [ 'horizontal', 'vertical' ];
20
21
  export function useHasDimensionsPanel( name ) {
21
22
  const hasPadding = useHasPadding( name );
22
23
  const hasMargin = useHasMargin( name );
24
+ const hasGap = useHasGap( name );
23
25
 
24
- return hasPadding || hasMargin;
26
+ return hasPadding || hasMargin || hasGap;
25
27
  }
26
28
 
27
29
  function useHasPadding( name ) {
@@ -38,6 +40,18 @@ function useHasMargin( name ) {
38
40
  return settings && supports.includes( 'margin' );
39
41
  }
40
42
 
43
+ function useHasGap( name ) {
44
+ const supports = getSupportedGlobalStylesPanels( name );
45
+ const [ settings ] = useSetting( 'spacing.blockGap', name );
46
+ // Do not show the gap control panel for block-level global styles
47
+ // as they do not work on the frontend.
48
+ // See: https://github.com/WordPress/gutenberg/pull/39845.
49
+ // We can revert this condition when they're working again.
50
+ return !! name
51
+ ? false
52
+ : settings && supports.includes( '--wp--style--block-gap' );
53
+ }
54
+
41
55
  function filterValuesBySides( values, sides ) {
42
56
  if ( ! sides ) {
43
57
  // If no custom side configuration all sides are opted into by default.
@@ -79,6 +93,7 @@ function splitStyleValue( value ) {
79
93
  export default function DimensionsPanel( { name } ) {
80
94
  const showPaddingControl = useHasPadding( name );
81
95
  const showMarginControl = useHasMargin( name );
96
+ const showGapControl = useHasGap( name );
82
97
  const units = useCustomUnits( {
83
98
  availableUnits: useSetting( 'spacing.units', name )[ 0 ] || [
84
99
  '%',
@@ -118,9 +133,15 @@ export default function DimensionsPanel( { name } ) {
118
133
  const resetMarginValue = () => setMarginValues( {} );
119
134
  const hasMarginValue = () =>
120
135
  !! marginValues && Object.keys( marginValues ).length;
136
+
137
+ const [ gapValue, setGapValue ] = useStyle( 'spacing.blockGap', name );
138
+ const resetGapValue = () => setGapValue( undefined );
139
+ const hasGapValue = () => !! gapValue;
140
+
121
141
  const resetAll = () => {
122
142
  resetPaddingValue();
123
143
  resetMarginValue();
144
+ resetGapValue();
124
145
  };
125
146
 
126
147
  return (
@@ -161,6 +182,23 @@ export default function DimensionsPanel( { name } ) {
161
182
  />
162
183
  </ToolsPanelItem>
163
184
  ) }
185
+ { showGapControl && (
186
+ <ToolsPanelItem
187
+ hasValue={ hasGapValue }
188
+ label={ __( 'Block spacing' ) }
189
+ onDeselect={ resetGapValue }
190
+ isShownByDefault={ true }
191
+ >
192
+ <UnitControl
193
+ label={ __( 'Block spacing' ) }
194
+ __unstableInputWidth="80px"
195
+ min={ 0 }
196
+ onChange={ setGapValue }
197
+ units={ units }
198
+ value={ gapValue }
199
+ />
200
+ </ToolsPanelItem>
201
+ ) }
164
202
  </ToolsPanel>
165
203
  );
166
204
  }
@@ -9,7 +9,7 @@ import {
9
9
  __experimentalView as View,
10
10
  } from '@wordpress/components';
11
11
  import { isRTL, __ } from '@wordpress/i18n';
12
- import { chevronRight, chevronLeft, Icon } from '@wordpress/icons';
12
+ import { chevronRight, chevronLeft } from '@wordpress/icons';
13
13
 
14
14
  /**
15
15
  * Internal dependencies
@@ -22,12 +22,7 @@ function ScreenHeader( { title, description } ) {
22
22
  <HStack spacing={ 2 }>
23
23
  <View>
24
24
  <NavigationBackButton
25
- icon={
26
- <Icon
27
- icon={ isRTL() ? chevronRight : chevronLeft }
28
- variant="muted"
29
- />
30
- }
25
+ icon={ isRTL() ? chevronRight : chevronLeft }
31
26
  size="small"
32
27
  aria-label={ __( 'Navigate to the previous view' ) }
33
28
  />
@@ -0,0 +1,21 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import classnames from 'classnames';
5
+
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import { Icon } from '@wordpress/components';
10
+
11
+ export function IconWithCurrentColor( { className, ...props } ) {
12
+ return (
13
+ <Icon
14
+ className={ classnames(
15
+ className,
16
+ 'edit-site-global-styles-icon-with-current-color'
17
+ ) }
18
+ { ...props }
19
+ />
20
+ );
21
+ }
@@ -8,16 +8,18 @@ import {
8
8
  FlexItem,
9
9
  __experimentalHStack as HStack,
10
10
  } from '@wordpress/components';
11
- import { Icon } from '@wordpress/icons';
11
+
12
+ /**
13
+ * Internal dependencies
14
+ */
15
+ import { IconWithCurrentColor } from './icon-with-current-color';
12
16
 
13
17
  function GenericNavigationButton( { icon, children, ...props } ) {
14
18
  return (
15
19
  <Item { ...props }>
16
20
  { icon && (
17
21
  <HStack justify="flex-start">
18
- <FlexItem>
19
- <Icon icon={ icon } size={ 24 } />
20
- </FlexItem>
22
+ <IconWithCurrentColor icon={ icon } size={ 24 } />
21
23
  <FlexItem>{ children }</FlexItem>
22
24
  </HStack>
23
25
  ) }
@@ -7,7 +7,6 @@ import {
7
7
  __experimentalHStack as HStack,
8
8
  __experimentalZStack as ZStack,
9
9
  __experimentalVStack as VStack,
10
- FlexBlock,
11
10
  ColorIndicator,
12
11
  } from '@wordpress/components';
13
12
  import { __, _n, sprintf } from '@wordpress/i18n';
@@ -19,6 +18,7 @@ import { useMemo } from '@wordpress/element';
19
18
  import Subtitle from './subtitle';
20
19
  import { NavigationButton } from './navigation-button';
21
20
  import { useSetting } from './hooks';
21
+ import ColorIndicatorWrapper from './color-indicator-wrapper';
22
22
 
23
23
  const EMPTY_COLORS = [];
24
24
 
@@ -64,16 +64,13 @@ function Palette( { name } ) {
64
64
  colors.length === 0 ? 'row-reverse' : 'row'
65
65
  }
66
66
  >
67
- <FlexBlock>
68
- <ZStack isLayered={ false } offset={ -8 }>
69
- { colors.slice( 0, 5 ).map( ( { color } ) => (
70
- <ColorIndicator
71
- key={ color }
72
- colorValue={ color }
73
- />
74
- ) ) }
75
- </ZStack>
76
- </FlexBlock>
67
+ <ZStack isLayered={ false } offset={ -8 }>
68
+ { colors.slice( 0, 5 ).map( ( { color } ) => (
69
+ <ColorIndicatorWrapper key={ color }>
70
+ <ColorIndicator colorValue={ color } />
71
+ </ColorIndicatorWrapper>
72
+ ) ) }
73
+ </ZStack>
77
74
  <FlexItem>{ paletteButtonText }</FlexItem>
78
75
  </HStack>
79
76
  </NavigationButton>
@@ -5,65 +5,222 @@ import {
5
5
  __unstableIframe as Iframe,
6
6
  __unstableEditorStyles as EditorStyles,
7
7
  } from '@wordpress/block-editor';
8
+ import {
9
+ __unstableMotion as motion,
10
+ __experimentalHStack as HStack,
11
+ __experimentalVStack as VStack,
12
+ } from '@wordpress/components';
13
+ import { useReducedMotion, useResizeObserver } from '@wordpress/compose';
14
+ import { useState } from '@wordpress/element';
8
15
 
9
16
  /**
10
17
  * Internal dependencies
11
18
  */
12
- import { useStyle } from './hooks';
19
+ import { useSetting, useStyle } from './hooks';
13
20
  import { useGlobalStylesOutput } from './use-global-styles-output';
14
21
 
15
- const StylesPreview = ( { height = 150 } ) => {
22
+ const firstFrame = {
23
+ start: {
24
+ opacity: 1,
25
+ display: 'block',
26
+ },
27
+ hover: {
28
+ opacity: 0,
29
+ display: 'none',
30
+ },
31
+ };
32
+
33
+ const secondFrame = {
34
+ hover: {
35
+ opacity: 1,
36
+ display: 'block',
37
+ },
38
+ start: {
39
+ opacity: 0,
40
+ display: 'none',
41
+ },
42
+ };
43
+
44
+ const normalizedWidth = 248;
45
+ const normalizedHeight = 152;
46
+
47
+ const normalizedColorSwatchSize = 32;
48
+
49
+ const StylesPreview = ( { label, isFocused } ) => {
50
+ const [ fontWeight ] = useStyle( 'typography.fontWeight' );
16
51
  const [ fontFamily = 'serif' ] = useStyle( 'typography.fontFamily' );
52
+ const [ headingFontFamily = fontFamily ] = useStyle(
53
+ 'elements.h1.typography.fontFamily'
54
+ );
55
+ const [ headingFontWeight = fontWeight ] = useStyle(
56
+ 'elements.h1.typography.fontWeight'
57
+ );
17
58
  const [ textColor = 'black' ] = useStyle( 'color.text' );
59
+ const [ headingColor = textColor ] = useStyle( 'elements.h1.color.text' );
18
60
  const [ linkColor = 'blue' ] = useStyle( 'elements.link.color.text' );
19
61
  const [ backgroundColor = 'white' ] = useStyle( 'color.background' );
20
62
  const [ gradientValue ] = useStyle( 'color.gradient' );
21
63
  const [ styles ] = useGlobalStylesOutput();
64
+ const disableMotion = useReducedMotion();
65
+ const [ coreColors ] = useSetting( 'color.palette.core' );
66
+ const [ themeColors ] = useSetting( 'color.palette.theme' );
67
+ const [ customColors ] = useSetting( 'color.palette.custom' );
68
+ const [ isHovered, setIsHovered ] = useState( false );
69
+ const [ containerResizeListener, { width } ] = useResizeObserver();
70
+ const ratio = width ? width / normalizedWidth : 1;
71
+
72
+ const paletteColors = ( themeColors ?? [] )
73
+ .concat( customColors ?? [] )
74
+ .concat( coreColors ?? [] );
75
+ const highlightedColors = paletteColors
76
+ .filter(
77
+ // we exclude these two colors because they are already visible in the preview.
78
+ ( { color } ) => color !== backgroundColor && color !== headingColor
79
+ )
80
+ .slice( 0, 2 );
22
81
 
23
82
  return (
24
83
  <Iframe
25
84
  className="edit-site-global-styles-preview__iframe"
26
85
  head={ <EditorStyles styles={ styles } /> }
27
- style={ { height } }
86
+ style={ {
87
+ height: normalizedHeight * ratio,
88
+ visibility: ! width ? 'hidden' : 'visible',
89
+ } }
90
+ onMouseEnter={ () => setIsHovered( true ) }
91
+ onMouseLeave={ () => setIsHovered( false ) }
92
+ tabIndex={ -1 }
28
93
  >
29
- <div
94
+ { containerResizeListener }
95
+ <motion.div
30
96
  style={ {
31
- display: 'flex',
32
- gap: 20,
33
- alignItems: 'center',
34
- justifyContent: 'center',
35
- height: '100%',
36
- transform: `scale(${ height / 150 })`,
97
+ height: normalizedHeight * ratio,
98
+ width: '100%',
37
99
  background: gradientValue ?? backgroundColor,
38
100
  cursor: 'pointer',
39
101
  } }
102
+ initial="start"
103
+ animate={
104
+ ( isHovered || isFocused ) && ! disableMotion
105
+ ? 'hover'
106
+ : 'start'
107
+ }
40
108
  >
41
- <div style={ { fontFamily, fontSize: '80px' } }>Aa</div>
42
- <div
109
+ <motion.div
110
+ variants={ firstFrame }
43
111
  style={ {
44
- display: 'flex',
45
- gap: 20,
46
- flexDirection: 'column',
112
+ height: '100%',
113
+ overflow: 'hidden',
47
114
  } }
48
115
  >
49
- <div
116
+ <HStack
117
+ spacing={ 10 * ratio }
118
+ justify="center"
50
119
  style={ {
51
- height: 40,
52
- width: 40,
53
- background: textColor,
54
- borderRadius: 20,
120
+ height: '100%',
121
+ overflow: 'hidden',
55
122
  } }
56
- />{ ' ' }
57
- <div
123
+ >
124
+ <div
125
+ style={ {
126
+ fontFamily: headingFontFamily,
127
+ fontSize: 65 * ratio,
128
+ color: headingColor,
129
+ fontWeight: headingFontWeight,
130
+ } }
131
+ >
132
+ Aa
133
+ </div>
134
+ <VStack spacing={ 4 * ratio }>
135
+ { highlightedColors.map( ( { slug, color } ) => (
136
+ <div
137
+ key={ slug }
138
+ style={ {
139
+ height:
140
+ normalizedColorSwatchSize * ratio,
141
+ width:
142
+ normalizedColorSwatchSize * ratio,
143
+ background: color,
144
+ borderRadius:
145
+ ( normalizedColorSwatchSize *
146
+ ratio ) /
147
+ 2,
148
+ } }
149
+ />
150
+ ) ) }
151
+ </VStack>
152
+ </HStack>
153
+ </motion.div>
154
+ <motion.div
155
+ variants={ secondFrame }
156
+ style={ {
157
+ height: '100%',
158
+ overflow: 'hidden',
159
+ } }
160
+ >
161
+ <VStack
162
+ spacing={ 3 * ratio }
163
+ justify="center"
58
164
  style={ {
59
- height: 40,
60
- width: 40,
61
- background: linkColor,
62
- borderRadius: 20,
165
+ height: '100%',
166
+ overflow: 'hidden',
167
+ padding: 10 * ratio,
168
+ boxSizing: 'border-box',
63
169
  } }
64
- />
65
- </div>
66
- </div>
170
+ >
171
+ { label && (
172
+ <div
173
+ style={ {
174
+ fontSize: 35 * ratio,
175
+ fontFamily: headingFontFamily,
176
+ color: headingColor,
177
+ fontWeight: headingFontWeight,
178
+ lineHeight: '1em',
179
+ } }
180
+ >
181
+ { label }
182
+ </div>
183
+ ) }
184
+ <HStack spacing={ 2 * ratio } justify="flex-start">
185
+ <div
186
+ style={ {
187
+ fontFamily,
188
+ fontSize: 24 * ratio,
189
+ color: textColor,
190
+ } }
191
+ >
192
+ Aa
193
+ </div>
194
+ <div
195
+ style={ {
196
+ fontFamily,
197
+ fontSize: 24 * ratio,
198
+ color: linkColor,
199
+ } }
200
+ >
201
+ Aa
202
+ </div>
203
+ </HStack>
204
+ { paletteColors && (
205
+ <HStack spacing={ 0 }>
206
+ { paletteColors
207
+ .slice( 0, 4 )
208
+ .map( ( { color }, index ) => (
209
+ <div
210
+ key={ index }
211
+ style={ {
212
+ height: 10 * ratio,
213
+ width: 30 * ratio,
214
+ background: color,
215
+ flexGrow: 1,
216
+ } }
217
+ />
218
+ ) ) }
219
+ </HStack>
220
+ ) }
221
+ </VStack>
222
+ </motion.div>
223
+ </motion.div>
67
224
  </Iframe>
68
225
  );
69
226
  };