0.4.1 • Published 12 months ago

adonis-htmx v0.4.1

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

Adonis HTMX

typescript-image npm-image license-image

Better HTMX development with AdonisJS framework.

Instalation

Install and configure it in two steps.

# npm
npm i adonis-htmx
node ace configure adonis-htmx

Or use ace add command that combines those two steps:

node ace add adonis-htmx

Api

Request

You can check if given request has been made by htmx and act accordingly

async function handle({ request }: HtppContext) {
  if(request.htmx) {
    // Request has been made by HTMX - you can now use request.htmx to get access to HTMX related info e.g.
    request.htmx.boosted // true if boosted
  }
}

Response

The provider adds set of htmxX properties to Response. This introduces fluent interface for setting correct htmx headers.

async function handle({ response, view }: HttpContext) {

  response
    .htmxLocation('/client-redirect')
    .htmxTrigger('some-event')

  return view('page/test', { data });
}

Properties that expect urls (htmxLocation, htmxRedirect, htmxPushUrl, htmxReplaceUrl) can be provided with route definitions in a form of [string, params, options] - these are passed to router.makeUrl function to resolve the final path e.g:

async function handle({ response, view }: HttpContext) {

  response
    .htmxLocation(['profile.show', { userId: 4 }])

  return response.status(200)
}
0.4.1

12 months ago

0.4.0

1 year ago

0.3.4

1 year ago

0.3.3

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.1-0

1 year ago

0.2.0-0

1 year ago