Skip to content

Commit 80a323f

Browse files
author
Administrator
committed
more samples ( custom ctrl )
1 parent f02acfb commit 80a323f

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

src/CascadeForms/CascadeForms.stories.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,24 @@ import "./story.css";
66
import React,{ createRef } from "react";
77
import { ComponentStory, ComponentMeta } from "@storybook/react";
88

9-
import CascadeForms,{ CascadeFormProps,FormActions,FormState,FormItem,OnChangeFn } from "./CascadeForms";
9+
import CascadeForms,{ ControlRenderProps,CascadeFormProps,FormActions,FormState,FormItem,OnChangeFn } from "./CascadeForms";
1010
import FORM from "./form1.json";
1111

12-
import { Button,Checkbox, InputGroup, RadioGroup, Switch } from "@blueprintjs/core";
12+
import { Button,Callout,Checkbox, EditableText, InputGroup, RadioGroup, Switch } from "@blueprintjs/core";
13+
14+
15+
const CustomCtrl = (props:ControlRenderProps) => {
16+
const { item,formState, onChange } = props;
17+
console.log("Custom !");
18+
return (
19+
<div className="customCtrl">
20+
<Callout intent="warning">
21+
Enter some chars..
22+
</Callout>
23+
<EditableText value={formState[item.id]?.value} multiline={true} minLines={5} onChange={(text) => onChange(item.id,text || "") } />
24+
</div>
25+
);
26+
};
1327

1428
const onRender = (formState:FormState,item:FormItem,onChange:OnChangeFn) => {
1529
console.log("onRender",formState);
@@ -20,6 +34,8 @@ const onRender = (formState:FormState,item:FormItem,onChange:OnChangeFn) => {
2034
return <Checkbox value={formState[item.id]?.value || false} label={item.title} onChange={(ev) => onChange(item.id,ev.target.checked)} />;
2135
case "radio":
2236
return <Switch checked={formState[item.id]?.value || false} label={item.title} onChange={(ev) => onChange(item.id,ev.target.checked)} />;
37+
case "custom":
38+
return <CustomCtrl formState={formState} item={item} onChange={onChange} />;
2339
default:
2440
return <div className="default">{item.title}</div>;
2541
}

src/CascadeForms/CascadeForms.types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ export type OnChangeFn = (id:string,value:string) => void;
3131
export type FormControlRenderFn = (formState:FormState,item:FormItem,onChange:OnChangeFn) => JSX.Element;
3232
export type StateUpdateFn = (state:FormState) => void;
3333

34+
export type ControlRenderProps = {
35+
formState:FormState;
36+
item:FormItem;
37+
onChange:OnChangeFn;
38+
}
39+
3440

3541
export type EntryProps = {
3642
item:FormItem;

src/CascadeForms/form1.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
"type":"text",
1212
"title":"Surpise !",
1313
"visible":{ "state":"agree","expect":true }
14+
},
15+
{
16+
"id":"custom",
17+
"type":"custom",
18+
"title":"Custom"
1419
}
1520
]
1621
},

src/CascadeForms/story.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ body {
1515

1616
.formView {
1717
width: 50%;
18+
}
19+
20+
.customCtrl {
21+
color: black;
1822
}

0 commit comments

Comments
 (0)