ud-components 0.7.7 → 0.7.9
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/fesm2022/ud-components.mjs +230 -3
- package/fesm2022/ud-components.mjs.map +1 -1
- package/lib/form-fields/money-input/money-input.component.d.ts +50 -0
- package/lib/form-fields/money-input/money.utils.d.ts +25 -0
- package/lib/summary-view/summary-view.component.d.ts +14 -2
- package/lib/summary-view/summary-view.interface.d.ts +2 -0
- package/package.json +1 -1
- package/public-api.d.ts +2 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { OnChanges, OnInit, SimpleChanges } from '@angular/core';
|
|
2
|
+
import { FormControl } from '@angular/forms';
|
|
3
|
+
import { UdInputSize } from '../text-input/text-input.component';
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
export type UdMoneyMode = 'amount' | 'percent';
|
|
6
|
+
/**
|
|
7
|
+
* An amount of money, or a percentage, as a decimal string (UC-23).
|
|
8
|
+
*
|
|
9
|
+
* <p>Same conventions as the other form fields: bound by {@code controlName}
|
|
10
|
+
* inside a parent FormGroup. The control's value is a normalised decimal
|
|
11
|
+
* string ({@code "412.30"}), never a number, so float error never reaches an
|
|
12
|
+
* API. Paste-tolerant ({@code "$1,234.5"}), shown with thousands separators
|
|
13
|
+
* once the field loses focus. While the text cannot be read, the control holds
|
|
14
|
+
* the raw text and carries a {@code udMoney} error.
|
|
15
|
+
*
|
|
16
|
+
* <p>Percent mode: a {@code %} suffix, 0 to 100 unless min / max say
|
|
17
|
+
* otherwise, still two decimals.
|
|
18
|
+
*/
|
|
19
|
+
export declare class MoneyInputComponent implements OnInit, OnChanges {
|
|
20
|
+
controlName: string;
|
|
21
|
+
label: string;
|
|
22
|
+
placeholder: string;
|
|
23
|
+
/** Shown before the amount, e.g. "$" or "CAD". Ignored in percent mode. */
|
|
24
|
+
currency: string;
|
|
25
|
+
mode: UdMoneyMode;
|
|
26
|
+
/** Decimal strings, inclusive. Percent mode defaults to 0 and 100. */
|
|
27
|
+
min?: string;
|
|
28
|
+
max?: string;
|
|
29
|
+
allowNegative: boolean;
|
|
30
|
+
disabled: boolean;
|
|
31
|
+
hint: string;
|
|
32
|
+
size: UdInputSize;
|
|
33
|
+
readonly text: import("@angular/core").WritableSignal<string>;
|
|
34
|
+
readonly focused: import("@angular/core").WritableSignal<boolean>;
|
|
35
|
+
private controlContainer;
|
|
36
|
+
private destroyRef;
|
|
37
|
+
private validator;
|
|
38
|
+
get control(): FormControl;
|
|
39
|
+
get error(): string | null;
|
|
40
|
+
ngOnInit(): void;
|
|
41
|
+
ngOnChanges(changes: SimpleChanges): void;
|
|
42
|
+
onInput(raw: string): void;
|
|
43
|
+
onBlur(): void;
|
|
44
|
+
private showValue;
|
|
45
|
+
private get effectiveMin();
|
|
46
|
+
private get effectiveMax();
|
|
47
|
+
private validate;
|
|
48
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<MoneyInputComponent, never>;
|
|
49
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<MoneyInputComponent, "ud-money-input", never, { "controlName": { "alias": "controlName"; "required": true; }; "label": { "alias": "label"; "required": false; }; "placeholder": { "alias": "placeholder"; "required": false; }; "currency": { "alias": "currency"; "required": false; }; "mode": { "alias": "mode"; "required": false; }; "min": { "alias": "min"; "required": false; }; "max": { "alias": "max"; "required": false; }; "allowNegative": { "alias": "allowNegative"; "required": false; }; "disabled": { "alias": "disabled"; "required": false; }; "hint": { "alias": "hint"; "required": false; }; "size": { "alias": "size"; "required": false; }; }, {}, never, never, true, never>;
|
|
50
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Money as decimal strings, never JS numbers (UC-23). `0.1 + 0.2` is
|
|
3
|
+
* `0.30000000000000004`; an amount that went through a float can reach the API
|
|
4
|
+
* a cent off. Everything here works on the digits of the string, and the only
|
|
5
|
+
* arithmetic is on whole cents.
|
|
6
|
+
*/
|
|
7
|
+
export type MoneyParseError = 'format' | 'decimals' | 'negative';
|
|
8
|
+
export interface MoneyParseResult {
|
|
9
|
+
/** Normalised decimal string ("1234.50"), or null for an empty input. Undefined when invalid. */
|
|
10
|
+
value?: string | null;
|
|
11
|
+
error?: MoneyParseError;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Reads what a person typed or pasted: "1,234.5", "$1234.50", " 12 ", "CA$ 3".
|
|
15
|
+
* Currency symbols, letters, spaces and thousands commas are dropped; at most
|
|
16
|
+
* {@link decimals} decimals are allowed; the result is padded to exactly that
|
|
17
|
+
* many ("12" → "12.00").
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseMoney(raw: string | number | null | undefined, decimals?: number, allowNegative?: boolean): MoneyParseResult;
|
|
20
|
+
/** Whole cents of a normalised 2-decimal string: "1234.50" → 123450. */
|
|
21
|
+
export declare function moneyToCents(value: string): number;
|
|
22
|
+
/** The inverse of {@link moneyToCents}: 123450 → "1234.50". Rounds nothing; give it whole cents. */
|
|
23
|
+
export declare function centsToMoney(cents: number): string;
|
|
24
|
+
/** For display only: "1234.50" → "1,234.50". Never parse this back as a number. */
|
|
25
|
+
export declare function groupThousands(value: string): string;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { OnDestroy } from '@angular/core';
|
|
1
2
|
import { SummaryAction, SummaryField } from './summary-view.interface';
|
|
2
3
|
import * as i0 from "@angular/core";
|
|
3
4
|
type LAYOUTS = 'text-left' | 'text-right' | 'text-all' | 'text-none' | 'text-top';
|
|
4
|
-
export declare class SummaryViewComponent {
|
|
5
|
+
export declare class SummaryViewComponent implements OnDestroy {
|
|
6
|
+
private readonly clipboard;
|
|
5
7
|
title: string | null;
|
|
6
8
|
actions: SummaryAction[];
|
|
7
9
|
summaryFields: SummaryField[];
|
|
@@ -9,7 +11,17 @@ export declare class SummaryViewComponent {
|
|
|
9
11
|
layout: LAYOUTS;
|
|
10
12
|
skeletonTitleHeight: string;
|
|
11
13
|
skeletonBodyHeight: string;
|
|
14
|
+
/** Tooltip of a copyable field's button; an i18n key or plain text, like action labels. */
|
|
15
|
+
copyLabel: string;
|
|
16
|
+
/** Tooltip right after copying. */
|
|
17
|
+
copiedLabel: string;
|
|
18
|
+
/** Index of the field just copied, so its button shows a check for a moment. */
|
|
19
|
+
protected readonly copiedIndex: import("@angular/core").WritableSignal<number | null>;
|
|
20
|
+
private resetTimer?;
|
|
21
|
+
protected hasValue(field: SummaryField): boolean;
|
|
22
|
+
protected copy(field: SummaryField, index: number): void;
|
|
23
|
+
ngOnDestroy(): void;
|
|
12
24
|
static ɵfac: i0.ɵɵFactoryDeclaration<SummaryViewComponent, never>;
|
|
13
|
-
static ɵcmp: i0.ɵɵComponentDeclaration<SummaryViewComponent, "ud-summary-view", never, { "title": { "alias": "title"; "required": false; }; "actions": { "alias": "actions"; "required": false; }; "summaryFields": { "alias": "summaryFields"; "required": false; }; "loading": { "alias": "loading"; "required": false; }; "layout": { "alias": "layout"; "required": false; }; "skeletonTitleHeight": { "alias": "skeletonTitleHeight"; "required": false; }; "skeletonBodyHeight": { "alias": "skeletonBodyHeight"; "required": false; }; }, {}, never, ["[header-actions]", "*"], true, never>;
|
|
25
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<SummaryViewComponent, "ud-summary-view", never, { "title": { "alias": "title"; "required": false; }; "actions": { "alias": "actions"; "required": false; }; "summaryFields": { "alias": "summaryFields"; "required": false; }; "loading": { "alias": "loading"; "required": false; }; "layout": { "alias": "layout"; "required": false; }; "skeletonTitleHeight": { "alias": "skeletonTitleHeight"; "required": false; }; "skeletonBodyHeight": { "alias": "skeletonBodyHeight"; "required": false; }; "copyLabel": { "alias": "copyLabel"; "required": false; }; "copiedLabel": { "alias": "copiedLabel"; "required": false; }; }, {}, never, ["[header-actions]", "*"], true, never>;
|
|
14
26
|
}
|
|
15
27
|
export {};
|
|
@@ -2,6 +2,8 @@ export interface SummaryField {
|
|
|
2
2
|
label?: string;
|
|
3
3
|
icon: string;
|
|
4
4
|
value: string | number | boolean | undefined;
|
|
5
|
+
/** Shows a copy button next to the value on hover (UC-24). Ignored when the value is empty. */
|
|
6
|
+
copyable?: boolean;
|
|
5
7
|
}
|
|
6
8
|
export interface SummaryAction {
|
|
7
9
|
label: string;
|
package/package.json
CHANGED
package/public-api.d.ts
CHANGED
|
@@ -32,6 +32,8 @@ export * from './lib/form-fields/time-picker/time-picker.component';
|
|
|
32
32
|
export * from './lib/form-fields/textarea/textarea.component';
|
|
33
33
|
export * from './lib/form-fields/phone-input/phone-input.component';
|
|
34
34
|
export * from './lib/form-fields/chip-input/chip-input.component';
|
|
35
|
+
export * from './lib/form-fields/money-input/money-input.component';
|
|
36
|
+
export * from './lib/form-fields/money-input/money.utils';
|
|
35
37
|
export * from './lib/calendar/calendar.component';
|
|
36
38
|
export * from './lib/tooltip/tooltip.component';
|
|
37
39
|
export * from './lib/tooltip/tooltip.directive';
|