Skip to content

Commit

Permalink
upd: add qSubPage component
Browse files Browse the repository at this point in the history
  • Loading branch information
KermanX committed Nov 24, 2023
1 parent 3fb6655 commit 982f95f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/runtime/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * from "./input.r";
export * from "./list.r";
export * from "./paragraph.r";
export * from "./span.r";
export * from "./subPage.r";
export * from "./table.r";
export * from "./tableItem.r";
export * from "./textNode.r";
Expand All @@ -22,12 +23,14 @@ import qInput from "./input.r";
import qList from "./list.r";
import qParagraph from "./paragraph.r";
import qSpan from "./span.r";
import qSubPage from "./subPage.r";
import qTable from "./table.r";
import qTableItem from "./tableItem.r";
import qTextNode from "./textNode.r";

export const componentInfoObj = {
qAppLayout,
qSubPage,
qButton,
qCard,
qDiv,
Expand Down
44 changes: 44 additions & 0 deletions packages/runtime/src/components/subPage.r.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { ComponentContext, Content, OutputComponent } from "refina";
import QuasiRuntime from "../plugin";
import { AppLayoutModel, currentNavSymbol } from "./appLayout.r";
import { component, content, input, textProp } from "../types";

export default component({
displayName: () => "Sub page",
contents: {
inner: content("inner"),
},
inputs: {
title: input("title", "as-primary"),
},
props: {
icon: textProp("icon"),
},
});

export interface SubPageProps {
title: string;
icon: string;
inner: Content;
}

@QuasiRuntime.outputComponent("qSubPage")
export class QSubPage extends OutputComponent {
main(_: ComponentContext, props: SubPageProps): void {
const model = _.$runtimeData[currentNavSymbol] as AppLayoutModel;

if (model.renderingState === "nav") {
model.items.push([props.title, props.icon]);
} else {
if (model.current === props.title) {
_.embed(props.inner);
}
}
}
}

declare module "refina" {
interface OutputComponents {
qSubPage: QSubPage;
}
}

0 comments on commit 982f95f

Please sign in to comment.