JSFiddle - React, Tailwind, and code Playground

by rich_harris

HTML

<script src="http://cdn.ractivejs.org/edge/ractive.js"></script>
<script src="//cdn.jsdelivr.net/select2/3.4.8/select2.min.js"></script>
<link rel="stylesheet" href="//cdn.jsdelivr.net/select2/3.4.8/select2.css">
<script src="https://rawgit.com/Rich-Harris/simulant/master/simulant.js"></script>
<main></main>

<script id='template' type='text/ractive'>
    <p>selected value: {{JSON.stringify(selection)}}</p>
    
    <select decorator="select2:selection" value="{{selection}}">
        {{#options}}
            <option value="{{.}}">{{name}}</option>
        {{/options}}
    </select>
</script>

CSS

body {
    font-family: 'Helvetica Neue', arial, sans-serif;
    font-weight: 200;
    color: #353535;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 200;
}

JavaScript

Ractive.decorators.select2 = function ( node ) {
    var ractive = this;
    
    $(node).select2().on( 'change', function () {
        ractive.updateModel();
    });
    
    return {
        teardown: function () {
            $(node).select2( 'destroy' );
        }
    };
};

var ractive = new Ractive({
    el: 'main',
    template: '#template',
    data: { options: [
        { name: 'a' },
        { name: 'b' },
        { name: 'c' }
    ] }
});