Skip to content

Commit b058141

Browse files
authored
Add DataForm story about field visibility (#70996)
1 parent 452c28f commit b058141

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

packages/dataviews/src/components/dataform/stories/index.story.tsx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,3 +435,53 @@ export const Validation = {
435435
required: true,
436436
},
437437
};
438+
439+
const DataFormVisibilityComponent = () => {
440+
type Post = {
441+
name: string;
442+
email: string;
443+
isActive: boolean;
444+
};
445+
const [ data, setData ] = useState( {
446+
name: '',
447+
email: '',
448+
isActive: true,
449+
} );
450+
451+
const _fields = [
452+
{ id: 'isActive', label: 'Is module active?', type: 'boolean' },
453+
{
454+
id: 'name',
455+
label: 'Name',
456+
type: 'text',
457+
isVisible: ( post ) => post.isActive === true,
458+
},
459+
{
460+
id: 'email',
461+
label: 'Email',
462+
type: 'email',
463+
isVisible: ( post ) => post.isActive === true,
464+
},
465+
] satisfies Field< Post >[];
466+
const form = {
467+
fields: [ 'isActive', 'name', 'email' ],
468+
};
469+
return (
470+
<DataForm< Post >
471+
data={ data }
472+
fields={ _fields }
473+
form={ form }
474+
onChange={ ( edits ) =>
475+
setData( ( prev ) => ( {
476+
...prev,
477+
...edits,
478+
} ) )
479+
}
480+
/>
481+
);
482+
};
483+
484+
export const Visibility = {
485+
title: 'DataForm/Visibility',
486+
render: DataFormVisibilityComponent,
487+
};

0 commit comments

Comments
 (0)