carbon-footprint-widget
TypeScript icon, indicating that this package has built-in type declarations

1.0.26 • Public • Published

carbon-footprint-widget

A JavaScript library for calculating carbon footprint values.

Installation

You can install the carbon-footprint-widget library using npm. Open your terminal or command prompt and run the following command:

npm install carbon-footprint-widget

Usage

In index.js or index.tsx

Import the necessary components in your JavaScript or TypeScript file:

import React from "react";
import ReactDOM from "react-dom";
import { CarbonWidgetProvider } from "carbon-footprint-widget";
import App from "./App/App";
import { WIDGET_API_KEY } from "./generated/from-web/constants";

ReactDOM.render(
  <React.StrictMode>
    <CarbonWidgetProvider apiKey={WIDGET_API_KEY}>
      <App />
    </CarbonWidgetProvider>
  </React.StrictMode>,
  document.getElementById("root")
);

Make sure to replace WIDGET_API_KEY with your actual API key.

Add Hooks and Component

Import the required components and hooks into your React component:

import React from "react";
import { Widget, useOffsetDeduction } from "carbon-footprint-widget";

const Cart: React.FC = () => {
  // Use the useOffsetDeduction hook to get relevant information
  const {
    isWidgetToggleOn,
    deductionAmount,
  } = useOffsetDeduction();

  return (
    <div>
      {/* Render the Widget component with the desired amount */}
      <Widget amount={Number(totalPrice)} />
    </div>
  );
};

Ensure that you have the necessary dependencies installed, and replace totalPrice with the actual value you want to calculate the carbon footprint for TAP.

Feel free to include any additional information, configuration options, or explanations as needed.

/carbon-footprint-widget/

    Package Sidebar

    Install

    npm i carbon-footprint-widget

    Weekly Downloads

    3

    Version

    1.0.26

    License

    MIT

    Unpacked Size

    157 kB

    Total Files

    66

    Last publish

    Collaborators

    • programmer_abby