Skip to content

Commit

Permalink
textNode function
Browse files Browse the repository at this point in the history
  • Loading branch information
Just-a-Jason committed Jul 19, 2024
1 parent 6961355 commit e988ae5
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 12 deletions.
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"dependencies": {
"@tauri-apps/api": "^1",
"@types/node": "^20.14.11",
"sass": "^1.77.8"
},
"devDependencies": {
Expand Down
18 changes: 18 additions & 0 deletions src/Figa/Figa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Router, { RouterOptions } from "./Router";
import FigaConfig from "./Interfaces/FigaConfig";
import { RoutesMap } from "./Types/RoutesMap";
import { Nullable } from "./Types/Nullable";
import { HtmlTextNode, HtmlTextNodeProps } from "./Types/HtmlTextNode";

export const removeChildren = (
el: HTMLElement | FigaComponent | DocumentFragment
Expand Down Expand Up @@ -173,3 +174,20 @@ export const img = (src: string, alt?: string): HTMLImageElement => {

return img;
};

export const textNode = <K extends HtmlTextNode>(
type: K,
props: HtmlTextNodeProps
): HTMLElementTagNameMap[K] => {
const element = create(type);

if (props.content) element.textContent = props.content;
if (props.innerHtml) element.innerHTML = props.innerHtml;
if (props.cssClasses) {
if (typeof props.cssClasses === "string")
element.classList.add(props.cssClasses);
else props.cssClasses.forEach((css) => element.classList.add(css));
}

return element;
};
19 changes: 19 additions & 0 deletions src/Figa/Types/HtmlTextNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export type HtmlTextNode =
| "h1"
| "h2"
| "h3"
| "h4"
| "h5"
| "h6"
| "p"
| "code"
| "span"
| "b"
| "i"
| "blockquote";

export interface HtmlTextNodeProps {
cssClasses?: string | string[];
innerHtml?: string;
content?: string;
}
21 changes: 9 additions & 12 deletions src/Screens/Home.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { FigaComponentProps } from "../Figa/Interfaces/FigaComponentProps";
import { FigaUITemplate } from "../Figa/Components/FigaUITemplate";
import { boxify, create, cssClass, img } from "../Figa/Figa";
import ReactiveButton from "../Components/ReactiveButton";
import FigaScreen from "../Figa/Components/FigaScreen";
import ReenderStat from "../Components/RenderStat";
import { boxify, img, textNode } from "../Figa/Figa";
import RenderStat from "../Components/RenderStat";
import { Link } from "../Figa/Router";
import "./Home.scss";

Expand All @@ -15,23 +15,20 @@ export default class Home extends FigaScreen {
protected template(): FigaUITemplate<FigaComponentProps> {
const start = performance.now();

const i = img("assets/icons/figa-icon.png");

const p = create("p");

p.innerHTML = "Edit: <span>src/Screens/Home.ts</span> to modify the page!";
cssClass(p, "figa-modify");

return {
element: boxify(
[
i,
img("assets/icons/figa-icon.png"),
boxify(
[new ReactiveButton(), new Link("About ✨", "/about")],
"wrapper"
),
p,
new ReenderStat(start),
textNode("p", {
innerHtml:
"Edit: <span>src/Screens/Home.ts</span> to modify the page!",
cssClasses: "figa-modify",
}),
new RenderStat(start),
],
"figa-content"
),
Expand Down

0 comments on commit e988ae5

Please sign in to comment.