Monsoon v0.2.0
Made by Alexandre Kohler Star

Interactive

Number counter

The .input-counter buttons call stepDown() and stepUp(), repeat while held, follow min, max and step, and disable at the limits. Needs monsoon.js.

Interactive3 classesNeeds monsoon.jsLight and dark

Needs monsoon.js. The styles work on their own, and the behavior comes from the optional interactive layer: add <script src="https://cdn.jsdelivr.net/npm/monsooncss/dist/monsoon.js" defer></script> or import 'monsooncss/js'. See the interactive layer.

Example

Full

JavaScript API

Attribute

data-m-counter

Options

OptionDescription
min, max and step on the number input

Methods

MethodDescription
Monsoon.counter(el).increment()
Monsoon.counter(el).decrement()

Events

EventDescription
monsoon:change { value }
input and change on the native input

Classes

3 classes. Click a name to copy it. Utilities on the same element always win over component defaults, so any of them can be adjusted with plain utility classes.

ClassTypeWhat it does
Part Part of the number counter. On a <div> in the example. Sets flex display, alignment, width, inline-flex display, corner radius and margin.
CSS
.input-counter {
  display: inline-flex;
  width: auto;
}

.input-group > :hover, .input-counter > :hover {
  z-index: 1;
}
Part Part of the number counter. On a <button> in the example. Sets grid display, alignment, width, text size, text style and text color, and --_line and --_shadow.
CSS
.input-counter-button:hover {
  background-color: var(--surface-3);
}

.input-counter-button:disabled {
  cursor: not-allowed;
  opacity: var(--m-disabled-opacity);
}
Base Base class of the number counter. On an <input> in the example. Sets block display, width, height, padding, text size and text style, and 9 custom properties.
CSS
.input-group > .input, .input-group > .select {
  flex: 1 1 0%;
  width: auto;
}

.input::-webkit-calendar-picker-indicator:hover {
  background: var(--foreground);
}

Usage

The styles ship inside the same stylesheet as the utilities, and the behavior comes from the optional monsoon.js script, which enhances any element with a matching data-m attribute, including markup added later.

index.html
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/monsooncss">
<script src="https://cdn.jsdelivr.net/npm/monsooncss/dist/monsoon.js" defer></script>

<!-- Number counter: start from the base class, then add modifiers -->
<div class="flex flex-wrap items-center gap-4">
  <div class="input-counter" data-m-counter>
    <button type="button" class="input-counter-button" aria-label="Decrease">-</button>
    <input type="number" class="input" value="2" min="1" max="10" aria-label="Guests">
    <button type="button" class="input-counter-button" aria-label="Increase">+</button>
  </div>
  <div class="input-counter input-group-sm" data-m-counter>
    <button type="button" class="input-counter-button" aria-label="Decrease">-</button>
    <input type="number" class="input input-sm" value="0.5" min="0" max="5" step="0.25" aria-label="Weight in kilograms">
    <button type="button" class="input-counter-button" aria-label="Increase">+</button>
  </div>
</div>

Theme it with --seed on any ancestor, for example style="--seed: #0d9488", and force a scheme with class="dark" or class="light" on a wrapper.

Accessibility

  • Give every control a visible label linked with for, or an aria-label when the purpose is obvious from context. Link help and error text with aria-describedby; invalid styles use :user-invalid, so they appear only after the user interacts.
  • Use button for actions and a for navigation. Icon only buttons need an aria-label; decorative icons carry aria-hidden="true".
  • Every interactive part shows a visible focus ring with :focus-visible, and tone colors pair with -foreground tokens that keep text at 4.5:1 or better in light and dark mode.

No recent searches

Try , , or .

Recent

Loading the search index

No results for ""

Check the spelling, or search a class name such as px-4.