Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <svg hidden>
  <symbol id="icon-delete" viewBox="0 0 24 24" >
    <path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path>  </symbol>
  <symbol id="icon-bars" viewBox="0 0 24 24">
    <path fill="none"  stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 8h16M4 16h16"></path>  </symbol>
  <symbol id="icon-envelope" viewBox="0 0 24 24" >
    <path fill="none" stroke="currentColor"  stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"></path>  </symbol>
</svg>

<div id="app">
  <header class="bg-white flex flex-wrap px-4 pb-4 pt-1 border-b border-solid border-gray-400">
    <div class="flex flex-grow items-center mr-2 mt-2">
      <svg class="mr-1 h-8 w-8" xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="square" stroke-linejoin="round"><rect x="3" y="3" width="7" height="7"></rect><rect x="14" y="3" width="7" height="7"></rect><rect x="14" y="14" width="7" height="7"></rect><rect x="3" y="14" width="7" height="7"></rect></svg>
      <div>
        <h1 class="text-lg font-semibold mb-0">Billfold</h1>
        <p class="text-sm"><em>A graphical budget calculator</em></p>
      </div>
    </div>
    <div class="flex mt-2">
      <div class="flex flex-col">
        <label class="text-xs">Monthly Income</label>
        <input class="w-24 border border-solid border-gray-600 rounded-sm px-2 py-1" inputmode="numeric" placeholder="" v-model="monthlyIncome">
      </div>
      <div class="flex flex-col ml-4">
        <label class="text-xs	">Other Money</label>
        <input class="w-24 border border-solid border-gray-600 rounded-sm px-2 py-1 align-right" inputmode="numeric" placeholder="" v-model="otherIncome">
      </div>
      <div class="flex flex-col ml-4">
        <label class="text-xs	">Bill Size</label>
        <select class="border border-solid border-gray-600 rounded-sm px-2 py-1" v-model="blockSize">
          <option>10</option>
          <option>20</option>
          <option>50</option>
          <option>100</option>
          <option>500</option>
          <option>1000</option>
          <option value="10000">10,000 (万)</option>
        </select>
      </div>
    </div>
  </header>
  
  <main>
    
    <section id="tutorial" v-if="envelopes.length < 2">
      <div id="welcome" class="py-8 px-4 bg-cyan" v-if="!totalIncome || !blockSize || !envelopes.length">
        <h2 class="text-3xl leading-none font-bold pb-4">Welcome to Billfold.</h2>
        <ol class="pl-4">
          <li :class="totalIncome? '' : 'list-decimal'">
            <svg v-if="totalIncome" class="h-4 w-4 inline-block -ml-4 animation-pop" xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="#00ebc7" stroke-width="6" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"></polyline></svg>
            <strong>Enter your income</strong> and any other money you have lying around up above. 👆
          </li>
          <li :class="blockSize > 1? '' : 'list-decimal'">
            <svg v-if="blockSize > 1" class="h-4 w-4 inline-block -ml-4 animation-pop" xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="#00ebc7" stroke-width="6" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"></polyline></svg>
            <strong>Set your bill size</strong> to your favorite government issued note. <code>100</code> is a good place to start. 💵
          </li>
          <li :class="envelopes.length? '' : 'list-decimal'">
            <svg v-if="envelopes.length" class="h-5 w-5 inline-block -ml-4 animation-pop" xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="#00ebc7" stroke-width="6" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"></polyline></svg>
            <strong>Create an envelope</strong> for each category of things you spend money on. 📩
          </li>
        </ol>
        
        <div class="mt-4">
          <button class="appearance-none border-none rounded-sm px-4 py-3 bg-pink text-white font-semibold" @click="quickStart">Use Quick Start Budget</button>
        </div>
      </div>
      
      <p id="alert-nice" v-if="totalIncome && blockSize && envelopes.length" class="p-4 border-b border-solid border-gray-500">🙌 <strong>Nice Work!</strong> Create more envelopes, add blocks, and have blocks leftover! That's how you win at capitalism!</p>
    </section>
  
    <form v-if="totalIncome && blockSize > 1" v-on:submit.prevent="addNewEnvelope" class="p-4 flex w-full items-end">
      <div class="flex flex-col flex-grow">
        <label class="text-xs">Add envelope</label>
        <input v-model="envelope.name" class="border border-solid border-gray-600 rounded-sm px-2 py-1 w-full" placeholder="Rent, Underwear, Tacos, etc"/>
      </div>
      <div class="flex flex-col flex-shrink mx-2 md:mx-4">
        <label class="text-xs">Amount</label>
        <input v-model="envelope.amount" type="number" inputmode="decimal" class="border border-solid border-gray-600 rounded-sm px-2 py-1 w-full" placeholder="540" />
      </div>
      <button type="submit" aria-label="Add Envelope" class="appearance-none border-none rounded-sm px-3 py-2 bg-pink text-white font-semibold">Add</button>
    
    </form>
    
    <draggable v-model="envelopes" @start="drag=true" @end="drag=false" handle=".handle">
      <div v-for="(envelope, index) in envelopes" v-if="envelopes" class="px-4 bg-white animation-fadeIn" :key="index">
        <header class="flex py-4 border-t border-solid border-gray-300 items-center w-100">
          <span class="flex flex-grow items-center handle">
            <svg class="mr-2 h-4 w-4 cursor-move"><use href="#icon-bars"></use></svg>
            <input v-model="envelope.name" class="flex-grow" />
          </span>
          <span class="flex flex-shrink items-center justify-end">
            <input v-model="envelope.amount" class="text-right"  />
          </span>
          
          <button :aria-label="`Delete ${envelope.name}`" @click="deleteEnvelope( index )" class="ml-2 h-5 w-5"><svg class="trash w-5 h-5"><use href="#icon-delete"></use></svg></button>

        </header>
        <div class="block-grid pb-4" v-if="blocksForEnvelope(envelope.amount)">
          <svg viewBox="0 0 150 100" class="animation-pop" height="100" width="150" v-for="block in blocksForEnvelope(envelope.amount)">
            <rect class="bill"  width="150" height="100" />
            <text fill="currentColor" x=75 y=60 text-anchor="middle" font-size="2rem">{{ blockSize }}</text>
          </svg>
          
        </div>
      </div>
    
    </draggable>
    
    <div id="unbudgeted" class="px-4 animation-fadeIn" v-if="totalIncome && blockSize > 1">
      <header class="flex py-4 border-t border-solid border-gray-300 items-center">
        <span class="flex flex-shrink items-center">
           <svg class="mr-2 h-5 w-5"><use href="#icon-envelope"></use></svg>
            Unbudgeted
        </span>
          <span class="flex flex-grow items-center justify-end">
          {{ this.unbudgeted }}
           <span class="ml-2">
          <span v-if="this.unbudgeted > 0">😎</span>
          <span v-if="this.unbudgeted == 0">😮</span>
          <span  v-if="this.unbudgeted < 0">😭</span>
          </span>
        </span>
      </header>
      <div class="block-grid pb-4" >
        <svg viewBox="0 0 150 100" class="animation-pop"  height="100" width="150" v-for="block in blocksForEnvelope(this.unbudgeted)">
          <rect fill="#f2f4f6" stroke="#00214d" stroke-width="1" width="150" height="100" />
        </svg>
      </div>
    </div>
    
  </main>
</div>
              
            
!

CSS

              
                // https://www.happyhues.co/palettes/10
body {
  color: #333;

  h1, h2, h3 {
    color: #111
  }
    
  code {
    color: #ff5470;
  }  
}

#app > header {
  background: #f8f8f8; 
  
  border-bottom: 1px solid #001858!important;
}

.block-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
  grid-gap: 0.5em;
  
  svg {
    max-width: 100%;
    width: 100%;
    height: auto;
  }
}

.bill {
  fill: #e3f6f5;
}

// https://www.happyhues.co/palettes/14
.bg-cyan {
  background-color: #e3f6f5;
}

.bg-pink {
  background-color: #F99;
  color: #333;
}

// https://www.happyhues.co/palettes/2
#alert-nice {
  background-color: #f2f4f6;
}

.animation-pop {
  animation: pop 0.5s;
}

.animation-fadeIn {
  animation: fadeIn 0.5s;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes pop {
  0% {  transform: scale(0.1) }
  75% {  transform: scale(1.1) }
  100% { transform: scale(1)   }
}
              
            
!

JS

              
                var quickStartBudget = [
  { name: "Housing", amount: 1200 },
  { name: "Transportation", amount: 650 },
  { name: "Groceries", amount: 250 },
  { name: "Personal & Family Care", amount: 50 },
  { name: "Health", amount: 300 },
  { name: "Restaurants", amount: 200 },
  { name: "Shopping & Entertainment", amount: 300 },
  { name: "Cash", amount: 150 },
  { name: "Education", amount: 100 },
  { name: "Finance", amount: 800 },
];

var app = new Vue({
  el: '#app',
  // data: {
  //   monthlyIncome: 0,
  //   otherIncome: 0,
  //   blockSize: 0,
  //   envelopes: [],
  //   envelope: {}
  // },
  // Test Data
  data: {
    monthlyIncome: 5400,
    otherIncome: 0,
    blockSize: 100,
    envelopes: [],
    envelope: {}
  },
  computed: {
    totalIncome() {
      return parseInt( this.monthlyIncome ) + parseInt( this.otherIncome )
    },
    totalBudgeted() {
      if(!this.envelopes.length) return 0;
      
      let total_budgeted = this.envelopes.reduce( (sum, obj) => {
          return {
            amount: parseFloat(sum.amount) + parseFloat(obj.amount)
          }
        }).amount;
      
      return total_budgeted;
    },
    unbudgeted() {
        return this.totalIncome - this.totalBudgeted;
    },
  },
  methods: {
    quickStart() {
      this.envelopes = quickStartBudget;
    },
    blocksForEnvelope(amount) {
      if( parseInt(amount) < 0) {
        return 0;
      }
      let tbs = Math.floor( parseInt(amount) / parseInt(this.blockSize) );
      return tbs;      
    },
     addNewEnvelope() {
        this.envelopes.push({ 
          name: this.envelope.name, 
          amount: this.envelope.amount 
        });
        this.envelope = {}
     },
    deleteEnvelope: function( index ) {
      if (confirm(`Delete "${this.envelopes[index].name}" envelope?`)) {
        this.envelopes.splice(index, 1);
      }
    }
   }

})
              
            
!
999px

Console