add_control(
* 'box_shadow',
* [
* 'label' => __( 'Box Shadow', 'plugin-domain' ),
* 'type' => Controls_Manager::BOX_SHADOW,
* 'default' => [
* 'color' => 'rgba(0,0,0,.5)',
* ],
* 'selectors' => [
* '{{WRAPPER}} .your-class' => 'box-shadow: {{HORIZONTAL}}px {{VERTICAL}}px {{BLUR}}px {{SPREAD}}px {{COLOR}};',
* ],
* ]
* );
*
* PHP usage (inside `Widget_Base::render()` method):
*
* echo '
...
';
*
* JS usage (inside `Widget_Base::_content_template()` method):
*
* ...
*
* @since 1.0.0
*
* @param string $label Optional. The label that appears above of the
* field. Default is empty.
* @param string $description Optional. The description that appears below the
* field. Default is empty.
* @param string $placeholder Optional. The field placeholder that appears when
* the field has no values. Default is empty.
* @param array $default {
* Optional. Defautl box shadow values.
*
* @type int $horizontal Optional. Horizontal shadow. Default is 0.
* @type int $vertical Optional. Vertical shadow. Default is 0.
* @type int $blur Optional. Shadow blur. Default is 10.
* @type int $spread Optional. Shadow spread. Default is 0.
* @type string $color Optional. Shadow color. Available values are
* `rgb`, `rgba`, `hex` or `format`. Default is
* `rgba(0,0,0,0.5)`.
* }
* @param string $separator Optional. Set the position of the control separator.
* Available values are 'default', 'before', 'after'
* and 'none'. 'default' will position the separator
* depending on the control type. 'before' / 'after'
* will position the separator before/after the
* control. 'none' will hide the separator. Default
* is 'default'.
* @param bool $show_label Optional. Whether to display the label. Default is
* true.
* @param bool $label_block Optional. Whether to display the label in a
* separate line. Default is false.
*
* @return array {
* Box shadow values.
*
* @type int $horizontal Horizontal shadow.
* @type int $vertical Vertical shadow.
* @type int $blur Shadow blur.
* @type int $spread Shadow spread.
* @type string $color Shadow color.
* }
*/
class Control_Box_Shadow extends Control_Base_Multiple {
/**
* Retrieve box shadow control type.
*
* @since 1.0.0
* @access public
*
* @return string Control type.
*/
public function get_type() {
return 'box_shadow';
}
/**
* Retrieve box shadow control default value.
*
* Get the default value of the box shadow control. Used to return the
* default values while initializing the box shadow control.
*
* @since 1.0.0
* @access public
*
* @return array Control default value.
*/
public function get_default_value() {
return [
'horizontal' => 0,
'vertical' => 0,
'blur' => 10,
'spread' => 0,
'color' => 'rgba(0,0,0,0.5)',
];
}
/**
* Retrieve box shadow control sliders.
*
* Get the sliders of the box shadow control. Sliders are used while
* rendering the control output in the editor.
*
* @since 1.0.0
* @access public
*
* @return array Control sliders.
*/
public function get_sliders() {
return [
'blur' => [
'label' => __( 'Blur', 'elementor' ),
'min' => 0,
'max' => 100,
],
'spread' => [
'label' => __( 'Spread', 'elementor' ),
'min' => -100,
'max' => 100,
],
'horizontal' => [
'label' => __( 'Horizontal', 'elementor' ),
'min' => -100,
'max' => 100,
],
'vertical' => [
'label' => __( 'Vertical', 'elementor' ),
'min' => -100,
'max' => 100,
],
];
}
/**
* Render box shadow control output in the editor.
*
* Used to generate the control HTML in the editor using Underscore JS
* template. The variables for the class are available using `data` JS
* object.
*
* @since 1.0.0
* @access public
*/
public function content_template() {
?>
<#
var defaultColorValue = '';
if ( data.default.color ) {
defaultColorValue = ' data-default-color=' + data.default.color; // Quotes added automatically.
}
#>
get_sliders() as $slider_name => $slider ) :
$control_uid = $this->get_control_uid( $slider_name );
?>