Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/clement-joye/react-websitecarbon-badge

React component for Website Carbon badge: https://www.websitecarbon.com/badge/
https://github.com/clement-joye/react-websitecarbon-badge

Last synced: 2 months ago
JSON representation

React component for Website Carbon badge: https://www.websitecarbon.com/badge/

Awesome Lists containing this project

README

        

# react-websitecarbon-badge

React component for Website Carbon badge: https://www.websitecarbon.com/badge/. Can be used both for static and dynamic websites.

## Introduction

This React component fits both static and dynamic web apps.
The values on the badge can be set directly via props or fetched from https://www.websitecarbon.com/api/.

If using GatsbyJS, this react component goes hand in hand with: https://www.npmjs.com/package/gatsby-source-websitecarbon

## Install

```bash
npm install react-websitecarbon-badge
```

## How to use

```js
import { WebsiteCarbonBadge } from 'react-websitecarbon-badge';

class MyComponent extends React.Component {
render() {
return ;
}
}
```

## Props

* `dark`:
* Boolean
* Optional. Default `false`
* Specify to use dark badge version
* `co2`:
* String
* Optional. Default to empty string
* Sets the co2/view value.
* `percentage`:
* String
* Optional. Default to empty string
* Sets the ranking percentage value.
* `url`:
* String
* Optional. Default to empty string
* Sets the url to fetch data from website carbon api.
* `lang`:
* String
* optional. Default to '`en`'
* Sets the default language to use. (Currently supports '`en`' or '`fr`')

*NB: setting co2 and percentage takes precedence over the url, preventing unnecessary api fetch.*

## Examples

```js

```
Fetches data from `www.google.com` via http request if not found in local storage.
```js

```
Uses dark version and sets co2 = 0.12 and percentage = 89%.
```js

```
Uses french as language for the badge.
```js

```
Uses co2 = 0.56 and percentage = 41%, and does not use the url provided.