{-# LANGUAGE OverloadedStrings #-}
module Lucid.Htmx
( hxBoost_,
hxConfirm_,
hxEncoding_,
hxExt_,
hxDelete_,
hxDisable_,
hxGet_,
hxHeaders_,
hxHistoryElt_,
hxInclude_,
hxIndicator_,
hxParams_,
hxPatch_,
hxPost_,
hxPreserve_,
hxPrompt_,
hxPushUrl_,
hxPut_,
hxRequest_,
hxSelect_,
hxSse_,
hxSwapOob_,
hxSwap_,
hxTarget_,
hxTrigger_,
hxVals_,
hxWs_,
useHtmx,
useHtmxExtension,
useHtmxVersion,
useHtmxVersionExtension,
)
where
import Data.Text (Text, pack)
import Lucid (Html, HtmlT, script_, src_)
import Lucid.Base (Attribute, makeAttribute)
hxBoost_ :: Text -> Attribute
hxBoost_ = makeAttribute "data-hx-boost"
hxConfirm_ :: Text -> Attribute
hxConfirm_ = makeAttribute "data-hx-confirm"
hxDelete_ :: Text -> Attribute
hxDelete_ = makeAttribute "data-hx-delete"
hxDisable_ :: Attribute
hxDisable_ = makeAttribute "data-hx-disable" mempty
hxEncoding_ :: Text -> Attribute
hxEncoding_ = makeAttribute "data-hx-encoding"
hxExt_ :: Text -> Attribute
hxExt_ = makeAttribute "data-hx-ext"
hxGet_ :: Text -> Attribute
hxGet_ = makeAttribute "data-hx-get"
hxHeaders_ :: Text -> Attribute
hxHeaders_ = makeAttribute "data-hx-headers"
hxHistoryElt_ :: Attribute
hxHistoryElt_ = makeAttribute "data-hx-history-elt" mempty
hxInclude_ :: Text -> Attribute
hxInclude_ = makeAttribute "data-hx-include"
hxIndicator_ :: Text -> Attribute
hxIndicator_ = makeAttribute "data-hx-indicator"
hxParams_ :: Text -> Attribute
hxParams_ = makeAttribute "data-hx-params"
hxPatch_ :: Text -> Attribute
hxPatch_ = makeAttribute "data-hx-patch"
hxPost_ :: Text -> Attribute
hxPost_ = makeAttribute "data-hx-post"
hxPreserve_ :: Text -> Attribute
hxPreserve_ = makeAttribute "data-hx-preserve"
hxPrompt_ :: Text -> Attribute
hxPrompt_ = makeAttribute "data-hx-prompt"
hxPushUrl_ :: Text -> Attribute
hxPushUrl_ = makeAttribute "data-hx-push-url"
hxPut_ :: Text -> Attribute
hxPut_ = makeAttribute "data-hx-put"
hxRequest_ :: Text -> Attribute
hxRequest_ = makeAttribute "data-hx-request"
hxSelect_ :: Text -> Attribute
hxSelect_ = makeAttribute "data-hx-select"
hxSse_ :: Text -> Attribute
hxSse_ = makeAttribute "data-hx-sse"
hxSwapOob_ :: Text -> Attribute
hxSwapOob_ = makeAttribute "data-hx-swap-oob"
hxSwap_ :: Text -> Attribute
hxSwap_ = makeAttribute "data-hx-swap"
hxTarget_ :: Text -> Attribute
hxTarget_ = makeAttribute "data-hx-target"
hxTrigger_ :: Text -> Attribute
hxTrigger_ = makeAttribute "data-hx-trigger"
hxVals_ :: Text -> Attribute
hxVals_ = makeAttribute "data-hx-vals"
hxWs_ :: Text -> Attribute
hxWs_ = makeAttribute "data-hx-ws"
useHtmx :: Monad m => HtmlT m ()
useHtmx = script_ [src_ htmxSrc] ("" :: Html ())
useHtmxExtension :: Monad m => Text -> HtmlT m ()
useHtmxExtension ext = script_ [src_ $ htmxSrc <> extensionPath ext] ("" :: Html ())
useHtmxVersion :: Monad m => (Int, Int, Int) -> HtmlT m ()
useHtmxVersion semVer = script_ [src_ $ htmxSrcWithSemVer semVer] ("" :: Html ())
useHtmxVersionExtension :: Monad m => (Int, Int, Int) -> Text -> HtmlT m ()
useHtmxVersionExtension semVer ext = script_ [src_ $ htmxSrcWithSemVer semVer <> extensionPath ext] ("" :: Html ())
htmxSrc :: Text
htmxSrc = "https://unpkg.com/htmx.org"
showT :: Show a => a -> Text
showT = pack . show
htmxSrcWithSemVer :: (Int, Int, Int) -> Text
htmxSrcWithSemVer (major, minor, patch) =
htmxSrc
<> "@"
<> showT major
<> "."
<> showT minor
<> "."
<> showT patch
extensionPath :: Text -> Text
extensionPath ext = "/dist/ext/" <> ext <> ".js"