1.0.0-next.8 • Published 2 months ago

@dlightjs/components v1.0.0-next.8

Weekly downloads
-
License
MIT
Repository
-
Last release
2 months 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

2 months ago

1.0.0-next.2

2 months ago

1.0.0-next.3

2 months ago

1.0.0-next.4

2 months ago

1.0.0-next.5

2 months ago

1.0.0-next.6

2 months ago

1.0.0-next.7

2 months ago

1.0.0-next.8

2 months ago

1.0.0-next.0

2 months ago

1.0.0-beta.0

3 months ago

1.0.0-alpha.24

4 months ago

1.0.0-alpha.19

4 months ago

1.0.0-alpha.21

4 months ago

1.0.0-alpha.20

4 months ago

1.0.0-alpha.23

4 months ago

1.0.0-alpha.22

4 months ago

1.0.0-alpha.9

5 months ago

1.0.0-alpha.8

5 months ago

1.0.0-alpha.7

5 months ago

1.0.0-alpha.6

5 months ago

1.0.0-alpha.5

5 months ago

1.0.0-alpha.4

5 months ago

1.0.0-alpha.3

5 months ago

1.0.0-alpha.10

5 months ago

1.0.0-alpha.16

5 months ago

1.0.0-alpha.15

5 months ago

1.0.0-alpha.18

4 months ago

1.0.0-alpha.17

5 months ago

1.0.0-alpha.12

5 months ago

1.0.0-alpha.11

5 months ago

1.0.0-alpha.14

5 months ago

1.0.0-alpha.13

5 months ago

1.0.0-alpha.2

5 months ago

1.0.0-alpha.1

5 months ago

1.0.0-alpha.0

5 months ago

0.9.34

8 months ago

0.9.8

10 months ago

0.9.7

10 months ago

0.9.9

10 months ago

0.9.30

8 months ago

0.9.31

8 months ago

0.9.3

10 months ago

0.9.32

8 months ago

0.9.6

10 months ago

0.9.33

8 months ago

0.9.5

10 months ago

0.10.1

8 months ago

0.10.2

8 months ago

0.9.23

10 months ago

0.9.24

9 months ago

0.9.25

9 months ago

0.9.26

9 months ago

0.9.20

10 months ago

0.9.21

10 months ago

0.10.0

8 months ago

0.9.22

10 months ago

0.9.27

9 months ago

0.9.28

9 months ago

0.9.29

9 months ago

0.9.12

10 months ago

0.9.13

10 months ago

0.9.14

10 months ago

0.9.15

10 months ago

0.9.10

10 months ago

0.9.11

10 months ago

0.9.16

10 months ago

0.9.17

10 months ago

0.9.18

10 months ago

0.9.19

10 months ago

0.9.0

10 months ago

0.9.2

10 months ago

0.9.1

10 months ago

0.9.0-pre

10 months ago

0.8.27

11 months ago

0.8.23

11 months ago

0.8.22

11 months ago

0.8.25

11 months ago

0.8.24

11 months ago

0.8.21

11 months ago

0.8.26

11 months ago

0.8.9

11 months ago

0.8.8

11 months ago

0.8.5

11 months ago

0.8.4

11 months ago

0.8.6

11 months ago

0.7.2

11 months ago

0.7.1

11 months ago

0.7.4

11 months ago

0.7.3

11 months ago

0.5.0

12 months ago

0.7.0

11 months ago

0.7.11

11 months ago

0.7.9

11 months ago

0.7.13

11 months ago

0.7.12

11 months ago

0.8.20

11 months ago

0.7.7

11 months ago

0.7.18

11 months ago

0.7.15

11 months ago

0.7.17-4

11 months ago

0.7.17-3

11 months ago

0.7.17-2

11 months ago

0.7.16

11 months ago

0.7.0-alpha

11 months ago

0.7.0-alpha-2

11 months ago

0.8.14

11 months ago

0.8.13

11 months ago

0.8.19

11 months ago

0.8.16

11 months ago

0.8.15

11 months ago

0.8.18

11 months ago

0.8.17

11 months ago

0.7.17-1

11 months ago

0.7.11-0

11 months ago

0.8.1

11 months ago

0.8.0

11 months ago

0.4.4

12 months ago

0.8.3

11 months ago

0.8.2

11 months ago

0.6.1

12 months ago

0.6.0

12 months ago

0.4.3

1 year ago

0.4.2

1 year ago

0.4.1

1 year 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.0

1 year ago

0.2.0-alpha

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.11

1 year ago