1.0.58 • Published 2 years ago

helium-ui v1.0.58

Weekly downloads
203
License
ISC
Repository
gitlab
Last release
2 years ago

helium-ui

Based on helium-sdx, utilizes Source Derivation (SDx) to create, mutate, and structure HTMLElements in the DOM.

import {div, Sourcify, onDomReady, button} from "helium-ui";

const state = Sourcify({
  a: 1,
  b: {
    c: 2
  }
});

const exampleApp = div("Example", [
  button("ButtonA", { onPush: () => state.a++}, "a++"),
  button({ 
    class: "ButtonC",
    onPush: () => state.b.c++, 
    innards: "c++"
  }),
  // will update every time buttons are pressed
  () => `${state.a} + ${state.b.c} = ${state.a + state.b.c}`
])

onDomReady(() => document.body.append(exampleApp));

Website: helium-ui.tech


Quick Reference Example (QRE)

Here's most of the general functionality

import { 
  Sourcify, div, span, HeliumRouteState, 
  anchor, deriveDomAnchored, syncWithLocalStorage 
} from "helium-ui";

const state = Sourcify({
  a: 1
})

const app = div("App", [
  // All the ways you can pass className, Props, and Innards
  div("FormatTypes", [
    span("MyClass"),
    span("MyClass", { id: null }),
    span("MyClass", "child text"),
    span("MyClass", { id: null }, ["child text"]),
    span("MyClass", { id: null }, "child text"),
    span({ id: null }),
    span({ id: null }, "child text"),
    span([ "child text" ]) // <--- must be array or else will be treated as class name
  ]),


  // Various different ways to supply innards
  div("InnardsTypes", [
    div("AnyHtmlElement"),
    document.createElement("div"),
    "text",
    42,
    0,                          // adds "0"
    false, null, undefined, "", // all add nothing,
    [
      ["nested", "arrays"],
      'flatten',
      [
        [div("Wacky")]
      ]
    ],
    () => ["a"],
    () => "a",
    () => {
      return () => "functions can return functions"
    },
    { hackableHTML: "<div>Don't put user generated data in these!</div>"}
  ]),
   

  // All of the different props
  div("AllProps", {
    // will create "AllProps additionalClass" as className
    class: "additionalClass",
    // have the class "classA" only when state.a equals 1
    ddxClass: () => state.a === 1 && "classA",
    title: "for tooltip hover",
    style: { background: "red" },

    // will show up as <div draggable="true"/>
    attr: {
      draggable: "true"
    },
    // will set the returned HTMLDivElement.someVal to 123
    this: {
      someVal: 123
    },
    ref: (ref: HTMLDivElement) => console.log(ref.className),
    // for keeping some part of the element in sync with state without re-creating it
    ddx: (ref) => ref.style.left = state.a + "px",

    // if you want to stop processing when element is not on page
    onFreeze: ({currentTarget}) => console.log("Removed from page", currentTarget),
    onUnfreeze: ({currentTarget}) => console.log("Added to page", currentTarget),

    // event listeners
    on: {
      load: (ev) => console.log(`Load event`)
    },
    onPush: null,               // a click or tap
    onTouch: null,              // mousedown or touch
    onToucherMove: null,        // mousemove or touch move
    onToucherEnterExit: null,   // mouse enter/exit or touch
    onKeyDown: null,
    onHoverChange: null,

    // same as innards above, but can be passed in as a props argument
    innards: [
      span("Child1"),
      "some text",
      span("Child2"),
    ]
  }),  
]);


// -------------- OTHER STUFF ----------------

// watches for url changes, then updates routeState.id if one matches
const routeState = new HeliumRouteState<"home" | "profile">({
  home: { test: "/" },
  profile: { test: "/profile" }
});


const linkNode = anchor({ 
  // href can be derived.
  href: () => routeState.getUrlForRoute("profile"),
  innards: "Go to profile"
});

// anchors a deriver to an HTMLElement
deriveDomAnchored(linkNode, () => {
  console.log(`linkNode is currently on page and routeState.id is "${routeState.id}"`)
});

// state will stay the same between page refreshes
syncWithLocalStorage("StateID", state as any);
1.0.55

2 years ago

1.0.58

2 years ago

1.0.57

2 years ago

1.0.56

2 years ago

1.0.54

2 years ago

1.0.53

2 years ago

1.0.52

2 years ago

1.0.51

2 years ago

1.0.49

3 years ago

1.0.44

3 years ago

1.0.43

3 years ago

1.0.42

3 years ago

1.0.48

3 years ago

1.0.47

3 years ago

1.0.46

3 years ago

1.0.45

3 years ago

1.0.40

3 years ago

1.0.41

3 years ago

1.0.39

3 years ago

1.0.38

4 years ago

1.0.37

4 years ago

1.0.33

4 years ago

1.0.32

4 years ago

1.0.36

4 years ago

1.0.35

4 years ago

1.0.34

4 years ago

1.0.31

4 years ago

1.0.29

4 years ago

1.0.30

4 years ago

1.0.28

4 years ago

1.0.26

4 years ago

1.0.27

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.23

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago