forked from microsoft/fluentui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderField.tsx
More file actions
36 lines (31 loc) · 1.16 KB
/
renderField.tsx
File metadata and controls
36 lines (31 loc) · 1.16 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
/** @jsxRuntime automatic */
/** @jsxImportSource @fluentui/react-jsx-runtime */
import { assertSlots } from '@fluentui/react-utilities';
import type { JSXElement } from '@fluentui/react-utilities';
import { FieldContextProvider, getFieldControlProps } from '../../contexts/index';
import type { FieldContextValues, FieldSlots, FieldBaseState } from './Field.types';
/**
* Render the final JSX of Field
*/
export const renderField_unstable = (state: FieldBaseState, contextValues: FieldContextValues): JSXElement => {
assertSlots<FieldSlots>(state);
let { children } = state;
if (typeof children === 'function') {
children = children(getFieldControlProps(contextValues.field) || {});
}
return (
<FieldContextProvider value={contextValues?.field}>
<state.root>
{state.label && <state.label />}
{children}
{state.validationMessage && (
<state.validationMessage>
{state.validationMessageIcon && <state.validationMessageIcon />}
{state.validationMessage.children}
</state.validationMessage>
)}
{state.hint && <state.hint />}
</state.root>
</FieldContextProvider>
);
};