Skip to content

Commit f3101de

Browse files
committed
docs: README
1 parent bcc5ff3 commit f3101de

3 files changed

Lines changed: 132 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@vnphanquang/green-check': patch
3+
---
4+
5+
add README

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ indent_size = 2
1111
trim_trailing_whitespace = true
1212
max_line_length = 100
1313

14+
[*.md]
15+
indent_size = 2
16+
indent_style = space
17+

README.md

Lines changed: 123 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,127 @@
1-
# GreenCheck Custom Element - [Green Web Foundation][greenwebfoundation]
1+
# Green Web Badge as Custom Element
22

3+
![green badge example](https://raw.githubusercontent.com/vnphanquang/green-check/main/.github/green.svg)
4+
5+
## Introduction
6+
7+
This library defines an [HTML Custom Element](https://developer.mozilla.org/en-US/docs/Web/API/Web_components) to check and display a badge if your site passes the [Green Web Check][greenwebcheck] from [The Green Web Foundation][greenwebfoundation].
8+
9+
See https://github.com/thegreenwebfoundation/admin-portal/issues/234 for the original discussion that led to this library.
10+
11+
## 1. Installation
12+
13+
Install `@vnphanquang/green-check` with your package manager of choice (recommended):
14+
15+
```bash
16+
pnpm add @vnphanquang/green-check
17+
npm install @vnphanquang/green-check
18+
yarn add @vnphanquang/green-check
19+
```
20+
21+
> [!NOTE]
22+
> This method is recommended as it allows the `green-check` module to be part of your dependency tree and build process, making it easier to integrate into framework contexts, track version, and deploy with high availability (you are effectively self-hosting the module).
23+
24+
Alternatively, you may load the module via a CDN by adding to [importmap](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap) in your html:
25+
26+
```html
27+
<script type="importmap">
28+
{
29+
"imports": {
30+
"@vnphanquang/green-check": "https://cdn.jsdelivr.net/npm/@vnphanquang/green-check/dist/greencheck.js"
31+
}
32+
}
33+
</script>
34+
```
35+
36+
## 2. Register the Custom Element
37+
38+
Import `GreenCheck` and register `<green-check>` using the global [customElements](https://developer.mozilla.org/en-US/docs/Web/API/Window/customElements), where applicable:
39+
40+
```javascript
41+
import { GreenCheck } from '@vnphanquang/green-check';
42+
43+
// later where applicable
44+
customElements.define('green-check', GreenCheck);
45+
```
46+
47+
Optionally, you may find dynamically importing the module to be more efficient depending on your use case:
48+
49+
```javascript
50+
async function loadGreenCheck() {
51+
const { GreenCheck } = await import('@vnphanquang/green-check');
52+
customElements.define('green-check', GreenCheck);
53+
}
54+
55+
// later
56+
loadGreenCheck();
57+
```
58+
59+
## 3. Using the Custom Element
60+
61+
```html
62+
<green-check hostname="www.yourdomain.xyz">
63+
<img
64+
src="https://cdn.jsdelivr.net/npm/@vnphanquang/green-check/dist/fallback.svg"
65+
width="200"
66+
height="95"
67+
alt="Fallback blank greencheck badge from The Green Web Foundation, in case JS is not (yet) available"
68+
/>
69+
</green-check>
70+
```
71+
72+
### Customizing Colors
73+
74+
Colors of the badge can be customized by providing the following CSS custom properties (default values are shown):
75+
76+
```html
77+
<green-check>
78+
<!-- [...truncated fallback image...] -->
79+
</green-check>
80+
81+
<style>
82+
green-check {
83+
--green-check-fg: #000;
84+
--green-check-bg: linear-gradient(45deg, #06ff06 4%, #dffcdd 24%, #fff 32%);
85+
}
86+
</style>
87+
```
88+
89+
This is helpful to ensure consistency with your site's color scheme or to support dark mode.
90+
91+
## Development
92+
93+
### Prerequisites
94+
95+
| Dependency | Installation | Description |
96+
| ---------- | --------------------------------------- | ------------------------------- |
97+
| [node] | recommended via [volta] | |
98+
| [pnpm] | [follow guide on website][pnpm.install] | alternative to `npm` and `yarn` |
99+
100+
See [package.json] for preferred versions of `node` and `pnpm`. At project root, run:
101+
102+
### Getting Started
103+
104+
This project is built with [Vite](https://vitejs.dev/). Start by installing dependencies
105+
106+
```bash
107+
pnpm install
108+
```
109+
110+
And run development server
111+
112+
```bash
113+
pnpm dev
114+
```
115+
116+
### Todos
117+
118+
- [ ] Add tests
3119

4120
[greenwebfoundation]: https://www.thegreenwebfoundation.org
121+
[greenwebcheck]: https://www.thegreenwebfoundation.org/green-web-check
122+
123+
[node]: https://nodejs.org/en/
124+
[volta]: https://volta.sh/
125+
[pnpm]: https://pnpm.io/
126+
[pnpm.install]: https://pnpm.io/installation
5127

0 commit comments

Comments
 (0)