@babylonlabs-io/core-ui 1.24.0 → 1.26.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/dist/components/Accordion/Accordion.d.ts +2 -1
- package/dist/components/Accordion/Accordion.js +2 -2
- package/dist/components/Accordion/components/AccordionSummary.d.ts +3 -1
- package/dist/components/Accordion/components/AccordionSummary.js +2 -2
- package/dist/components/Button/IconButton.d.ts +9 -3
- package/dist/components/Button/IconButton.js +4 -3
- package/dist/components/Button/IconButton.stories.d.ts +6 -0
- package/dist/components/Button/IconButton.stories.js +42 -0
- package/dist/components/Form/Input.js +1 -1
- package/dist/components/SubSection/SubSection.d.ts +3 -1
- package/dist/components/SubSection/SubSection.js +2 -1
- package/dist/components/Table/Table.js +5 -2
- package/dist/components/Table/Table.stories.d.ts +1 -0
- package/dist/components/Table/Table.stories.js +6 -0
- package/dist/components/Table/types/index.d.ts +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +984 -953
- package/dist/index.es.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/widgets/sections/AmountSubsection/AmountSubsection.d.ts +2 -1
- package/dist/widgets/sections/AmountSubsection/AmountSubsection.js +20 -2
- package/dist/widgets/sections/AmountSubsection/AmountSubsection.stories.d.ts +1 -0
- package/dist/widgets/sections/AmountSubsection/AmountSubsection.stories.js +21 -0
- package/package.json +1 -1
|
@@ -16,6 +16,7 @@ interface Props {
|
|
|
16
16
|
min?: string;
|
|
17
17
|
step?: string;
|
|
18
18
|
autoFocus?: boolean;
|
|
19
|
+
decimals?: number;
|
|
19
20
|
}
|
|
20
|
-
export declare const AmountSubsection: ({ fieldName, currencyIcon, currencyName, displayBalance, placeholder, balanceDetails, prefix, min, step, autoFocus, }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
export declare const AmountSubsection: ({ fieldName, currencyIcon, currencyName, displayBalance, placeholder, balanceDetails, prefix, min, step, autoFocus, decimals, }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
21
22
|
export {};
|
|
@@ -5,7 +5,7 @@ import { useFormContext, useWatch } from "react-hook-form";
|
|
|
5
5
|
import { AmountItem } from "../../../components/AmountItem/AmountItem";
|
|
6
6
|
import { calculateTokenValueInCurrency, maxDecimals } from "@/utils/helpers";
|
|
7
7
|
import { BTC_DECIMAL_PLACES } from "@/utils/constants";
|
|
8
|
-
export const AmountSubsection = ({ fieldName, currencyIcon, currencyName, displayBalance, placeholder = "Enter Amount", balanceDetails, prefix, min = "0", step = "any", autoFocus = true, }) => {
|
|
8
|
+
export const AmountSubsection = ({ fieldName, currencyIcon, currencyName, displayBalance, placeholder = "Enter Amount", balanceDetails, prefix, min = "0", step = "any", autoFocus = true, decimals, }) => {
|
|
9
9
|
const amount = useWatch({ name: fieldName, defaultValue: "" });
|
|
10
10
|
const { setValue } = useFormContext();
|
|
11
11
|
const amountValue = parseFloat(amount || "0");
|
|
@@ -13,7 +13,25 @@ export const AmountSubsection = ({ fieldName, currencyIcon, currencyName, displa
|
|
|
13
13
|
zeroDisplay: "$0.00",
|
|
14
14
|
});
|
|
15
15
|
const handleInputChange = (e) => {
|
|
16
|
-
|
|
16
|
+
let value = e.target.value;
|
|
17
|
+
// If decimals is specified, validate and restrict input
|
|
18
|
+
if (decimals !== undefined && decimals >= 0) {
|
|
19
|
+
// Handle multiple decimal points by taking only the first one
|
|
20
|
+
const [integer, decimal] = value.split('.', 2);
|
|
21
|
+
if (decimal !== undefined && decimal.length > decimals) {
|
|
22
|
+
// Truncate decimal part to specified length
|
|
23
|
+
value = integer + '.' + decimal.slice(0, decimals);
|
|
24
|
+
}
|
|
25
|
+
else if (decimal !== undefined) {
|
|
26
|
+
// Ensure we only have one decimal point
|
|
27
|
+
value = integer + '.' + decimal;
|
|
28
|
+
}
|
|
29
|
+
else if (value.includes('.')) {
|
|
30
|
+
// Handle case where there are multiple dots but no decimal part
|
|
31
|
+
value = integer;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
setValue(fieldName, value, {
|
|
17
35
|
shouldValidate: true,
|
|
18
36
|
shouldDirty: true,
|
|
19
37
|
shouldTouch: true,
|
|
@@ -207,3 +207,24 @@ export const NoPrefix = {
|
|
|
207
207
|
(Story) => (_jsx(Form, { onChange: console.log, schema: schema, children: _jsx(Story, {}) })),
|
|
208
208
|
],
|
|
209
209
|
};
|
|
210
|
+
export const RestrictedDecimals = {
|
|
211
|
+
args: {
|
|
212
|
+
fieldName: "amount",
|
|
213
|
+
currencyIcon: "https://placehold.co/40x40/FF6B6B/FFFFFF?text=₿",
|
|
214
|
+
currencyName: "BTC",
|
|
215
|
+
placeholder: "Enter BTC amount (max 2 decimals)",
|
|
216
|
+
prefix: "Available",
|
|
217
|
+
displayBalance: true,
|
|
218
|
+
decimals: 2, // Restrict to 2 decimal places
|
|
219
|
+
balanceDetails: {
|
|
220
|
+
balance: 1.23456789,
|
|
221
|
+
symbol: "BTC",
|
|
222
|
+
price: 65000,
|
|
223
|
+
displayUSD: true,
|
|
224
|
+
decimals: 8,
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
decorators: [
|
|
228
|
+
(Story) => (_jsx(Form, { onChange: console.log, schema: schema, children: _jsx(Story, {}) })),
|
|
229
|
+
],
|
|
230
|
+
};
|