-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Expand file tree
/
Copy pathaxial-input-controls.js
More file actions
62 lines (55 loc) · 1.32 KB
/
axial-input-controls.js
File metadata and controls
62 lines (55 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Internal dependencies
*/
import SpacingInputControl from './spacing-input-control';
import { LABELS } from './utils';
const groupedSides = [ 'vertical', 'horizontal' ];
export default function AxialInputControls( {
onChange,
values,
sides,
spacingSizes,
type,
minimumCustomValue,
} ) {
const createHandleOnChange = ( side ) => ( next ) => {
if ( ! onChange ) {
return;
}
const nextValues = { ...values };
if ( side === 'vertical' ) {
nextValues.top = next;
nextValues.bottom = next;
}
if ( side === 'horizontal' ) {
nextValues.left = next;
nextValues.right = next;
}
onChange( nextValues );
};
// Filter sides if custom configuration provided, maintaining default order.
const filteredSides = sides?.length
? groupedSides.filter( ( side ) => sides.includes( side ) )
: groupedSides;
return (
<>
{ filteredSides.map( ( side ) => {
const axisValue =
side === 'vertical' ? values.top : values.left;
return (
<SpacingInputControl
value={ axisValue }
onChange={ createHandleOnChange( side ) }
label={ LABELS[ side ] }
key={ `spacing-sizes-control-${ side }` }
withInputField={ false }
side={ side }
spacingSizes={ spacingSizes }
type={ type }
minimumCustomValue={ minimumCustomValue }
/>
);
} ) }
</>
);
}