11import type { Meta , StoryObj } from '@storybook/react' ;
2- import { SchemaRenderer } from '../SchemaRenderer ' ;
2+ import { SchemaRenderer , SchemaRendererProvider } from '@object-ui/react ' ;
33import type { BaseSchema } from '@object-ui/types' ;
4+ import { createStorybookDataSource } from '@storybook-config/datasource' ;
45
56const meta = {
67 title : 'Views/Object Form' ,
@@ -17,14 +18,21 @@ const meta = {
1718export default meta ;
1819type Story = StoryObj < typeof meta > ;
1920
20- const renderStory = ( args : any ) => < SchemaRenderer schema = { args as unknown as BaseSchema } /> ;
21+ // Create a DataSource instance that connects to MSW
22+ const dataSource = createStorybookDataSource ( ) ;
23+
24+ const renderStory = ( args : any ) => (
25+ < SchemaRendererProvider dataSource = { dataSource } >
26+ < SchemaRenderer schema = { args as unknown as BaseSchema } />
27+ </ SchemaRendererProvider >
28+ ) ;
2129
2230export const BasicSchema : Story = {
2331 render : renderStory ,
2432 args : {
2533 type : 'object-form' ,
2634 objectName : 'User' ,
27- fields : [
35+ customFields : [
2836 { name : 'firstName' , label : 'First Name' , type : 'text' , required : true } ,
2937 { name : 'lastName' , label : 'Last Name' , type : 'text' , required : true } ,
3038 { name : 'email' , label : 'Email' , type : 'email' , required : true } ,
@@ -66,7 +74,7 @@ export const ComplexFields: Story = {
6674 args : {
6775 type : 'object-form' ,
6876 objectName : 'Product' ,
69- fields : [
77+ customFields : [
7078 { name : 'name' , label : 'Product Name' , type : 'text' , required : true } ,
7179 { name : 'category' , label : 'Category' , type : 'select' , options : [ 'Electronics' , 'Clothing' , 'Food' ] , required : true } ,
7280 { name : 'price' , label : 'Price' , type : 'number' , required : true } ,
@@ -76,3 +84,47 @@ export const ComplexFields: Story = {
7684 className : 'w-full max-w-2xl'
7785 } as any ,
7886} ;
87+
88+ /**
89+ * Contact Form - Uses MSW-backed schema from ObjectStack runtime
90+ *
91+ * This story demonstrates integration with the MSW plugin runtime mode.
92+ * The form schema is fetched from /api/v1/metadata/contact via the ObjectStack kernel.
93+ */
94+ export const ContactForm : Story = {
95+ render : renderStory ,
96+ args : {
97+ type : 'object-form' ,
98+ objectName : 'contact' ,
99+ customFields : [
100+ { name : 'name' , label : 'Name' , type : 'text' , required : true } ,
101+ { name : 'email' , label : 'Email' , type : 'email' , required : true } ,
102+ { name : 'phone' , label : 'Phone' , type : 'tel' } ,
103+ { name : 'title' , label : 'Title' , type : 'text' } ,
104+ { name : 'company' , label : 'Company' , type : 'text' } ,
105+ { name : 'status' , label : 'Status' , type : 'select' , options : [ 'Active' , 'Lead' , 'Customer' ] }
106+ ] ,
107+ className : 'w-full max-w-2xl'
108+ } as any ,
109+ } ;
110+
111+ /**
112+ * Opportunity Form - Uses MSW-backed schema from ObjectStack runtime
113+ *
114+ * This story demonstrates creating/editing opportunity records via MSW runtime.
115+ */
116+ export const OpportunityForm : Story = {
117+ render : renderStory ,
118+ args : {
119+ type : 'object-form' ,
120+ objectName : 'opportunity' ,
121+ customFields : [
122+ { name : 'name' , label : 'Opportunity Name' , type : 'text' , required : true } ,
123+ { name : 'amount' , label : 'Amount' , type : 'number' , required : true } ,
124+ { name : 'stage' , label : 'Stage' , type : 'select' , options : [ 'Prospecting' , 'Qualification' , 'Proposal' , 'Negotiation' , 'Closed Won' , 'Closed Lost' ] } ,
125+ { name : 'closeDate' , label : 'Close Date' , type : 'date' } ,
126+ { name : 'description' , label : 'Description' , type : 'textarea' , rows : 4 }
127+ ] ,
128+ className : 'w-full max-w-2xl'
129+ } as any ,
130+ } ;
0 commit comments