cognitom / riot-bootstrap

Bootstrap-like Components for Riot.js
http://cognitom.github.io/riot-bootstrap/
136 stars 11 forks source link

Riot Bootstrap

Bootstrap-like Components for Riot.js

v1.0 API Changed

Demo

Getting started

In short, use the tags as just like HTML: <btn>, <btn-group>, <menu>...etc.

<btn>Your Button</btn>

1) Use directly in HTML file

<!DOCTYPE html>
<html>
  <head>
    <title>riot-bootstrap</title>
    <link rel="stylesheet" href="https://github.com/cognitom/riot-bootstrap/blob/master//cdn.jsdelivr.net/normalize/3.0.3/normalize.css">
  </head>
  <body>
    <section>
      <btn>Default</btn>
      <btn option="primary">Primary</btn>
      <btn option="success">Success</btn>
    </section>
    <script src="https://github.com/cognitom/riot-bootstrap/raw/master//cdn.jsdelivr.net/riot/2.0/riot.js"></script>
    <script src="https://github.com/cognitom/riot-bootstrap/raw/master/dist/riot-bootstrap.js"></script>
    <script>riot.mount('*')</script>
  </body>
</html>

2) Use in tag file (better)

<!DOCTYPE html>
<html>
  <head>
    <title>riot-bootstrap</title>
    <link rel="stylesheet" href="https://github.com/cognitom/riot-bootstrap/blob/master//cdn.jsdelivr.net/normalize/3.0.3/normalize.css">
  </head>
  <body>
    <app></app>
    <script src="https://github.com/cognitom/riot-bootstrap/raw/master//cdn.jsdelivr.net/riot/2.0/riot.js"></script>
    <script src="https://github.com/cognitom/riot-bootstrap/raw/master/dist/riot-bootstrap.js"></script>
    <script src="https://github.com/cognitom/riot-bootstrap/raw/master/app.js"></script>
    <script>riot.mount('app')</script>
  </body>
</html>
// app.html
<app>
  <section>
    <btn onclick={ click }>Say 'Hi!'</btn>
  </section>
  <script>
    click (e) {
      alert('Hi!')
    }
  </script>
</app>

3) Use with rollup (best)

$ npm install --save riot-bootstrap
// app.js
import riot from 'riot'
import 'riot-bootstrap'
import './app.tag' // and other components
riot.mount('app')
// app.tag
<app>
  <section>
    <btn onclick={ click }>Say 'Hi!'</btn>
  </section>
  <script>
    this.click = e => {
      alert('Hi!')
    }
  </script>
</app>
<!DOCTYPE html>
<html>
  <head>
    <title>riot-bootstrap</title>
    <link rel="stylesheet" href="https://github.com/cognitom/riot-bootstrap/blob/master//cdn.jsdelivr.net/normalize/3.0.3/normalize.css">
  </head>
  <body>
    <app></app>
    <script src="https://github.com/cognitom/riot-bootstrap/raw/master/app.js"></script>
  </body>
</html>

Components

See the demo page.

Scope emulation

Riot.js has a scope for most inner Tag element. So we need to write like this:

<app>
  <btn-group>
    <btn onpush={ parent.parent.push }>{ parent.parent.message }</btn>
  </btn-group>
  this.message = 'Click me!'
  push (e) {
    this.message = 'Thanks!'
    this.update() // needed to re-render
  }
</app>

But this is a little bit inconvenient, so riot-bootstrap has a simple 'Scope emulation' mechanism. Now we can write like this.

<app>
  <btn-group>
    <btn onpush={ push }>{ message }</btn>
  </btn-group>
  this.message = 'Click me!'
  push (e) {
    this.message = 'Thanks!'
    // automatically re-rendered
  }
</app>

There is some limitation:

History

TODO:

Rebuilding Bootstrap components for Riot.js