PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.7.2
Block Animations, Motion & Scroll Effects – Ghost Kit v3.7.2
3.7.2 3.7.1 3.7.0 3.6.1 trunk 1.6.3 2.25.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.5.0 3.5.1 3.6.0
ghostkit / gutenberg / components / input-group / index.js

index.js in Block Animations, Motion & Scroll Effects – Ghost Kit 3.7.2, at gutenberg/components/input-group/index.js

161 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { BaseControl } from '@wordpress/components';
2 import { useState } from '@wordpress/element';
3 import classnames from 'classnames/dedupe';
4
5 import useResponsive from '../../hooks/use-responsive';
6 import ElementStateToggle from '../element-state-toggle';
7 import ImportantToggle from '../important-toggle';
8 import InputDrag from '../input-drag';
9 import ResponsiveToggle from '../responsive-toggle';
10
11 const noop = () => {};
12
13 function InputGroupWithChildren(props) {
14 const { className, children, ...restProps } = props;
15
16 return (
17 <BaseControl
18 className={classnames('ghostkit-component-input-group', className)}
19 {...restProps}
20 >
21 <div className="ghostkit-component-input-group-wrapper">
22 {children}
23 </div>
24 </BaseControl>
25 );
26 }
27
28 /**
29 * Component
30 *
31 * @param props
32 */
33 export default function InputGroup(props) {
34 if (props.children) {
35 return <InputGroupWithChildren {...props} />;
36 }
37
38 const {
39 label,
40 inputs,
41 hasValue = noop,
42 getValue = noop,
43 onChange = noop,
44 withResponsive,
45 withState,
46 withImportant,
47 expandOnFocus,
48 className,
49 ...restProps
50 } = props;
51
52 const [isHover, setIsHover] = useState(false);
53 const { device } = useResponsive();
54
55 return (
56 <BaseControl
57 id={inputs[0].name}
58 className={classnames('ghostkit-component-input-group', className)}
59 label={
60 <>
61 {label}
62 {withResponsive && (
63 <ResponsiveToggle
64 checkActive={(checkMedia) =>
65 inputs.some((inputDate) =>
66 hasValue(
67 inputDate.name,
68 checkMedia,
69 isHover
70 )
71 )
72 }
73 />
74 )}
75 {withState && (
76 <ElementStateToggle
77 isHover={isHover}
78 onChange={() => {
79 setIsHover(!isHover);
80 }}
81 checkActive={() =>
82 inputs.some((inputDate) =>
83 hasValue(inputDate.name, device, true)
84 )
85 }
86 />
87 )}
88 </>
89 }
90 {...restProps}
91 >
92 <div className="ghostkit-component-input-group-wrapper">
93 {inputs.map((inputData) => {
94 let value = getValue(inputData.name, device, isHover);
95 let hasImportant = false;
96
97 if (withImportant) {
98 hasImportant = / !important$/.test(value);
99
100 if (hasImportant) {
101 value = value.replace(/ !important$/, '');
102 }
103 }
104
105 return (
106 <div
107 key={inputData.name}
108 className="ghostkit-component-input-group-item"
109 >
110 <InputDrag
111 id={inputData.name}
112 help={inputData.label}
113 value={value}
114 onChange={(newValue) => {
115 newValue = newValue
116 ? `${newValue}${
117 hasImportant
118 ? ' !important'
119 : ''
120 }`
121 : undefined;
122
123 onChange(
124 inputData.name,
125 newValue,
126 device,
127 isHover
128 );
129 }}
130 expandOnFocus={expandOnFocus}
131 autoComplete="off"
132 />
133 {withImportant && typeof value !== 'undefined' && (
134 <ImportantToggle
135 onClick={(newWithImportant) => {
136 if (value) {
137 const newValue = `${value}${
138 newWithImportant
139 ? ' !important'
140 : ''
141 }`;
142
143 onChange(
144 inputData.name,
145 newValue,
146 device,
147 isHover
148 );
149 }
150 }}
151 isActive={hasImportant}
152 />
153 )}
154 </div>
155 );
156 })}
157 </div>
158 </BaseControl>
159 );
160 }
161