Skip to content

Commit

Permalink
Remove sample field example
Browse files Browse the repository at this point in the history
  • Loading branch information
louwie17 committed Oct 28, 2024
1 parent 4803094 commit 7f0fe61
Showing 1 changed file with 3 additions and 33 deletions.
36 changes: 3 additions & 33 deletions packages/dataviews/src/components/dataform/stories/index.story.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { useMemo, useState } from '@wordpress/element';
import { useState } from '@wordpress/element';

/**
* Internal dependencies
Expand All @@ -17,7 +17,6 @@ type SamplePost = {
reviewer: string;
date: string;
birthdate: string;
sampleField?: string;
password?: string;
};

Expand All @@ -31,15 +30,6 @@ const meta = {
'Chooses the layout of the form. "regular" is the default layout.',
options: [ 'regular', 'panel' ],
},
sampleFieldType: {
name: 'Sample Field Type',
control: { type: 'select' },
description: 'Chooses the type of the sample field.',
options: [ 'text', 'integer', 'datetime' ],
},
},
args: {
sampleFieldType: 'text',
},
};
export default meta;
Expand Down Expand Up @@ -109,26 +99,7 @@ const fields = [
},
] as Field< SamplePost >[];

export const Default = ( {
type,
sampleFieldType = 'text',
}: {
type: 'panel' | 'regular';
sampleFieldType: 'text' | 'integer' | 'datetime';
} ) => {
const visibileFields = useMemo( () => {
return [
...fields,
{
id: 'sampleField',
label: 'Sample Field',
type: sampleFieldType,
isVisible: ( item: SamplePost ) => {
return item.order < 3 && item.sampleField !== 'hide';
},
},
] as Field< SamplePost >[];
}, [ sampleFieldType ] );
export const Default = ( { type }: { type: 'panel' | 'regular' } ) => {
const [ post, setPost ] = useState( {
title: 'Hello, World!',
order: 2,
Expand All @@ -142,7 +113,6 @@ export const Default = ( {
const form = {
fields: [
'title',
'sampleField',
'order',
'author',
'reviewer',
Expand All @@ -156,7 +126,7 @@ export const Default = ( {
return (
<DataForm< SamplePost >
data={ post }
fields={ visibileFields }
fields={ fields }
form={ {
...form,
type,
Expand Down

0 comments on commit 7f0fe61

Please sign in to comment.