fixing field

This commit is contained in:
rizky 2024-07-25 22:33:53 -07:00
parent 96d4bf72fb
commit 0e3b4f7c4a
6 changed files with 28 additions and 6 deletions

View File

@ -192,13 +192,12 @@ export function Popover({
const popover = usePopover({ modal, ...restOptions });
let _content = content;
console.log(!content)
if (!content) _content = <div className={"w-[300px] h-[150px]"}></div>;
console.log(typeof restOptions.open)
return (
<PopoverContext.Provider value={popover}>
<PopoverTrigger
asChild
className="c-w-full c-h-full"
onClick={
typeof restOptions.open !== "undefined"
? () => {

View File

@ -25,6 +25,11 @@ export const Field: FC<FieldProp> = (arg) => {
) {
validate(field, fm);
}
if (arg.on_change) {
arg.on_change({ value: fm.data[name], name, fm });
}
fm.events.on_change(name, fm.data[name]);
fm.render();
}

View File

@ -62,7 +62,11 @@ export type FieldProp = {
required: ("y" | "n") | (() => "y" | "n");
field_ref?: (ref: any) => void;
required_msg: (name: string) => string | ReactElement;
on_change: (arg: { value: any }) => void | Promise<void>;
on_change: (arg: {
value: any;
name: string;
fm: any;
}) => void | Promise<void>;
PassProp: any;
disabled: ("y" | "n") | (() => true | false);
child: any;

View File

@ -44,7 +44,7 @@ type LYTChild = {
};
export const Layout: FC<LYTChild> = (props) => {
const local = useLocal({ loading: false });
const local = useLocal({ loading: false, current_menu: "" });
const render = local.render;
useLayoutEffect(() => {
if (!isEditor) {
@ -174,6 +174,8 @@ export const Layout: FC<LYTChild> = (props) => {
local.render();
});
}}
layout={local}
current_menu={local.current_menu}
>
{props.default_layout}
</props.PassProp>

View File

@ -52,6 +52,12 @@ export const Menu: FC<MenuProp> = (props) => {
pm={props}
depth={0}
mode={local.mode}
activate={(label) => {
if (typeof props.layout !== "undefined") {
props.layout.current_menu = label;
props.layout.render();
}
}}
/>
</div>
</div>
@ -72,9 +78,10 @@ export const SideBar: FC<{
depth: number;
pm: MenuProp;
mode: "full" | "mini";
activate: (label: string) => void;
expanded?: boolean;
parent?: string;
}> = ({ data: _data, local, depth, pm, mode, expanded, parent }) => {
}> = ({ data: _data, local, depth, pm, mode, expanded, parent, activate }) => {
const PassProp = pm.PassProp;
w.prasi_menu = {
...w.prasi_menu,
@ -93,6 +100,7 @@ export const SideBar: FC<{
let should_render = false;
if (local.active !== menu.hash && !local.loading) {
local.active = menu.hash;
activate(menu.label);
should_render = true;
}
if (!local.open.has(menu.hash)) {
@ -164,6 +172,7 @@ export const SideBar: FC<{
local.loading = true;
if (typeof menu.value === "string") {
local.active = menu.hash;
clearTimeout(local.nav_timeout);
local.nav_timeout = setTimeout(() => {
if (
@ -182,6 +191,7 @@ export const SideBar: FC<{
!Array.isArray(menu.value) &&
typeof menu.value === "string"
) {
activate(menu.label);
if (pm.on_load) {
if (preloaded(menu.value)) {
pm.on_load((exec) => {
@ -222,6 +232,7 @@ export const SideBar: FC<{
<SideBar
data={menu.value}
local={local}
activate={activate}
depth={(depth || 0) + 1}
pm={pm}
mode={mode}

View File

@ -10,6 +10,7 @@ export type MenuProp = {
mode: "full" | "mini";
item: PrasiItem;
style: "navbar" | "sidebar";
layout?: { current_menu: string; render: () => void };
on_load?: (on_done: (exec: () => void) => void) => void;
get_menu?: (mn: Array<Record<string, IMenu[]>>) => Array<Record<string, IMenu[]>>
};