@@ -10,6 +10,9 @@ import {
1010 __experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue ,
1111 Flex ,
1212 FlexItem ,
13+ __experimentalBoxControlIcon as BoxControlIcon ,
14+ __experimentalHStack as HStack ,
15+ __experimentalText as Text ,
1316} from '@wordpress/components' ;
1417import { __ } from '@wordpress/i18n' ;
1518import { settings } from '@wordpress/icons' ;
@@ -21,14 +24,17 @@ import { settings } from '@wordpress/icons';
2124 *
2225 * @return {WPElement } Font size edit element.
2326 */
24- export default function SpacingRangeControl ( props ) {
27+ export default function SpacingRangeControl ( {
28+ spacingSizes,
29+ value,
30+ side,
31+ label,
32+ onChange,
33+ } ) {
2534 const [ valueNow , setValueNow ] = useState ( null ) ;
2635 const [ showCustomValueControl , setShowCustomValueControl ] =
2736 useState ( false ) ;
28- const customTooltipContent = ( value ) => props . spacingSizes [ value ] ?. name ;
29- const createHandleOnFocus = ( side ) => ( ) => {
30- props . onFocus ( side ) ;
31- } ;
37+ const customTooltipContent = ( newValue ) => spacingSizes [ newValue ] ?. name ;
3238 const useSelect = false ; //props.useSelect;
3339 const getNewCustomValue = ( newSize ) => {
3440 return newSize ;
@@ -39,87 +45,91 @@ export default function SpacingRangeControl( props ) {
3945 if ( size === 0 ) {
4046 return '0' ;
4147 }
42- return `var:preset|spacing|${ props . spacingSizes [ newSize ] ?. slug } ` ;
48+ return `var:preset|spacing|${ spacingSizes [ newSize ] ?. slug } ` ;
4349 } ;
4450
45- const currentValueHint = customTooltipContent ( props . value ) ;
51+ const currentValueHint = customTooltipContent ( value ) ;
4652
47- const options = props . spacingSizes . map ( ( size , index ) => ( {
53+ const options = spacingSizes . map ( ( size , index ) => ( {
4854 key : index ,
4955 name : size . name ,
5056 } ) ) ;
51- const marks = props . spacingSizes . map ( ( value , index ) => ( {
57+ const marks = spacingSizes . map ( ( newValue , index ) => ( {
5258 value : index ,
5359 lable : undefined ,
5460 } ) ) ;
5561
5662 return (
5763 < >
58- < Flex >
59- < FlexItem >
60- < div >
61- < span > { props . label } </ span > { ' ' }
62- < span className = "components-spacing-sizes-control__hint" >
63- { currentValueHint !== undefined
64- ? currentValueHint
65- : __ ( 'Default' ) }
66- </ span >
67- </ div >
68- </ FlexItem >
69- < FlexItem >
70- < Button
71- label = {
72- showCustomValueControl
73- ? __ ( 'Use size preset' )
74- : __ ( 'Set custom size' )
75- }
76- icon = { settings }
77- onClick = { ( ) => {
78- setShowCustomValueControl (
79- ! showCustomValueControl
80- ) ;
81- } }
82- isPressed = { showCustomValueControl }
83- isSmall
84- />
85- </ FlexItem >
86- </ Flex >
64+ < HStack >
65+ < BoxControlIcon
66+ side = { side }
67+ sides = { [
68+ 'top' ,
69+ 'right' ,
70+ 'bottom' ,
71+ 'left' ,
72+ 'vertical' ,
73+ 'horizontal' ,
74+ ] }
75+ />
76+
77+ < Text className = "components-spacing-sizes-control__hint" >
78+ { currentValueHint !== undefined
79+ ? currentValueHint
80+ : __ ( 'Default' ) }
81+ </ Text >
82+
83+ < Button
84+ label = {
85+ showCustomValueControl
86+ ? __ ( 'Use size preset' )
87+ : __ ( 'Set custom size' )
88+ }
89+ icon = { settings }
90+ onClick = { ( ) => {
91+ setShowCustomValueControl ( ! showCustomValueControl ) ;
92+ } }
93+ isPressed = { showCustomValueControl }
94+ isSmall
95+ className = "components-spacing-sizes-control__custom-toggle"
96+ />
97+ </ HStack >
8798 { showCustomValueControl && (
8899 < div >
89100 < UnitControl
90- label = { props . label }
101+ label = { label }
91102 onChange = { ( newSize ) =>
92- props . onChange ( getNewCustomValue ( newSize ) )
103+ onChange ( getNewCustomValue ( newSize ) )
93104 }
94105 value = "28%"
95106 />
96107
97108 < RangeControl
98- value = { props . value }
109+ value = { value }
99110 label = { < > </ > }
100111 min = { 0 }
101112 max = { 50 }
102113 // initialPosition={ 0 }
103114 withInputField = { false }
104- onChange = { ( value ) => console . log ( value ) }
115+ onChange = { ( newValue ) => console . log ( newValue ) }
105116 // step={ step }
106117 />
107118 </ div >
108119 ) }
109120 { ! useSelect && ! showCustomValueControl && (
110121 < RangeControl
111- value = { props . value }
122+ value = { value }
112123 label = { < > </ > }
113124 onChange = { ( newSize ) =>
114- props . onChange ( getNewRangeValue ( newSize ) )
125+ onChange ( getNewRangeValue ( newSize ) )
115126 }
116- onFocus = { createHandleOnFocus ( props . side ) }
117127 withInputField = { false }
118128 aria-valuenow = { valueNow }
119- aria-valuetext = { props . spacingSizes [ valueNow ] ?. name }
129+ aria-valuetext = { spacingSizes [ valueNow ] ?. name }
120130 renderTooltipContent = { customTooltipContent }
121131 min = { 0 }
122- max = { props . spacingSizes . length - 1 }
132+ max = { spacingSizes . length - 1 }
123133 marks = { marks }
124134 />
125135 ) }
@@ -128,15 +138,15 @@ export default function SpacingRangeControl( props ) {
128138 value = { options . find (
129139 ( option ) => option . key === valueNow
130140 ) }
131- label = { props . label }
141+ label = { label }
132142 onChange = { ( selectedItem ) => {
133- props . onChange ( getNewRangeValue ( selectedItem . key ) ) ;
143+ onChange ( getNewRangeValue ( selectedItem . key ) ) ;
134144 } }
135- onFocus = { createHandleOnFocus ( props . side ) }
145+ onFocus = { createHandleOnFocus ( side ) }
136146 options = { options }
137147 onHighlightedIndexChange = { ( index ) => {
138148 if ( index . type === '__item_mouse_move__' ) {
139- props . onChange (
149+ onChange (
140150 getNewRangeValue ( index . highlightedIndex )
141151 ) ;
142152 }
0 commit comments