Description
The Visibility
component makes it possible to show or hide components on the screen based on the state of data. It can either be fed with the values directly via props, or it can read data from a surrounding DataContext.Provider and show or hide components based on the data it points to.
Demos
Direct properties
This is visible
<Visibility visible={true}>This is visible</Visibility>
False (not visible)
<Visibilityvisible={{foo: 'foo',}.foo === 'bar'}>This is not visible</Visibility>
Based on DataContext
This will show, as long as `toBe` is true.
<DataContext.Context.Providervalue={{...defaultContextState,data: {toBe: true,notToBe: false,},}}><Visibility pathTrue="/toBe"><p>This will show, as long as `toBe` is true.</p></Visibility><Visibility pathTrue="/notToBe"><p>This will not show until `notToBe` is true.</p></Visibility></DataContext.Context.Provider>
Properties
Property | Type | Description |
---|---|---|
visible | boolean | (optional) Control visibility directly by boolean value. |
pathDefined | string | (optional) Given data context path must be defined to show children. |
pathUndefined | string | (optional) Given data context path must be undefined to show children. |
pathTruthy | string | (optional) Given data context path must be truthy to show children. |
pathFalsy | string | (optional) Given data context path must be falsy to show children. |
pathTrue | string | (optional) Given data context path must be true to show children. |
pathFalse | string | (optional) Given data context path must be false to show children. |
inferData | function | (optional) Will be called to decide by external logic, and show/hide contents based on the return value. |
children | React.Node | (required) Contents. |