Skip to content
This repository was archived by the owner on Oct 26, 2024. It is now read-only.

stimulus-components/stimulus-character-counter

Repository files navigation

Stimulus Character Counter

Netlify Status

Getting started

A Stimulus controller that counts the number of characters in any input fields.

Installation

$ yarn add stimulus-character-counter

And use it in your JS file:

import { Application } from "stimulus"
import CharacterCounter from "stimulus-character-counter"

const application = Application.start()
application.register("character-counter", CharacterCounter)

Usage

In your view:

<div data-controller="character-counter">
  <textarea data-target="character-counter.input"></textarea>

  <p>
    There are <strong data-target="character-counter.counter"></strong> characters in this textarea.
  </p>
</div>

Extending Controller

You can use inheritance to extend the functionality of any Stimulus components.

import CharacterCounter from "stimulus-character-counter"

export default class extends CharacterCounter {
  connect() {
    super.connect()
    console.log("Do what you want here.")

    this.count() // Will return the number of characters in the input/texterea.
  }
}

These controllers will automatically have access to targets defined in the parent class.

If you override the connect, disconnect or any other methods from the parent, you'll want to call super.method() to make sure the parent functionality is executed.

Development

Project setup

$ yarn install
$ yarn dev

Linter

Prettier and ESLint are responsible to lint and format this component:

$ yarn lint
$ yarn format

Contributing

Do not hesitate to contribute to the project by adapting or adding features ! Bug reports or pull requests are welcome.

License

This project is released under the MIT license.

About

A Stimulus controller that counts the number of characters in any input fields.

Topics

Resources

Stars

Watchers

Forks

Sponsor this project

 

Contributors 2

  •  
  •