Giter Site home page Giter Site logo

semajthomasprimm / calculator-app Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 431 KB

A responsive calculator that features a three-way theme toggle switch.

Home Page: https://calculator-app-spr.netlify.app/

HTML 15.42% JavaScript 66.35% CSS 18.23%
css-flexbox css-grid javascipt react tailwindcss

calculator-app's Introduction

Frontend Mentor - Calculator app solution

Desktop

This is a solution to the Calculator app challenge on Frontend Mentor.

Table of contents

Overview

The challenge

To build a calculator with features including:

  • A three-way theme toggle button
  • Perform arithmetic operations: addition, subtraction, multiplication, and division.
  • Responsive design for mobile, tablet, and desktop screens

Screenshot

Default Theme

Desktop

Desktop Default

Mobile

Mobile

Day Theme

Desktop

Desktop Day

Mobile

Mobile

Neon Theme

Desktop

Desktop Day

Mobile

Mobile

Links

My process

Built with

  • React - JS library
  • TailwindCSS - For styling
  • Flexbox
  • CSS Grid
  • Mobile-first workflow

What I learned

How to define multiple themes with TailwindCSS

This app has 3 different themes, so I immediately researched a tutorial for help with this. Thanks to the TailwindCSS YouTube channel, I was able learn how to define multiple themes.

Using CSS variables, I defined the theme in index.css and utilized the CSS variables in my Tailwind config file.

Naming the variables was difficult, I had to make sure that the class names I used in the React components weren't theme specific.

Combining the 3-way toggle, I way able to easily fix any lingering style mistakes.

Develop a 3-way toggle using React hooks

A 3-way toggle requires 3 states to be monitored, as opposed to a regular 2-way toggle. After researching different approaches in vanilla JS and ReactJS, I declared a state variable using useState, which would contain a Boolean array of 3 values.

The index of each Boolean value refers to a specific theme. Default is 0, Day is 1, and Neon is 2.

The default theme is true initially. When the toggle is switched, the state variable updates the array and the selected theme is conditionally rendered.

Useful resources

  • TailwindCSS Custom Themes Tutorial - This helped me with defining multiple themes using TailwindCSS and CSS variables. I really liked this pattern and will use it going forward.
  • 3 way toggle CodePen example - This is a helpful vanilla JS approach to developing a 3-way toggle. I used it help model my ReactJS implementation.

Author

calculator-app's People

Contributors

semajthomasprimm avatar

Stargazers

Abbas Manning avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.