Zubra UI
Code for
GitHub

money-input

An amount of money. Typing is free-form; on blur it's formatted (1234.5 → 1,234.50). The value is a number (or null when empty). A form control: required and min validate it.

Try it: events appear here (valuechange).

Source: money-input.zb, and its registry item.

Install

Compiled (any project)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/money-input.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/money-input.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/money-input.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/money-input.json
One file, no dependencies (3.3 KB gzipped)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/money-input.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/money-input.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/money-input.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/money-input.json
.zb source (to edit it with Zubra)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/money-input.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/money-input.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/money-input.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/money-input.json
No build: a script tag, straight from this site
HTML
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/money-input.js"></script>

The compiled install writes src/components/zubra/money-input.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.

Usage

index.html
<money-input label="Budget" name="budget"></money-input>

<script type="module">
  import './components/zubra/money-input.js';

  const element = document.querySelector('money-input');
  element.value = 1250;
  element.min = 0;
  element.addEventListener('valuechange', (event) => console.log('valuechange', event.detail));
</script>
Example.jsx
import './components/zubra/money-input.js';

const value = 1250;
const min = 0;

export function MoneyInputExample() {
  return (
    <money-input
      label="Budget"
      name="budget"
      value={value}
      min={min}
      onvaluechange={(event) => console.log('valuechange', event.detail)}
    ></money-input>
  );
}
Example.vue
<script setup>
import './components/zubra/money-input.js';
const value = 1250;
const min = 0;
const onValuechange = (event) => console.log('valuechange', event.detail);
</script>

<template>
  <money-input
    label="Budget"
    name="budget"
    :value.prop="value"
    :min.prop="min"
    @valuechange="onValuechange"
  ></money-input>
</template>

<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) -->
Example.svelte
<script>
  import './components/zubra/money-input.js';
  const value = 1250;
  const min = 0;
</script>

<money-input
  label="Budget"
  name="budget"
  {value}
  {min}
  onvaluechange={(event) => console.log('valuechange', event.detail)}
></money-input>
example.component.ts
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/money-input.js';

@Component({
  selector: 'app-money-input-example',
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: `
    <money-input
      label="Budget"
      name="budget"
      [value]="value"
      [min]="min"
      (valuechange)="onValuechange($event)"
    ></money-input>
  `,
})
export class MoneyInputExample {
  value = 1250;

  min = 0;

  onValuechange(event: Event) {
    console.log('valuechange', (event as CustomEvent).detail);
  }
}

API

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
valueunknownnull
symbolstring"$"
requiredbooleanfalse
minnumber0
disabledbooleanfalse
labelstring"Amount"
Events
EventWhen
valuechangeThe amount changed; detail is the number, or null.

Size

1.4 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 18.2 KB.

Theme

Every component reads shadcn/ui's CSS variables, so any shadcn theme works. Pick a look or a colour, or paste a theme's CSS.

Look: colours, fonts, corners and motion

Accent colour