2022-11-08 10:17:56 +08:00
|
|
|
import React from 'react';
|
|
|
|
import {Button, ConfirmBox, Controller, Form, InputBox} from 'amis-ui';
|
|
|
|
|
|
|
|
export default function ButtonExamples() {
|
|
|
|
const [isShow, setIsShow] = React.useState(false);
|
|
|
|
const handleClick = React.useCallback(() => {
|
|
|
|
setIsShow(!isShow);
|
|
|
|
}, [isShow]);
|
|
|
|
const handleCancel = React.useCallback(() => {
|
|
|
|
setIsShow(false);
|
|
|
|
}, []);
|
|
|
|
// const beforeConfirm = React.useCallback(async () => {
|
|
|
|
// return false;
|
|
|
|
// }, []);
|
|
|
|
const handleConfirm = React.useCallback((data: any) => {
|
|
|
|
console.log('confirmed', data);
|
|
|
|
setIsShow(false);
|
|
|
|
}, []);
|
|
|
|
|
2022-11-11 18:27:13 +08:00
|
|
|
async function handleValidate() {
|
|
|
|
return new Promise<void>((resolve, reject) => {
|
|
|
|
// setTimeout(() => reject('error message'), 200);
|
|
|
|
setTimeout(() => resolve(), 200);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-11-08 10:17:56 +08:00
|
|
|
return (
|
|
|
|
<div className="wrapper">
|
|
|
|
<Button onClick={handleClick}>Open</Button>
|
|
|
|
<ConfirmBox
|
|
|
|
type="drawer"
|
|
|
|
size="md"
|
|
|
|
position="bottom"
|
|
|
|
onConfirm={handleConfirm}
|
|
|
|
show={isShow}
|
|
|
|
onCancel={handleCancel}
|
|
|
|
>
|
|
|
|
{({bodyRef}) => (
|
2022-11-11 18:27:13 +08:00
|
|
|
<Form ref={bodyRef} onValidate={handleValidate}>
|
2022-11-08 10:17:56 +08:00
|
|
|
{({control}) => (
|
|
|
|
<>
|
|
|
|
<Controller
|
|
|
|
mode="horizontal"
|
|
|
|
label="A"
|
|
|
|
name="a"
|
|
|
|
control={control}
|
|
|
|
rules={{maxLength: 20}}
|
|
|
|
isRequired
|
|
|
|
render={({field, fieldState}) => (
|
|
|
|
<InputBox
|
|
|
|
{...field}
|
|
|
|
hasError={!!fieldState.error}
|
|
|
|
disabled={false}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Controller
|
|
|
|
mode="horizontal"
|
|
|
|
label="B"
|
|
|
|
name="b"
|
|
|
|
control={control}
|
|
|
|
rules={{maxLength: 20}}
|
|
|
|
isRequired
|
|
|
|
render={({field, fieldState}) => (
|
|
|
|
<InputBox
|
|
|
|
{...field}
|
|
|
|
hasError={!!fieldState.error}
|
|
|
|
disabled={false}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Form>
|
|
|
|
)}
|
|
|
|
</ConfirmBox>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|