JSFiddle - React, Tailwind, and code Playground

by rich_harris

HTML

<main></main>

<script id="template" type='text/html'>
    <table class="table table-striped">
        <thead>
            <tr>
                <th>Categories</th>
                <th>Monthly Budget</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>
                    <form class="form-inline">
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">Income</div>
                                <input type="number" class="form-control" id="income-input-amount" value='{{incomeamount}}' placeholder="Amount"/>
                            </div>
                        </div>
                        <button on-click="addIncome(incomeamount)" type="submit" id="IncomeInputAmount" class="btn btn-primary">Add Income </button>
                    </form>
                </td>
                
                <td>{{totalincome}}</td>
            </tr>
        </tbody>
    </table>
</script>

<script id='template' type='text/ractive'>
    <h1>Hello {{name}}!</h1>
    <p>We're using Ractive.js version {{version}}</p>
</script>

CSS

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

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

.error {
    color: #d00;
    font-family: monospace;
}

JavaScript

var ractive = new Ractive({
    el: 'main',
    template: '#template',
    data: { 
        name: 'Income',
        totalincome: 1200,
        Expense1: 300
    },
    addIncome: function ( incomeamount ) {
        // update the model... `this.add('foo',x)` is a shortcut for
        // `this.set('foo', this.get('foo')+x)`
        this.add( 'totalincome', incomeamount );
        
        // ...then prevent the form from submitting (which reloads the page).
        // `this.event` is the Ractive event that triggered this method call;
        // `this.event.original` is the underlying `click` DOM event
        this.event.original.preventDefault();
    }
});