vendor: amis 6.13.0 base (fork root)
This commit is contained in:
59
packages/amis-ui/examples/form/Combo.tsx
Normal file
59
packages/amis-ui/examples/form/Combo.tsx
Normal file
@@ -0,0 +1,59 @@
|
||||
import React from 'react';
|
||||
import {Button, Combo, Form, Controller, InputBox} from 'amis-ui';
|
||||
|
||||
export default function ButtonExamples() {
|
||||
const handleSubmit = React.useCallback((data: any) => {
|
||||
console.log('submit', data);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="wrapper">
|
||||
<Form defaultValue={{items: [{a: 1, b: 2}]}} onSubmit={handleSubmit}>
|
||||
{({control, onSubmit}) => {
|
||||
return (
|
||||
<>
|
||||
<Combo
|
||||
name="items"
|
||||
control={control}
|
||||
minLength={2}
|
||||
maxLength={5}
|
||||
itemRender={({control}) => (
|
||||
<>
|
||||
<Controller
|
||||
name="key"
|
||||
control={control}
|
||||
isRequired
|
||||
render={({field, fieldState}) => (
|
||||
<InputBox
|
||||
{...field}
|
||||
placeholder="Key"
|
||||
hasError={!!fieldState.error}
|
||||
disabled={false}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
name="title"
|
||||
control={control}
|
||||
isRequired
|
||||
render={({field, fieldState}) => (
|
||||
<InputBox
|
||||
{...field}
|
||||
placeholder="Title"
|
||||
hasError={!!fieldState.error}
|
||||
disabled={false}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
/>
|
||||
<Button onClick={onSubmit}>Submit</Button>
|
||||
</>
|
||||
);
|
||||
}}
|
||||
</Form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
63
packages/amis-ui/examples/form/ControlledForm.tsx
Normal file
63
packages/amis-ui/examples/form/ControlledForm.tsx
Normal file
@@ -0,0 +1,63 @@
|
||||
import React from 'react';
|
||||
import {Button, Combo, Form, Controller, InputBox} from 'amis-ui';
|
||||
|
||||
export default function ControlledFormExamples() {
|
||||
const [formValues, setFormValues] = React.useState<{
|
||||
a: any;
|
||||
b: any;
|
||||
}>({a: 1, b: 2});
|
||||
const handleSubmit = React.useCallback((data: any) => {
|
||||
console.log('submit', data);
|
||||
}, []);
|
||||
const handleChange = React.useCallback((values: any) => {
|
||||
setFormValues(values);
|
||||
}, []);
|
||||
const handleRandomChange = React.useCallback(() => {
|
||||
setFormValues({
|
||||
a: Math.random(),
|
||||
b: Math.random()
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="wrapper">
|
||||
<Form value={formValues} onSubmit={handleSubmit} onChange={handleChange}>
|
||||
{({control, onSubmit}) => {
|
||||
return (
|
||||
<>
|
||||
<Controller
|
||||
name="a"
|
||||
control={control}
|
||||
isRequired
|
||||
render={({field, fieldState}) => (
|
||||
<InputBox
|
||||
{...field}
|
||||
placeholder="Key"
|
||||
hasError={!!fieldState.error}
|
||||
disabled={false}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
name="b"
|
||||
control={control}
|
||||
isRequired
|
||||
render={({field, fieldState}) => (
|
||||
<InputBox
|
||||
{...field}
|
||||
placeholder="Title"
|
||||
hasError={!!fieldState.error}
|
||||
disabled={false}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
<Button onClick={handleRandomChange}>修改</Button>
|
||||
<Button onClick={onSubmit}>Submit</Button>
|
||||
</>
|
||||
);
|
||||
}}
|
||||
</Form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
50
packages/amis-ui/examples/form/InputTable.tsx
Normal file
50
packages/amis-ui/examples/form/InputTable.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
import React from 'react';
|
||||
import {Button, InputTable, Form, Controller, InputBox} from 'amis-ui';
|
||||
|
||||
export default function ButtonExamples() {
|
||||
const handleSubmit = React.useCallback((data: any) => {
|
||||
console.log('submit', data);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="wrapper">
|
||||
<Form defaultValue={{items: [{a: 1, b: 2}]}} onSubmit={handleSubmit}>
|
||||
{({control, onSubmit}) => {
|
||||
return (
|
||||
<>
|
||||
<InputTable
|
||||
name="items"
|
||||
control={control}
|
||||
minLength={2}
|
||||
maxLength={5}
|
||||
columns={[
|
||||
{
|
||||
title: 'Name',
|
||||
tdRender: ({control}) => {
|
||||
return (
|
||||
<Controller
|
||||
name="key"
|
||||
control={control}
|
||||
isRequired
|
||||
render={({field, fieldState}) => (
|
||||
<InputBox
|
||||
{...field}
|
||||
placeholder="Key"
|
||||
hasError={!!fieldState.error}
|
||||
disabled={false}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
]}
|
||||
/>
|
||||
<Button onClick={onSubmit}>Submit</Button>
|
||||
</>
|
||||
);
|
||||
}}
|
||||
</Form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
71
packages/amis-ui/examples/form/MixedInput.tsx
Normal file
71
packages/amis-ui/examples/form/MixedInput.tsx
Normal file
@@ -0,0 +1,71 @@
|
||||
import React from 'react';
|
||||
import {Button, InputTable, Form, Controller, MixedInput} from 'amis-ui';
|
||||
|
||||
export default function MixedInputExamples() {
|
||||
const handleSubmit = React.useCallback((data: any) => {
|
||||
alert(JSON.stringify(data, null, 2));
|
||||
}, []);
|
||||
|
||||
const methods = React.useMemo(
|
||||
() => [
|
||||
{
|
||||
label: '%',
|
||||
pipeIn: (value: any) => {
|
||||
return value ? value.replace('%', '') : '';
|
||||
},
|
||||
pipeOut: (value: any) => {
|
||||
return value ? `${value}%` : '';
|
||||
},
|
||||
test: (value: any) => {
|
||||
return typeof value === 'string' && value.endsWith('%');
|
||||
},
|
||||
value: 'percent'
|
||||
},
|
||||
{
|
||||
label: 'px',
|
||||
type: 'number',
|
||||
inputSettings: {
|
||||
precision: 2
|
||||
},
|
||||
pipeIn: (value: any) => {
|
||||
return value ? parseFloat(value.replace('px', '')) || 0 : '';
|
||||
},
|
||||
pipeOut: (value: any) => {
|
||||
return value ? `${value}px` : '';
|
||||
},
|
||||
test: (value: any) => {
|
||||
return typeof value === 'string' && value.endsWith('px');
|
||||
},
|
||||
value: 'pixel'
|
||||
}
|
||||
],
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="wrapper">
|
||||
<Form defaultValue={{}} onSubmit={handleSubmit}>
|
||||
{({control, onSubmit, getValues}) => {
|
||||
return (
|
||||
<>
|
||||
<Controller
|
||||
name="a"
|
||||
control={control}
|
||||
isRequired
|
||||
render={({field, fieldState}) => (
|
||||
<MixedInput
|
||||
{...field}
|
||||
hasError={!!fieldState.error}
|
||||
disabled={false}
|
||||
methods={methods}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
<Button onClick={onSubmit}>Submit</Button>
|
||||
</>
|
||||
);
|
||||
}}
|
||||
</Form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user