fix form size

This commit is contained in:
rizky 2024-04-12 03:16:39 +00:00
parent ed83357ab5
commit a318a9a7dc
5 changed files with 38 additions and 12 deletions

View File

@ -47,6 +47,7 @@ export const Breadcrumb: FC<BreadcrumbProps> = (_arg) => {
})(); })();
}, [on_load]); }, [on_load]);
return ( return (
<div <div
className={cx( className={cx(

View File

@ -9,6 +9,8 @@ import get from "lodash.get";
import { Field } from "./field/Field"; import { Field } from "./field/Field";
import { getProp } from "../../.."; import { getProp } from "../../..";
const editorFormWidth = {} as Record<string, { w: number; f: any }>;
export const Form: FC<FMProps> = (props) => { export const Form: FC<FMProps> = (props) => {
const { PassProp, body } = props; const { PassProp, body } = props;
const fm = useLocal<FMInternal>({ const fm = useLocal<FMInternal>({
@ -32,9 +34,13 @@ export const Form: FC<FMProps> = (props) => {
}, },
props: {} as any, props: {} as any,
size: { size: {
width: 0, width: editorFormWidth[props.item.id]
? editorFormWidth[props.item.id].w
: 0,
height: 0, height: 0,
field: "full", field: editorFormWidth[props.item.id]
? editorFormWidth[props.item.id].f
: "full",
}, },
}); });
@ -44,7 +50,8 @@ export const Form: FC<FMProps> = (props) => {
if (e.contentRect.width > 0) { if (e.contentRect.width > 0) {
fm.size.height = e.contentRect.height; fm.size.height = e.contentRect.height;
fm.size.width = e.contentRect.width; fm.size.width = e.contentRect.width;
if (fm.status === "ready") fm.status = "resizing";
if (fm.status === "ready" && !isEditor) fm.status = "resizing";
if (fm.props.layout === "auto") { if (fm.props.layout === "auto") {
if (fm.size.width > 650) { if (fm.size.width > 650) {
@ -57,6 +64,13 @@ export const Form: FC<FMProps> = (props) => {
if (fm.props.layout === "2-col") fm.size.field = "half"; if (fm.props.layout === "2-col") fm.size.field = "half";
} }
if (isEditor) {
editorFormWidth[props.item.id] = {
w: fm.size.width,
f: fm.size.field,
};
}
fm.render(); fm.render();
} }
}), }),
@ -87,10 +101,12 @@ export const Form: FC<FMProps> = (props) => {
fm.submit(); fm.submit();
}} }}
ref={(el) => { ref={(el) => {
if (!ref.current.el && el) { if (el) {
if (!ref.current.el) {
ref.current.el = el; ref.current.el = el;
ref.current.rob.observe(el); ref.current.rob.observe(el);
} }
}
}} }}
className={cx( className={cx(
"form c-flex-1 c-w-full c-h-full c-relative c-overflow-auto" "form c-flex-1 c-w-full c-h-full c-relative c-overflow-auto"

View File

@ -13,7 +13,7 @@ export const InputText: FC<{ field: FieldLocal; fm: FMLocal }> = ({
fm.data[field.name] = ev.currentTarget.value; fm.data[field.name] = ev.currentTarget.value;
fm.render(); fm.render();
}} }}
value={value} value={value || ''}
disabled={field.disabled} disabled={field.disabled}
className="c-flex-1 c-rounded c-bg-transparent c-outline-none c-px-2 c-text-sm" className="c-flex-1 c-rounded c-bg-transparent c-outline-none c-px-2 c-text-sm"
spellCheck={false} spellCheck={false}

View File

@ -5,6 +5,12 @@ import { useEffect } from "react";
export const useField = (arg: FieldProp) => { export const useField = (arg: FieldProp) => {
const field = useLocal<FieldInternal>({ const field = useLocal<FieldInternal>({
status: "init", status: "init",
Child: () => {
return <arg.PassProp>{arg.child}</arg.PassProp>;
},
} as any);
const update_field = {
name: arg.name, name: arg.name,
label: arg.label, label: arg.label,
type: arg.type, type: arg.type,
@ -16,10 +22,10 @@ export const useField = (arg: FieldProp) => {
required_msg: arg.required_msg, required_msg: arg.required_msg,
focused: false, focused: false,
disabled: arg.disabled === "y", disabled: arg.disabled === "y",
Child: () => { };
return <arg.PassProp>{arg.child}</arg.PassProp>; for (const [k, v] of Object.entries(update_field)) {
}, (field as any)[k] = v;
}); }
const fm = arg.fm; const fm = arg.fm;

View File

@ -12,7 +12,10 @@ export const should_show_tab = (md: MDLocal) => {
export const MDTab: FC<{ md: MDLocal; mdr: MDRef }> = ({ md, mdr }) => { export const MDTab: FC<{ md: MDLocal; mdr: MDRef }> = ({ md, mdr }) => {
const detail = md.childs[md.tab.active]; const detail = md.childs[md.tab.active];
const PassProp = mdr.PassProp; const PassProp = mdr.PassProp;
if (!detail) return null; if (!detail) {
return null;
}
return ( return (
<> <>