PsSpa.Html.DSL
- Package
- purescript-ps-spa
- Repository
- the-man-with-a-golden-mind/ps-spa
Record-based DSL on top of PsSpa.Html.
Usage:
import PsSpa.Html.DSL as D
view = D.div { className: "page" } [ D.h1 { className: "title" } [ D.text "Hello" ] , D.button { className: "cta", onClick: Submit } [ D.text "Click" ] ]
The DSL desugars to the same Html / Attribute ADT used by the rest of
ps-spa, so it interoperates with the existing PsSpa.Html helpers.
#ToAttribute Source
class ToAttribute :: Symbol -> Type -> Type -> Constraintclass ToAttribute (name :: Symbol) typ msg where
Each (field name, value type) pair produces zero or more attributes.
Returning an empty array is the way to opt out — e.g. boolean attributes
with the value false should not render at all. Instances that need to
emit more than one attribute (data-* / aria-* / event composites) can.
Members
toAttribute :: Proxy name -> typ -> Array (Attribute msg)
Instances
ToAttribute "className" String msgToAttribute "id" String msgToAttribute "style" String msgToAttribute "title" String msgToAttribute "role" String msgToAttribute "lang" String msgToAttribute "dir" String msgToAttribute "slot" String msgToAttribute "part" String msgToAttribute "tabIndex" Int msgToAttribute "tabIndex" String msgToAttribute "href" String msgToAttribute "target" String msgToAttribute "rel" String msgToAttribute "download" String msgToAttribute "hrefLang" String msgToAttribute "ping" String msgToAttribute "referrerPolicy" String msgToAttribute "src" String msgToAttribute "srcSet" String msgToAttribute "sizes" String msgToAttribute "alt" String msgToAttribute "poster" String msgToAttribute "preload" String msgToAttribute "crossOrigin" String msgToAttribute "loading" String msgToAttribute "decoding" String msgToAttribute "kind" String msgToAttribute "srcLang" String msgToAttribute "label" String msgToAttribute "type_" String msgToAttribute "name" String msgToAttribute "value" String msgToAttribute "value" Int msgToAttribute "defaultValue" String msgToAttribute "placeholder" String msgToAttribute "htmlFor" String msgToAttribute "action" String msgToAttribute "method" String msgToAttribute "encType" String msgToAttribute "accept" String msgToAttribute "acceptCharset" String msgToAttribute "autoComplete" String msgToAttribute "autoCapitalize" String msgToAttribute "inputMode" String msgToAttribute "pattern" String msgToAttribute "form" String msgToAttribute "formAction" String msgToAttribute "formMethod" String msgToAttribute "formEncType" String msgToAttribute "formTarget" String msgToAttribute "max" String msgToAttribute "max" Int msgToAttribute "min" String msgToAttribute "min" Int msgToAttribute "step" String msgToAttribute "step" Int msgToAttribute "maxLength" Int msgToAttribute "minLength" Int msgToAttribute "size" Int msgToAttribute "rows" Int msgToAttribute "cols" Int msgToAttribute "wrap" String msgToAttribute "width" String msgToAttribute "width" Int msgToAttribute "height" String msgToAttribute "height" Int msgToAttribute "colSpan" Int msgToAttribute "rowSpan" Int msgToAttribute "spanCount" Int msgToAttribute "headers" String msgToAttribute "scope" String msgToAttribute "charset" String msgToAttribute "content" String msgToAttribute "httpEquiv" String msgToAttribute "icon" String msgToAttribute "start" String msgToAttribute "start" Int msgToAttribute "reversed" Boolean msgToAttribute "list" String msgToAttribute "ariaLabel" String msgToAttribute "ariaLabelledBy" String msgToAttribute "ariaDescribedBy" String msgToAttribute "ariaControls" String msgToAttribute "ariaCurrent" String msgToAttribute "ariaLive" String msgToAttribute "ariaHidden" Boolean msgToAttribute "ariaExpanded" Boolean msgToAttribute "ariaSelected" Boolean msgToAttribute "ariaPressed" Boolean msgToAttribute "ariaDisabled" Boolean msgToAttribute "disabled" Boolean msgToAttribute "checked" Boolean msgToAttribute "readOnly" Boolean msgToAttribute "required" Boolean msgToAttribute "autoFocus" Boolean msgToAttribute "multiple" Boolean msgToAttribute "noValidate" Boolean msgToAttribute "formNoValidate" Boolean msgToAttribute "hidden" Boolean msgToAttribute "selected" Boolean msgToAttribute "defaultChecked" Boolean msgToAttribute "defaultSelected" Boolean msgToAttribute "open" Boolean msgToAttribute "controls" Boolean msgToAttribute "autoPlay" Boolean msgToAttribute "loop" Boolean msgToAttribute "muted" Boolean msgToAttribute "playsInline" Boolean msgToAttribute "async" Boolean msgToAttribute "defer" Boolean msgToAttribute "isMap" Boolean msgToAttribute "contentEditable" Boolean msgToAttribute "spellCheck" Boolean msgToAttribute "draggable" Boolean msgToAttribute "translate" String msg(TypeEquals typ msg) => ToAttribute "onClick" typ msg(TypeEquals typ msg) => ToAttribute "onDoubleClick" typ msg(TypeEquals typ msg) => ToAttribute "onSubmit" typ msg(TypeEquals typ msg) => ToAttribute "onFocus" typ msg(TypeEquals typ msg) => ToAttribute "onBlur" typ msg(TypeEquals typ msg) => ToAttribute "onMouseEnter" typ msg(TypeEquals typ msg) => ToAttribute "onMouseLeave" typ msg(TypeEquals (String -> msg) f) => ToAttribute "onInput" f msg(TypeEquals (String -> msg) f) => ToAttribute "onChange" f msg(TypeEquals (String -> msg) f) => ToAttribute "onKeyDown" f msg(TypeEquals (String -> msg) f) => ToAttribute "onKeyUp" f msgToAttribute "accessKey" String msgToAttribute "enterKeyHint" String msgToAttribute "popover" String msgToAttribute "nonce" String msgToAttribute "is" String msgToAttribute "inert" Boolean msgToAttribute "itemProp" String msgToAttribute "itemId" String msgToAttribute "itemRef" String msgToAttribute "itemType" String msgToAttribute "itemScope" Boolean msgToAttribute "ariaActiveDescendant" String msgToAttribute "ariaAtomic" Boolean msgToAttribute "ariaAutoComplete" String msgToAttribute "ariaBusy" Boolean msgToAttribute "ariaChecked" String msgToAttribute "ariaColCount" Int msgToAttribute "ariaColIndex" Int msgToAttribute "ariaColSpan" Int msgToAttribute "ariaDetails" String msgToAttribute "ariaErrorMessage" String msgToAttribute "ariaFlowTo" String msgToAttribute "ariaHasPopup" String msgToAttribute "ariaInvalid" String msgToAttribute "ariaKeyShortcuts" String msgToAttribute "ariaLevel" Int msgToAttribute "ariaModal" Boolean msgToAttribute "ariaMultiLine" Boolean msgToAttribute "ariaMultiSelectable" Boolean msgToAttribute "ariaOrientation" String msgToAttribute "ariaOwns" String msgToAttribute "ariaPlaceholder" String msgToAttribute "ariaPosInSet" Int msgToAttribute "ariaReadOnly" Boolean msgToAttribute "ariaRelevant" String msgToAttribute "ariaRequired" Boolean msgToAttribute "ariaRoleDescription" String msgToAttribute "ariaRowCount" Int msgToAttribute "ariaRowIndex" Int msgToAttribute "ariaRowSpan" Int msgToAttribute "ariaSetSize" Int msgToAttribute "ariaSort" String msgToAttribute "ariaValueMax" Int msgToAttribute "ariaValueMin" Int msgToAttribute "ariaValueNow" Int msgToAttribute "ariaValueText" String msgToAttribute "dataAttrs" (Array KeyValue) msgToAttribute "ariaAttrs" (Array KeyValue) msg
#FromAttrs Source
#KeyValue Source
newtype KeyValueLightweight pair used for dataAttrs and ariaAttrs lists.
D.div { dataAttrs: [ D.kv "state" "open", D.kv "test-id" "main" ] } []
Constructors
Instances
ToAttribute "dataAttrs" (Array KeyValue) msgToAttribute "ariaAttrs" (Array KeyValue) msg
#keyed Source
keyed :: forall r rl msg. RowToList r rl => FromAttrs rl r msg => String -> Record r -> Array (Tuple String (Html msg)) -> Html msgRecord-attr flavour of Html.keyed. Use this when you want stable per-row
DOM identity across reorders (drag-and-drop, virtualisation, list sorts).
D.keyed "ul" { className: "list" } [ Tuple "todo-1" (D.li { className: "row" } [ D.text "A" ]) , Tuple "todo-2" (D.li { className: "row" } [ D.text "B" ]) ]