import classnames from 'classnames/dedupe'; import { BaseControl } from '@wordpress/components'; import { useState } from '@wordpress/element'; import useResponsive from '../../hooks/use-responsive'; import ElementStateToggle from '../element-state-toggle'; import ImportantToggle from '../important-toggle'; import InputDrag from '../input-drag'; import ResponsiveToggle from '../responsive-toggle'; const noop = () => {}; function InputGroupWithChildren(props) { const { className, children, ...restProps } = props; return (
{children}
); } /** * Component * * @param props */ export default function InputGroup(props) { if (props.children) { return ; } const { label, inputs, hasValue = noop, getValue = noop, onChange = noop, withResponsive, withState, withImportant, expandOnFocus, className, ...restProps } = props; const [isHover, setIsHover] = useState(false); const { device } = useResponsive(); return ( {label} {withResponsive && ( inputs.some((inputDate) => hasValue( inputDate.name, checkMedia, isHover ) ) } /> )} {withState && ( { setIsHover(!isHover); }} checkActive={() => inputs.some((inputDate) => hasValue(inputDate.name, device, true) ) } /> )} } {...restProps} >
{inputs.map((inputData) => { let value = getValue(inputData.name, device, isHover); let hasImportant = false; if (withImportant) { hasImportant = / !important$/.test(value); if (hasImportant) { value = value.replace(/ !important$/, ''); } } return (
{ newValue = newValue ? `${newValue}${ hasImportant ? ' !important' : '' }` : undefined; onChange( inputData.name, newValue, device, isHover ); }} expandOnFocus={expandOnFocus} autoComplete="off" /> {withImportant && typeof value !== 'undefined' && ( { if (value) { const newValue = `${value}${ newWithImportant ? ' !important' : '' }`; onChange( inputData.name, newValue, device, isHover ); } }} isActive={hasImportant} /> )}
); })}
); }