@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.
- package/CHANGELOG.md +31 -0
- package/dist/index.d.mts +37 -13
- package/dist/index.d.ts +37 -13
- package/dist/index.js +443 -234
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +389 -171
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
- package/src/bound-prop-context/prop-context.tsx +11 -2
- package/src/bound-prop-context/prop-key-context.tsx +9 -2
- package/src/bound-prop-context/use-bound-prop.ts +1 -0
- package/src/components/repeater.tsx +5 -2
- package/src/controls/autocomplete-control.tsx +181 -0
- package/src/controls/background-control/background-overlay/background-overlay-repeater-control.tsx +32 -2
- package/src/controls/equal-unequal-sizes-control.tsx +1 -1
- package/src/controls/image-media-control.tsx +1 -1
- package/src/controls/link-control.tsx +56 -26
- package/src/controls/linked-dimensions-control.tsx +60 -34
- package/src/controls/url-control.tsx +7 -2
- package/src/index.ts +1 -0
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
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(
|
|
14
|
-
const {
|
|
18
|
+
const { value: dimensionsValue, setValue: setDimensionsValue, propType } = useBoundProp( dimensionsPropTypeUtil );
|
|
19
|
+
const { value: sizeValue, setValue: setSizeValue } = useBoundProp( sizePropTypeUtil );
|
|
15
20
|
|
|
16
|
-
const
|
|
21
|
+
const isLinked = ! dimensionsValue && ! sizeValue ? true : !! sizeValue;
|
|
22
|
+
|
|
23
|
+
const setValue: SetValue< DimensionsPropValue[ 'value' ] > = ( newValue ) => {
|
|
17
24
|
if ( ! isLinked ) {
|
|
18
|
-
|
|
25
|
+
setDimensionsValue( newValue );
|
|
26
|
+
return;
|
|
19
27
|
}
|
|
20
28
|
|
|
21
|
-
|
|
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
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
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={
|
|
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={
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
103
|
-
<SizeControl startIcon={ startIcon }
|
|
104
|
-
|
|
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
|
|
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';
|