# @piyoppi/counter-button

> Simple counter tools for web pages

Latest version **0.1.4** (published 2022-03-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install @piyoppi/counter-button
pnpm add @piyoppi/counter-button
yarn add @piyoppi/counter-button
bun add @piyoppi/counter-button
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.4 |
| Published | 2022-03-30 |
| First published | 2022-03-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 39.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | piyoppi |

## Links

- npm: https://www.npmjs.com/package/@piyoppi/counter-button
- Repository: https://github.com/piyoppi/counter-tools
- Homepage: https://github.com/piyoppi/counter-tools#readme
- Issues: https://github.com/piyoppi/counter-tools/issues
- npm.io page: https://npm.io/package/@piyoppi/counter-button

## Recent versions

- 0.1.4 (latest) — 2022-03-30

## README

# @piyoppi/counter-button

Custom elements that increment counts, display counts.

This elements call API provided by [@piyoppi/counter-api](../counter).
The API must be deployed previously.

## Install

To get packages from github package registry, you should edit .npmrc file. Show an example below. (authToken must have the read:packages scope. [ref](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry))

```
//npm.pkg.github.com/:_authToken=xxxxxxxx
@piyoppi:registry=https://npm.pkg.github.com
```

```
npm install --save @piyoppi/counter-button
```

## Example

Displays the count of the page on which this element is placed. It also places a vote button.

```html
<counter-container
  apiurl="https://api.example.com"
  >
  <counter-increment-button>
    <span>
      &#x1f31f;
      <counter-display>
        <span slot="loading">...</span>
      </counter-display>
    </span>
  </counter-increment-button>
</counter-container>
```

## `counter-increment-button`

The button is used to increment the counter. The API (`POST /count`) is called when the button is clicked.

### Attributes

| attribute | detail |
| --- | --- |
| apiurl | The url of API (ex: `https://api.example.com`) |
| url (optional) | The url of a current page  (default `window.location.href`) |


## `counter-display`

The element displays the counted value. The API (`GET /current`) is called when the element is shown.

### Attributes

| attribute | detail |
| --- | --- |
| apiurl | The url of API (ex: `https://api.example.com`) |
| addition (optional) | Additional count values. The element is displayed the value provided by api + addition value|
| url (optional) | The url of a current page (default `window.location.href`) |

### Slots

| name | detail |
| --- | --- |
| loading | Displayed when calling api. |
| error | Displayed when api call fails. |

## `counter-container`

This element integrates `counter-increment-button` and `counter-display`.

- Attribute `apiurl` and `url` on this element is applied in the child elements.
- When the counter display button in this element is clicked, the attribute `addition` is incremented by the `counter-display`.


### Attributes

| attribute | detail |
| --- | --- |
| apiurl | The url of API (ex: `https://api.example.com`) |
| url (optional) | The url of a current page (default `window.location.href`) |

---
_Source: https://npm.io/package/@piyoppi/counter-button · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
