w3ts-jsx
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

w3ts-jsx

Add JSX to your WC3 maps!

Features

Feature Status
Box model
Base frame types ✔️
Lifecycle methods ❌ (possible with hooks)
JSX ✔️
Class components ✔️
Functional components ✔️
Hooks ✔️
Fragments ✔️

Usage

  1. Install dependencies
npm install -D w3ts-jsx basic-pragma
  1. Configure tsconfig.json
{
  "compilerOptions": {
    "jsx": "react",
    "jsxFactory": "createElement",
    "jsxFragmentFactory": "Fragment"
  }
}
  1. Implement a JSX component
import { createElement, useEffect, useState } from "w3ts-jsx";
import { Timer } from "@voces/w3ts";

export const App = () => {
  const [count, setCount] = useState(0);

  useEffect(() => {
    const timer = new Timer();
    timer.start(1, true, () => setCount((c) => c + 1));

    return () => timer.destroy();
  }, []);

  return (
    <button
      inherits="ScoreScreenTabButtonTemplate"
      absPosition={{ point: FRAMEPOINT_CENTER, x: 0.4, y: 0.3 }}
      size={{ width: 0.1, height: 0.04 }}
      onClick={() => print("Button Clicked")}
    >
      <backdrop
        position="parent"
        texture="ReplaceableTextures\\CommandButtons\\BTNSelectHeroOn"
      />
      <text text={`Waited ${count} seconds`} position="parent" />
    </button>
  );
};
  1. Render it
import { adapter, createElement, render, setAdapter } from "w3ts-jsx";
import { App } from "./App";

setAdapter(adapter);

render(<App />, BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0));

Examples

Readme

Keywords

none

Package Sidebar

Install

npm i w3ts-jsx

Weekly Downloads

12

Version

3.0.1

License

ISC

Unpacked Size

138 kB

Total Files

12

Last publish

Collaborators

  • voces