@elementor/editor-variables 0.11.0 → 0.13.0

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.
@@ -1,11 +1,11 @@
1
1
  import * as React from 'react';
2
2
  import { useId, useRef } from 'react';
3
+ import { PopoverHeader } from '@elementor/editor-ui';
3
4
  import { ColorFilterIcon, DetachIcon, PlusIcon } from '@elementor/icons';
4
5
  import {
5
6
  bindPopover,
6
7
  bindTrigger,
7
8
  Box,
8
- CloseButton,
9
9
  IconButton,
10
10
  Popover,
11
11
  Stack,
@@ -16,8 +16,10 @@ import {
16
16
  import { __ } from '@wordpress/i18n';
17
17
 
18
18
  import { colorVariablePropTypeUtil } from '../prop-types/color-variable-prop-type';
19
+ import { fontVariablePropTypeUtil } from '../prop-types/font-variable-prop-type';
19
20
  import { type Variable } from '../types';
20
21
  import { ColorVariableCreation } from './color-variable-creation';
22
+ import { FontVariableCreation } from './font-variable-creation';
21
23
 
22
24
  type Props = {
23
25
  selectedVariable: Variable;
@@ -26,6 +28,8 @@ type Props = {
26
28
  startTagAdornment?: React.ReactNode;
27
29
  };
28
30
 
31
+ const SIZE = 'tiny';
32
+
29
33
  export const VariablesSelectionPopover = ( {
30
34
  selectedVariable,
31
35
  unlinkVariable,
@@ -47,6 +51,7 @@ export const VariablesSelectionPopover = ( {
47
51
  const { label } = selectedVariable;
48
52
 
49
53
  const colorCreationEnabled = colorVariablePropTypeUtil.key === selectedVariable.type;
54
+ const fontCreationEnabled = fontVariablePropTypeUtil.key === selectedVariable.type;
50
55
 
51
56
  return (
52
57
  <Box ref={ anchorRef }>
@@ -68,8 +73,8 @@ export const VariablesSelectionPopover = ( {
68
73
  </Box>
69
74
  }
70
75
  actions={
71
- <IconButton size="tiny" onClick={ unlinkVariable } aria-label={ __( 'Unlink', 'elementor' ) }>
72
- <DetachIcon fontSize="tiny" />
76
+ <IconButton size={ SIZE } onClick={ unlinkVariable } aria-label={ __( 'Unlink', 'elementor' ) }>
77
+ <DetachIcon fontSize={ SIZE } />
73
78
  </IconButton>
74
79
  }
75
80
  />
@@ -80,26 +85,35 @@ export const VariablesSelectionPopover = ( {
80
85
  anchorOrigin={ { vertical: 'bottom', horizontal: 'right' } }
81
86
  transformOrigin={ { vertical: 'top', horizontal: 'right' } }
82
87
  >
83
- <Stack direction="row" alignItems="center" pl={ 1.5 } pr={ 0.5 } py={ 1.5 }>
84
- <ColorFilterIcon fontSize="tiny" sx={ { mr: 0.5 } } />
85
- <Typography variant="subtitle2">{ __( 'Variables', 'elementor' ) }</Typography>
86
- <Stack direction="row" sx={ { ml: 'auto' } }>
87
- { colorCreationEnabled && (
88
- <IconButton
89
- { ...bindTrigger( creationPopupState ) }
90
- size="tiny"
91
- onClick={ handleCreateButtonClick }
92
- >
93
- <PlusIcon fontSize="tiny" />
94
- </IconButton>
95
- ) }
96
- <CloseButton slotProps={ { icon: { fontSize: 'tiny' } } } onClick={ closePopover } />
97
- </Stack>
98
- </Stack>
88
+ <PopoverHeader
89
+ title={ __( 'Variables', 'elementor' ) }
90
+ onClose={ closePopover }
91
+ icon={ <ColorFilterIcon fontSize={ SIZE } /> }
92
+ actions={ [
93
+ <IconButton
94
+ key="createVariable"
95
+ { ...bindTrigger( creationPopupState ) }
96
+ size={ SIZE }
97
+ onClick={ handleCreateButtonClick }
98
+ >
99
+ <PlusIcon fontSize={ SIZE } />
100
+ </IconButton>,
101
+ ] }
102
+ />
99
103
  { children?.( { closePopover } ) }
100
104
  </Popover>
101
105
 
102
- { colorCreationEnabled && <ColorVariableCreation popupState={ creationPopupState } /> }
106
+ <Box ref={ anchorRef }>
107
+ <Popover
108
+ { ...bindPopover( creationPopupState ) }
109
+ anchorEl={ anchorRef.current }
110
+ anchorOrigin={ { vertical: 'bottom', horizontal: 'right' } }
111
+ transformOrigin={ { vertical: 'top', horizontal: 'right' } }
112
+ >
113
+ { colorCreationEnabled && <ColorVariableCreation onClose={ creationPopupState.close } /> }
114
+ { fontCreationEnabled && <FontVariableCreation onClose={ creationPopupState.close } /> }
115
+ </Popover>
116
+ </Box>
103
117
  </Box>
104
118
  );
105
119
  };