Gelerator - js 快速生成 html,支持并列、嵌套、css-in-js

1,170 阅读1分钟
原文链接: gaoryrt.com

Gelerator

Generate Element in a simple, HTML-in-JS way.

        
          const g = require('gelerator')

          const H1 = g('bold', 'h1')('h1 with class: blod')
          const H2 = g({ style: 'background: #ccc; color: #444' }, 'h2')('h2 with style')
          const P = g({}, 'p')

          const content = g({ id: 'content' })(
              H1,
              H2,
              P('Lorem ipsum dolor sit amet'),
              P('Consectetur adipisicing elit. Facilis, aliquid!')
          )

          $('.target').appendChild(content)
        
      

Installation

  • npm
  • yarn
            $  npm install gelerator
            
          

    Javascript

  • g('btn')('click me')
  • g('btn', 'botton')('content')
  • g({ id: 'main', style: 'color: #888' })('ctt')
  • g('demo-jpg', 'img')('./demo.jpg')
  • g(css`color: rebeccapurple`)('with css-in-js')

    Elements

  • <div class="btn">click me</div>
  • <botton class="btn">content</botton>
  • <div id="main" style="color: #888">ctt</div>
  • <img class="demo-jpg" src="./demo.jpg">
  • <div class="hAsH3dC1as5">with css-in-js</div>

Generate html in js, no editor window switching.

Star