@elementor/editor-controls 0.5.0 → 0.6.1

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,5 +1,10 @@
1
1
  import * as React from 'react';
2
- import { linkedDimensionsPropTypeUtil, type LinkedDimensionsPropValue, type PropKey } from '@elementor/editor-props';
2
+ import {
3
+ dimensionsPropTypeUtil,
4
+ type DimensionsPropValue,
5
+ type PropKey,
6
+ sizePropTypeUtil,
7
+ } from '@elementor/editor-props';
3
8
  import { DetachIcon, LinkIcon, SideBottomIcon, SideLeftIcon, SideRightIcon, SideTopIcon } from '@elementor/icons';
4
9
  import { Grid, Stack, ToggleButton } from '@elementor/ui';
5
10
  import { __ } from '@wordpress/i18n';
@@ -10,41 +15,40 @@ import { createControl } from '../create-control';
10
15
  import { SizeControl } from './size-control';
11
16
 
12
17
  export const LinkedDimensionsControl = createControl( ( { label }: { label: string } ) => {
13
- const { value, setValue, propType } = useBoundProp( linkedDimensionsPropTypeUtil );
14
- const { top, right, bottom, left, isLinked = true } = value || {};
18
+ const { value: dimensionsValue, setValue: setDimensionsValue, propType } = useBoundProp( dimensionsPropTypeUtil );
19
+ const { value: sizeValue, setValue: setSizeValue } = useBoundProp( sizePropTypeUtil );
15
20
 
16
- const setLinkedValue: SetValue< LinkedDimensionsPropValue[ 'value' ] > = ( newValue, _, meta ) => {
21
+ const isLinked = ! dimensionsValue && ! sizeValue ? true : !! sizeValue;
22
+
23
+ const setValue: SetValue< DimensionsPropValue[ 'value' ] > = ( newValue ) => {
17
24
  if ( ! isLinked ) {
18
- return setValue( newValue );
25
+ setDimensionsValue( newValue );
26
+ return;
19
27
  }
20
28
 
21
- const newDimension = newValue[ meta?.bind as keyof LinkedDimensionsPropValue[ 'value' ] ];
22
-
23
- setValue( {
24
- isLinked,
25
- top: newDimension,
26
- right: newDimension,
27
- bottom: newDimension,
28
- left: newDimension,
29
- } );
29
+ setSizeValue( newValue.top );
30
30
  };
31
31
 
32
- const toggleLinked = () => {
33
- const updatedValue = {
34
- isLinked: ! isLinked,
35
- top,
36
- right: ! isLinked ? top : right,
37
- bottom: ! isLinked ? top : bottom,
38
- left: ! isLinked ? top : left,
39
- };
32
+ const onLinkToggle = () => {
33
+ if ( ! isLinked ) {
34
+ setSizeValue( dimensionsValue?.top.value );
35
+ return;
36
+ }
37
+
38
+ const value = sizeValue ? sizePropTypeUtil.create( sizeValue ) : null;
40
39
 
41
- setValue( updatedValue );
40
+ setDimensionsValue( {
41
+ top: value,
42
+ right: value,
43
+ bottom: value,
44
+ left: value,
45
+ } );
42
46
  };
43
47
 
44
48
  const LinkedIcon = isLinked ? LinkIcon : DetachIcon;
45
49
 
46
50
  return (
47
- <PropProvider propType={ propType } value={ value } setValue={ setLinkedValue }>
51
+ <PropProvider propType={ propType } value={ dimensionsValue } setValue={ setValue }>
48
52
  <Stack direction="row" gap={ 2 } flexWrap="nowrap">
49
53
  <ControlLabel>{ label }</ControlLabel>
50
54
  <ToggleButton
@@ -53,7 +57,7 @@ export const LinkedDimensionsControl = createControl( ( { label }: { label: stri
53
57
  value={ 'check' }
54
58
  selected={ isLinked }
55
59
  sx={ { marginLeft: 'auto' } }
56
- onChange={ toggleLinked }
60
+ onChange={ onLinkToggle }
57
61
  >
58
62
  <LinkedIcon fontSize={ 'tiny' } />
59
63
  </ToggleButton>
@@ -64,7 +68,11 @@ export const LinkedDimensionsControl = createControl( ( { label }: { label: stri
64
68
  <ControlLabel>{ __( 'Top', 'elementor' ) }</ControlLabel>
65
69
  </Grid>
66
70
  <Grid item xs={ 12 }>
67
- <Control bind={ 'top' } startIcon={ <SideTopIcon fontSize={ 'tiny' } /> } />
71
+ <Control
72
+ bind={ 'top' }
73
+ startIcon={ <SideTopIcon fontSize={ 'tiny' } /> }
74
+ isLinked={ isLinked }
75
+ />
68
76
  </Grid>
69
77
  </Grid>
70
78
  <Grid container gap={ 1 } alignItems="center">
@@ -72,7 +80,11 @@ export const LinkedDimensionsControl = createControl( ( { label }: { label: stri
72
80
  <ControlLabel>{ __( 'Right', 'elementor' ) }</ControlLabel>
73
81
  </Grid>
74
82
  <Grid item xs={ 12 }>
75
- <Control bind={ 'right' } startIcon={ <SideRightIcon fontSize={ 'tiny' } /> } />
83
+ <Control
84
+ bind={ 'right' }
85
+ startIcon={ <SideRightIcon fontSize={ 'tiny' } /> }
86
+ isLinked={ isLinked }
87
+ />
76
88
  </Grid>
77
89
  </Grid>
78
90
  </Stack>
@@ -82,7 +94,11 @@ export const LinkedDimensionsControl = createControl( ( { label }: { label: stri
82
94
  <ControlLabel>{ __( 'Bottom', 'elementor' ) }</ControlLabel>
83
95
  </Grid>
84
96
  <Grid item xs={ 12 }>
85
- <Control bind={ 'bottom' } startIcon={ <SideBottomIcon fontSize={ 'tiny' } /> } />
97
+ <Control
98
+ bind={ 'bottom' }
99
+ startIcon={ <SideBottomIcon fontSize={ 'tiny' } /> }
100
+ isLinked={ isLinked }
101
+ />
86
102
  </Grid>
87
103
  </Grid>
88
104
  <Grid container gap={ 1 } alignItems="center">
@@ -90,7 +106,11 @@ export const LinkedDimensionsControl = createControl( ( { label }: { label: stri
90
106
  <ControlLabel>{ __( 'Left', 'elementor' ) }</ControlLabel>
91
107
  </Grid>
92
108
  <Grid item xs={ 12 }>
93
- <Control bind={ 'left' } startIcon={ <SideLeftIcon fontSize={ 'tiny' } /> } />
109
+ <Control
110
+ bind={ 'left' }
111
+ startIcon={ <SideLeftIcon fontSize={ 'tiny' } /> }
112
+ isLinked={ isLinked }
113
+ />
94
114
  </Grid>
95
115
  </Grid>
96
116
  </Stack>
@@ -98,8 +118,14 @@ export const LinkedDimensionsControl = createControl( ( { label }: { label: stri
98
118
  );
99
119
  } );
100
120
 
101
- const Control = ( { bind, startIcon }: { bind: PropKey; startIcon: React.ReactNode } ) => (
102
- <PropKeyProvider bind={ bind }>
103
- <SizeControl startIcon={ startIcon } />
104
- </PropKeyProvider>
105
- );
121
+ const Control = ( { bind, startIcon, isLinked }: { bind: PropKey; startIcon: React.ReactNode; isLinked: boolean } ) => {
122
+ if ( isLinked ) {
123
+ return <SizeControl startIcon={ startIcon } />;
124
+ }
125
+
126
+ return (
127
+ <PropKeyProvider bind={ bind }>
128
+ <SizeControl startIcon={ startIcon } />
129
+ </PropKeyProvider>
130
+ );
131
+ };
@@ -8,12 +8,17 @@ import { createControl } from '../create-control';
8
8
 
9
9
  export const UrlControl = createControl( ( { placeholder }: { placeholder?: string } ) => {
10
10
  const { value, setValue } = useBoundProp( urlPropTypeUtil );
11
-
12
11
  const handleChange = ( event: React.ChangeEvent< HTMLInputElement > ) => setValue( event.target.value );
13
12
 
14
13
  return (
15
14
  <ControlActions>
16
- <TextField size="tiny" fullWidth value={ value } onChange={ handleChange } placeholder={ placeholder } />
15
+ <TextField
16
+ size="tiny"
17
+ fullWidth
18
+ value={ value ?? '' }
19
+ onChange={ handleChange }
20
+ placeholder={ placeholder }
21
+ />
17
22
  </ControlActions>
18
23
  );
19
24
  } );
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  // control types
2
2
  export { ImageControl } from './controls/image-control';
3
+ export { AutocompleteControl } from './controls/autocomplete-control';
3
4
  export { TextControl } from './controls/text-control';
4
5
  export { TextAreaControl } from './controls/text-area-control';
5
6
  export { SizeControl } from './controls/size-control';