Fix: Component optimization
- Enhanced form reference interface functionality and optimized implementation - Optimized modal title area layout and close button position
This commit is contained in:
parent
4fb18fa45d
commit
17df74126d
2 changed files with 27 additions and 22 deletions
|
|
@ -11,6 +11,7 @@ import {
|
||||||
DefaultValues,
|
DefaultValues,
|
||||||
FieldValues,
|
FieldValues,
|
||||||
SubmitHandler,
|
SubmitHandler,
|
||||||
|
UseFormTrigger,
|
||||||
useForm,
|
useForm,
|
||||||
useFormContext,
|
useFormContext,
|
||||||
} from 'react-hook-form';
|
} from 'react-hook-form';
|
||||||
|
|
@ -99,8 +100,9 @@ interface DynamicFormProps<T extends FieldValues> {
|
||||||
// Form ref interface
|
// Form ref interface
|
||||||
export interface DynamicFormRef {
|
export interface DynamicFormRef {
|
||||||
submit: () => void;
|
submit: () => void;
|
||||||
getValues: () => any;
|
getValues: (name?: string) => any;
|
||||||
reset: (values?: any) => void;
|
reset: (values?: any) => void;
|
||||||
|
trigger: UseFormTrigger<any>;
|
||||||
watch: (field: string, callback: (value: any) => void) => () => void;
|
watch: (field: string, callback: (value: any) => void) => () => void;
|
||||||
updateFieldType: (fieldName: string, newType: FormFieldType) => void;
|
updateFieldType: (fieldName: string, newType: FormFieldType) => void;
|
||||||
onFieldUpdate: (
|
onFieldUpdate: (
|
||||||
|
|
@ -704,8 +706,8 @@ const DynamicForm = {
|
||||||
useImperativeHandle(
|
useImperativeHandle(
|
||||||
ref,
|
ref,
|
||||||
() => ({
|
() => ({
|
||||||
submit: () => form.handleSubmit(onSubmit)(),
|
submit: form.handleSubmit,
|
||||||
getValues: () => form.getValues(),
|
getValues: form.getValues,
|
||||||
reset: (values?: T) => {
|
reset: (values?: T) => {
|
||||||
if (values) {
|
if (values) {
|
||||||
form.reset(values);
|
form.reset(values);
|
||||||
|
|
|
||||||
|
|
@ -174,20 +174,23 @@ const Modal: ModalType = ({
|
||||||
onClick={() => maskClosable && onOpenChange?.(false)}
|
onClick={() => maskClosable && onOpenChange?.(false)}
|
||||||
>
|
>
|
||||||
<DialogPrimitive.Content
|
<DialogPrimitive.Content
|
||||||
className={`relative w-[700px] ${full ? 'max-w-full' : sizeClasses[size]} ${className} bg-bg-base rounded-lg shadow-lg border border-border-default transition-all focus-visible:!outline-none`}
|
className={cn(
|
||||||
|
`relative w-[700px] ${full ? 'max-w-full' : sizeClasses[size]} ${className} bg-bg-base rounded-lg shadow-lg border border-border-default transition-all focus-visible:!outline-none`,
|
||||||
|
{ 'pt-10': closable && !title },
|
||||||
|
)}
|
||||||
style={style}
|
style={style}
|
||||||
onClick={(e) => e.stopPropagation()}
|
onClick={(e) => e.stopPropagation()}
|
||||||
>
|
>
|
||||||
{/* title */}
|
{/* title */}
|
||||||
{(title || closable) && (
|
{title && (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
'flex items-start px-6 py-4',
|
'flex items-start px-6 py-4 justify-start',
|
||||||
{
|
// {
|
||||||
'justify-end': closable && !title,
|
// 'justify-end': closable && !title,
|
||||||
'justify-between': closable && title,
|
// 'justify-between': closable && title,
|
||||||
'justify-start': !closable,
|
// 'justify-start': !closable,
|
||||||
},
|
// },
|
||||||
titleClassName,
|
titleClassName,
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
|
|
@ -196,19 +199,19 @@ const Modal: ModalType = ({
|
||||||
{title}
|
{title}
|
||||||
</DialogPrimitive.Title>
|
</DialogPrimitive.Title>
|
||||||
)}
|
)}
|
||||||
{closable && (
|
|
||||||
<DialogPrimitive.Close asChild>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
className="flex h-7 w-7 items-center justify-center text-text-secondary rounded-full hover:text-text-primary focus-visible:outline-none"
|
|
||||||
onClick={handleCancel}
|
|
||||||
>
|
|
||||||
{closeIcon}
|
|
||||||
</button>
|
|
||||||
</DialogPrimitive.Close>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{closable && (
|
||||||
|
<DialogPrimitive.Close asChild>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="flex absolute right-5 top-5 h-7 w-7 items-center justify-center text-text-secondary rounded-full hover:text-text-primary focus-visible:outline-none"
|
||||||
|
onClick={handleCancel}
|
||||||
|
>
|
||||||
|
{closeIcon}
|
||||||
|
</button>
|
||||||
|
</DialogPrimitive.Close>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* content */}
|
{/* content */}
|
||||||
<div className="py-2 px-6 overflow-y-auto scrollbar-auto max-h-[calc(100vh-280px)] focus-visible:!outline-none">
|
<div className="py-2 px-6 overflow-y-auto scrollbar-auto max-h-[calc(100vh-280px)] focus-visible:!outline-none">
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue