@molecule/app-amount-input-react 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,115 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work.
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship.
43
+
44
+ "Contribution" shall mean any work of authorship, including the
45
+ original version of the Work and any modifications or additions
46
+ to that Work, that is intentionally submitted to the Licensor for
47
+ inclusion in the Work by the copyright owner or by an individual or
48
+ Legal Entity authorized to submit on behalf of the copyright owner.
49
+
50
+ "Contributor" shall mean Licensor and any individual or Legal Entity
51
+ on behalf of whom a Contribution has been received by the Licensor and
52
+ subsequently incorporated within the Work.
53
+
54
+ 2. Grant of Copyright License. Subject to the terms and conditions of
55
+ this License, each Contributor hereby grants to You a perpetual,
56
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
57
+ copyright license to reproduce, prepare Derivative Works of,
58
+ publicly display, publicly perform, sublicense, and distribute the
59
+ Work and such Derivative Works in Source or Object form.
60
+
61
+ 3. Grant of Patent License. Subject to the terms and conditions of
62
+ this License, each Contributor hereby grants to You a perpetual,
63
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
64
+ patent license to make, have made, use, offer to sell, sell, import,
65
+ and otherwise transfer the Work.
66
+
67
+ 4. Redistribution. You may reproduce and distribute copies of the
68
+ Work or Derivative Works thereof in any medium, with or without
69
+ modifications, and in Source or Object form, provided that You
70
+ meet the following conditions:
71
+
72
+ (a) You must give any other recipients of the Work or
73
+ Derivative Works a copy of this License; and
74
+
75
+ (b) You must cause any modified files to carry prominent notices
76
+ stating that You changed the files; and
77
+
78
+ (c) You must retain, in the Source form of any Derivative Works
79
+ that You distribute, all copyright, patent, trademark, and
80
+ attribution notices from the Source form of the Work,
81
+ excluding those notices that do not pertain to any part of
82
+ the Derivative Works; and
83
+
84
+ (d) If the Work includes a "NOTICE" text file as part of its
85
+ distribution, then any Derivative Works that You distribute must
86
+ include a readable copy of the attribution notices contained
87
+ within such NOTICE file.
88
+
89
+ 5. Submission of Contributions.
90
+
91
+ 6. Trademarks. This License does not grant permission to use the trade
92
+ names, trademarks, service marks, or product names of the Licensor.
93
+
94
+ 7. Disclaimer of Warranty. Unless required by applicable law or
95
+ agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
96
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
97
+
98
+ 8. Limitation of Liability. In no event and under no legal theory shall
99
+ any Contributor be liable to You for damages.
100
+
101
+ 9. Accepting Warranty or Additional Liability.
102
+
103
+ Copyright 2026 Molecule Dev, Inc.
104
+
105
+ Licensed under the Apache License, Version 2.0 (the "License");
106
+ you may not use this file except in compliance with the License.
107
+ You may obtain a copy of the License at
108
+
109
+ http://www.apache.org/licenses/LICENSE-2.0
110
+
111
+ Unless required by applicable law or agreed to in writing, software
112
+ distributed under the License is distributed on an "AS IS" BASIS,
113
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
114
+ See the License for the specific language governing permissions and
115
+ limitations under the License.
@@ -0,0 +1,43 @@
1
+ import type { ReactElement } from 'react';
2
+ import { formatCurrency } from './utils.js';
3
+ /** Transaction type used to categorise an amount entry. */
4
+ export type AmountType = 'income' | 'expense' | 'transfer' | 'other';
5
+ /** Props for {@link AmountInput}. */
6
+ export interface AmountInputProps {
7
+ /** Current numeric amount (major units). */
8
+ amount: number | '';
9
+ /** Called whenever the amount text changes. */
10
+ onAmountChange: (amount: number | '') => void;
11
+ /** Optional type (income/expense/transfer) toggle. */
12
+ type?: AmountType;
13
+ /** Called when the user changes the type. When omitted, the toggle is hidden. */
14
+ onTypeChange?: (type: AmountType) => void;
15
+ /** Type options to show in the toggle. Defaults to `['income', 'expense']`. */
16
+ typeOptions?: AmountType[];
17
+ /**
18
+ * Optional per-type label overrides. A value provided for a type wins over
19
+ * the translated / `defaultValue` label (prop > `t()` > default), letting a
20
+ * consumer relabel the toggle without wiring a locale bond.
21
+ */
22
+ typeLabels?: Partial<Record<AmountType, string>>;
23
+ /** Currency symbol or label rendered to the left of the input. Defaults to `'$'`. */
24
+ currencySymbol?: string;
25
+ /**
26
+ * Accessible label for the numeric input. Overrides the translated /
27
+ * `defaultValue` `'Amount'` (prop > `t()` > default).
28
+ */
29
+ ariaLabel?: string;
30
+ /** Input size. */
31
+ size?: 'md' | 'lg' | 'xl';
32
+ /** Extra classes. */
33
+ className?: string;
34
+ }
35
+ /**
36
+ * Large transaction-style amount input with optional type toggle +
37
+ * currency symbol. Common in budgeting, expense-reporting, and
38
+ * financial-form UX.
39
+ * @param props - Component props (see {@link AmountInputProps}).
40
+ */
41
+ export declare function AmountInput({ amount, onAmountChange, type, onTypeChange, typeOptions, typeLabels, currencySymbol, ariaLabel, size, className, }: AmountInputProps): ReactElement;
42
+ export { formatCurrency };
43
+ //# sourceMappingURL=AmountInput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AmountInput.d.ts","sourceRoot":"","sources":["../src/AmountInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,YAAY,EAAE,MAAM,OAAO,CAAA;AAMtD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE3C,2DAA2D;AAC3D,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,SAAS,GAAG,UAAU,GAAG,OAAO,CAAA;AAEpE,qCAAqC;AACrC,MAAM,WAAW,gBAAgB;IAC/B,4CAA4C;IAC5C,MAAM,EAAE,MAAM,GAAG,EAAE,CAAA;IACnB,+CAA+C;IAC/C,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,EAAE,KAAK,IAAI,CAAA;IAC7C,sDAAsD;IACtD,IAAI,CAAC,EAAE,UAAU,CAAA;IACjB,iFAAiF;IACjF,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAA;IACzC,+EAA+E;IAC/E,WAAW,CAAC,EAAE,UAAU,EAAE,CAAA;IAC1B;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAA;IAChD,qFAAqF;IACrF,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,kBAAkB;IAClB,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAA;IACzB,qBAAqB;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAUD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,EAC1B,MAAM,EACN,cAAc,EACd,IAAI,EACJ,YAAY,EACZ,WAAmC,EACnC,UAAU,EACV,cAAoB,EACpB,SAAS,EACT,IAAW,EACX,SAAS,GACV,EAAE,gBAAgB,GAAG,YAAY,CAoDjC;AAGD,OAAO,EAAE,cAAc,EAAE,CAAA"}
@@ -0,0 +1,41 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { t } from '@molecule/app-i18n';
3
+ import { getClassMap } from '@molecule/app-ui';
4
+ import { Button } from '@molecule/app-ui-react';
5
+ import { formatCurrency } from './utils.js';
6
+ /** English fallback labels for each amount type — keyed to `amountInput.type.*`. */
7
+ const TYPE_LABEL = {
8
+ income: 'Income',
9
+ expense: 'Expense',
10
+ transfer: 'Transfer',
11
+ other: 'Other',
12
+ };
13
+ /**
14
+ * Large transaction-style amount input with optional type toggle +
15
+ * currency symbol. Common in budgeting, expense-reporting, and
16
+ * financial-form UX.
17
+ * @param props - Component props (see {@link AmountInputProps}).
18
+ */
19
+ export function AmountInput({ amount, onAmountChange, type, onTypeChange, typeOptions = ['income', 'expense'], typeLabels, currencySymbol = '$', ariaLabel, size = 'lg', className, }) {
20
+ const cm = getClassMap();
21
+ const amountLabel = ariaLabel ?? t('amountInput.ariaLabel', undefined, { defaultValue: 'Amount' });
22
+ /**
23
+ * Parses the raw input value and fires onAmountChange with a number or empty string.
24
+ * @param e
25
+ */
26
+ function handleChange(e) {
27
+ const raw = e.target.value.replace(/[^0-9.-]/g, '');
28
+ if (raw === '' || raw === '-') {
29
+ onAmountChange('');
30
+ return;
31
+ }
32
+ const n = Number(raw);
33
+ if (Number.isFinite(n))
34
+ onAmountChange(n);
35
+ }
36
+ const fontClass = size === 'xl' ? cm.textSize('5xl') : size === 'lg' ? cm.textSize('4xl') : cm.textSize('2xl');
37
+ return (_jsxs("div", { className: cm.cn(cm.stack(3), className), children: [onTypeChange && (_jsx("div", { className: cm.flex({ align: 'center', gap: 'xs' }), children: typeOptions.map((opt) => (_jsx(Button, { type: "button", variant: type === opt ? 'solid' : 'ghost', color: type === opt ? 'primary' : undefined, size: "sm", onClick: () => onTypeChange(opt), children: typeLabels?.[opt] ??
38
+ t(`amountInput.type.${opt}`, undefined, { defaultValue: TYPE_LABEL[opt] }) }, opt))) })), _jsxs("div", { className: cm.flex({ align: 'baseline', gap: 'xs' }), children: [_jsx("span", { className: cm.cn(fontClass, cm.fontWeight('bold')), children: currencySymbol }), _jsx("input", { type: "text", inputMode: "decimal", value: amount === '' ? '' : String(amount), onChange: handleChange, placeholder: "0", "aria-label": amountLabel, className: cm.cn(fontClass, cm.fontWeight('bold')), style: { border: 'none', outline: 'none', background: 'transparent', flex: 1 } })] })] }));
39
+ }
40
+ // Re-export formatCurrency util for convenience.
41
+ export { formatCurrency };
@@ -0,0 +1,37 @@
1
+ /**
2
+ * React amount input with type toggle.
3
+ *
4
+ * Exports:
5
+ * - `<AmountInput>` — large currency input with income/expense toggle.
6
+ * - `AmountType` — `'income' | 'expense' | 'transfer' | 'other'`.
7
+ * - `formatCurrency` — convenience re-export.
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * import { AmountInput } from '@molecule/app-amount-input-react'
12
+ *
13
+ * const [amount, setAmount] = useState<number | ''>(0)
14
+ * const [type, setType] = useState<'income' | 'expense'>('expense')
15
+ *
16
+ * <AmountInput
17
+ * amount={amount}
18
+ * onAmountChange={setAmount}
19
+ * type={type}
20
+ * onTypeChange={(t) => setType(t as 'income' | 'expense')}
21
+ * currencySymbol="$"
22
+ * size="lg"
23
+ * />
24
+ * ```
25
+ *
26
+ * @remarks
27
+ * All user-facing text flows through `t()` with English `defaultValue`
28
+ * fallbacks under the `amountInput.*` keys, so a wired locale bond (or the
29
+ * host app's own locale) can translate the type-toggle labels and the input's
30
+ * accessible name. Both are also overridable per-instance without a bond: the
31
+ * `typeLabels` prop relabels the toggle and `ariaLabel` sets the input's
32
+ * accessible name (prop > `t()` > default).
33
+ *
34
+ * @module
35
+ */
36
+ export * from './AmountInput.js';
37
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,cAAc,kBAAkB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,36 @@
1
+ /**
2
+ * React amount input with type toggle.
3
+ *
4
+ * Exports:
5
+ * - `<AmountInput>` — large currency input with income/expense toggle.
6
+ * - `AmountType` — `'income' | 'expense' | 'transfer' | 'other'`.
7
+ * - `formatCurrency` — convenience re-export.
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * import { AmountInput } from '@molecule/app-amount-input-react'
12
+ *
13
+ * const [amount, setAmount] = useState<number | ''>(0)
14
+ * const [type, setType] = useState<'income' | 'expense'>('expense')
15
+ *
16
+ * <AmountInput
17
+ * amount={amount}
18
+ * onAmountChange={setAmount}
19
+ * type={type}
20
+ * onTypeChange={(t) => setType(t as 'income' | 'expense')}
21
+ * currencySymbol="$"
22
+ * size="lg"
23
+ * />
24
+ * ```
25
+ *
26
+ * @remarks
27
+ * All user-facing text flows through `t()` with English `defaultValue`
28
+ * fallbacks under the `amountInput.*` keys, so a wired locale bond (or the
29
+ * host app's own locale) can translate the type-toggle labels and the input's
30
+ * accessible name. Both are also overridable per-instance without a bond: the
31
+ * `typeLabels` prop relabels the toggle and `ariaLabel` sets the input's
32
+ * accessible name (prop > `t()` > default).
33
+ *
34
+ * @module
35
+ */
36
+ export * from './AmountInput.js';
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Formats a numeric amount as currency via `Intl.NumberFormat`.
3
+ * (Duplicated from `@molecule/app-currency-display-react` so this package
4
+ * stays standalone — or wire the peer dep if you prefer.)
5
+ *
6
+ * @module
7
+ */
8
+ /**
9
+ * Formats a numeric amount as a localized currency string.
10
+ * @param amount
11
+ * @param currency
12
+ * @param locale
13
+ */
14
+ export declare function formatCurrency(amount: number, currency?: string, locale?: string): string;
15
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAc,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAEhG"}
package/dist/utils.js ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Formats a numeric amount as currency via `Intl.NumberFormat`.
3
+ * (Duplicated from `@molecule/app-currency-display-react` so this package
4
+ * stays standalone — or wire the peer dep if you prefer.)
5
+ *
6
+ * @module
7
+ */
8
+ /**
9
+ * Formats a numeric amount as a localized currency string.
10
+ * @param amount
11
+ * @param currency
12
+ * @param locale
13
+ */
14
+ export function formatCurrency(amount, currency = 'USD', locale) {
15
+ return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(amount);
16
+ }
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@molecule/app-amount-input-react",
3
+ "version": "1.0.0",
4
+ "description": "Large amount input with income/expense toggle + currency symbol",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "test": "vitest run",
11
+ "test:watch": "vitest"
12
+ },
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "keywords": [
23
+ "molecule",
24
+ "amount-input",
25
+ "react"
26
+ ],
27
+ "license": "Apache-2.0",
28
+ "peerDependencies": {
29
+ "@molecule/app-react": "^1.0.0",
30
+ "@molecule/app-ui": "^1.0.0",
31
+ "@molecule/app-ui-react": "^1.0.0",
32
+ "react": "^18.0.0 || ^19.0.0"
33
+ },
34
+ "devDependencies": {
35
+ "@molecule/app-i18n": "1.0.0",
36
+ "@molecule/app-react": "1.0.0",
37
+ "@molecule/app-ui": "1.0.0",
38
+ "@molecule/app-ui-react": "1.0.0",
39
+ "@types/node": "26.1.2",
40
+ "@types/react": "19.2.17",
41
+ "@types/react-dom": "19.2.3",
42
+ "react": "19.2.8",
43
+ "react-dom": "19.2.8",
44
+ "typescript": "6.0.3",
45
+ "vitest": "4.1.10"
46
+ }
47
+ }