From 982f95fbde1ee960e1518d29ce3edb373261e3b8 Mon Sep 17 00:00:00 2001 From: _Kerman Date: Fri, 24 Nov 2023 15:01:15 +0800 Subject: [PATCH] upd: add `qSubPage` component --- packages/runtime/src/components/index.ts | 3 ++ packages/runtime/src/components/subPage.r.ts | 44 ++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 packages/runtime/src/components/subPage.r.ts diff --git a/packages/runtime/src/components/index.ts b/packages/runtime/src/components/index.ts index 26a39b9..5bdfe8d 100644 --- a/packages/runtime/src/components/index.ts +++ b/packages/runtime/src/components/index.ts @@ -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"; @@ -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, diff --git a/packages/runtime/src/components/subPage.r.ts b/packages/runtime/src/components/subPage.r.ts new file mode 100644 index 0000000..339f8d9 --- /dev/null +++ b/packages/runtime/src/components/subPage.r.ts @@ -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; + } +}