forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
isVisible
option to fields within DataForm (WordPress#65826)
Co-authored-by: louwie17 <[email protected]> Co-authored-by: oandregal <[email protected]> Co-authored-by: youknowriad <[email protected]>
- Loading branch information
1 parent
e62588a
commit 3e151e2
Showing
6 changed files
with
84 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/dataviews/src/components/form-field-visibility/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useMemo } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { NormalizedField } from '../../types'; | ||
|
||
type FormFieldVisibilityProps< Item > = React.PropsWithChildren< { | ||
field: NormalizedField< Item >; | ||
data: Item; | ||
} >; | ||
|
||
export default function FormFieldVisibility< Item >( { | ||
data, | ||
field, | ||
children, | ||
}: FormFieldVisibilityProps< Item > ) { | ||
const isVisible = useMemo( () => { | ||
if ( field.isVisible ) { | ||
return field.isVisible( data ); | ||
} | ||
return true; | ||
}, [ field.isVisible, data ] ); | ||
|
||
if ( ! isVisible ) { | ||
return null; | ||
} | ||
return children; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters