UNPKG

@transact-open-ux/react

Version:

Library to integrate React with Transact Open UX

39 lines (38 loc) 1.33 kB
import { FunctionComponent } from "react"; export interface FormState { [key: string]: any; } export interface VisibilityProps { /** * The children of the visibility condition component will show if the function returns true */ children: any; /** * The condition prop is a function that takes the forms state values as a parameter * The children of this component will be visible if the returned value is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). */ condition: (values: FormState) => boolean; } /** * Allows conditional show/hide of elements based on a condition function passed as a prop. * <br> * This component needs to be within the `TransactForm` component to work as it uses the form state values. * * ## Example * Shows the Applicant.LastName field when the Applicant.FirstName field is 'Homer' * ```jsx * import { Field } from 'formik'; * import { Visibility } from '@transact-open-ux/react'; * * export const Page = () => ( * <Visibility condition={data => data.Applicant.FirstName === 'Homer'}> * <Field * name="Applicant.LastName" * required * label="Last Name" * /> * </Visibility> * ); * ``` */ export declare const Visibility: FunctionComponent<VisibilityProps>;