-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathtext.tsx
46 lines (42 loc) · 946 Bytes
/
text.tsx
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
/**
* WordPress dependencies
*/
import { TextControl } from '@wordpress/components';
import { useCallback } from '@wordpress/element';
/**
* Internal dependencies
*/
import type { DataFormControlProps } from '../types';
export default function Text< Item >( {
data,
field,
onChange,
hideLabelFromVision,
errorMessage,
}: DataFormControlProps< Item > ) {
const { id, label, placeholder } = field;
const value = field.getValue( { item: data } );
const onChangeControl = useCallback(
( newValue: string ) =>
onChange( {
[ id ]: newValue,
} ),
[ id, onChange ]
);
return (
<>
<TextControl
label={ label }
placeholder={ placeholder }
value={ value ?? '' }
onChange={ onChangeControl }
__next40pxDefaultSize
__nextHasNoMarginBottom
hideLabelFromVision={ hideLabelFromVision }
/>
{ errorMessage && (
<p className="dataform-control-error">{ errorMessage }</p>
) }
</>
);
}