Warning
This web component is still being actively developed. It is currently not suitable for production use.
This web component is designed to work with the Grid-aware Websites library. It aims to provide website users with contextual information about their local energy grid and enables customization options for grid-aware website designs.
- Display contextual information about the user's local energy grid
- Show different states based on grid carbon intensity (low, moderate, high, or unknown)
- Allow users to opt-out of automatically applying grid-aware website designs
- Enable users to manually switch between different design modes
npm install @greenweb/gaw-info-bar
Add the component to your project's HTML using a script
tag using a code CDN.
<script type="module" src="https://esm.sh/@greenweb/gaw-info-bar"></script>
Add the component to a project manually. To do this:
- Copy the
dist/gaw-info-bar.js
file to your project. - In your project's HTML add the following script tag:
<script type="module" src="path/to/gaw-info-bar.js"></script>
Add the component to your HTML and configure it with appropriate data attributes:
<gaw-info-bar data-gaw-level="low" data-gaw-location="US"> </gaw-info-bar>
Attribute | Description | Values | Default |
---|---|---|---|
data-gaw-level |
Current carbon intensity level | "low" , "moderate" , "high" |
undefined (shows as "Data unavailable") |
data-gaw-location |
Location code | Alpha-2 country code or valid Electricity Maps Zone ID | undefined (shows as "Location unknown") |
data-ignore-cookie |
Name of the cookie used to store user preference | Any valid cookie name | "gaw-ignore" |
data-ignore-cookie-max-age |
Max age for the ignore cookie | Valid cookie max-age or "Session" | "Session" |
The component displays different states based on the specified grid intensity level:
<gaw-info-bar data-gaw-level="low" data-gaw-location="TW"></gaw-info-bar>
Shows a green indicator with message "Your local grid: Cleaner than average."
<gaw-info-bar data-gaw-level="moderate" data-gaw-location="TW"></gaw-info-bar>
Shows an orange indicator with message "Your local grid: Around average emissions."
<gaw-info-bar data-gaw-level="high" data-gaw-location="TW"></gaw-info-bar>
Shows a red indicator with message "Your local grid: Dirtier than average."
<gaw-info-bar data-gaw-location="TW"></gaw-info-bar>
Shows a gray indicator with message "Your local grid: Data unavailable."
The component supports displaying user-friendly location names for:
- Regular country codes (e.g., "TW" for Taiwan)
- Regions (e.g., "AU-NSW" for New South Wales, Australia)
- Complex regions (e.g., "US-CENT-SPA" displays as "USA - Central")
These location identifiers align with the zones supported by the Electricity Maps API.
The component provides users with two types of controls:
-
Auto/Manual Toggle: Allows users to switch between automatic grid-aware design (based on actual grid intensity) and manual selection.
-
Manual Mode Buttons: When auto mode is disabled, users can select between low, moderate, and high grid intensity design modes.
These settings are stored in cookies to persist user preferences across page loads:
gaw-ignore
: Stores whether the user has opted out of automatic grid-aware designgaw-manual-view
: Stores the user's manually selected grid intensity level
This component is built using standard web components and supports all modern browsers.
- Node.js and npm
-
Clone the repository:
git clone https://github.com/thegreenwebfoundation/gaw-web-component.git cd gaw-web-component
-
Install dependencies:
npm install
-
Start the development server:
npm run dev
This will allow you to preview changes made to the web component.
Developed by The Green Web Foundation as part of their Grid-aware Web initiative.