Skip to content

Commit

Permalink
Add page definition
Browse files Browse the repository at this point in the history
Signed-off-by: macdonst <[email protected]>
  • Loading branch information
macdonst committed May 21, 2024
1 parent 8f8293b commit 02732a7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ export type EnhanceHeadFn = (payload: EnhanceHeadFnArg) => EnhanceElemResult;

export type EnhanceElemFn = (payload: EnhanceElemArg) => EnhanceElemResult;

export type EnhancePageFn = EnhanceElemFn;

export type EnhancePreflightFn = (
payload: EnhanceApiReq,
) => Promise<Record<string, any>> | Record<string, any>;
29 changes: 29 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
EnhanceElemFn,
EnhanceHeadFn,
EnhanceHtmlFn,
EnhancePageFn,
EnhancePreflightFn,
} from ".";

Expand Down Expand Up @@ -97,6 +98,34 @@ export const TodoItem: EnhanceElemFn = function ({
`;
};

// Page Element
export const page: EnhancePageFn = function ({
html,
state: { attrs, store, instanceID, context },
}) {
const todoId = attrs["todo-id"];
const completed = typeof attrs.completed === "string";
const myHtml: EnhanceHtmlFn = html;
typeof myHtml === "function";

context.todoId = todoId;

store.myCustomData;

return html`
<div class="flex gap-2 mb-1">
<input
id="todo-${instanceID}"
todo-id="${todoId}"
type="checkbox"
name="completed"
${completed ? "checked" : ""}
/>
<slot></slot>
</div>
`;
};

// Head Function
export const Head: EnhanceHeadFn = function (state) {
const { req, status, error, store } = state;
Expand Down

0 comments on commit 02732a7

Please sign in to comment.