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
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
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
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
<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
<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>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>
);
}<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('-') } } }) --><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>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
| Property | Type | Default |
|---|---|---|
value | unknown | null |
symbol | string | "$" |
required | boolean | false |
min | number | 0 |
disabled | boolean | false |
label | string | "Amount" |
| Event | When |
|---|---|
valuechange | The 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.