@boomitra/carbon-calculator 0.2.13 → 0.2.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,2 +1,111 @@
1
- # carbon-calculator
2
- Frontend Repo
1
+ # Carbon Calculator
2
+
3
+ A versatile Carbon Calculator available as both a React package and a standalone embeddable widget.
4
+
5
+ ## 📦 Usage as a React Package
6
+
7
+ If you have an existing React application, you can install and use the component directly.
8
+
9
+ ### 1. Installation
10
+
11
+ ```bash
12
+ npm install @boomitra/carbon-calculator
13
+ ```
14
+
15
+ ### 2. Integration
16
+
17
+ Import the component and its styles in your application:
18
+
19
+ ```jsx
20
+ import React from 'react';
21
+ import CarbonCalculator from '@boomitra/carbon-calculator';
22
+ import '@boomitra/carbon-calculator/style.css'; // Don't forget the styles!
23
+
24
+ function App() {
25
+ return (
26
+ <div className="App">
27
+ <h1>Carbon Footprint Calculator</h1>
28
+ <CarbonCalculator />
29
+ </div>
30
+ );
31
+ }
32
+
33
+ export default App;
34
+ ```
35
+
36
+ ---
37
+
38
+ ## 🌐 Usage as an Embedded Widget
39
+
40
+ You can embed the calculator into **any website** (HTML, WordPress, Webflow, Wix, etc.) using a simple script tag.
41
+
42
+ ### 1. Build the Widget
43
+
44
+ To generate the standalone widget file:
45
+
46
+ ```bash
47
+ npm run build:widget
48
+ ```
49
+
50
+ This will create the widget file at: `dist-embed/carbon-calculator-widget.iife.js`
51
+
52
+ ### 2. Embed in HTML
53
+
54
+ Add the following code to your website where you want the calculator to appear.
55
+
56
+
57
+
58
+ ```html
59
+ <!-- Load the Widget Script -->
60
+ <!-- Replace source with the actual path to your hosted file or CDN URL -->
61
+ <script src="./dist-embed/carbon-calculator-widget.iife.js"></script>
62
+
63
+ <!-- Add the Widget Element -->
64
+ <carbon-calculator-widget></carbon-calculator-widget>
65
+ ```
66
+
67
+ ### Styling
68
+
69
+ The widget uses **Shadow DOM** to encapsulate its styles, ensuring:
70
+ - Your website's CSS won't break the widget.
71
+ - The widget's CSS won't affect your website.
72
+
73
+ You can style the positioning of the widget container using standard CSS:
74
+
75
+ ```css
76
+ carbon-calculator-widget {
77
+ display: block;
78
+ max-width: 800px;
79
+ margin: 0 auto;
80
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1);
81
+ }
82
+ ```
83
+
84
+ For more detailed integration guides (WordPress, Wix, etc.), see [WIDGET_INTEGRATION_GUIDE.md](./WIDGET_INTEGRATION_GUIDE.md).
85
+
86
+ ---
87
+
88
+ ## 🛠️ Development
89
+
90
+ ### Setup
91
+
92
+ ```bash
93
+ npm install
94
+ ```
95
+
96
+ ### Run Locally
97
+
98
+ ```bash
99
+ npm start
100
+ ```
101
+ Runs the app in development mode at `http://localhost:5173`.
102
+
103
+ ### Build Commands
104
+
105
+ - **Build Package**: `npm run build`
106
+ - Outputs to `dist-package/`
107
+ - Used for publishing to npm (ESM + CommonJS).
108
+
109
+ - **Build Widget**: `npm run build:widget`
110
+ - Outputs to `dist-embed/`
111
+ - Used for standalone embedding.