Bootstrap-like Components for Riot.js
onclick
event handler on <btn>
, instead of onpush
onselect
event handler on <menu>
now passes an event object instead of a selected string.In short, use the tags as just like HTML: <btn>
, <btn-group>
, <menu>
...etc.
<btn>Your Button</btn>
riot.mount('*')
<!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>
riot.mount('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//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>
riot-bootstrap
via NPM.$ 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>
See the demo page.
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:
update
event.Tag
element. In NG case below, this.update()
is needed to call manually.
<btn onpush={ push }>Hi!</btn>
<btn onpush={ memberOf.subObject }>Hi!</btn>
<btn onpush={ returnFunction() }>Hi!</btn>
opts
also supported in scope emulationdisabled
now works with boolean
disabled
status after second updateparentScope
as a mixinhref
attribute to btn
tagdomEvent
, makes parentScope
external. Add: <calendar>
and <time-picker>
.align="right"
option for <menu>
by @cuu508Rebuilding Bootstrap components for Riot.js