1.0.1 • Published 7 months ago

tauri-plugin-htmx v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

tauri-plugin-htmx

htmx plugin for Tauri

How it works

tauri-plugin-htmx works by creating a fake ajax response by patching XMLHttpRequest.send().

How to use

  1. Start a Tauri project using create-tauri-app and choosing "Vanilla" Javascript/Typescript as frontend.

    $ cargo create-tauri-app                                                  
    ✔ Project name · tauri-htmx-ts
    ✔ Choose which language to use for your frontend · TypeScript / JavaScript - (pnpm, yarn, npm, bun)
    ✔ Choose your package manager · npm
    ✔ Choose your UI template · Vanilla
    ✔ Choose your UI flavor · TypeScript
    
    Template created! To get started run:
    cd tauri-htmx-ts
    npm install
    npm run tauri dev
  2. Install htmx

    npm i htmx.org
  3. Install tauri-plugin-htmx
    npm i tauri-plugin-htmx
  4. Modify the form in index.html to use htmx. Instead of using a URL in hx-post (or hx-get), use the command name prefixed with command: (e.g. command:greet).
    -      <form class="row" id="greet-form">
    -        <input id="greet-input" placeholder="Enter a name..." />
    -        <button type="submit">Greet</button>
    -      </form>
    +      <div class="row">
    +        <input id="greet-input" name="name" placeholder="Enter a name..." />
    +        <button hx-post="command:greet" hx-include="[name='name']" hx-trigger="click" hx-target="#greet-msg" hx-swap="innerHTML">Greet</button>
    +      </div>
  5. Modify main.ts or main.js removing everything and replacing it with just htmx and tauri-plugin-htmx imports.

    // main.ts
    import "htmx.org";
    import "tauri-plugin-htmx";

    If you are using JavaScript as frontend, you need to copy the JS files from node_modules.

    cp node_modules/htmx.org/dist/htmx.min.js src
    cp node_modules/tauri-plugin-htmx/tauri-plugin-htmx.js src

    Importing will be a little different.

    // main.js
    import "./htmx.min.js";
    import "./tauri-plugin-htmx.js";
  6. Run your Tauri app

    cargo tauri dev

    Vanilla TypeScript Vanilla JavaScript

Author

Ronie Martinez

1.0.1

7 months ago

1.0.0

7 months ago

0.6.0

7 months ago

0.5.0

7 months ago

0.4.0

7 months ago

0.3.0

7 months ago

0.2.0

7 months ago

0.1.0

7 months ago