Skip to content

Commit 3369198

Browse files
(Tree): define FormItem
1 parent c377e8a commit 3369198

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/scripts/Form.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { FC, HTMLAttributes } from 'react';
1+
import React, { useContext, FC, HTMLAttributes } from 'react';
22
import classnames from 'classnames';
33
import { FormElement } from './FormElement';
44

@@ -20,6 +20,32 @@ export const FormTypeContext =
2020
*/
2121
const IsFormContext = React.createContext<boolean>(false);
2222

23+
/**
24+
*
25+
*/
26+
export const FormItem: FC<{
27+
commonClassNames?: string;
28+
children: (commonClassName: string) => JSX.Element;
29+
}> = ({ commonClassNames, children }) => {
30+
const isForm = useContext(IsFormContext);
31+
const type = useContext(FormTypeContext);
32+
33+
if (!isForm || type === 'inline') {
34+
return children(commonClassNames ?? '');
35+
}
36+
37+
return (
38+
<div
39+
className={classnames('slds-form__item', commonClassNames)}
40+
role='listitem'
41+
>
42+
<IsFormContext.Provider value={false}>
43+
{children('')}
44+
</IsFormContext.Provider>
45+
</div>
46+
);
47+
};
48+
2349
/**
2450
*
2551
*/

0 commit comments

Comments
 (0)