-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
47 lines (42 loc) · 1012 Bytes
/
index.js
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
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';
/**
* Internal dependencies
*/
import NumberControl from '../';
export default {
title: 'Components (Experimental)/NumberControl',
component: NumberControl,
argTypes: {
onChange: { action: 'onChange' },
prefix: { control: { type: 'text' } },
step: { control: { type: 'text' } },
suffix: { control: { type: 'text' } },
type: { control: { type: 'text' } },
value: { control: null },
},
};
function Template( { onChange, ...props } ) {
const [ value, setValue ] = useState( '0' );
const [ isValidValue, setIsValidValue ] = useState( true );
return (
<>
<NumberControl
{ ...props }
value={ value }
onChange={ ( v, extra ) => {
setValue( v );
setIsValidValue( extra.event.target.validity.valid );
onChange( v, extra );
} }
/>
<p>Is valid? { isValidValue ? 'Yes' : 'No' }</p>
</>
);
}
export const Default = Template.bind( {} );
Default.args = {
label: 'Value',
};