(props: T)
| 41 | |
| 42 | export const FormContext = createContext<Partial<FormStyleProps | null>>(null); |
| 43 | export function useFormProps<T extends FormStyleProps>(props: T): T { |
| 44 | let ctx = useContext(FormContext); |
| 45 | let isSkeleton = useIsSkeleton(); |
| 46 | return useMemo(() => { |
| 47 | let result: T = props; |
| 48 | if (ctx || isSkeleton) { |
| 49 | result = {...props}; |
| 50 | } |
| 51 | |
| 52 | if (ctx) { |
| 53 | // This is a subset of mergeProps. We just need to merge non-undefined values. |
| 54 | for (let key in ctx) { |
| 55 | if (result[key] === undefined) { |
| 56 | result[key] = ctx[key]; |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | // Skeleton always wins over local props. |
| 62 | if (isSkeleton) { |
| 63 | result.isDisabled = true; |
| 64 | } |
| 65 | |
| 66 | return result; |
| 67 | }, [ctx, props, isSkeleton]); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Forms allow users to enter data that can be submitted while providing alignment and styling for |
no test coverage detected