Skip to content

Commit

Permalink
✨ Implement the structure and webform fieldset preview
Browse files Browse the repository at this point in the history
Both simply display their nested children.
  • Loading branch information
sergei-maertens committed Aug 16, 2024
1 parent 926295e commit 2980a2f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/registry/fieldset/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import {RegistryEntry} from '@/registry/types';
import EditForm from './edit';
import validationSchema from './edit-validation';
import PanelPreview from './panel-preview';
import StructureSubtreePreview from './structure-preview';
import WebformPreview from './webform-preview';

export default {
edit: EditForm,
editSchema: validationSchema,
preview: {
panel: PanelPreview,
structureSubtree: StructureSubtreePreview,
webform: WebformPreview,
},
defaultValue: undefined, // a fieldset component does not hold a value itself
} satisfies RegistryEntry<FieldsetComponentSchema>;
10 changes: 10 additions & 0 deletions src/registry/fieldset/structure-preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type {FieldsetComponentSchema} from '@open-formulieren/types';

import type {StructureSubtreeProps} from '@/registry/types';

const StructureSubtreePreview: React.FC<StructureSubtreeProps<FieldsetComponentSchema>> = ({
component: {components},
renderSubtree,
}) => <>{renderSubtree(components)}</>;

export default StructureSubtreePreview;
18 changes: 18 additions & 0 deletions src/registry/fieldset/webform-preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type {FieldsetComponentSchema} from '@open-formulieren/types';

import {FieldSet} from '@/components/formio';
import type {WebformPreviewProps} from '@/registry/types';

const WebformPreview: React.FC<WebformPreviewProps<FieldsetComponentSchema>> = ({
component,
renderSubtree,
}) => {
const {label, hideHeader, tooltip, components} = component;
return (
<FieldSet label={hideHeader ? undefined : label} tooltip={tooltip}>
{renderSubtree(components)}
</FieldSet>
);
};

export default WebformPreview;

0 comments on commit 2980a2f

Please sign in to comment.