@commercelayer/app-elements 0.0.34 → 0.0.36

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.
@@ -0,0 +1,44 @@
1
+ import { type InputWrapperBaseProps } from '../../forms/InputWrapper';
2
+ import { type CurrencyInputProps } from 'react-currency-input-field';
3
+ import { type CurrencyCode } from './currencies';
4
+ export interface InputCurrencyProps extends InputWrapperBaseProps, Pick<CurrencyInputProps, 'onBlur' | 'onClick' | 'disabled'> {
5
+ /**
6
+ * HTML input id
7
+ */
8
+ id?: string;
9
+ /**
10
+ * Field name
11
+ */
12
+ name?: string;
13
+ /**
14
+ * Input placeholder
15
+ */
16
+ placeholder?: string;
17
+ /**
18
+ * optional css class names used for the input element
19
+ */
20
+ className?: string;
21
+ /**
22
+ * Valid 3-digit iso currency code (eg: EUR, USD, GBP)
23
+ */
24
+ currencyCode: Uppercase<CurrencyCode>;
25
+ /**
26
+ * Value in cents
27
+ */
28
+ cents?: number | null;
29
+ /**
30
+ * onChange callback triggered when during typing
31
+ */
32
+ onChange: (cents: number | null, formatted: string) => void;
33
+ }
34
+ declare const InputCurrency: import("react").ForwardRefExoticComponent<InputCurrencyProps & import("react").RefAttributes<HTMLInputElement>>;
35
+ /**
36
+ * Format cents to currency.
37
+ * Useful to display the returned value from `<InputCurrency>` component.
38
+ *
39
+ * Example: formatCentsToCurrency(100, 'EUR') -> €1,00
40
+ * Example: formatCentsToCurrency(100000, 'USD') -> $1,000.00
41
+ * Example: formatCentsToCurrency(100, 'JPY') -> ¥100
42
+ **/
43
+ declare function formatCentsToCurrency(cents: number, currencyCode: Uppercase<CurrencyCode>): string;
44
+ export { InputCurrency, formatCentsToCurrency };
@@ -0,0 +1,26 @@
1
+ import { type Currency, type CurrencyCode } from './currencies';
2
+ /**
3
+ * Returns a currency object for a given currency code
4
+ */
5
+ export declare function getCurrency(currencyCode: Uppercase<CurrencyCode> | CurrencyCode): Currency | undefined;
6
+ /**
7
+ * Returns the number of decimals for a given currency
8
+ */
9
+ export declare function getDecimalLength(currency: Currency): number;
10
+ /**
11
+ * Add currency symbol to formatted value based on currency.symbol_first.
12
+ * Some currencies have symbol as prefix, some as suffix.
13
+ * Example: EUR -> € 1.000,00
14
+ * Example: LRD -> 1,000.00 $ (:iberian dollar)
15
+ */
16
+ export declare function addCurrencySymbol({ formattedValue, currency }: {
17
+ formattedValue: string;
18
+ currency: Currency;
19
+ }): string;
20
+ /**
21
+ * Create a placeholder based on the currency decimal length.
22
+ * Example: EUR -> 0,00
23
+ * Example: JPY -> 0
24
+ * Example: CLF -> 0,0000
25
+ */
26
+ export declare function makePlaceholder(currency: Currency): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercelayer/app-elements",
3
- "version": "0.0.34",
3
+ "version": "0.0.36",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -29,6 +29,7 @@
29
29
  "jwt-decode": "^3.1.2",
30
30
  "lodash": "^4.17.21",
31
31
  "react": "^18.2.0",
32
+ "react-currency-input-field": "^3.6.10",
32
33
  "react-datepicker": "^4.11.0",
33
34
  "react-dom": "^18.2.0",
34
35
  "react-select": "^5.7.2",