1.0.0-next.8 • Published 1 year ago

@dlightjs/components v1.0.0-next.8

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

@dlightjs/components

This is a well-maintained components library for DLight.

Stack

HStack

usage

class MyComp extends View {
  Body() {
    HStack() 
    {
      div("we will")
      div("be in one line")
    }
  }
}

props

nametypedefault valuedescription
alignment"top" | "center" | "button""top"how elements with different height inside HStack will align
spacingnumber10column-gap between elements
widthstring"100%"HStack div's width
heightstring"max-content"HStack div's height

VStack

usage

class MyComp extends View {
  Body() {
    VStack() 
    {
      div("we will")
      div("be vertically displayed")
    }
  }
}

props

nametypedefault valuedescription
alignment"leading" | "center" | "tailing""leading"how elements with different width inside VStack will align
spacingnumber10row-gap between elements
widthstring"max-content"VStack div's width
heightstring"100%"VStack div's height

ZStack

usage

class MyComp extends View {
  Body() {
    ZStack() 
    {
      div("we will")
      div("be overlapped")
    }
  }
}

props

nametypedefault valuedescription
hAlignment"leading" | "center" | "tailing""leading"how elements with different width inside ZStack will align
vAlignment"top" | "center" | "button""top"how elements with different height inside HStack will align
widthstring"max-content"ZStack div's width
heightstring"max-content"ZStack div's height

Spacer

Push elements away.

usage

class MyComp extends View {
  Body() {
    HStack() 
    {
      Spacer()
      div("I will be in the center horizontally")
      Spacer()
    }
  }
}

Route

It's too powerful and easy to use, try it out.

class Page extends View {
  // RouteParam will be passed through env. It has navigator and current path.
  @Env RouteParam = required 
  navigator = this.RouteParam.navigator
  path = this.RouteParam.navigator
  
  Body() {
    div(`I am page: ${this.path}`)
    button("goto home")
    	.onclick(() => {
      	this.navigator.to("../home")
    	})
    // nested router
    RouterSpace() 
    {
      Route("hello")  // -> /page/hello
      {
        div("hello")
      }
      Route("world")  // -> /page/world
      {
        div("world")
      }
    }
  }
  
}

class MyComp extends View {
  navigator?
  
  Body() {
    RouterSpace() 
    	.navigator(navigator)
    {
      Route("home")  // -> /home
      {
        div("I am home")
      } 
      Route("page")  // -> /pate
      {
        Page()
      }
      Route(/abc+/)   // -> /abcc....
      {
        div("I will match abc+++")  // regex route
      }
      Route()
      {
        div("I am others")	// default route
      }
    }
  }
}

Switch

Simple implemented switch-case expression.

class MyComp extends View {
  idx = 0
  
  Body() {
    Switch(idx)
    {
      Case(0) 
      {
        div("0")
      } 
      Case(1) 
      {
        div("1")
      }
      Case()
      {
        div("other")
      }
    }
  }
}

Transition

Transition

usage

class MyComp extends View {
  @State width = 50
  
  Body() {
    button("+ width")
    	.onclick(() => {
      	this.width += 50
    	})
    Transition()
    {
      div()
        ._backgroundColor("red")
        ._width(this.width)
    }
  }
}

props

nametypedefault valuedescription
durationnumber0.5transition's duration (s)
easingstring"ease-in-out"transition's easing type
delaynumber0transition's delay (s)

TransitionGroup

Too powerful to describe, just try these codes and you'll know how to use it(maybe).

function getData(text) {
    return {
      id: Math.random().toString(20),
      text
    }
}
export class TransitionTest extends View {
    @State list = [
        getData("First one"),
        getData("II 222"),
        getData("333333 okk"),
        getData("This is four"),
        getData("555555!!"),
    ]
    remove() {
        this.list.splice(Math.floor(Math.random()*(this.list.length-1)), 1)
        this.list = [...this.list]
    }
    add() {
        this.list.splice(Math.floor(Math.random()*(this.list.length-1)), 0, getData(`---${this.list.length}`))
        this.list = [...this.list]
    }
    shuffle() {
        let newList = this.list
        while(JSON.stringify(newList) === JSON.stringify(this.list)) {
            newList = this.list
                .map(value => ({ value, sort: Math.random() }))
                .sort((a, b) => a.sort - b.sort)
                .map(({ value }) => value)
        }
        this.list = [...newList]
    }
    @State length = 100
    @State toggle = true

    Body() {
        button("shuffle")
            .onclick(() => {
                this.shuffle()
            })
        button("toggle")
            .onclick(() => {
                this.toggle = !this.toggle
            })
        button("remove")
            .onclick(() => {
                this.remove()
            })
        button("add")
            .onclick(() => {
                this.add()
            })
        button("+")
            .onclick(() => {
                this.length += 50
            })
        button("-")
            .onclick(() => {
                this.length -= 50
            })
        if (this.toggle){
            TransitionGroup()
                .duration(1)
                .delay({
                    firstAppear: (el) => {
                        return el.dataset.index * 0.7 ?? 0
                    }
                })
                .appearWith((el) => ({
                    opacity: 0,
                    backgroundColor: "yellow",
                    transform: `translateX(${40 + 80 * el.dataset.index ?? 0}px)`
                }))
                .disappearWith({
                    opacity: 0,
                    transform: "translateX(100px)",
                    backgroundColor: "yellow"
                })
            {
                for(let [idx, ok] of Object.entries(this.list)) { [ok.id]
                    div(ok.text)
                        .willAppear((el) => {
                            el.dataset.index = idx
                        })
                        ._width(`${this.length}px`)
                        ._marginTop("10px")
                        ._backgroundColor(this.toggle ? "blue" : "red")
                }
            }
        }
    }

}
1.0.0-next.1

1 year ago

1.0.0-next.2

1 year ago

1.0.0-next.3

1 year ago

1.0.0-next.4

1 year ago

1.0.0-next.5

1 year ago

1.0.0-next.6

1 year ago

1.0.0-next.7

1 year ago

1.0.0-next.8

1 year ago

1.0.0-next.0

1 year ago

1.0.0-beta.0

1 year ago

1.0.0-alpha.24

1 year ago

1.0.0-alpha.19

1 year ago

1.0.0-alpha.21

1 year ago

1.0.0-alpha.20

1 year ago

1.0.0-alpha.23

1 year ago

1.0.0-alpha.22

1 year ago

1.0.0-alpha.9

1 year ago

1.0.0-alpha.8

1 year ago

1.0.0-alpha.7

1 year ago

1.0.0-alpha.6

1 year ago

1.0.0-alpha.5

1 year ago

1.0.0-alpha.4

1 year ago

1.0.0-alpha.3

1 year ago

1.0.0-alpha.10

1 year ago

1.0.0-alpha.16

1 year ago

1.0.0-alpha.15

1 year ago

1.0.0-alpha.18

1 year ago

1.0.0-alpha.17

1 year ago

1.0.0-alpha.12

1 year ago

1.0.0-alpha.11

1 year ago

1.0.0-alpha.14

1 year ago

1.0.0-alpha.13

1 year ago

1.0.0-alpha.2

1 year ago

1.0.0-alpha.1

1 year ago

1.0.0-alpha.0

1 year ago

0.9.34

2 years ago

0.9.8

2 years ago

0.9.7

2 years ago

0.9.9

2 years ago

0.9.30

2 years ago

0.9.31

2 years ago

0.9.3

2 years ago

0.9.32

2 years ago

0.9.6

2 years ago

0.9.33

2 years ago

0.9.5

2 years ago

0.10.1

2 years ago

0.10.2

2 years ago

0.9.23

2 years ago

0.9.24

2 years ago

0.9.25

2 years ago

0.9.26

2 years ago

0.9.20

2 years ago

0.9.21

2 years ago

0.10.0

2 years ago

0.9.22

2 years ago

0.9.27

2 years ago

0.9.28

2 years ago

0.9.29

2 years ago

0.9.12

2 years ago

0.9.13

2 years ago

0.9.14

2 years ago

0.9.15

2 years ago

0.9.10

2 years ago

0.9.11

2 years ago

0.9.16

2 years ago

0.9.17

2 years ago

0.9.18

2 years ago

0.9.19

2 years ago

0.9.0

2 years ago

0.9.2

2 years ago

0.9.1

2 years ago

0.9.0-pre

2 years ago

0.8.27

2 years ago

0.8.23

2 years ago

0.8.22

2 years ago

0.8.25

2 years ago

0.8.24

2 years ago

0.8.21

2 years ago

0.8.26

2 years ago

0.8.9

2 years ago

0.8.8

2 years ago

0.8.5

2 years ago

0.8.4

2 years ago

0.8.6

2 years ago

0.7.2

2 years ago

0.7.1

2 years ago

0.7.4

2 years ago

0.7.3

2 years ago

0.5.0

2 years ago

0.7.0

2 years ago

0.7.11

2 years ago

0.7.9

2 years ago

0.7.13

2 years ago

0.7.12

2 years ago

0.8.20

2 years ago

0.7.7

2 years ago

0.7.18

2 years ago

0.7.15

2 years ago

0.7.17-4

2 years ago

0.7.17-3

2 years ago

0.7.17-2

2 years ago

0.7.16

2 years ago

0.7.0-alpha

2 years ago

0.7.0-alpha-2

2 years ago

0.8.14

2 years ago

0.8.13

2 years ago

0.8.19

2 years ago

0.8.16

2 years ago

0.8.15

2 years ago

0.8.18

2 years ago

0.8.17

2 years ago

0.7.17-1

2 years ago

0.7.11-0

2 years ago

0.8.1

2 years ago

0.8.0

2 years ago

0.4.4

2 years ago

0.8.3

2 years ago

0.8.2

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.2.0-alpha

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.11

2 years ago