Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import PropTypes from 'prop-types';
import ColorPickerControlWithDevices from '../color-with-devices/color-picker-control';
import {useState} from 'react';
import { useState } from 'react';

const ColorComponentWithDevicesAndHover = props => {

const [props_value, setPropsValue] = useState( props.control.settings );
const [props_value, setPropsValue] = useState(props.control.settings);

const updateColors = (device, value) => {
let updateColor = {...props_value};
let updateColor = { ...props_value };
updateColor[`${device}`].set(value);
setPropsValue(updateColor);
};
const handleChangeComplete = ( device, color ) => {
const handleChangeComplete = (device, color) => {
let value;
if (typeof color === 'string' || color instanceof String) {
value = color;
Expand All @@ -24,9 +24,9 @@ const ColorComponentWithDevicesAndHover = props => {
updateColors(device, value);
};

let labelHtml = null,
inputHtml = null,
htmlDescription = null;
let labelHtml = null,
inputHtml = null,
htmlDescription = null;

const {
label,
Expand All @@ -36,7 +36,7 @@ const ColorComponentWithDevicesAndHover = props => {
if (label) {
labelHtml = <span className="customize-control-title">
<span>{label}</span>
<ul className="responsive-switchers">
<ul className="responsive-switchers">
<li className="desktop">
<button type="button" className="preview-desktop active" data-device="desktop">
<i className="dashicons dashicons-desktop"></i>
Expand All @@ -55,52 +55,52 @@ const ColorComponentWithDevicesAndHover = props => {
</ul>
</span>;
}
if (description) {
htmlDescription = <i className="res-control-tooltip dashicons dashicons-editor-help" title={description}></i>;
}
if (description) {
htmlDescription = <i className="res-control-tooltip dashicons dashicons-editor-help" title={description}></i>;
}

const renderColorPicker = (device, active = '') => {
const renderColorPicker = (device, active = '') => {

return <div className={`${device} control-wrap ${active}`}>
<div className="responsive-color-hover-wrapper">
<div className="responsive-color-normal">
{/* <label className="responsive-color-label">Normal</label> */}
<ColorPickerControlWithDevices
<ColorPickerControlWithDevices
color={undefined !== props_value[`${device}`].get() && props_value[`${device}`].get() ? props_value[`${device}`].get() : ''}
onChangeComplete={(color) => handleChangeComplete(device, color)}
backgroundType={'color'}
inputattr={props.control.params}
defaultValue = {props.control.params[`${device}`].default}
defaultValue={props.control.params[`${device}`].default}
swatchTitle="Normal"
/>
</div>
<div className="responsive-color-hover">
{/* <label className="responsive-color-label">Hover</label> */}
<ColorPickerControlWithDevices
<ColorPickerControlWithDevices
color={undefined !== props_value[`${device}_hover`].get() && props_value[`${device}_hover`].get() ? props_value[`${device}_hover`].get() : ''}
onChangeComplete={(color) => handleChangeComplete(`${device}_hover`, color)}
backgroundType={'color'}
inputattr={props.control.params}
defaultValue = {props.control.params[`${device}_hover`].default}
defaultValue={props.control.params[`${device}_hover`].default}
swatchTitle="Hover"
/>
</div>
</div>
</div>
</div>
};

inputHtml = <>
{renderColorPicker('desktop', 'active')}
{renderColorPicker('tablet')}
{renderColorPicker('mobile')}
</>;
inputHtml = <>
{renderColorPicker('desktop', 'active')}
{renderColorPicker('tablet')}
{renderColorPicker('mobile')}
</>;

return <>
<label className='responsive-color-control-main-wrap'>
<div className='responsive-color-control-main-wrap'>
{labelHtml}
{inputHtml}
</label>
{htmlDescription}
{inputHtml}
</div>
{htmlDescription}
</>;

};
Expand All @@ -109,5 +109,5 @@ ColorComponentWithDevicesAndHover.propTypes = {
control: PropTypes.object.isRequired
};

export default React.memo ( ColorComponentWithDevicesAndHover );
export default React.memo(ColorComponentWithDevicesAndHover);

Original file line number Diff line number Diff line change
@@ -1,63 +1,73 @@
import ColorComponentWithDevicesAndHover from './color-component-with-hover';

export const responsiveColorWithDevicesAndHover = wp.customize.responsiveControl.extend( {
renderContent: function renderContent() {
let control = this;
ReactDOM.render(
<ColorComponentWithDevicesAndHover control={control} customizer={ wp.customize }/>,
control.container[0]
);
},
ready : function() {
'use strict';
let control = this;
jQuery(document).mouseup(function(e){
var container = jQuery(control.container);
var colorWrap = container.find('.wp-picker-container');
jQuery('.components-color-picker').on('click', function( event ){
event.preventDefault();
});
// If the target of the click isn't the container nor a descendant of the container.
if (!colorWrap.is(e.target) && colorWrap.has(e.target).length === 0 ){
container.find('button.wp-color-result.wp-picker-open').click();
}
});

control.container.on( 'click',
export const responsiveColorWithDevicesAndHover = wp.customize.responsiveControl.extend({
renderContent: function renderContent() {
let control = this;
ReactDOM.render(
<ColorComponentWithDevicesAndHover control={control} customizer={wp.customize} />,
control.container[0]
);
},
ready: function () {
'use strict';
let control = this;
jQuery(document).mouseup(function (e) {
var container = jQuery(control.container);
var colorWrap = container.find('.wp-picker-container');
jQuery('.components-color-picker').on('click', function (event) {
event.preventDefault();
});
// If the target of the click isn't the container nor a descendant of the container.
if (!colorWrap.is(e.target) && colorWrap.has(e.target).length === 0) {
container.find('button.wp-color-result.wp-picker-open').click();
}

});
control.container.on(
'click',
'.responsive-switchers button',
function( event ) {
function (event) {
event.stopPropagation();

// Set up variables
let $this = jQuery( this ),
$devices = jQuery( '.responsive-switchers' ),
$device = jQuery( event.currentTarget ).data( 'device' ),
$control = jQuery( '.customize-control.has-switchers' ),
$body = jQuery( '.wp-full-overlay' ),
$footer_devices = jQuery( '.wp-full-overlay-footer .devices' );

let $this = jQuery(this),
$control = $this.closest('.customize-control'),
$devices = $control.find('.responsive-switchers'),
$device = $this.data('device'),
$body = jQuery('.wp-full-overlay'),
$footer_devices = jQuery('.wp-full-overlay-footer .devices');

// Button class
$devices.find( 'button' ).removeClass( 'active' );
$devices.find( 'button.preview-' + $device ).addClass( 'active' );

// Control class
$control.find( '.control-wrap' ).removeClass( 'active' );
$control.find( '.control-wrap.' + $device ).addClass( 'active' );
$control.removeClass( 'control-device-desktop control-device-tablet control-device-mobile' ).addClass( 'control-device-' + $device );

$devices.find('button').removeClass('active');
$devices.find('button.preview-' + $device).addClass('active');

// Control class (ONLY inside this control)
$control.find('.control-wrap').removeClass('active');
$control.find('.control-wrap.' + $device).addClass('active');

$control
.removeClass('control-device-desktop control-device-tablet control-device-mobile')
.addClass('control-device-' + $device);

// Wrapper class
$body.removeClass( 'preview-desktop preview-tablet preview-mobile' ).addClass( 'preview-' + $device );

$body
.removeClass('preview-desktop preview-tablet preview-mobile')
.addClass('preview-' + $device);

// Panel footer buttons
$footer_devices.find( 'button' ).removeClass( 'active' ).attr( 'aria-pressed', false );
$footer_devices.find( 'button.preview-' + $device ).addClass( 'active' ).attr( 'aria-pressed', true );

// Open switchers
if ( $this.hasClass( 'preview-desktop' ) ) {
$control.toggleClass( 'responsive-switchers-open' );
$footer_devices.find('button')
.removeClass('active')
.attr('aria-pressed', false);

$footer_devices.find('button.preview-' + $device)
.addClass('active')
.attr('aria-pressed', true);

// Toggle switchers
if ($this.hasClass('preview-desktop')) {
$control.toggleClass('responsive-switchers-open');
}
}
}
);
}
} );
}
});

Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import PropTypes from 'prop-types';
import ColorPickerControlWithDevices from '../color-with-devices/color-picker-control';
import {useState} from 'react';
import { useState } from 'react';

const ColorComponentWithStatesAndDevices = props => {

const [props_value, setPropsValue] = useState( props.control.settings );
const [props_value, setPropsValue] = useState(props.control.settings);

const updateColors = (device, value) => {
let updateColor = {...props_value};
let updateColor = { ...props_value };
updateColor[`${device}`].set(value);
setPropsValue(updateColor);
};
const handleChangeComplete = ( device, color ) => {
const handleChangeComplete = (device, color) => {
let value;
if (typeof color === 'string' || color instanceof String) {
value = color;
Expand All @@ -24,9 +24,9 @@ const ColorComponentWithStatesAndDevices = props => {
updateColors(device, value);
};

let labelHtml = null,
inputHtml = null,
htmlDescription = null;
let labelHtml = null,
inputHtml = null,
htmlDescription = null;

const {
label,
Expand All @@ -36,7 +36,7 @@ const ColorComponentWithStatesAndDevices = props => {
if (label) {
labelHtml = <span className="customize-control-title">
<span>{label}</span>
<ul className="responsive-switchers">
<ul className="responsive-switchers">
<li className="desktop">
<button type="button" className="preview-desktop active" data-device="desktop">
<i className="dashicons dashicons-desktop"></i>
Expand All @@ -55,60 +55,60 @@ const ColorComponentWithStatesAndDevices = props => {
</ul>
</span>;
}
if (description) {
htmlDescription = <i className="res-control-tooltip dashicons dashicons-editor-help" title={description}></i>;
}
if (description) {
htmlDescription = <i className="res-control-tooltip dashicons dashicons-editor-help" title={description}></i>;
}

const renderColorPicker = (device, active = '') => {
const renderColorPicker = (device, active = '') => {

return <div className={`${device} control-wrap ${active}`}>
<div className="responsive-color-states-wrapper">
<div className="responsive-color-normal">
<ColorPickerControlWithDevices
<ColorPickerControlWithDevices
color={undefined !== props_value[`${device}`].get() && props_value[`${device}`].get() ? props_value[`${device}`].get() : ''}
onChangeComplete={(color) => handleChangeComplete(device, color)}
backgroundType={'color'}
inputattr={props.control.params}
defaultValue = {props.control.params[`${device}`].default}
defaultValue={props.control.params[`${device}`].default}
swatchTitle="Normal"
/>
</div>
<div className="responsive-color-hover">
<ColorPickerControlWithDevices
<ColorPickerControlWithDevices
color={undefined !== props_value[`${device}_hover`].get() && props_value[`${device}_hover`].get() ? props_value[`${device}_hover`].get() : ''}
onChangeComplete={(color) => handleChangeComplete(`${device}_hover`, color)}
backgroundType={'color'}
inputattr={props.control.params}
defaultValue = {props.control.params[`${device}_hover`].default}
defaultValue={props.control.params[`${device}_hover`].default}
swatchTitle="Hover"
/>
</div>
<div className="responsive-color-active">
<ColorPickerControlWithDevices
<ColorPickerControlWithDevices
color={undefined !== props_value[`${device}_active`].get() && props_value[`${device}_active`].get() ? props_value[`${device}_active`].get() : ''}
onChangeComplete={(color) => handleChangeComplete(`${device}_active`, color)}
backgroundType={'color'}
inputattr={props.control.params}
defaultValue = {props.control.params[`${device}_active`].default}
defaultValue={props.control.params[`${device}_active`].default}
swatchTitle="Active"
/>
</div>
</div>
</div>
</div>
};

inputHtml = <>
{renderColorPicker('desktop', 'active')}
{renderColorPicker('tablet')}
{renderColorPicker('mobile')}
</>;
inputHtml = <>
{renderColorPicker('desktop', 'active')}
{renderColorPicker('tablet')}
{renderColorPicker('mobile')}
</>;

return <>
<label className='responsive-color-control-main-wrap'>
<div className='responsive-color-control-main-wrap'>
{labelHtml}
{inputHtml}
</label>
{htmlDescription}
{inputHtml}
</div>
{htmlDescription}
</>;

};
Expand All @@ -117,4 +117,4 @@ ColorComponentWithStatesAndDevices.propTypes = {
control: PropTypes.object.isRequired
};

export default React.memo ( ColorComponentWithStatesAndDevices );
export default React.memo(ColorComponentWithStatesAndDevices);
Loading