With build in router! Package size: ~20 KB β¨
import { FigaComponentProps } from "../Figa/Components/Interfaces/FigaComponentProps";
import { FigaUITemplate } from "../Figa/Components/FigaUITemplate";
import { create, cssClass, listen, reactive } from "../Figa/Figa";
import FigaComponent from "../Figa/Components/FigaComponent";
export default class ReactiveButton extends FigaComponent {
protected template(): FigaUITemplate<FigaComponentProps> {
const state = reactive(0);
const btn = create("button");
state.changed(
(v) => (btn.innerHTML = `You ate <span>${v}</span> cookies! πͺ`)
);
listen(btn, "click", () => state.set(state.val + 1));
btn.textContent = "Eat a cookie! πͺ";
cssClass(btn, "reactive-button");
return { element: btn };
}
}
import { FigaComponentProps } from "../Figa/Components/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 { Link } from "../Figa/Router";
export default class Home extends FigaScreen {
public constructor() {
super();
}
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,
boxify(
[new ReactiveButton(), new Link("About β¨", "/about")],
"wrapper"
),
p,
new ReenderStat(start),
],
"figa-content"
),
};
}
public override rendered(): void {
// handle router navigation
// example if user is not login navigate to "/login" page (protect the route)
// if (!login) navigate("/login");
// Refresh Screen all components are rerendered! β
this.refresh();
}
}
import FigaScreen from "./Figa/Components/FigaScreen";
import { RoutesMap } from "./Figa/Types/RoutesMap";
import About from "./Screens/About";
import Home from "./Screens/Home";
import Figa from "./Figa/Figa";
Figa.config({
staticPath: "",
});
export const routes: RoutesMap = new Map([
["/about", new About() as FigaScreen],
["/", new Home()],
]);
import Figa, { find } from "./Figa/Figa";
import { routes } from "./config";
// Main figa app entry π
const main = () => {
const root = find("#app") as HTMLElement;
Figa.initRouter(root, routes, {
animation: "slide-up",
duration: 400,
});
};
document.addEventListener("DOMContentLoaded", main);