@elementor/editor-editing-panel 1.41.0 → 1.43.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.
@@ -2,7 +2,20 @@ import * as React from 'react';
2
2
  import { useMemo, useState } from 'react';
3
3
  import { createPropsResolver, type PropsResolver } from '@elementor/editor-canvas';
4
4
  import { type PropKey, type PropType } from '@elementor/editor-props';
5
- import { Box, Card, CardContent, CloseButton, IconButton, Infotip, Stack, Typography } from '@elementor/ui';
5
+ import {
6
+ Backdrop,
7
+ Box,
8
+ Card,
9
+ CardContent,
10
+ ClickAwayListener,
11
+ CloseButton,
12
+ IconButton,
13
+ Infotip,
14
+ Stack,
15
+ type Theme,
16
+ Tooltip,
17
+ Typography,
18
+ } from '@elementor/ui';
6
19
  import { __ } from '@wordpress/i18n';
7
20
 
8
21
  import { useSectionContentRef } from '../components/section-content';
@@ -23,8 +36,10 @@ type Props = {
23
36
  const SIZE = 'tiny';
24
37
 
25
38
  export const StyleIndicatorInfotip = ( { inheritanceChain, propType, path, label, children }: Props ) => {
26
- const [ open, setOpen ] = useState( false );
27
- const { isSiteRtl } = useDirection();
39
+ const [ showInfotip, setShowInfotip ] = useState< boolean >( false );
40
+ const toggleInfotip = () => setShowInfotip( ( prev ) => ! prev );
41
+ const closeInfotip = () => setShowInfotip( false );
42
+
28
43
  const key = path.join( '.' );
29
44
 
30
45
  const sectionContentRef = useSectionContentRef();
@@ -39,99 +54,139 @@ export const StyleIndicatorInfotip = ( { inheritanceChain, propType, path, label
39
54
 
40
55
  const items = useNormalizedInheritanceChainItems( inheritanceChain, key, resolve );
41
56
 
42
- const toggleOpen = () => setOpen( ( prev ) => ! prev );
43
- const closeInfotip = () => {
44
- setOpen( false );
45
- };
46
-
47
- const forceInfotipAlignLeft = isSiteRtl ? 9999999 : -9999999;
48
-
49
57
  const infotipContent = (
50
- <Card
51
- elevation={ 0 }
52
- sx={ {
53
- width: `${ sectionContentWidth }px`,
54
- maxWidth: 500,
55
- overflowX: 'hidden',
56
- } }
57
- >
58
- <CardContent
58
+ <ClickAwayListener onClickAway={ closeInfotip }>
59
+ <Card
60
+ elevation={ 0 }
59
61
  sx={ {
60
- display: 'flex',
61
- gap: 0.5,
62
- flexDirection: 'column',
63
- p: 0,
64
- '&:last-child': {
65
- pb: 0,
66
- },
62
+ width: `${ sectionContentWidth }px`,
63
+ maxWidth: 500,
64
+ overflowX: 'hidden',
67
65
  } }
68
66
  >
69
- <Stack direction="row" alignItems="center" sx={ { pl: 1.5, pr: 0.5, minHeight: 36, py: 0.5 } }>
70
- <Typography variant="subtitle2" color="secondary" sx={ { fontSize: 12, fontWeight: '500' } }>
71
- { __( 'Style origin', 'elementor' ) }
72
- </Typography>
73
- <CloseButton
74
- slotProps={ { icon: { fontSize: SIZE } } }
75
- sx={ { ml: 'auto' } }
76
- onClick={ closeInfotip }
77
- />
78
- </Stack>
79
- <Stack gap={ 1.5 } sx={ { pl: 2, pr: 1, pb: 2, overflowX: 'hidden', overflowY: 'auto' } } role="list">
80
- { items.map( ( item, index ) => {
81
- return (
82
- <Box
83
- key={ item.id }
84
- display="flex"
85
- gap={ 0.5 }
86
- role="listitem"
87
- /* translators: %s: Label of the inheritance item */
88
- aria-label={ __( 'Inheritance item: %s', 'elementor' ).replace(
89
- '%s',
90
- item.displayLabel
91
- ) }
92
- >
93
- <Box display="flex" gap={ 0.5 } sx={ { flexWrap: 'wrap', width: '100%' } }>
94
- <BreakpointIcon breakpoint={ item.breakpoint } />
95
- <LabelChip displayLabel={ item.displayLabel } provider={ item.provider } />
96
- <ValueComponent index={ index } value={ item.value } />
67
+ <CardContent
68
+ sx={ {
69
+ display: 'flex',
70
+ gap: 0.5,
71
+ flexDirection: 'column',
72
+ p: 0,
73
+ '&:last-child': {
74
+ pb: 0,
75
+ },
76
+ } }
77
+ >
78
+ <Stack direction="row" alignItems="center" sx={ { pl: 1.5, pr: 0.5, minHeight: 36, py: 0.5 } }>
79
+ <Typography variant="subtitle2" color="secondary" sx={ { fontSize: 12, fontWeight: '500' } }>
80
+ { __( 'Style origin', 'elementor' ) }
81
+ </Typography>
82
+ <CloseButton
83
+ slotProps={ { icon: { fontSize: SIZE } } }
84
+ sx={ { ml: 'auto' } }
85
+ onClick={ closeInfotip }
86
+ />
87
+ </Stack>
88
+ <Stack
89
+ gap={ 1.5 }
90
+ sx={ { pl: 2, pr: 1, pb: 2, overflowX: 'hidden', overflowY: 'auto' } }
91
+ role="list"
92
+ >
93
+ { items.map( ( item, index ) => {
94
+ return (
95
+ <Box
96
+ key={ item.id }
97
+ display="flex"
98
+ gap={ 0.5 }
99
+ role="listitem"
100
+ /* translators: %s: Label of the inheritance item */
101
+ aria-label={ __( 'Inheritance item: %s', 'elementor' ).replace(
102
+ '%s',
103
+ item.displayLabel
104
+ ) }
105
+ >
106
+ <Box display="flex" gap={ 0.5 } sx={ { flexWrap: 'wrap', width: '100%' } }>
107
+ <BreakpointIcon breakpoint={ item.breakpoint } />
108
+ <LabelChip
109
+ displayLabel={ item.displayLabel }
110
+ provider={ item.provider }
111
+ chipColor={ item.chipColor }
112
+ />
113
+ <ValueComponent index={ index } value={ item.value } />
114
+ </Box>
115
+ <ActionIcons />
97
116
  </Box>
98
- <ActionIcons />
99
- </Box>
100
- );
101
- } ) }
102
- </Stack>
103
- </CardContent>
104
- </Card>
117
+ );
118
+ } ) }
119
+ </Stack>
120
+ </CardContent>
121
+ </Card>
122
+ </ClickAwayListener>
105
123
  );
106
124
 
107
125
  return (
108
- <Infotip
109
- placement="top"
110
- content={ infotipContent }
111
- open={ open }
112
- onClose={ closeInfotip }
113
- disableHoverListener={ true }
114
- componentsProps={ {
115
- tooltip: {
116
- sx: {
117
- mx: 2,
118
- },
119
- },
120
- } }
121
- slotProps={ {
122
- popper: {
123
- modifiers: [
124
- {
125
- name: 'offset',
126
- options: { offset: [ forceInfotipAlignLeft, 0 ] },
127
- },
128
- ],
129
- },
130
- } }
131
- >
132
- <IconButton onClick={ toggleOpen } aria-label={ label } sx={ { my: '-1px' } }>
126
+ <TooltipOrInfotip showInfotip={ showInfotip } onClose={ closeInfotip } infotipContent={ infotipContent }>
127
+ <IconButton onClick={ toggleInfotip } aria-label={ label } sx={ { my: '-1px' } }>
133
128
  { children }
134
129
  </IconButton>
135
- </Infotip>
130
+ </TooltipOrInfotip>
136
131
  );
137
132
  };
133
+
134
+ function TooltipOrInfotip( {
135
+ children,
136
+ showInfotip,
137
+ onClose,
138
+ infotipContent,
139
+ }: {
140
+ children: React.ReactNode;
141
+ showInfotip: boolean;
142
+ onClose: () => void;
143
+ infotipContent: React.ReactNode;
144
+ } ) {
145
+ const { isSiteRtl } = useDirection();
146
+ const forceInfotipAlignLeft = isSiteRtl ? 9999999 : -9999999;
147
+
148
+ if ( showInfotip ) {
149
+ return (
150
+ <>
151
+ <Backdrop
152
+ open={ showInfotip }
153
+ onClick={ onClose }
154
+ sx={ {
155
+ backgroundColor: 'transparent',
156
+ zIndex: ( theme: Theme ) => theme.zIndex.modal - 1,
157
+ } }
158
+ />
159
+ <Infotip
160
+ placement="top"
161
+ content={ infotipContent }
162
+ open={ showInfotip }
163
+ onClose={ onClose }
164
+ disableHoverListener
165
+ componentsProps={ {
166
+ tooltip: {
167
+ sx: { mx: 2 },
168
+ },
169
+ } }
170
+ slotProps={ {
171
+ popper: {
172
+ modifiers: [
173
+ {
174
+ name: 'offset',
175
+ options: { offset: [ forceInfotipAlignLeft, 0 ] },
176
+ },
177
+ ],
178
+ },
179
+ } }
180
+ >
181
+ { children }
182
+ </Infotip>
183
+ </>
184
+ );
185
+ }
186
+
187
+ return (
188
+ <Tooltip title={ __( 'Style origin', 'elementor' ) } placement="top">
189
+ { children }
190
+ </Tooltip>
191
+ );
192
+ }
@@ -50,3 +50,5 @@ export type StylesInheritanceAPI = {
50
50
  basePropType: PropType
51
51
  ) => SnapshotPropValue[];
52
52
  };
53
+
54
+ export type ChipColors = 'default' | 'global' | 'accent';