Skip to content

Commit

Permalink
✨ Wire up form component to formio render component
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed Dec 22, 2024
1 parent ddba1bf commit 68d85cf
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
28 changes: 28 additions & 0 deletions src/components/FormioComponent.stories.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import {FieldsetComponentSchema, TextFieldComponentSchema} from '@open-formulieren/types';
import type {Meta, StoryObj} from '@storybook/react';

import {withFormik} from '@/sb-decorators';

import FormioComponent from './FormioComponent';

export default {
title: 'Internal API / FormioComponent',
component: FormioComponent,
decorators: [withFormik],
} satisfies Meta<typeof FormioComponent>;

type Story = StoryObj<typeof FormioComponent>;
Expand All @@ -19,6 +22,15 @@ export const TextField: Story = {
label: 'A simple textfield',
} satisfies TextFieldComponentSchema,
},
parameters: {
formik: {
initialValues: {
my: {
textfield: 'some initial value',
},
},
},
},
};

export const FieldSet: Story = {
Expand All @@ -39,6 +51,15 @@ export const FieldSet: Story = {
],
} satisfies FieldsetComponentSchema,
},
parameters: {
formik: {
initialValues: {
my: {
textfield: 'some initial value',
},
},
},
},
};

// TODO: remove story when all component types are implemented
Expand All @@ -52,4 +73,11 @@ export const UnregisteredComponent: Story = {
validateOn: 'blur',
},
},
parameters: {
formik: {
initialValues: {
'component-unregistered': '',
},
},
},
};
File renamed without changes.
14 changes: 8 additions & 6 deletions src/registry/textfield/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import type {TextFieldComponentSchema} from '@open-formulieren/types';

export interface TextFieldProps {
import TextField from '@/components/forms/TextField';

export interface FormioTextFieldProps {
componentDefinition: TextFieldComponentSchema;
}

const TextField: React.FC<TextFieldProps> = ({componentDefinition: {key, label}}) => {
const FormioTextField: React.FC<FormioTextFieldProps> = ({
componentDefinition: {key, label, description, validate},
}) => {
return (
<div>
I am a text field with name {key} and label {label}!
</div>
<TextField name={key} label={label} description={description} isRequired={validate?.required} />
);
};

export default TextField;
export default FormioTextField;

0 comments on commit 68d85cf

Please sign in to comment.