Move forms to sidepanel

表单组件迁移到 SidePanel
原 Popup 引导打开 SidePanel
优化表单组件和 Hooks,获取 Form 组件 Ref
This commit is contained in:
2024-04-12 14:09:38 +08:00
parent 288de31580
commit 0240b13123
10 changed files with 152 additions and 54 deletions
+10 -4
View File
@@ -1,4 +1,4 @@
import type { FormHTMLAttributes } from "react";
import { useImperativeHandle, type FormHTMLAttributes, useRef, forwardRef, type Ref } from "react";
import { clsn } from "~utils";
import styles from "./form.module.less";
@@ -6,12 +6,18 @@ interface FormProps extends FormHTMLAttributes<HTMLFormElement> {
}
function Form({ children, className, ...props }: FormProps) {
function Form({ children, className, ...props }: FormProps, ref: Ref<HTMLFormElement>) {
const formRef = useRef();
useImperativeHandle(ref, () => {
return formRef.current;
}, []);
return (
<form className={clsn(styles.form, className)} {...props}>
<form ref={formRef} className={clsn(styles.form, className)} {...props}>
{children}
</form>
);
}
export default Form;
export default forwardRef(Form);