Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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

Save Automatically?

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

              
                <div id="app"></div>

              
            
!

CSS

              
                body {
  background: linear-gradient(150deg, #000000, #1f1f1f);
}

.body {
  background: linear-gradient(150deg, #000000, #1f1f1f);
  font-family: calibri, Times New Roman, constantia, Times, serif;
  color: #ffffff;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  align-items: center;
}

.calcie {
  background: linear-gradient(180deg, #001d3d, #000d1c);
}

.calcie-curves {
  background: transparent;
}

.calcie-corners {
  background: radial-gradient(#004691, #001d3d, #001d3d);
  border-radius: 2px;
}

#whole-title {
  display: flex;
  width: 18em;
  padding: 0.5em 0em 0em 1.5em;
  margin: auto;
}

#title {
  background: transparent;
  font-size: 2em;
  margin-top: -0.2em;
}

#sub-title {
  font-size: 0.7em;
  padding-left: 1em;
  margin-bottom: 1em;
  background: transparent;
  width: 10em;
  text-align: left; 
}

.calculator {
  width: 410px;
  margin-right: 1em;
  padding: 1em 1em 2em 1em;
  text-align: center;
  box-shadow: 0 0 0 1px #cfcfcf;
  -moz-box-shadow: 0 0 0 1px #cfcfcf;
  -webkit-box-shadow: 0 0 0 1px #cfcfcf;
}

.legend {
  margin-top: 1em;
  padding: 0em 1em 1em 1em;
  box-shadow: 0 0 0 1px #cfcfcf;
  -moz-box-shadow: 0 0 0 1px #cfcfcf;
  -webkit-box-shadow: 0 0 0 1px #cfcfcf;
}

.legend-hidden {
  display: none;
  padding: 0em 1em 0em 1em;
  box-shadow: 0 0 0 1px #cfcfcf;
  -moz-box-shadow: 0 0 0 1px #cfcfcf;
  -webkit-box-shadow: 0 0 0 1px #cfcfcf;
}

code {
  background: #002752;
  padding: 5px;
}

#display {
  font-size: 5em;
  margin: 8px;
  box-shadow: 0 0 0 2px #cfcfcf, inset 0 0 15px #000000;
  -moz-box-shadow: 0 0 0 2px #cfcfcf, inset 0 0 15px #000000;
  -webkit-box-shadow: 0 0 0 2px #cfcfcf, inset 0 0 15px #000000;
  word-wrap: break-word;
  background: linear-gradient(180deg, #ffffff, #bababa);
  color: #000000;
}

#keypad {
  margin: 1em 0.8em -0.7em 0em;
  background: transparent;
}

.button {
  background: linear-gradient(300deg, #002752, #00152b);
  margin: 8px 8px 8px 8px;
  position: relative;
  display: inline-block;
  width: 5em;
  height: 5em;
  border-radius: 5px;
  box-shadow: -2px -2px 3px 2px #000000, 6px 4px 7px 0px #b8b8b8;
  -moz-box-shadow: -2px -2px 3px 2px #000000, 6px 4px 7px 0px #b8b8b8;
  -webkit-box-shadow: -3px -3px 3px 2px #000000, 6px 4px 7px 0px #b8b8b8;
}

.button:active {
  left: 7px;
  bottom: -5px;
  box-shadow: -2px -2px 3px 1px #000000, 0px 0px 7px 0px #b6b5ff;
  -moz-box-shadow: -2px -2px 3px 1px #000000, 0px 0px 7px 0px #b6b5ff;
  -webkit-box-shadow: -2px -2px 3px 1px #000000, 0px 0px 7px 0px #b6b5ff;
}

.curves {
  background: #004084;
  position: absolute;
  margin: 0.1em 0em 0em -1.5em;
  background-color: transparent;
  font-size: 1.6em;
  padding: 0.6em 1em 0.6em 1em;
  border-radius: 5px;
}

.corners {
  background: linear-gradient(140deg, #001d3d, #004084);
  position: absolute;
  margin: 0.1em 0em 0em -1.5em;
  background-color: transparent;
  font-size: 1.6em;
  padding: 0.6em 1em 0.6em 1em;
  border-radius: 5px;
}

#equals {
  width: 15em;
}

#toggle {
  width: 6em;
}

#equals el {
  left: 1.7em;
  width: 6.5em;
  text-align: left;
}

#decimal el {
  width: 0.45em;
}

#clear el {
  width: 0.55em;
  color: #ad0011;
}

#toggle el {
  width: 0.6em;
  padding-right: 1.4em;
  margin-left: -1.8em;
}

.noselect {
  -webkit-touch-callout: none; /* iOS Safari */
    -webkit-user-select: none; /* Safari */
     -khtml-user-select: none; /* Konqueror HTML */
       -moz-user-select: none; /* Old versions of Firefox */
        -ms-user-select: none; /* Internet Explorer/Edge */
            user-select: none; 
}

@media only screen and (max-width: 450px) {
  #whole-title {
    width: 18em;
    margin-left: -0.75em;
    background: transparent;
  }
  
  .calculator {
    width: 280px;
  }
  
  #display {
    font-size: 3em;
    padding: 0.2em;
  }
  
  #keypad {
    margin: 1em 0.65em -0.7em 0em;
  }
  
  .button {
    width: 3em;
    height: 3em;
    box-shadow: 0 0 0 2px #000000, 4px 2.5px 7px 0px #b6b5ff, -5px -5px 0px 0px #000000;
    -moz-box-shadow: 0 0 0 2px #000000, 4px 2.5px 7px 0px #b6b5ff, -5px -5px 0px 0px #000000;
    -webkit-box-shadow: 0 0 0 2px #000000, 4px 2.5px 7px 0px #b6b5ff, -5px -5px 0px 0px #000000;
    }

  .button:active {
    left: 4px;
    bottom: -2.5px;
    box-shadow: 0px 0px 7px 0px #8280ff;
    -moz-box-shadow: 0px 0px 7px 0px #8280ff;
    -webkit-box-shadow: 0px 0px 7px 0px #8280ff;
  }
  
  #keypad el {
    margin: 0em 0em 0em -1.1em;
    font-size: 1.3em;
    padding: 0.4em 0.8em 0.4em 0.6em;
  }
  
  #equals {
    width: 10.9em;
  }
  
  #equals el {
    left: 1.15em;
}

  #toggle {
    width: 3em;
    height: 3em;
    box-shadow: 0 0 0 2px #000000, 4px 2.5px 7px 0px #b6b5ff, -5px -5px 0px 0px #000000;
    -moz-box-shadow: 0 0 0 2px #000000, 4px 2.5px 7px 0px #b6b5ff, -5px -5px 0px 0px #000000;
    -webkit-box-shadow: 0 0 0 2px #000000, 4px 2.5px 7px 0px #b6b5ff, -5px -5px 0px 0px #000000;
  }
  
  #toggle el {
    width: 0.5em;
    height: 1.2em;
    padding: 0.5em 1em 0.27em 0.4em;
    margin: 0em 0em 0em -1.1em;
  }
}
              
            
!

JS

              
                 function App(){
   
   // STATE MANAGEMENT.
   const [sumX, setSumX] = React.useState(0);
   const [sumY, setSumY] = React.useState(0);
   const [func, setFunc] = React.useState([]);
   const [dot, setDot] = React.useState(0);
   const [style, setStyle] = React.useState(1);
      
   // CLEAR ALL.
   function allClear() {
     setSumX(0);
     setSumY(0);
     setFunc([]);
     setDot(0);
     console.log('all clear out here')
   }
   
   // DEBUGGING.
   React.useEffect(() => {
   //  console.log("sumX is", sumX, "sumY is", sumY, "func is", func)
   }, [sumX, sumY, func, dot, style]);
   
   // KEY PRESS LISTENER.
   React.useEffect(() => {
     window.addEventListener("keypress", keyHandler);
     return () => window.removeEventListener("keypress", keyHandler);
    }, []);
   
   // KEY PRESS HANDLER.
   // TESTS DEMAND ID'S WRITTEN AS WORDS NOT NUMBERS SO COMMENTING OUT SIMPLER CODE
   function keyHandler(event) {
     console.log(event.key);
//     if (event.key == '1' || event.key == '2' || event.key == '3' || event.key == '4' || event.key == '5' || event.key == '6' || event.key == '7' || event.key == '8' || event.key == '9' || event.key == '0') {
//      document.getElementById(event.key).click();
      if (event.key == '1') {
        document.getElementById('one').click();
    } else if (event.key == '2') {
        document.getElementById('two').click();
    } else if (event.key == '3') {
        document.getElementById('three').click();
    } else if (event.key == '4') {
        document.getElementById('four').click();
    } else if (event.key == '5') {
        document.getElementById('five').click();     
    } else if (event.key == '6') {
        document.getElementById('six').click();
    } else if (event.key == '7') {
        document.getElementById('seven').click();
    } else if (event.key == '8') {
        document.getElementById('eight').click();
    } else if (event.key == '9') {
        document.getElementById('nine').click();
    } else if (event.key == '0') {
        document.getElementById('zero').click();
    } else if (event.key == 'c' || event.key == 'C') {
      document.getElementById('clear').click();
    } else if (event.key == '+' || event.key == 'p' || event.key == 'P'|| event.key == 'a' || event.key == 'A') {
      document.getElementById('add').click();
    } else if (event.key == '-' || event.key == 's' || event.key == 'S') {
      document.getElementById('subtract').click();
    } else if (event.key == '.') {
      document.getElementById('decimal').click();
    } else if (event.key == '=' || event.key == 'Enter') {
      document.getElementById('equals').click();
    } else if (event.key == ' ') {
      document.getElementById('toggle').click();
    } else if (event.key == '/' || event.key == 'd' || event.key == 'D') {
      document.getElementById('divide').click();
    } else if (event.key == '*' || event.key == 'x' || event.key == 'X' || event.key == "m" || event.key == 'M') {
      document.getElementById('multiply').click();
    } else {
      console.log('no bind');
    }
   }
   
   // NUMERAL INPUT.
   function keystroke(key) {
     if (sumX == 0) {
       console.log('a');
       setSumX([key]);
   } else if (sumX == 0 && key == '.') {
       console.log('b');
       setSumX(sumX + key);
   } else if (sumX !== 0 && sumX !== sumY && func !== '=') {
       console.log('c')
       setSumX(sumX + key);
   } else if (sumX == sumY) {
       console.log('d');
       setSumX([key]);
   }
  }
   
   // DECIMAL TRACKING.
   function decimal(key) {
     if (dot == 0) {
       console.log("dec trigger")
       keystroke(key);
       setDot(1);
   } else {
     console.log("don't double dot dude")
   }
  }
   
   // OPERATOR INPUT.
   function functionKey(key) {
       if (sumX == 0 && func == []) {
       console.log("1")
       setFunc(key);
    } else if (sumX == 0 && func !== [] && key == '-') {
       console.log("2")
       setSumY(0 - sumY);
    } else if (sumX == 0 && func !== [] && key == '+') {
       console.log("3")
       setSumY(Math.abs(sumY));
       setFunc(key);
    } else if (sumX !== 0 && sumY == 0 && key !== '=') {
       console.log("4")
       setFunc(key);
       setSumY(sumX);
       setSumX(0);
       setDot(0);
    } else if (sumX !== 0 && sumY !== 0 && key !== '=') {
       console.log("5")
       setFunc(key);
       setSumX(eval(Number(sumY) + func + Number(sumX)));
       setSumY(eval(Number(sumY) + func + Number(sumX)));
       setDot(0);
    } else if (sumX == 0 && sumY == 0 && key == '=') {
       console.log("6")
       setFunc(key);
       setSumX(sumX);
       setSumY(0);
       setDot(0);
    } else if (sumX !== 0 && sumY !== 0 && key == '=') {
       console.log("7")
       setFunc(key);
       setSumX(eval(Number(sumY) + func + Number(sumX)));
       setSumY(0);
       setDot(0);
     }
   }
   
   // FLAME EMBLEM TOGGLE STYLE.
   function styleSwitcher() {
     if (style == 0) {
       setStyle(1);
     } else if (style == 1) {
       setStyle(0);
     }
   }
   
    return (
      <div class="body">
        <div class="calcie calculator">
          <div class={style === 0 ? "calcie-curves" : "calcie-corners"} id="whole-title">
          <div class={style === 0 ? "calcie-curves" : "calcie-corners"} id="title">C A L C I E</div>
          <div class={style === 0 ? "calcie-curves" : "calcie-corners"} id="sub-title">Reevesie's React Resolver</div>
          </div>
          <div id="display">{sumX}
          </div>
          <div class="calcie" id="keypad">
            <span id="seven" class="button noselect" onClick={() => keystroke(7)}><el class={style === 0 ? "curves" : "corners"}>7</el></span>
            <span id="eight" class="button noselect" onClick={() => keystroke(8)}><el class={style === 0 ? "curves" : "corners"}>8</el></span>
            <span id="nine" class="button noselect" onClick={() => keystroke(9)}><el class={style === 0 ? "curves" : "corners"}>9</el></span>
            <span id="clear" class="button noselect" onClick={() => allClear()}><el class={style === 0 ? "curves" : "corners"}>C</el></span>
            <span id="four" class="button noselect" onClick={() => keystroke(4)}><el class={style === 0 ? "curves" : "corners"}>4</el></span>
            <span id="five" class="button noselect" onClick={() => keystroke(5)}><el class={style === 0 ? "curves" : "corners"}>5</el></span>
            <span id="six" class="button noselect" onClick={() => keystroke(6)}><el class={style === 0 ? "curves" : "corners"}>6</el></span>
            <span id="add" class="button noselect" onClick={() => functionKey('+')}><el class={style === 0 ? "curves" : "corners"}>+</el></span>
            <span id="one" class="button noselect" onClick={() => keystroke(1)}><el class={style === 0 ? "curves" : "corners"}>1</el></span>
            <span id="two" class="button noselect" onClick={() => keystroke(2)}><el class={style === 0 ? "curves" : "corners"}>2</el></span>
            <span id="three" class="button noselect" onClick={() => keystroke(3)}><el class={style === 0 ? "curves" : "corners"}>3</el></span>
            <span id="subtract" class="button noselect" onClick={() => functionKey('-')}><el class={style === 0 ? "curves" : "corners"}>–</el></span>
            <span id="zero" class="button noselect" onClick={() => keystroke(0)}><el class={style === 0 ? "curves" : "corners"}>0</el></span>
            <span id="multiply" class="button noselect" onClick={() => functionKey('*')}><el class={style === 0 ? "curves" : "corners"}>×</el></span>
            <span id="divide" class="button noselect" onClick={() => functionKey('/')}><el class={style === 0 ? "curves" : "corners"}>÷</el></span>
            <span id="decimal" class="button noselect" onClick={() => decimal('.')}><el class={style === 0 ? "curves" : "corners"}>.</el></span>
            <span id="toggle" class="button noselect" onClick={() => styleSwitcher()}><el class={style === 0 ? "curves" : "corners"}>🔥</el></span>
            <span id="equals" class="button noselect" onClick={() => functionKey('=')}><el class={style === 0 ? "curves" : "corners"}>=</el></span>
          </div>
</div>
        <div class={style == 0 ? "legend-hidden" : "legend"}>
          <h1>Legend</h1>
           <p><code>Clear</code> –––– <code>C</code></p>
           <p><code>Add</code> –––– <code>+</code> <code>P</code> <code>A</code></p>
           <p><code>Subtract</code> –––– <code>-</code> <code>S</code></p>
           <p><code>Multiply</code> –––– <code>*</code> <code>X</code> <code>M</code></p>
           <p><code>Divide</code> –––– <code>/</code> <code>D</code></p>
           <p><code>Decimal</code> –––– <code>.</code></p>
           <p><code>Equals</code> –––– <code>=</code> <code>Enter</code></p>
           <p><code>🔥</code> –––– <code>Space</code></p>
</div>
      </div>
    );
 };

ReactDOM.render(<App/>, document.getElementById('app'))

              
            
!
999px

Console