@elementor/editor-controls 0.3.0 → 0.4.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.
- package/CHANGELOG.md +14 -0
- package/dist/index.d.mts +25 -23
- package/dist/index.d.ts +25 -23
- package/dist/index.js +234 -193
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +201 -158
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/control-actions/control-actions-context.tsx +6 -4
- package/src/controls/background-control/background-control.tsx +57 -0
- package/src/controls/background-control/background-overlay/background-overlay-repeater-control.tsx +89 -0
- package/src/controls/color-control.tsx +7 -1
- package/src/controls/equal-unequal-sizes-control.tsx +5 -1
- package/src/controls/select-control.tsx +3 -1
- package/src/controls/text-area-control.tsx +1 -1
- package/src/controls/text-control.tsx +7 -1
- package/src/index.ts +3 -1
- package/src/controls/background-overlay-repeater-control.tsx +0 -115
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
type BackgroundColorOverlayPropValue,
|
|
4
|
+
backgroundPropTypeUtil,
|
|
5
|
+
type ColorPropValue,
|
|
6
|
+
type PropValue,
|
|
7
|
+
} from '@elementor/editor-props';
|
|
8
|
+
import { Grid, Stack } from '@elementor/ui';
|
|
9
|
+
import { __ } from '@wordpress/i18n';
|
|
10
|
+
|
|
11
|
+
import { BoundPropProvider, useBoundProp } from '../../bound-prop-context';
|
|
12
|
+
import { ControlLabel } from '../../components/control-label';
|
|
13
|
+
import { createControl } from '../../create-control';
|
|
14
|
+
import { ColorControl } from '../color-control';
|
|
15
|
+
import { BackgroundOverlayRepeaterControl } from './background-overlay/background-overlay-repeater-control';
|
|
16
|
+
|
|
17
|
+
type SetContextValue = ( v: PropValue ) => void;
|
|
18
|
+
|
|
19
|
+
export const BackgroundControl = createControl( () => {
|
|
20
|
+
const { value, setValue } = useBoundProp( backgroundPropTypeUtil );
|
|
21
|
+
|
|
22
|
+
const setColor = ( newValue: ColorPropValue ) => {
|
|
23
|
+
setValue( {
|
|
24
|
+
...value,
|
|
25
|
+
color: newValue,
|
|
26
|
+
} );
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const setBackgroundColorOverlay = ( newValue: BackgroundColorOverlayPropValue ) => {
|
|
30
|
+
setValue( {
|
|
31
|
+
...value,
|
|
32
|
+
'background-overlay': newValue,
|
|
33
|
+
} );
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<Stack gap={ 1.5 }>
|
|
38
|
+
<BoundPropProvider
|
|
39
|
+
bind="background-overlay"
|
|
40
|
+
value={ value?.[ 'background-overlay' ] }
|
|
41
|
+
setValue={ setBackgroundColorOverlay as SetContextValue }
|
|
42
|
+
>
|
|
43
|
+
<BackgroundOverlayRepeaterControl />
|
|
44
|
+
</BoundPropProvider>
|
|
45
|
+
<BoundPropProvider bind="color" value={ value?.color } setValue={ setColor as SetContextValue }>
|
|
46
|
+
<Grid container gap={ 2 } alignItems="center" flexWrap="nowrap">
|
|
47
|
+
<Grid item xs={ 6 }>
|
|
48
|
+
<ControlLabel>{ __( 'Color', 'elementor' ) }</ControlLabel>
|
|
49
|
+
</Grid>
|
|
50
|
+
<Grid item xs={ 6 }>
|
|
51
|
+
<ColorControl />
|
|
52
|
+
</Grid>
|
|
53
|
+
</Grid>
|
|
54
|
+
</BoundPropProvider>
|
|
55
|
+
</Stack>
|
|
56
|
+
);
|
|
57
|
+
} );
|
package/src/controls/background-control/background-overlay/background-overlay-repeater-control.tsx
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
type BackgroundColorOverlayPropValue,
|
|
4
|
+
type BackgroundOverlayItemPropValue,
|
|
5
|
+
backgroundOverlayPropTypeUtil,
|
|
6
|
+
type BackgroundOverlayPropValue,
|
|
7
|
+
type PropValue,
|
|
8
|
+
} from '@elementor/editor-props';
|
|
9
|
+
import { Grid, Stack, UnstableColorIndicator } from '@elementor/ui';
|
|
10
|
+
import { __ } from '@wordpress/i18n';
|
|
11
|
+
|
|
12
|
+
import { BoundPropProvider, useBoundProp } from '../../../bound-prop-context';
|
|
13
|
+
import { ControlLabel } from '../../../components/control-label';
|
|
14
|
+
import { Repeater } from '../../../components/repeater';
|
|
15
|
+
import { createControl } from '../../../create-control';
|
|
16
|
+
import { ColorControl } from '../../color-control';
|
|
17
|
+
|
|
18
|
+
type SetContextValue = ( v: PropValue ) => void;
|
|
19
|
+
|
|
20
|
+
const initialBackgroundOverlay: BackgroundOverlayItemPropValue = {
|
|
21
|
+
$$type: 'background-color-overlay',
|
|
22
|
+
value: 'rgba(0, 0, 0, 0.2)',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const BackgroundOverlayRepeaterControl = createControl( () => {
|
|
26
|
+
const { value: overlayValues, setValue } = useBoundProp( backgroundOverlayPropTypeUtil );
|
|
27
|
+
|
|
28
|
+
const setColorOverlay = ( newValue: BackgroundOverlayPropValue[ 'value' ] ) => {
|
|
29
|
+
setValue( newValue );
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<Repeater
|
|
34
|
+
values={ overlayValues ?? [] }
|
|
35
|
+
setValues={ setColorOverlay }
|
|
36
|
+
label={ __( 'Overlay', 'elementor' ) }
|
|
37
|
+
itemSettings={ {
|
|
38
|
+
Icon: ItemIcon,
|
|
39
|
+
Label: ItemLabel,
|
|
40
|
+
Content: ItemContent,
|
|
41
|
+
initialValues: initialBackgroundOverlay,
|
|
42
|
+
} }
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
45
|
+
} );
|
|
46
|
+
|
|
47
|
+
const ItemIcon = ( { value }: { value: BackgroundOverlayItemPropValue } ) => (
|
|
48
|
+
<UnstableColorIndicator size="inherit" component="span" value={ value.value } />
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const ItemContent = ( {
|
|
52
|
+
value,
|
|
53
|
+
setValue,
|
|
54
|
+
}: {
|
|
55
|
+
value: BackgroundOverlayItemPropValue;
|
|
56
|
+
setValue: ( newValue: BackgroundOverlayItemPropValue ) => void;
|
|
57
|
+
} ) => {
|
|
58
|
+
const setBackgroundColorOverlay = ( newValue: BackgroundColorOverlayPropValue ) => {
|
|
59
|
+
setValue( {
|
|
60
|
+
$$type: 'background-color-overlay',
|
|
61
|
+
value: newValue.value,
|
|
62
|
+
} );
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<Stack gap={ 1.5 }>
|
|
67
|
+
<BoundPropProvider
|
|
68
|
+
bind="background-color-overlay"
|
|
69
|
+
value={ value }
|
|
70
|
+
setValue={ setBackgroundColorOverlay as SetContextValue }
|
|
71
|
+
>
|
|
72
|
+
<Grid container spacing={ 1 } alignItems="center">
|
|
73
|
+
<Grid item xs={ 12 }>
|
|
74
|
+
<ControlLabel>{ __( 'Color', 'elementor' ) }</ControlLabel>
|
|
75
|
+
</Grid>
|
|
76
|
+
<Grid item xs={ 12 }>
|
|
77
|
+
<ColorControl />
|
|
78
|
+
</Grid>
|
|
79
|
+
</Grid>
|
|
80
|
+
</BoundPropProvider>
|
|
81
|
+
</Stack>
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const ItemLabel = ( { value }: { value: BackgroundOverlayItemPropValue } ) => {
|
|
86
|
+
const color = value.value;
|
|
87
|
+
|
|
88
|
+
return <span>{ color }</span>;
|
|
89
|
+
};
|
|
@@ -16,7 +16,13 @@ export const ColorControl = createControl(
|
|
|
16
16
|
|
|
17
17
|
return (
|
|
18
18
|
<ControlActions>
|
|
19
|
-
<UnstableColorField
|
|
19
|
+
<UnstableColorField
|
|
20
|
+
size="tiny"
|
|
21
|
+
{ ...props }
|
|
22
|
+
value={ value ?? '' }
|
|
23
|
+
onChange={ handleChange }
|
|
24
|
+
fullWidth
|
|
25
|
+
/>
|
|
20
26
|
</ControlActions>
|
|
21
27
|
);
|
|
22
28
|
}
|
|
@@ -59,7 +59,11 @@ export function EqualUnequalSizesControl< TMultiPropType extends string, TPropVa
|
|
|
59
59
|
const { value: multiSizeValue, setValue: setMultiSizeValue } = useBoundProp( multiSizePropTypeUtil );
|
|
60
60
|
|
|
61
61
|
const splitEqualValue = () => {
|
|
62
|
-
|
|
62
|
+
if ( ! sizeValue ) {
|
|
63
|
+
return {};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return items.reduce( ( acc, { bind } ) => ( { ...acc, [ bind ]: sizePropTypeUtil.create( sizeValue ) } ), {} );
|
|
63
67
|
};
|
|
64
68
|
|
|
65
69
|
const setNestedProp = ( item: Item, newValue: SizePropValue ) => {
|
|
@@ -8,12 +8,14 @@ import { createControl } from '../create-control';
|
|
|
8
8
|
|
|
9
9
|
type Props = {
|
|
10
10
|
options: Array< { label: string; value: StringPropValue[ 'value' ]; disabled?: boolean } >;
|
|
11
|
+
onChange?: ( newValue: string | null, previousValue: string | null | undefined ) => void;
|
|
11
12
|
};
|
|
12
13
|
|
|
13
|
-
export const SelectControl = createControl( ( { options }: Props ) => {
|
|
14
|
+
export const SelectControl = createControl( ( { options, onChange }: Props ) => {
|
|
14
15
|
const { value, setValue } = useBoundProp( stringPropTypeUtil );
|
|
15
16
|
|
|
16
17
|
const handleChange = ( event: SelectChangeEvent< StringPropValue[ 'value' ] > ) => {
|
|
18
|
+
onChange?.( event.target.value, value );
|
|
17
19
|
setValue( event.target.value );
|
|
18
20
|
};
|
|
19
21
|
|
|
@@ -13,7 +13,13 @@ export const TextControl = createControl( ( { placeholder }: { placeholder?: str
|
|
|
13
13
|
|
|
14
14
|
return (
|
|
15
15
|
<ControlActions>
|
|
16
|
-
<TextField
|
|
16
|
+
<TextField
|
|
17
|
+
size="tiny"
|
|
18
|
+
fullWidth
|
|
19
|
+
value={ value ?? '' }
|
|
20
|
+
onChange={ handleChange }
|
|
21
|
+
placeholder={ placeholder }
|
|
22
|
+
/>
|
|
17
23
|
</ControlActions>
|
|
18
24
|
);
|
|
19
25
|
} );
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,6 @@ export { TextAreaControl } from './controls/text-area-control';
|
|
|
5
5
|
export { SizeControl } from './controls/size-control';
|
|
6
6
|
export { StrokeControl } from './controls/stroke-control';
|
|
7
7
|
export { BoxShadowRepeaterControl } from './controls/box-shadow-repeater-control';
|
|
8
|
-
export { BackgroundOverlayRepeaterControl } from './controls/background-overlay-repeater-control';
|
|
9
8
|
export { SelectControl } from './controls/select-control';
|
|
10
9
|
export { ColorControl } from './controls/color-control';
|
|
11
10
|
export { ToggleControl } from './controls/toggle-control';
|
|
@@ -16,6 +15,7 @@ export { FontFamilyControl } from './controls/font-family-control';
|
|
|
16
15
|
export { UrlControl } from './controls/url-control';
|
|
17
16
|
export { LinkControl } from './controls/link-control';
|
|
18
17
|
export { GapControl } from './controls/gap-control';
|
|
18
|
+
export { BackgroundControl } from './controls/background-control/background-control';
|
|
19
19
|
|
|
20
20
|
// components
|
|
21
21
|
export { ControlLabel } from './components/control-label';
|
|
@@ -25,6 +25,8 @@ export { ControlToggleButtonGroup } from './components/control-toggle-button-gro
|
|
|
25
25
|
export type { ControlComponent } from './create-control';
|
|
26
26
|
export type { ToggleButtonGroupItem } from './components/control-toggle-button-group';
|
|
27
27
|
export type { EqualUnequalItems } from './controls/equal-unequal-sizes-control';
|
|
28
|
+
export type { ControlActionsItems } from './control-actions/control-actions-context';
|
|
29
|
+
export type { BoundPropProviderProps } from './bound-prop-context';
|
|
28
30
|
|
|
29
31
|
// providers
|
|
30
32
|
export { createControlReplacement, ControlReplacementProvider } from './create-control-replacement';
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
backgroundImagePropTypeUtil,
|
|
4
|
-
type backgroundImageTypePropValue,
|
|
5
|
-
type ColorGradientPropValue,
|
|
6
|
-
type PropValue,
|
|
7
|
-
} from '@elementor/editor-props';
|
|
8
|
-
import { Grid, Stack, Typography, UnstableColorIndicator } from '@elementor/ui';
|
|
9
|
-
import { __ } from '@wordpress/i18n';
|
|
10
|
-
|
|
11
|
-
import { BoundPropProvider, useBoundProp } from '../bound-prop-context';
|
|
12
|
-
import { Repeater } from '../components/repeater';
|
|
13
|
-
import { createControl } from '../create-control';
|
|
14
|
-
import { ColorControl } from './color-control';
|
|
15
|
-
|
|
16
|
-
type SetContextValue = ( v: PropValue ) => void;
|
|
17
|
-
|
|
18
|
-
export const BackgroundOverlayRepeaterControl = createControl( () => {
|
|
19
|
-
const { value: colorOverlayValues, setValue } = useBoundProp( backgroundImagePropTypeUtil );
|
|
20
|
-
|
|
21
|
-
const setColorOverlay = ( newValue: backgroundImageTypePropValue[ 'value' ] ) => {
|
|
22
|
-
setValue( newValue );
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
return (
|
|
26
|
-
<Repeater
|
|
27
|
-
values={ colorOverlayValues }
|
|
28
|
-
setValues={ setColorOverlay }
|
|
29
|
-
label={ __( 'Overlay', 'elementor' ) }
|
|
30
|
-
itemSettings={ {
|
|
31
|
-
Icon: ItemIcon,
|
|
32
|
-
Label: ItemLabel,
|
|
33
|
-
Content: ItemContent,
|
|
34
|
-
initialValues: initialGradient,
|
|
35
|
-
} }
|
|
36
|
-
/>
|
|
37
|
-
);
|
|
38
|
-
} );
|
|
39
|
-
|
|
40
|
-
const ItemIcon = ( { value }: { value: ColorGradientPropValue } ) => (
|
|
41
|
-
<UnstableColorIndicator size="inherit" component="span" value={ value.value.color.value } />
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
const ItemContent = ( {
|
|
45
|
-
value,
|
|
46
|
-
setValue,
|
|
47
|
-
}: {
|
|
48
|
-
value: ColorGradientPropValue;
|
|
49
|
-
setValue: ( newValue: ColorGradientPropValue ) => void;
|
|
50
|
-
} ) => {
|
|
51
|
-
const setColor = ( newValue: ColorGradientPropValue[ 'value' ] ) => {
|
|
52
|
-
setValue( {
|
|
53
|
-
$$type: 'background-overlay',
|
|
54
|
-
value: newValue,
|
|
55
|
-
} );
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
return (
|
|
59
|
-
<Stack gap={ 1.5 }>
|
|
60
|
-
<Control
|
|
61
|
-
bind="color"
|
|
62
|
-
value={ value.value.color }
|
|
63
|
-
label={ __( 'Color', 'elementor' ) }
|
|
64
|
-
setValue={ ( v: ColorGradientPropValue[ 'value' ][ 'color' ] ) =>
|
|
65
|
-
setColor( { ...value.value, color: v } )
|
|
66
|
-
}
|
|
67
|
-
>
|
|
68
|
-
<ColorControl />
|
|
69
|
-
</Control>
|
|
70
|
-
</Stack>
|
|
71
|
-
);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const Control = < T extends PropValue >( {
|
|
75
|
-
value,
|
|
76
|
-
setValue,
|
|
77
|
-
label,
|
|
78
|
-
bind,
|
|
79
|
-
children,
|
|
80
|
-
}: {
|
|
81
|
-
value: T;
|
|
82
|
-
bind: string;
|
|
83
|
-
label: string;
|
|
84
|
-
children: React.ReactNode;
|
|
85
|
-
setValue: ( v: T ) => void;
|
|
86
|
-
} ) => (
|
|
87
|
-
<BoundPropProvider value={ value } setValue={ setValue as SetContextValue } bind={ bind }>
|
|
88
|
-
<Grid container spacing={ 1 } alignItems="center">
|
|
89
|
-
<Grid item xs={ 12 }>
|
|
90
|
-
<Typography component="label" variant="caption" color="text.secondary">
|
|
91
|
-
{ label }
|
|
92
|
-
</Typography>
|
|
93
|
-
</Grid>
|
|
94
|
-
<Grid item xs={ 12 }>
|
|
95
|
-
{ children }
|
|
96
|
-
</Grid>
|
|
97
|
-
</Grid>
|
|
98
|
-
</BoundPropProvider>
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
const ItemLabel = ( { value }: { value: ColorGradientPropValue } ) => {
|
|
102
|
-
const color = value.value.color.value;
|
|
103
|
-
|
|
104
|
-
return <span>{ color }</span>;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
const initialGradient: ColorGradientPropValue = {
|
|
108
|
-
$$type: 'background-overlay',
|
|
109
|
-
value: {
|
|
110
|
-
color: {
|
|
111
|
-
$$type: 'color',
|
|
112
|
-
value: 'rgba(0, 0, 0, 0.2)',
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
};
|