npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-calculator-ts

v1.1.1

Published

**`react-calculator-ts`** is a versatile calculator component built with TypeScript and React. It supports multiple types of calculators including simple, scientific, and offers customizable button colors. The component is designed for ease of use, and bo

Downloads

953

Readme

🎉 react-calculator-ts

react-calculator-ts is a versatile calculator component built with TypeScript and React. It supports multiple types of calculators including simple, scientific, and offers customizable button colors. The component is designed for ease of use, and both basic arithmetic and advanced scientific functions are supported.

Live Demo

Screenshot of React Scientific Calculator

🚀 Installation

To add react-calculator-ts to your project, run the following command:

npm install react-calculator-ts

📖 Usage

Example Code

Here’s how to use ReactCalculator, which allows you to select between different calculator types, in your React project.

import React from 'react';
import { ReactCalculator } from 'react-calculator-ts';

const App = () => (
  <div>
    <h1>My Calculator</h1>
    <ReactCalculator 
      type="SCIENTIFIC"                 // Choose between 'SIMPLE', 'SCIENTIFIC', 'GRAPHING', 'PROGRAMMER'
      numberButtonColor="#34d399"       // Optional: Green color for number buttons
      operationButtonColor="#f97316"    // Optional: Orange color for operation buttons
      clearButtonColor="#3b82f6"        // Optional: Blue color for the clear button
      equalButtonColor="#10b981"        // Optional: Green color for the equal button
      scientificButtonColor="#384B70"   // Optional: Blue-gray color for scientific function buttons
    />
  </div>
);

export default App;

🛠️ Methods

Customizable Props

The ReactCalculator component accepts the following optional props for UI customization:

  • type (String): Specifies the calculator type. Supported values are 'SIMPLE', 'SCIENTIFIC', 'GRAPHING' (not implemented), and 'PROGRAMMER' (not implemented).
  • numberButtonColor (String): Hex or RGB color for the number buttons (default: #4b5563).
  • operationButtonColor (String): Hex or RGB color for the operation buttons (default: #ef4444).
  • equalButtonColor (String): Hex or RGB color for the equal button (default: #10b981).
  • clearButtonColor (String): Hex or RGB color for the clear button (default: #f59e0b).
  • scientificButtonColor (String): Hex or RGB color for the scientific function buttons (only for the scientific calculator, default: #384B70).

Calculator Types

  • Simple Calculator: Basic arithmetic operations (addition, subtraction, multiplication, division).

    Example usage of the simple calculator:

    import React from 'react';
    import { ReactCalculator } from 'react-calculator-ts';
    
    const App = () => (
      <div>
        <h1>Simple Calculator</h1>
        <ReactCalculator 
          type="simple" 
          numberButtonColor="#4b5563" 
          operationButtonColor="#ef4444" 
          clearButtonColor="#f59e0b"
          equalButtonColor="#10b981"
        />
      </div>
    );
    
    export default App;
  • Scientific Calculator: Supports both basic operations and advanced functions like square root, powers, trigonometric calculations, and logarithms.

    Example usage of the scientific calculator:

    import React from 'react';
    import { ReactCalculator } from 'react-calculator-ts';
    
    const App = () => (
      <div>
        <h1>Scientific Calculator</h1>
        <ReactCalculator 
          type="scientific"
          numberButtonColor="#4b5563"
          operationButtonColor="#ef4444"
          clearButtonColor="#f59e0b"
          equalButtonColor="#10b981"
          scientificButtonColor="#384B70"
        />
      </div>
    );
    
    export default App;
  • Graphing Calculator (Not Yet Implemented): Future functionality for plotting graphs.

  • Programmer Calculator (Not Yet Implemented): Future functionality for binary, hexadecimal, and other programmer-specific operations.

📌 Notes

This component is designed for educational and simple application use cases. Make sure to pass valid CSS color strings (e.g., #34d399, rgb(52, 211, 153)) for button color customization.

🤝 Contributing

Contributions are welcome! Feel free to submit a pull request or open an issue if you have suggestions or improvements for the component.

📄 License

This project is licensed under the MIT License. See the LICENSE file for more details.

Tests Coverage

👤 Author

Khalil MEQQORI - Module Creator
For more information or questions, please open an issue on the GitHub repository or contact me at [email protected].