-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathIconField.js
42 lines (37 loc) · 1.33 KB
/
IconField.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
import React, { Children, cloneElement, useContext, useRef } from 'react';
import { PrimeReactContext } from '../api/Api';
import { useMergeProps } from '../hooks/Hooks';
import { classNames } from '../utils/Utils';
import { IconFieldBase } from './IconFieldBase';
export const IconField = React.memo(
React.forwardRef((inProps, ref) => {
const elementRef = useRef(ref);
const mergeProps = useMergeProps();
const context = useContext(PrimeReactContext);
const props = IconFieldBase.getProps(inProps, context);
const { ptm, cx } = IconFieldBase.setMetaData({
props,
...props.__parentMetadata,
context: {
iconPosition: props.iconPosition
}
});
const rootProps = mergeProps(
{
className: classNames(props.className, cx('root', { iconPosition: props.iconPosition }))
},
IconFieldBase.getOtherProps(props),
ptm('root')
);
return (
<div {...rootProps} ref={elementRef}>
{Children.map(props.children, (child, index) =>
cloneElement(child, {
iconPosition: props.iconPosition
})
)}
</div>
);
})
);
IconField.displayName = 'IconField';