From 69d0c447550c58bb36b4532c5bf5033d421bbb23 Mon Sep 17 00:00:00 2001 From: jialecl Date: Fri, 13 Nov 2026 12:08:56 +0100 Subject: [PATCH 1/8] Amount input implementation --- .../src/amount-input/AmountInput.stories.tsx | 62 ++++++++ packages/lib/src/amount-input/AmountInput.tsx | 138 +++++++++++++++++ packages/lib/src/amount-input/types.ts | 146 ++++++++++++++++++ packages/lib/src/amount-input/utils.ts | 93 +++++++++++ packages/lib/src/common/variables.ts | 10 +- packages/lib/src/index.ts | 6 + 6 files changed, 452 insertions(+), 3 deletions(-) create mode 100644 packages/lib/src/amount-input/AmountInput.stories.tsx create mode 100644 packages/lib/src/amount-input/AmountInput.tsx create mode 100644 packages/lib/src/amount-input/types.ts create mode 100644 packages/lib/src/amount-input/utils.ts diff --git a/packages/lib/src/amount-input/AmountInput.stories.tsx b/packages/lib/src/amount-input/AmountInput.stories.tsx new file mode 100644 index 000000000..05ef12436 --- /dev/null +++ b/packages/lib/src/amount-input/AmountInput.stories.tsx @@ -0,0 +1,62 @@ +import { Meta, StoryObj } from "@storybook/react-vite"; +import type { CurrencyConfigType, UnitsConfigType } from "./types"; +import ExampleContainer from "../../.storybook/components/ExampleContainer"; +import Title from "../../.storybook/components/Title"; +import DxcAmountInput from "./AmountInput"; +import { HalstackProvider } from "../HalstackContext"; + +export default { + title: "Amount Input", + component: DxcAmountInput, +} satisfies Meta; + +const AmountInput = () => { + const currencyConfig = { + currency: "CNY", + currencyDisplay: "symbol", + currencySign: "standard", + } as CurrencyConfigType; + + const unitsConfig = { + unit: "kilometer", + unitDisplay: "short", + } as UnitsConfigType; + return ( + <> + + + {/* <DxcAmountInput /> */} + <HalstackProvider localeTag="en-IN"> + <DxcAmountInput label="Amount default" helperText="US locale" /> + <DxcAmountInput + label="Amount in RMB" + config={{ currencyConfig: currencyConfig }} + defaultValue="1234.56" + maxValue={10000} + minValue={1000} + onChange={(event) => console.log(event)} + onBlur={(event) => console.log(event)} + alignment="right" + clearable + /> + <DxcAmountInput + label="Distance in km" + config={{ unitsConfig: unitsConfig, decimalSeparator: "()", thousandSeparator: "@" }} + /> + </HalstackProvider> + <DxcAmountInput label="Amount default" helperText="no locale" /> + <DxcAmountInput label="Amount in RMB" config={{ currencyConfig: currencyConfig }} /> + <DxcAmountInput + label="Distance in km" + config={{ unitsConfig: unitsConfig, decimalSeparator: "()", thousandSeparator: "@" }} + /> + </ExampleContainer> + </> + ); +}; + +type Story = StoryObj<typeof AmountInput>; + +export const Chromatic: Story = { + render: AmountInput, +}; diff --git a/packages/lib/src/amount-input/AmountInput.tsx b/packages/lib/src/amount-input/AmountInput.tsx new file mode 100644 index 000000000..df33c1b83 --- /dev/null +++ b/packages/lib/src/amount-input/AmountInput.tsx @@ -0,0 +1,138 @@ +import { HalstackLanguageContext } from "../HalstackContext"; +import TextInput from "../text-input/TextInput"; +import { AmountInputProps } from "./types"; +import { use, useCallback, useEffect, useMemo, useRef, useState } from "react"; +import { sanitizeAmount, formatString, getDefaultConfigBasedOnLocale, getErrorMessage } from "./utils"; + +const AmountInput = ({ + alignment, + ariaLabel, + clearable, + config, + defaultValue, + disabled, + error, + helperText, + label, + maxValue, + minValue, + name, + numberOfDecimals, + numberOfIntegers, + onChange, + onBlur, + optional, + placeholder, + readOnly, + ref, + size, + tabIndex, + value, +}: AmountInputProps) => { + const languageContext = use(HalstackLanguageContext); + const translatedLabels = languageContext.labels; + const locale = languageContext.locale ? languageContext.locale : undefined; + const [numberValue, setNumberValue] = useState<string | undefined>(""); + const [isFocused, setIsFocused] = useState(false); + const isControlled = useRef(value !== undefined); + const inputRef = useRef<HTMLInputElement | null>(null); + const setInputRef = useCallback( + (element: HTMLInputElement | null) => { + inputRef.current = element; + if (typeof ref === "function") { + const cleanup = ref(element); + if (typeof cleanup === "function") { + return () => { + inputRef.current = null; + cleanup(); + }; + } + } else if (ref) { + ref.current = element; + } + }, + [ref] + ); + const localeConfig = useMemo(() => { + return getDefaultConfigBasedOnLocale(locale, config); + }, [locale, config]); + + const displayValue = useMemo(() => { + if (numberValue === undefined || numberValue === "") return undefined; + if (config) { + return formatString(numberValue, locale, config); + } + return new Intl.NumberFormat(locale).format(parseFloat(numberValue)); + }, [numberValue, config, locale]); + + useEffect(() => { + setNumberValue( + sanitizeAmount( + value ?? defaultValue, + localeConfig.decimalSeparator, + localeConfig.thousandSeparator, + numberOfDecimals, + numberOfIntegers + ) + ); + }, [value, defaultValue, localeConfig, numberOfDecimals, numberOfIntegers]); + + const handleBlur = (event: { value: string; error?: string }) => { + setIsFocused(false); + const errorMessage = getErrorMessage(event.value, translatedLabels.amountInput, maxValue, minValue); + onBlur?.({ value: formatString(event.value, locale, config), error: errorMessage || event.error }); + }; + + const handleChange = (event: { value: string; error?: string }) => { + const sanitizedValue = sanitizeAmount( + event.value, + localeConfig.decimalSeparator, + localeConfig.thousandSeparator, + numberOfDecimals, + numberOfIntegers + ); + if (!isControlled.current) { + setNumberValue(sanitizedValue); + } + const errorMessage = getErrorMessage(sanitizedValue, translatedLabels.amountInput, maxValue, minValue); + onChange?.({ value: sanitizedValue, error: errorMessage || event.error }); + }; + + useEffect(() => { + const inputElement = inputRef.current?.querySelector("input"); + const handleFocus = () => { + if (!readOnly) setIsFocused(true); + }; + if (inputElement) { + inputElement.addEventListener("focus", handleFocus); + return () => { + inputElement.removeEventListener("focus", handleFocus); + }; + } + }, [readOnly]); + + return ( + <TextInput + alignment={alignment} + ariaLabel={ariaLabel} + autocomplete="off" + clearable={clearable} + disabled={disabled} + error={error} + helperText={helperText} + label={label} + name={name} + onChange={handleChange} + onBlur={handleBlur} + optional={optional} + placeholder={placeholder} + readOnly={readOnly} + ref={setInputRef} + size={size} + tabIndex={tabIndex} + value={isFocused ? (numberValue?.toString() ?? "") : displayValue} + /> + ); +}; + +export default AmountInput; diff --git a/packages/lib/src/amount-input/types.ts b/packages/lib/src/amount-input/types.ts new file mode 100644 index 000000000..6f795d033 --- /dev/null +++ b/packages/lib/src/amount-input/types.ts @@ -0,0 +1,146 @@ +import { PrettifyTypes } from "../common/types"; + +export type CurrencyConfigType = { + currency: string; + currencyDisplay?: "code" | "symbol" | "narrowSymbol" | "name"; + currencySign?: "standard" | "accounting"; +}; + +export type UnitsConfigType = { + unit: string; + unitDisplay?: "short" | "long" | "narrow"; +}; + +export type ConfigType = PrettifyTypes< + { + thousandSeparator?: string; + decimalSeparator?: string; + symbolPosition?: "before" | "after"; + } & ( + | { currencyConfig?: CurrencyConfigType; unitsConfig?: never } + | { currencyConfig?: never; unitsConfig?: UnitsConfigType } + ) +>; + +export type AmountInputProps = { + /** + * Sets the alignment inside the input. + */ + alignment?: "left" | "right"; + /** + * Specifies a string to be used as the name for the textInput element when no `label` is provided. + */ + ariaLabel?: string; + /** + * If true, the input will have an action to clear the entered value. + */ + clearable?: boolean; + /** + * Configuration for the amount input, including currency and units. + * This includes settings for currency, units, and formatting options like thousand and decimal separators, as well as the position of the currency symbol. + */ + config?: ConfigType; + /** + * Initial value of the input, only when it is uncontrolled. + */ + defaultValue?: string; + /** + * If true, the component will be disabled. + */ + disabled?: boolean; + /** + * If it is a defined value and also a truthy string, the component will + * change its appearance, showing the error below the input component. If + * the defined value is an empty string, it will reserve a space below + * the component for a future error, but it would not change its look. In + * case of being undefined or null, both the appearance and the space for + * the error message would not be modified. + */ + error?: string; + /** + * Helper text to be placed above the input. + */ + helperText?: string; + /** + * Text to be placed above the input. This label will be used as the aria-label attribute of the list of suggestions. + */ + label?: string; + /** + * Specifies the maximum value allowed in the input. + */ + maxValue?: number; + /** + * Specifies the minimum value allowed in the input. + */ + minValue?: number; + /** + * Name attribute of the input element. + */ + name?: string; + /** + * Specifies the number of decimal places allowed in the input. + */ + numberOfDecimals?: number; + /** + * Specifies the number of integer places allowed in the input. + */ + numberOfIntegers?: number; + /** + * This function will be called when the user types within the input + * element of the component. An object including the current value and + * the error (if the value entered is not valid) will be passed to this + * function. If there is no error, error will not be defined. + */ + onChange?: (val: { value: string; error?: string }) => void; + /** + * This function will be called when the input element loses the focus. + * An object including the input value and the error (if the value + * entered is not valid) will be passed to this function. If there is no error, + * error will not be defined. + */ + onBlur?: (val: { value: string; error?: string }) => void; + /** + * If true, the input will be optional, showing '(Optional)' + * next to the label. Otherwise, the field will be considered required and an error will be + * passed as a parameter to the OnBlur and onChange functions when it has + * not been filled. + */ + optional?: boolean; + /** + * Text to be put as placeholder of the input. + */ + placeholder?: string; + /** + * If true, the component will not be mutable, meaning the user can not edit the control. + * In addition, the clear action will not be displayed even if the flag is set to true + * and the custom action will not execute its onClick event. + */ + readOnly?: boolean; + /** + * Ref to the input element. + */ + ref?: React.Ref<HTMLInputElement>; + /** + * Size of the component. + */ + size?: "small" | "medium" | "large" | "fillParent"; + /** + * Value of the tabindex attribute. + */ + tabIndex?: number; + /** + * Value of the input. If undefined, the component will be uncontrolled and the value will be managed internally by the component. + */ + value?: string; +}; + +/** + * Reference to the component. + */ +export type RefType = HTMLDivElement; + +/** + * Single suggestion of a Text Input component. + */ + +export type { AmountInputProps as default }; diff --git a/packages/lib/src/amount-input/utils.ts b/packages/lib/src/amount-input/utils.ts new file mode 100644 index 000000000..74ae8f2f3 --- /dev/null +++ b/packages/lib/src/amount-input/utils.ts @@ -0,0 +1,93 @@ +import { ConfigType } from "./types"; + +/** + * Sanitizes the input amount string by removing thousand separators, replacing the decimal separator with a dot, and limiting the number of decimals. + */ +export const sanitizeAmount = ( + value: string | undefined, + decimalSeparator: string, + thousandSeparator: string, + numberOfDecimals?: number, + numberOfIntegers?: number +): string => { + if (!value) return ""; + value = value.replace(/[^\d.,()-]/g, ""); + const isNegative = value.includes("(") && value.includes(")"); + const decimalSeparatorCount = (value.match(new RegExp(`\\${decimalSeparator}`, "g")) || []).length; + if (decimalSeparatorCount > 1) { + const firstIndex = value.indexOf(decimalSeparator); + value = + value.slice(0, firstIndex + 1) + + value.slice(firstIndex + 1).replace(new RegExp(`\\${decimalSeparator}`, "g"), ""); + } + let sanitized = value + .replace(new RegExp(`\\${thousandSeparator}`, "g"), "") + .replace(new RegExp(`\\${decimalSeparator}`), "."); + + if (numberOfDecimals !== undefined && numberOfDecimals >= 0) { + const [integerPart, decimalPart] = sanitized.split("."); + if (decimalPart) { + sanitized = `${integerPart}.${decimalPart.slice(0, numberOfDecimals)}`; + } + } + if (numberOfIntegers !== undefined && numberOfIntegers >= 0) { + const [integerPart, decimalPart] = sanitized.split("."); + if (integerPart) { + sanitized = `${integerPart.slice(0, numberOfIntegers)}${decimalPart ? `.${decimalPart}` : ""}`; + } + } + return isNegative && sanitized ? `-${sanitized}` : sanitized; +}; + +export const formatString = (value: string, locale: string | undefined, config?: ConfigType): string => { + let formatter = new Intl.NumberFormat(locale); + if (config?.currencyConfig && config.currencyConfig.currency) { + formatter = new Intl.NumberFormat(locale, { + style: "currency", + currency: config.currencyConfig.currency, + currencyDisplay: config.currencyConfig.currencyDisplay || "symbol", + currencySign: config.currencyConfig.currencySign || "standard", + }); + } + if (config?.unitsConfig && config.unitsConfig.unit) { + formatter = new Intl.NumberFormat(locale, { + style: "unit", + unit: config.unitsConfig.unit, + unitDisplay: config.unitsConfig.unitDisplay || "short", + }); + } + return formatter + .formatToParts(parseFloat(value)) + .map((part) => { + if (part.type === "decimal" && config?.decimalSeparator) return config.decimalSeparator; + if (part.type === "group" && config?.thousandSeparator) return config.thousandSeparator; + return part.value; + }) + .join(""); +}; + +export const getDefaultConfigBasedOnLocale = (locale: string | undefined, config?: ConfigType) => { + const number = 5004.11; + const formattedNumber = formatString(number.toString(), locale, config); + const decimalSeparator = formattedNumber[formattedNumber.indexOf("4") + 1] || "."; + const thousandSeparator = formattedNumber[formattedNumber.indexOf("5") + 1] || ","; + return { decimalSeparator, thousandSeparator }; +}; + +export const getErrorMessage = ( + value: string, + amountLabels: { + valueGreaterThanOrEqualToErrorMessage: (value: number) => string; + valueLessThanOrEqualToErrorMessage: (value: number) => string; + }, + maxValue?: number, + minValue?: number +) => { + if (maxValue !== undefined && parseFloat(value) > maxValue) { + return amountLabels.valueLessThanOrEqualToErrorMessage(maxValue); + } + if (minValue !== undefined && parseFloat(value) < minValue) { + return amountLabels.valueGreaterThanOrEqualToErrorMessage(minValue); + } + return undefined; +}; diff --git a/packages/lib/src/common/variables.ts b/packages/lib/src/common/variables.ts index 98a2caf42..64e16868b 100644 --- a/packages/lib/src/common/variables.ts +++ b/packages/lib/src/common/variables.ts @@ -19,15 +19,19 @@ export const responsiveSizes = { }; export const defaultTranslatedComponentLabels = { - applicationLayout: { - visibilityToggleTitle: "Toggle sidenav visibility", - }, alert: { previousMessageActionTitle: "Previous message", nextMessageActionTitle: "Next message", closeAlertActionTitle: "Close alert", closeMessageActionTitle: "Close message", }, + applicationLayout: { + visibilityToggleTitle: "Toggle sidenav visibility", + }, + amountInput: { + valueGreaterThanOrEqualToErrorMessage: (value: number) => `Value must be greater than or equal to ${value}.`, + valueLessThanOrEqualToErrorMessage: (value: number) => `Value must be less than or equal to ${value}.`, + }, calendar: { daysShort: ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"], months: [ diff --git a/packages/lib/src/index.ts b/packages/lib/src/index.ts index 3d943d9b8..57978a589 100644 --- a/packages/lib/src/index.ts +++ b/packages/lib/src/index.ts @@ -3,6 +3,7 @@ import "./styles/variables.css"; export { default as DxcAccordion } from "./accordion/Accordion"; export { default as DxcAlert } from "./alert/Alert"; +export { default as DxcAmountInput } from "./amount-input/AmountInput"; export { default as DxcApplicationLayout } from "./layout/ApplicationLayout"; export { default as DxcAvatar } from "./avatar/Avatar"; export { default as DxcBadge } from "./badge/Badge"; @@ -77,6 +78,11 @@ export type { AlertAction as DxcAlertAction, AlertMessage as DxcAlertMessage, } from "./alert/types"; +export type { + AmountInputProps as DxcAmountInputProps, + CurrencyConfigType as DxcCurrencyConfigType, + UnitsConfigType as DxcUnitsConfigType, +} from "./amount-input/types"; export type { ApplicationLayoutProps as DxcAppLayoutProps, AppLayoutMainProps as DxcAppLayoutMainProps, From 87afab8b9d4f0af3df048c56f8f0fa9b17d79092 Mon Sep 17 00:00:00 2001 From: jialecl <jialestrabajos@gmail.com> Date: Mon, 16 Nov 2026 12:41:42 +0100 Subject: [PATCH 2/8] tests added --- .../src/amount-input/AmountInput.stories.tsx | 134 +++++++++++++++--- .../lib/src/amount-input/AmountInput.test.tsx | 87 ++++++++++++ packages/lib/src/amount-input/utils.ts | 3 + 3 files changed, 202 insertions(+), 22 deletions(-) create mode 100644 packages/lib/src/amount-input/AmountInput.test.tsx diff --git a/packages/lib/src/amount-input/AmountInput.stories.tsx b/packages/lib/src/amount-input/AmountInput.stories.tsx index 05ef12436..c51e30935 100644 --- a/packages/lib/src/amount-input/AmountInput.stories.tsx +++ b/packages/lib/src/amount-input/AmountInput.stories.tsx @@ -23,34 +23,124 @@ const AmountInput = () => { } as UnitsConfigType; return ( <> - <ExampleContainer> - <Title title="Without label" theme="light" level={4} /> - {/* <DxcAmountInput /> */} - <HalstackProvider localeTag="en-IN"> - <DxcAmountInput label="Amount default" helperText="US locale" /> + <HalstackProvider localeTag="en-US"> + <ExampleContainer> + <Title title="Without label" theme="light" level={4} /> + <DxcAmountInput ariaLabel="Amount" /> + </ExampleContainer> + <ExampleContainer> + <Title title="With label and placeholder" theme="light" level={4} /> + <DxcAmountInput label="Amount" placeholder="Enter an amount" /> + </ExampleContainer> + <ExampleContainer> + <Title title="Helper text, optional, value and clearable" theme="light" level={4} /> + <DxcAmountInput label="Amount" helperText="Enter an amount" optional defaultValue="1234.56" clearable /> + </ExampleContainer> + <ExampleContainer> + <Title title="Disabled with placeholder" theme="light" level={4} /> + <DxcAmountInput label="Disabled amount" disabled placeholder="Enter an amount" /> + </ExampleContainer> + <ExampleContainer> + <Title title="Disabled with value" theme="light" level={4} /> + <DxcAmountInput label="Disabled amount" helperText="Help message" disabled optional defaultValue="1234.56" /> + </ExampleContainer> + <ExampleContainer> + <Title title="Read only" theme="light" level={4} /> + <DxcAmountInput label="Amount" helperText="Help message" readOnly optional defaultValue="1234.56" /> + </ExampleContainer> + <ExampleContainer> + <Title title="Invalid" theme="light" level={4} /> + <DxcAmountInput label="Amount" helperText="Help message" error="Error message." defaultValue="1234.56" /> + </ExampleContainer> + <ExampleContainer pseudoState="pseudo-hover"> + <Title title="Hovered" theme="light" level={4} /> + <DxcAmountInput label="Amount" helperText="Help message" readOnly optional defaultValue="1234.56" /> + <DxcAmountInput label="Amount" helperText="Help message" optional defaultValue="1234.56" clearable /> <DxcAmountInput - label="Amount in RMB" - config={{ currencyConfig: currencyConfig }} - defaultValue="1234.56" - maxValue={10000} - minValue={1000} - onChange={(event) => console.log(event)} - onBlur={(event) => console.log(event)} alignment="right" + label="Distance" + defaultValue="1231234.56" + config={{ unitsConfig }} clearable /> + <DxcAmountInput label="Amount" helperText="Help message" error="Error message." defaultValue="1234.56" /> + </ExampleContainer> + <ExampleContainer pseudoState="pseudo-active"> + <Title title="Active" theme="light" level={4} /> + <DxcAmountInput label="Amount" helperText="Help message" readOnly optional defaultValue="1234.56" /> + <DxcAmountInput label="Amount" helperText="Help message" optional defaultValue="1234.56" clearable /> <DxcAmountInput - label="Distance in km" - config={{ unitsConfig: unitsConfig, decimalSeparator: "()", thousandSeparator: "@" }} + alignment="right" + label="Distance" + defaultValue="1231234.56" + config={{ unitsConfig }} + clearable + /> + <DxcAmountInput label="Amount" helperText="Help message" error="Error message." defaultValue="1234.56" /> + </ExampleContainer> + <ExampleContainer pseudoState="pseudo-focus"> + <Title title="Focused" theme="light" level={4} /> + <DxcAmountInput label="Amount" helperText="Help message" readOnly optional defaultValue="1234.56" /> + <DxcAmountInput label="Amount" helperText="Help message" optional defaultValue="1234.56" clearable /> + <DxcAmountInput + alignment="right" + label="Distance" + defaultValue="1231234.56" + config={{ unitsConfig }} + clearable + /> + <DxcAmountInput label="Amount" helperText="Help message" error="Error message." defaultValue="1234.56" /> + </ExampleContainer> + <ExampleContainer> + <Title title="Configuration" theme="light" level={2} /> + <DxcAmountInput label="Distance" defaultValue="1231234.56" config={{ unitsConfig }} /> + <DxcAmountInput label="Currency" defaultValue="1231234.56" config={{ currencyConfig }} /> + <DxcAmountInput + label="Custom separators" + defaultValue="1231234.56" + config={{ decimalSeparator: "@", thousandSeparator: "#" }} + /> + <DxcAmountInput alignment="right" label="Distance" defaultValue="1231234.56" config={{ unitsConfig }} /> + <DxcAmountInput alignment="right" label="Currency" defaultValue="1231234.56" config={{ currencyConfig }} /> + <DxcAmountInput + alignment="right" + label="Custom separators" + defaultValue="1231234.56" + config={{ decimalSeparator: "@", thousandSeparator: "#" }} /> - </HalstackProvider> - <DxcAmountInput label="Amount default" helperText="no locale" /> - <DxcAmountInput label="Amount in RMB" config={{ currencyConfig: currencyConfig }} /> - <DxcAmountInput - label="Distance in km" - config={{ unitsConfig: unitsConfig, decimalSeparator: "()", thousandSeparator: "@" }} - /> - </ExampleContainer> + </ExampleContainer> + <ExampleContainer> + <HalstackProvider localeTag="en-IN"> + <Title title="en-IN locale" theme="light" level={3} /> + <DxcAmountInput label="Amount" helperText="Help message" optional defaultValue="1231234.56" clearable /> + <DxcAmountInput + label="Amount" + helperText="Help message" + optional + defaultValue="1231234.56" + clearable + config={{ currencyConfig }} + /> + </HalstackProvider> + </ExampleContainer> + <Title title="Sizes" theme="light" level={2} /> + <ExampleContainer> + <Title title="Small size" theme="light" level={4} /> + <DxcAmountInput label="Small" size="small" /> + </ExampleContainer> + <ExampleContainer> + <Title title="Medium size" theme="light" level={4} /> + <DxcAmountInput label="Medium" size="medium" /> + </ExampleContainer> + <ExampleContainer> + <Title title="Large size" theme="light" level={4} /> + <DxcAmountInput label="Large" size="large" /> + </ExampleContainer> + <ExampleContainer> + <Title title="Fill parent size" theme="light" level={4} /> + <DxcAmountInput label="Fill parent" size="fillParent" /> + </ExampleContainer> + </HalstackProvider> </> ); }; diff --git a/packages/lib/src/amount-input/AmountInput.test.tsx b/packages/lib/src/amount-input/AmountInput.test.tsx new file mode 100644 index 000000000..7d99134a4 --- /dev/null +++ b/packages/lib/src/amount-input/AmountInput.test.tsx @@ -0,0 +1,87 @@ +import { fireEvent, render } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; +import { HalstackProvider } from "../HalstackContext"; +import MockDOMRect from "../../test/mocks/domRectMock"; +import AmountInput from "./AmountInput"; + +global.DOMRect = MockDOMRect; +global.ResizeObserver = jest.fn().mockImplementation(() => ({ + observe: jest.fn(), + unobserve: jest.fn(), + disconnect: jest.fn(), +})); + +describe("Amount input component", () => { + test("renders its label, helper text, and placeholder", () => { + const { getByLabelText, getByText } = render( + <AmountInput label="Amount" helperText="Enter an amount" placeholder="Amount placeholder" /> + ); + const input = getByLabelText("Amount") as HTMLInputElement; + + expect(getByText("Enter an amount")).toBeTruthy(); + expect(input.placeholder).toBe("Amount placeholder"); + }); + + test("formats a default value as currency", () => { + const { getByLabelText } = render( + <HalstackProvider localeTag="en-US"> + <AmountInput label="Amount" defaultValue="1234.5" config={{ currencyConfig: { currency: "USD" } }} /> + </HalstackProvider> + ); + + expect((getByLabelText("Amount") as HTMLInputElement).value).toBe("$1,234.50"); + }); + + test("sanitizes input and formats the value on blur", async () => { + const user = userEvent.setup(); + const onChange = jest.fn(); + const onBlur = jest.fn(); + const { getByLabelText } = render( + <HalstackProvider localeTag="en-US"> + <AmountInput label="Amount" onChange={onChange} onBlur={onBlur} /> + </HalstackProvider> + ); + const input = getByLabelText("Amount") as HTMLInputElement; + + await user.type(input, "1234.5"); + expect(onChange).toHaveBeenLastCalledWith({ value: "1234.5", error: undefined }); + expect(input.value).toBe("1234.5"); + + fireEvent.blur(input); + expect(onBlur).toHaveBeenLastCalledWith({ value: "1,234.5", error: undefined }); + expect(input.value).toBe("1,234.5"); + }); + + test("reports an error when the value exceeds the maximum", async () => { + const user = userEvent.setup(); + const onChange = jest.fn(); + const { getByLabelText } = render( + <HalstackProvider localeTag="en-US"> + <AmountInput label="Amount" maxValue={10} onChange={onChange} /> + </HalstackProvider> + ); + + await user.type(getByLabelText("Amount"), "12"); + expect(onChange).toHaveBeenLastCalledWith({ + value: "12", + error: "Value must be less than or equal to 10.", + }); + }); + + test("updates the displayed value when the controlled value changes", () => { + const { getByLabelText, rerender } = render( + <HalstackProvider localeTag="en-US"> + <AmountInput label="Amount" value="1000" /> + </HalstackProvider> + ); + const input = getByLabelText("Amount") as HTMLInputElement; + expect(input.value).toBe("1,000"); + + rerender( + <HalstackProvider localeTag="en-US"> + <AmountInput label="Amount" value="2000" /> + </HalstackProvider> + ); + expect(input.value).toBe("2,000"); + }); +}); diff --git a/packages/lib/src/amount-input/utils.ts b/packages/lib/src/amount-input/utils.ts index 74ae8f2f3..db7e5726d 100644 --- a/packages/lib/src/amount-input/utils.ts +++ b/packages/lib/src/amount-input/utils.ts @@ -39,6 +39,7 @@ export const sanitizeAmount = ( return isNegative && sanitized ? `-${sanitized}` : sanitized; }; +// TODO: take into account config.symbolPosition export const formatString = (value: string, locale: string | undefined, config?: ConfigType): string => { let formatter = new Intl.NumberFormat(locale); if (config?.currencyConfig && config.currencyConfig.currency) { @@ -56,6 +57,8 @@ export const formatString = (value: string, locale: string | undefined, config?: unitDisplay: config.unitsConfig.unitDisplay || "short", }); } + console.log("Formatter:", formatter.formatToParts(parseFloat(value))); + // check for unit/currency and any literal part next to it in the formatted output and position them based on config.symbolPosition if provided return formatter .formatToParts(parseFloat(value)) .map((part) => { From 9dd8036125f4b4aa1a0b03142b543b46aa10a147 Mon Sep 17 00:00:00 2001 From: jialecl <jialestrabajos@gmail.com> Date: Tue, 17 Nov 2026 17:34:38 +0100 Subject: [PATCH 3/8] Fixed controlled behabior and added base for documentation --- .../pages/components/amount-input/code.tsx | 17 ++ .../pages/components/amount-input/index.tsx | 17 ++ .../screens/common/componentsList.json | 6 + .../amount-input/AmountInputPageLayout.tsx | 27 ++ .../amount-input/code/AmountInputCodePage.tsx | 287 ++++++++++++++++++ .../overview/AmountInputOverviewPage.tsx | 208 +++++++++++++ .../src/amount-input/AmountInput.stories.tsx | 124 +++++--- .../lib/src/amount-input/AmountInput.test.tsx | 21 +- packages/lib/src/amount-input/AmountInput.tsx | 32 +- packages/lib/src/amount-input/types.ts | 4 - packages/lib/src/amount-input/utils.ts | 79 +++-- 11 files changed, 698 insertions(+), 124 deletions(-) create mode 100644 apps/website/pages/components/amount-input/code.tsx create mode 100644 apps/website/pages/components/amount-input/index.tsx create mode 100644 apps/website/screens/components/amount-input/AmountInputPageLayout.tsx create mode 100644 apps/website/screens/components/amount-input/code/AmountInputCodePage.tsx create mode 100644 apps/website/screens/components/amount-input/overview/AmountInputOverviewPage.tsx diff --git a/apps/website/pages/components/amount-input/code.tsx b/apps/website/pages/components/amount-input/code.tsx new file mode 100644 index 000000000..f6668e2a8 --- /dev/null +++ b/apps/website/pages/components/amount-input/code.tsx @@ -0,0 +1,17 @@ +import Head from "next/head"; +import type { ReactElement } from "react"; +import AmountInputPageLayout from "screens/components/amount-input/AmountInputPageLayout"; +import AmountInputCodePage from "screens/components/amount-input/code/AmountInputCodePage"; + +const Code = () => ( + <> + <Head> + <title>Amount input code — Halstack Design System + + + +); + +Code.getLayout = (page: ReactElement) => {page}; + +export default Code; diff --git a/apps/website/pages/components/amount-input/index.tsx b/apps/website/pages/components/amount-input/index.tsx new file mode 100644 index 000000000..c3ba93aa3 --- /dev/null +++ b/apps/website/pages/components/amount-input/index.tsx @@ -0,0 +1,17 @@ +import Head from "next/head"; +import type { ReactElement } from "react"; +import AmountInputOverviewPage from "screens/components/amount-input/overview/AmountInputOverviewPage"; +import AmountInputPageLayout from "screens/components/amount-input/AmountInputPageLayout"; + +const Index = () => ( + <> + + Amount input — Halstack Design System + + + +); + +Index.getLayout = (page: ReactElement) => {page}; + +export default Index; diff --git a/apps/website/screens/common/componentsList.json b/apps/website/screens/common/componentsList.json index 818d91ffb..1e765c453 100644 --- a/apps/website/screens/common/componentsList.json +++ b/apps/website/screens/common/componentsList.json @@ -117,6 +117,12 @@ "label": "Forms", "icon": "assignment", "links": [ + { + "label": "Amount input", + "path": "/components/amount-input", + "status": "experimental", + "icon": "smart_button" + }, { "label": "Button", "path": "/components/button", diff --git a/apps/website/screens/components/amount-input/AmountInputPageLayout.tsx b/apps/website/screens/components/amount-input/AmountInputPageLayout.tsx new file mode 100644 index 000000000..09e5c127c --- /dev/null +++ b/apps/website/screens/components/amount-input/AmountInputPageLayout.tsx @@ -0,0 +1,27 @@ +import { DxcParagraph, DxcFlex } from "@dxc-technology/halstack-react"; +import PageHeading from "@/common/PageHeading"; +import TabsPageHeading from "@/common/TabsPageLayout"; +import ComponentHeading from "@/common/ComponentHeading"; +import { ReactNode } from "react"; + +const AmountInputPageHeading = ({ children }: { children: ReactNode }) => { + const tabs = [ + { label: "Overview", path: "/components/amount-input" }, + { label: "Code", path: "/components/amount-input/code" }, + ]; + + return ( + + + + + Amount input's description. + + + + {children} + + ); +}; + +export default AmountInputPageHeading; diff --git a/apps/website/screens/components/amount-input/code/AmountInputCodePage.tsx b/apps/website/screens/components/amount-input/code/AmountInputCodePage.tsx new file mode 100644 index 000000000..cac2c363a --- /dev/null +++ b/apps/website/screens/components/amount-input/code/AmountInputCodePage.tsx @@ -0,0 +1,287 @@ +import { DxcFlex, DxcTable } from "@dxc-technology/halstack-react"; +import QuickNavContainer from "@/common/QuickNavContainer"; +import DocFooter from "@/common/DocFooter"; +// import Example from "@/common/example/Example"; +import Code, { TableCode, ExtendedTableCode } from "@/common/Code"; + +const configTypeString = `{ + thousandSeparator?: string; + decimalSeparator?: string; + symbolPosition?: 'before' | 'after'; +} & ( + | { + currencyConfig?: { + currency: string; + currencyDisplay?: 'code' | + 'symbol' | + 'narrowSymbol' | + 'name'; + currencySign?: 'standard' | 'accounting'; + }; + unitsConfig?: never; + } + | { + currencyConfig?: never; + unitsConfig?: { + unit: string; + unitDisplay?: 'short' | 'long' | 'narrow'; + }; + } +)`; + +const sections = [ + { + title: "Props", + content: ( + + + + Name + Type + Description + Default + + + + + alignment + + 'left' | 'right' + + Sets the alignment inside the input. + - + + + ariaLabel + + string + + + Specifies a string to be used as the name for the textInput element when no label is + provided. + + - + + + clearable + + boolean + + If true, the input will have an action to clear the entered value. + - + + + config + + {configTypeString} + + + Configuration for the amount input, including currency or units, and formatting options such as thousand + and decimal separators and the position of the currency symbol. currencyConfig and{" "} + unitsConfig are mutually exclusive. + + - + + + defaultValue + + string + + Initial value of the input, only when it is uncontrolled. + - + + + disabled + + boolean + + If true, the component will be disabled. + - + + + error + + string + + + If it is a defined value and also a truthy string, the component will change its appearance, showing the + error below the input component. If the defined value is an empty string, it will reserve a space below + the component for a future error, but it would not change its look. In case of being undefined or null, + both the appearance and the space for the error message would not be modified. + + - + + + helperText + + string + + Helper text to be placed above the input. + - + + + label + + string + + + Text to be placed above the input. This label will be used as the aria-label attribute of the list of + suggestions. + + - + + + maxValue + + number + + Specifies the maximum value allowed in the input. + - + + + minValue + + number + + Specifies the minimum value allowed in the input. + - + + + name + + string + + Name attribute of the input element. + - + + + numberOfDecimals + + number + + Specifies the number of decimal places allowed in the input. + - + + + numberOfIntegers + + number + + Specifies the number of integer places allowed in the input. + - + + + onBlur + + {"(val: { value: string; error?: string }) => void"} + + + This function will be called when the input element loses the focus. An object including the input value + and the error (if the value entered is not valid) will be passed to this function. If there is no error,{" "} + error will not be defined. + + - + + + onChange + + {"(val: { value: string; error?: string }) => void"} + + + This function will be called when the user types within the input element of the component. An object + including the current value and the error (if the value entered is not valid) will be passed to this + function. If there is no error, error will not be defined. + + - + + + optional + + boolean + + + If true, the input will be optional, showing '(Optional)' next to the label. Otherwise, the field will be + considered required and an error will be passed as a parameter to the onBlur and{" "} + onChange functions when it has not been filled. + + - + + + placeholder + + string + + Text to be put as placeholder of the input. + - + + + readOnly + + boolean + + + If true, the component will not be mutable, meaning the user can not edit the control. In addition, the + clear action will not be displayed even if the flag is set to true. + + - + + + ref + + {"React.Ref"} + + Ref to the input element. + - + + + size + + 'small' | 'medium' | 'large' | 'fillParent' + + Size of the component. + - + + + tabIndex + + number + + + Value of the tabindex attribute. + + - + + + value + + string + + + Value of the input. If undefined, the component will be uncontrolled and the value will be managed + internally by the component. + + - + + + + ), + }, + { + title: "Examples", + subSections: [ + { + title: "Controlled", + // content: , + }, + ], + }, +]; + +const AmountInputCodePage = () => ( + + + + +); + +export default AmountInputCodePage; diff --git a/apps/website/screens/components/amount-input/overview/AmountInputOverviewPage.tsx b/apps/website/screens/components/amount-input/overview/AmountInputOverviewPage.tsx new file mode 100644 index 000000000..69565db23 --- /dev/null +++ b/apps/website/screens/components/amount-input/overview/AmountInputOverviewPage.tsx @@ -0,0 +1,208 @@ +import { DxcParagraph, DxcBulletedList, DxcFlex } from "@dxc-technology/halstack-react"; +import QuickNavContainer from "@/common/QuickNavContainer"; +// import Figure from "@/common/Figure"; +import DocFooter from "@/common/DocFooter"; +// import Image from "@/common/Image"; + +const sections = [ + { + title: "Introduction", + content: Introduction, + }, + { + title: "Anatomy", + content: ( + <> + {/* Amount input anatomy */} + + + Label (Optional): a descriptive text that helps users understand what information + is expected in the amount input field. It should be clear, concise, and placed near the input for better + readability. + + + Optional indicator (Optional): a small indicator that signals the input field is + not mandatory. It helps users know they can leave the field empty without causing validation errors. + + + Clear action (Optional): a small button, represented by an "X" icon, that allows + users to clear the entered text quickly without manually deleting it. + + + Helper text (Optional): additional text placed below the input field that provides + guidance, examples, or explanations to assist users in filling out the field correctly. + + + Container: the visual wrapper around the input field that provides structure, ensures + accessibility, and helps differentiate the input from other UI elements. + + + Placeholder/Value: a short hint displayed inside the input field before any text is + entered, offering a brief example or instruction on what type of data is expected. It disappears when the + user starts typing. The value represents the actual content entered by the user. Unlike the placeholder, the + value persists during interaction and is what gets submitted with the form. + + + + ), + }, + { + title: "Form inputs", + content: ( + <> + + Form inputs are essential UI elements that allow users to interact with digital products by{" "} + entering or selecting data. Choosing the right input type and structure is key to designing + efficient, user-friendly forms that support task completion and data accuracy. + + + A form input (also known as a form field) is used to capture user data. Common input types include text + fields, date pickers, number fields, radio buttons, checkboxes, toggles, and dropdowns. Forms should always + include a submission method, such as a submit button, link, or keyboard trigger, to complete the interaction. + + + ), + subSections: [ + { + title: "Shared input characteristics", + content: ( + <> + + Although input fields vary in type and purpose, they often share a common set of features: + + + + Placeholder: a short hint displayed inside the input field that describes its expected + value or purpose. + + + Size and max length: inputs can have both a visual size (width of the field) and a + character limit that defines how much text can be entered. + + + Prefix or suffix: some inputs include a visual element before or after the user input, + like currency symbols or units, to help clarify the expected data. + + + Helper text: additional information displayed below the field to guide the user in + providing the correct input. + + + Optional label: inputs that are not mandatory can be marked with an "Optional" tag to + set clear expectations. + + + + ), + }, + { + title: "Common input states", + content: ( + <> + Most inputs can also present standard interactive or informative states: + + + Disabled: this state prevents users from interacting with the field. It's typically + used when a value is not applicable or editable under certain conditions or roles. + + + Error: when a user enters invalid or incomplete data, the input shows an error state, + often accompanied by a helpful message to guide corrections. + + + Read-only: the input is visible, focusable, and hoverable, but not editable. This is + ideal for fields with auto-calculated values. Unlike disabled fields, read-only inputs can still be + submitted with the form and are part of the form data. + + + + ), + }, + ], + }, + { + title: "Best practices", + subSections: [ + { + title: "General", + content: ( + + + Always use clear labels: ensure every text input has a visible, descriptive label that + doesn't disappear as users begin typing. Avoid relying solely on placeholder text. + + + Use placeholders as hints only: placeholders should provide examples or expected formats + (e.g., "e.g., johndoe@email.com"), not serve as the primary field descriptor. + + + Clarify field requirements: use an "Optional" tag next to labels to indicate when a field + isn't mandatory, reducing user uncertainty. + + + Provide helper text when needed: include contextual guidance below the input to help + users provide the correct information, especially for complex or specific inputs. + + + Support various states consistently: reflect focus, disabled, error, and read-only states + with distinct, accessible visual cues. + + + Apply appropiate alignment: It is recommended to use left alignment in general, except + when there is a specific need for right alignment, such as in currency inputs or numeric fields, generally + using a suffix. + + + ), + }, + { + title: "Actions", + content: ( + + + Provide a way to clear content: allow users to easily clear the input with a clear icon + or button, especially useful for fields like search or filters. + + + Use custom action icons appropriately: if adding custom icons inside the input (e.g., a + calendar icon for date inputs or a search icon), ensure they're meaningful, accessible, and do not + interfere with user input. + + + Avoid distracting behaviors: don't introduce actions that reset, redirect, or submit + forms unexpectedly from within a text field. + + + ), + }, + { + title: "Prefix/suffix", + content: ( + + + Use prefixes and suffixes to add clarity: add visual cues like currency symbols (€), + units (kg), or domain suffixes (.com) to help users understand the context of their input. + + + Do not confuse with input content: ensure prefixes/suffixes are visually distinct and not + editable to avoid confusion with the actual value being typed. + + + Keep it minimal and functional: avoid decorative or unnecessary additions. Prefixes and + suffixes should always serve a clear purpose. + + + ), + }, + ], + }, +]; + +const AmountInputOverviewPage = () => ( + + + + +); + +export default AmountInputOverviewPage; diff --git a/packages/lib/src/amount-input/AmountInput.stories.tsx b/packages/lib/src/amount-input/AmountInput.stories.tsx index c51e30935..e22f8d0dd 100644 --- a/packages/lib/src/amount-input/AmountInput.stories.tsx +++ b/packages/lib/src/amount-input/AmountInput.stories.tsx @@ -10,17 +10,71 @@ export default { component: DxcAmountInput, } satisfies Meta; -const AmountInput = () => { - const currencyConfig = { - currency: "CNY", - currencyDisplay: "symbol", - currencySign: "standard", - } as CurrencyConfigType; +const currencyConfig = { + currency: "CNY", + currencyDisplay: "symbol", + currencySign: "accounting", +} as CurrencyConfigType; + +const unitsConfig = { + unit: "kilometer", + unitDisplay: "short", +} as UnitsConfigType; - const unitsConfig = { - unit: "kilometer", - unitDisplay: "short", - } as UnitsConfigType; +const Examples = () => { + return ( + <> + + + + + + ); +}; + +const LocalizationExamples = () => { + return ( + <> + + + + + { + console.log({ value, error }); + }} + clearable + /> + + + ); +}; + +const AmountInput = () => { return ( <> @@ -54,42 +108,16 @@ const AmountInput = () => { - <DxcAmountInput label="Amount" helperText="Help message" readOnly optional defaultValue="1234.56" /> - <DxcAmountInput label="Amount" helperText="Help message" optional defaultValue="1234.56" clearable /> - <DxcAmountInput - alignment="right" - label="Distance" - defaultValue="1231234.56" - config={{ unitsConfig }} - clearable - /> + <Examples /> <DxcAmountInput label="Amount" helperText="Help message" error="Error message." defaultValue="1234.56" /> </ExampleContainer> <ExampleContainer pseudoState="pseudo-active"> <Title title="Active" theme="light" level={4} /> - <DxcAmountInput label="Amount" helperText="Help message" readOnly optional defaultValue="1234.56" /> - <DxcAmountInput label="Amount" helperText="Help message" optional defaultValue="1234.56" clearable /> - <DxcAmountInput - alignment="right" - label="Distance" - defaultValue="1231234.56" - config={{ unitsConfig }} - clearable - /> - <DxcAmountInput label="Amount" helperText="Help message" error="Error message." defaultValue="1234.56" /> + <Examples /> </ExampleContainer> <ExampleContainer pseudoState="pseudo-focus"> <Title title="Focused" theme="light" level={4} /> - <DxcAmountInput label="Amount" helperText="Help message" readOnly optional defaultValue="1234.56" /> - <DxcAmountInput label="Amount" helperText="Help message" optional defaultValue="1234.56" clearable /> - <DxcAmountInput - alignment="right" - label="Distance" - defaultValue="1231234.56" - config={{ unitsConfig }} - clearable - /> - <DxcAmountInput label="Amount" helperText="Help message" error="Error message." defaultValue="1234.56" /> + <Examples /> </ExampleContainer> <ExampleContainer> <Title title="Configuration" theme="light" level={2} /> @@ -110,17 +138,13 @@ const AmountInput = () => { /> </ExampleContainer> <ExampleContainer> - <HalstackProvider localeTag="en-IN"> - <Title title="en-IN locale" theme="light" level={3} /> - <DxcAmountInput label="Amount" helperText="Help message" optional defaultValue="1231234.56" clearable /> - <DxcAmountInput - label="Amount" - helperText="Help message" - optional - defaultValue="1231234.56" - clearable - config={{ currencyConfig }} - /> + <HalstackProvider localeTag="nl-NL"> + <Title title="nl-NL locale" theme="light" level={3} /> + <LocalizationExamples /> + </HalstackProvider> + <HalstackProvider localeTag="fr-FR"> + <Title title="fr-FR locale" theme="light" level={3} /> + <LocalizationExamples /> </HalstackProvider> </ExampleContainer> <Title title="Sizes" theme="light" level={2} /> diff --git a/packages/lib/src/amount-input/AmountInput.test.tsx b/packages/lib/src/amount-input/AmountInput.test.tsx index 7d99134a4..a5015d5f0 100644 --- a/packages/lib/src/amount-input/AmountInput.test.tsx +++ b/packages/lib/src/amount-input/AmountInput.test.tsx @@ -61,27 +61,10 @@ describe("Amount input component", () => { </HalstackProvider> ); - await user.type(getByLabelText("Amount"), "12"); + await user.type(getByLabelText("Amount"), "121234.34"); expect(onChange).toHaveBeenLastCalledWith({ - value: "12", + value: "121234.34", error: "Value must be less than or equal to 10.", }); }); - - test("updates the displayed value when the controlled value changes", () => { - const { getByLabelText, rerender } = render( - <HalstackProvider localeTag="en-US"> - <AmountInput label="Amount" value="1000" /> - </HalstackProvider> - ); - const input = getByLabelText("Amount") as HTMLInputElement; - expect(input.value).toBe("1,000"); - - rerender( - <HalstackProvider localeTag="en-US"> - <AmountInput label="Amount" value="2000" /> - </HalstackProvider> - ); - expect(input.value).toBe("2,000"); - }); }); diff --git a/packages/lib/src/amount-input/AmountInput.tsx b/packages/lib/src/amount-input/AmountInput.tsx index df33c1b83..1a65625fe 100644 --- a/packages/lib/src/amount-input/AmountInput.tsx +++ b/packages/lib/src/amount-input/AmountInput.tsx @@ -2,7 +2,7 @@ import { HalstackLanguageContext } from "../HalstackContext"; import TextInput from "../text-input/TextInput"; import { AmountInputProps } from "./types"; import { use, useCallback, useEffect, useMemo, useRef, useState } from "react"; -import { sanitizeAmount, formatString, getDefaultConfigBasedOnLocale, getErrorMessage } from "./utils"; +import { sanitizeAmount, formatString, getErrorMessage } from "./utils"; const AmountInput = ({ alignment, @@ -32,9 +32,10 @@ const AmountInput = ({ const languageContext = use(HalstackLanguageContext); const translatedLabels = languageContext.labels; const locale = languageContext.locale ? languageContext.locale : undefined; - const [numberValue, setNumberValue] = useState<string | undefined>(""); + const [internalValue, setInternalValue] = useState(defaultValue ?? ""); const [isFocused, setIsFocused] = useState(false); const isControlled = useRef(value !== undefined); + const numberValue = isControlled.current ? (value ?? "") : internalValue; const inputRef = useRef<HTMLInputElement | null>(null); const setInputRef = useCallback( (element: HTMLInputElement | null) => { @@ -53,10 +54,6 @@ const AmountInput = ({ }, [ref] ); - const localeConfig = useMemo(() => { - return getDefaultConfigBasedOnLocale(locale, config); - }, [locale, config]); - const displayValue = useMemo(() => { if (numberValue === undefined || numberValue === "") return undefined; if (config) { @@ -65,18 +62,6 @@ const AmountInput = ({ return new Intl.NumberFormat(locale).format(parseFloat(numberValue)); }, [numberValue, config, locale]); - useEffect(() => { - setNumberValue( - sanitizeAmount( - value ?? defaultValue, - localeConfig.decimalSeparator, - localeConfig.thousandSeparator, - numberOfDecimals, - numberOfIntegers - ) - ); - }, [value, defaultValue, localeConfig, numberOfDecimals, numberOfIntegers]); - const handleBlur = (event: { value: string; error?: string }) => { setIsFocused(false); const errorMessage = getErrorMessage(event.value, translatedLabels.amountInput, maxValue, minValue); @@ -84,15 +69,10 @@ const AmountInput = ({ }; const handleChange = (event: { value: string; error?: string }) => { - const sanitizedValue = sanitizeAmount( - event.value, - localeConfig.decimalSeparator, - localeConfig.thousandSeparator, - numberOfDecimals, - numberOfIntegers - ); + const sanitizedValue = sanitizeAmount(event.value, numberOfDecimals, numberOfIntegers); + console.log("onChange Sanitized value:", sanitizedValue); if (!isControlled.current) { - setNumberValue(sanitizedValue); + setInternalValue(sanitizedValue); } const errorMessage = getErrorMessage(sanitizedValue, translatedLabels.amountInput, maxValue, minValue); onChange?.({ value: sanitizedValue, error: errorMessage || event.error }); diff --git a/packages/lib/src/amount-input/types.ts b/packages/lib/src/amount-input/types.ts index 6f795d033..f6d9299ec 100644 --- a/packages/lib/src/amount-input/types.ts +++ b/packages/lib/src/amount-input/types.ts @@ -139,8 +139,4 @@ export type AmountInputProps = { */ export type RefType = HTMLDivElement; -/** - * Single suggestion of a Text Input component. - */ - export type { AmountInputProps as default }; diff --git a/packages/lib/src/amount-input/utils.ts b/packages/lib/src/amount-input/utils.ts index db7e5726d..6b449186a 100644 --- a/packages/lib/src/amount-input/utils.ts +++ b/packages/lib/src/amount-input/utils.ts @@ -5,41 +5,38 @@ import { ConfigType } from "./types"; */ export const sanitizeAmount = ( value: string | undefined, - decimalSeparator: string, - thousandSeparator: string, numberOfDecimals?: number, numberOfIntegers?: number ): string => { if (!value) return ""; - value = value.replace(/[^\d.,()-]/g, ""); + value = value.replace(/[^\d.-]/g, ""); + if (value.startsWith("-")) { + value = "-" + value.slice(1).replace(/-/g, ""); + } else { + value = value.replace(/-/g, ""); + } const isNegative = value.includes("(") && value.includes(")"); - const decimalSeparatorCount = (value.match(new RegExp(`\\${decimalSeparator}`, "g")) || []).length; + const decimalSeparatorCount = (value.match(new RegExp(`\\.`, "g")) || []).length; if (decimalSeparatorCount > 1) { - const firstIndex = value.indexOf(decimalSeparator); - value = - value.slice(0, firstIndex + 1) + - value.slice(firstIndex + 1).replace(new RegExp(`\\${decimalSeparator}`, "g"), ""); + const firstIndex = value.indexOf("."); + value = value.slice(0, firstIndex + 1) + value.slice(firstIndex + 1).replace(new RegExp(`\\.`, "g"), ""); } - let sanitized = value - .replace(new RegExp(`\\${thousandSeparator}`, "g"), "") - .replace(new RegExp(`\\${decimalSeparator}`), "."); if (numberOfDecimals !== undefined && numberOfDecimals >= 0) { - const [integerPart, decimalPart] = sanitized.split("."); + const [integerPart, decimalPart] = value.split("."); if (decimalPart) { - sanitized = `${integerPart}.${decimalPart.slice(0, numberOfDecimals)}`; + value = `${integerPart}.${decimalPart.slice(0, numberOfDecimals)}`; } } if (numberOfIntegers !== undefined && numberOfIntegers >= 0) { - const [integerPart, decimalPart] = sanitized.split("."); + const [integerPart, decimalPart] = value.split("."); if (integerPart) { - sanitized = `${integerPart.slice(0, numberOfIntegers)}${decimalPart ? `.${decimalPart}` : ""}`; + value = `${integerPart.slice(0, numberOfIntegers)}${decimalPart ? `.${decimalPart}` : ""}`; } } - return isNegative && sanitized ? `-${sanitized}` : sanitized; + return isNegative && value ? `-${value}` : value; }; -// TODO: take into account config.symbolPosition export const formatString = (value: string, locale: string | undefined, config?: ConfigType): string => { let formatter = new Intl.NumberFormat(locale); if (config?.currencyConfig && config.currencyConfig.currency) { @@ -57,10 +54,40 @@ export const formatString = (value: string, locale: string | undefined, config?: unitDisplay: config.unitsConfig.unitDisplay || "short", }); } - console.log("Formatter:", formatter.formatToParts(parseFloat(value))); - // check for unit/currency and any literal part next to it in the formatted output and position them based on config.symbolPosition if provided - return formatter - .formatToParts(parseFloat(value)) + let formattedParts = formatter.formatToParts(parseFloat(value)); + + console.log(formattedParts); + + if ( + config?.symbolPosition === "before" && + formattedParts.some((part) => part.type === "currency" || part.type === "unit") + ) { + let symbolIndex = formattedParts.findIndex((part) => part.type === "currency" || part.type === "unit"); + if (symbolIndex > 0) { + if (formattedParts[symbolIndex - 1]?.type === "literal") { + const [literalPart] = formattedParts.splice(symbolIndex - 1, 1); + if (literalPart) formattedParts.unshift(literalPart); + // symbolIndex--; + } + const [symbolPart] = formattedParts.splice(symbolIndex, 1); + if (symbolPart) formattedParts.unshift(symbolPart); + } + } else if ( + config?.symbolPosition === "after" && + formattedParts.some((part) => part.type === "currency" || part.type === "unit") + ) { + let symbolIndex = formattedParts.findIndex((part) => part.type === "currency" || part.type === "unit"); + if (symbolIndex < formattedParts.length - 1) { + if (formattedParts[symbolIndex + 1]?.type === "literal") { + const [literalPart] = formattedParts.splice(symbolIndex + 1, 1); + if (literalPart) formattedParts.push(literalPart); + } + const [symbolPart] = formattedParts.splice(symbolIndex, 1); + if (symbolPart) formattedParts.push(symbolPart); + } + } + + return formattedParts .map((part) => { if (part.type === "decimal" && config?.decimalSeparator) return config.decimalSeparator; if (part.type === "group" && config?.thousandSeparator) return config.thousandSeparator; @@ -70,10 +97,12 @@ export const formatString = (value: string, locale: string | undefined, config?: }; export const getDefaultConfigBasedOnLocale = (locale: string | undefined, config?: ConfigType) => { - const number = 5004.11; - const formattedNumber = formatString(number.toString(), locale, config); - const decimalSeparator = formattedNumber[formattedNumber.indexOf("4") + 1] || "."; - const thousandSeparator = formattedNumber[formattedNumber.indexOf("5") + 1] || ","; + const number = 1234.56; + let formatter = new Intl.NumberFormat(locale); + const decimalSeparator = + config?.decimalSeparator || formatter.formatToParts(number).find((part) => part.type === "decimal")?.value || "."; + const thousandSeparator = + config?.thousandSeparator || formatter.formatToParts(number).find((part) => part.type === "group")?.value || ","; return { decimalSeparator, thousandSeparator }; }; From e3a6f30fe76a95848dca59a5806f0847a7988927 Mon Sep 17 00:00:00 2001 From: jialecl <jialestrabajos@gmail.com> Date: Wed, 18 Nov 2026 10:27:36 +0100 Subject: [PATCH 4/8] Amountinput examples added to themeGenerator --- .../screens/theme-generator/componentsRegistry.tsx | 2 ++ .../previews/components/AmountInputPreview.tsx | 11 +++++++++++ .../theme-generator/previews/components/index.ts | 1 + 3 files changed, 14 insertions(+) create mode 100644 apps/website/screens/theme-generator/previews/components/AmountInputPreview.tsx diff --git a/apps/website/screens/theme-generator/componentsRegistry.tsx b/apps/website/screens/theme-generator/componentsRegistry.tsx index 9a93204d3..ddccc01b7 100644 --- a/apps/website/screens/theme-generator/componentsRegistry.tsx +++ b/apps/website/screens/theme-generator/componentsRegistry.tsx @@ -1,6 +1,7 @@ import { AccordionPreview, AlertPreview, + AmountInputPreview, AvatarPreview, BadgePreview, BreadcrumbsPreview, @@ -42,6 +43,7 @@ import { ApplicationPreview, DashboardPreview, FormPreview } from "./previews/ex export const componentsRegistry = { "/components/accordion": AccordionPreview, + "/components/amount-input": AmountInputPreview, "/components/avatar": AvatarPreview, "/components/divider": DividerPreview, "/components/wizard": WizardPreview, diff --git a/apps/website/screens/theme-generator/previews/components/AmountInputPreview.tsx b/apps/website/screens/theme-generator/previews/components/AmountInputPreview.tsx new file mode 100644 index 000000000..bddcd915d --- /dev/null +++ b/apps/website/screens/theme-generator/previews/components/AmountInputPreview.tsx @@ -0,0 +1,11 @@ +import { DxcFlex, DxcAmountInput } from "@dxc-technology/halstack-react"; +const AmountInputPreview = () => { + return ( + <DxcFlex gap="var(--spacing-gap-ml)"> + <DxcAmountInput label="Amount" helperText="Select the amount." /> + <DxcAmountInput label="Amount paid" helperText="Select the amount." error="Incorrect amount" /> + </DxcFlex> + ); +}; + +export default AmountInputPreview; diff --git a/apps/website/screens/theme-generator/previews/components/index.ts b/apps/website/screens/theme-generator/previews/components/index.ts index 531d41e62..a29541a48 100644 --- a/apps/website/screens/theme-generator/previews/components/index.ts +++ b/apps/website/screens/theme-generator/previews/components/index.ts @@ -1,5 +1,6 @@ export { default as AccordionPreview } from "./AccordionPreview"; export { default as AlertPreview } from "./AlertPreview"; +export { default as AmountInputPreview } from "./AmountInputPreview"; export { default as AvatarPreview } from "./AvatarPreview"; export { default as BadgePreview } from "./BadgePreview"; export { default as BreadcrumbsPreview } from "./BreadcrumbsPreview"; From 973d9d743383fd0104fb57906acec0e3e0097996 Mon Sep 17 00:00:00 2001 From: jialecl <jialestrabajos@gmail.com> Date: Thu, 19 Nov 2026 17:30:28 +0100 Subject: [PATCH 5/8] Component documentation --- .../amount-input/AmountInputPageLayout.tsx | 5 +- .../amount-input/code/AmountInputCodePage.tsx | 28 +- .../amount-input/code/examples/controlled.tsx | 24 ++ .../amount-input/code/examples/currency.tsx | 27 ++ .../amount-input/code/examples/unit.tsx | 28 ++ .../overview/AmountInputOverviewPage.tsx | 284 +++++++++++++----- .../overview/images/amount_input_anatomy.png | Bin 0 -> 20432 bytes 7 files changed, 312 insertions(+), 84 deletions(-) create mode 100644 apps/website/screens/components/amount-input/code/examples/controlled.tsx create mode 100644 apps/website/screens/components/amount-input/code/examples/currency.tsx create mode 100644 apps/website/screens/components/amount-input/code/examples/unit.tsx create mode 100644 apps/website/screens/components/amount-input/overview/images/amount_input_anatomy.png diff --git a/apps/website/screens/components/amount-input/AmountInputPageLayout.tsx b/apps/website/screens/components/amount-input/AmountInputPageLayout.tsx index 09e5c127c..136d66793 100644 --- a/apps/website/screens/components/amount-input/AmountInputPageLayout.tsx +++ b/apps/website/screens/components/amount-input/AmountInputPageLayout.tsx @@ -15,7 +15,10 @@ const AmountInputPageHeading = ({ children }: { children: ReactNode }) => { <PageHeading> <DxcFlex direction="column" gap="var(--spacing-gap-xl)"> <ComponentHeading name="Amount input" /> - <DxcParagraph>Amount input's description.</DxcParagraph> + <DxcParagraph> + Amount inputs are fields specifically designed to capture and display{" "} + <strong>monetary or amount-based numeric values</strong> in a structured, readable, and accessible format. + </DxcParagraph> <TabsPageHeading tabs={tabs} /> </DxcFlex> </PageHeading> diff --git a/apps/website/screens/components/amount-input/code/AmountInputCodePage.tsx b/apps/website/screens/components/amount-input/code/AmountInputCodePage.tsx index cac2c363a..520c578ee 100644 --- a/apps/website/screens/components/amount-input/code/AmountInputCodePage.tsx +++ b/apps/website/screens/components/amount-input/code/AmountInputCodePage.tsx @@ -1,8 +1,13 @@ -import { DxcFlex, DxcTable } from "@dxc-technology/halstack-react"; +import { DxcFlex, DxcLink, DxcTable } from "@dxc-technology/halstack-react"; import QuickNavContainer from "@/common/QuickNavContainer"; import DocFooter from "@/common/DocFooter"; // import Example from "@/common/example/Example"; import Code, { TableCode, ExtendedTableCode } from "@/common/Code"; +import controlled from "./examples/controlled"; +import Example from "@/common/example/Example"; +import currency from "./examples/currency"; +import unit from "./examples/unit"; +import Link from "next/link"; const configTypeString = `{ thousandSeparator?: string; @@ -78,7 +83,11 @@ const sections = [ <td> Configuration for the amount input, including currency or units, and formatting options such as thousand and decimal separators and the position of the currency symbol. <Code>currencyConfig</Code> and{" "} - <Code>unitsConfig</Code> are mutually exclusive. + <Code>unitsConfig</Code> are mutually exclusive. To better understand the allowed values for currencies + and units, please refer to the{" "} + <Link href="/theme-generator/user-guide" legacyBehavior passHref> + <DxcLink newWindow>respective documentation.</DxcLink> + </Link> </td> <td>-</td> </tr> @@ -159,7 +168,10 @@ const sections = [ <td> <TableCode>number</TableCode> </td> - <td>Specifies the number of decimal places allowed in the input.</td> + <td> + Specifies the number of decimal places allowed in the input. By default it is set to 3 or the permitted + amount by the currency. + </td> <td>-</td> </tr> <tr> @@ -271,7 +283,15 @@ const sections = [ subSections: [ { title: "Controlled", - // content: <Example example={controlled} defaultIsVisible />, + content: <Example example={controlled} defaultIsVisible />, + }, + { + title: "Currency", + content: <Example example={currency} defaultIsVisible />, + }, + { + title: "Unit", + content: <Example example={unit} defaultIsVisible />, }, ], }, diff --git a/apps/website/screens/components/amount-input/code/examples/controlled.tsx b/apps/website/screens/components/amount-input/code/examples/controlled.tsx new file mode 100644 index 000000000..59a1f1d7e --- /dev/null +++ b/apps/website/screens/components/amount-input/code/examples/controlled.tsx @@ -0,0 +1,24 @@ +import { DxcAmountInput, DxcInset } from "@dxc-technology/halstack-react"; +import { useState } from "react"; + +const code = `() => { + const [value, setValue] = useState(""); + + return ( + <DxcInset space="var(--spacing-padding-xl)"> + <DxcAmountInput + label="Enter your amount" + value={value} + onChange={({value}) => setValue(value)} + /> + </DxcInset> + ); +}`; + +const scope = { + DxcAmountInput, + DxcInset, + useState, +}; + +export default { code, scope }; diff --git a/apps/website/screens/components/amount-input/code/examples/currency.tsx b/apps/website/screens/components/amount-input/code/examples/currency.tsx new file mode 100644 index 000000000..b5b289ec0 --- /dev/null +++ b/apps/website/screens/components/amount-input/code/examples/currency.tsx @@ -0,0 +1,27 @@ +import { DxcAmountInput, DxcInset } from "@dxc-technology/halstack-react"; +import { useState } from "react"; + +const code = `() => { + const config = { + currencyConfig: { + currency: "USD", + }, + }; + + return ( + <DxcInset space="var(--spacing-padding-xl)"> + <DxcAmountInput + label="Enter your income" + config={config} + /> + </DxcInset> + ); +}`; + +const scope = { + DxcAmountInput, + DxcInset, + useState, +}; + +export default { code, scope }; diff --git a/apps/website/screens/components/amount-input/code/examples/unit.tsx b/apps/website/screens/components/amount-input/code/examples/unit.tsx new file mode 100644 index 000000000..c7b318a5e --- /dev/null +++ b/apps/website/screens/components/amount-input/code/examples/unit.tsx @@ -0,0 +1,28 @@ +import { DxcAmountInput, DxcInset } from "@dxc-technology/halstack-react"; +import { useState } from "react"; + +const code = `() => { + const config = { + unitsConfig: { + unit: "kilogram", + unitDisplay: "short", + }, + }; + + return ( + <DxcInset space="var(--spacing-padding-xl)"> + <DxcAmountInput + label="Enter your weight" + config={config} + /> + </DxcInset> + ); +}`; + +const scope = { + DxcAmountInput, + DxcInset, + useState, +}; + +export default { code, scope }; diff --git a/apps/website/screens/components/amount-input/overview/AmountInputOverviewPage.tsx b/apps/website/screens/components/amount-input/overview/AmountInputOverviewPage.tsx index 69565db23..dd39e0cd5 100644 --- a/apps/website/screens/components/amount-input/overview/AmountInputOverviewPage.tsx +++ b/apps/website/screens/components/amount-input/overview/AmountInputOverviewPage.tsx @@ -1,46 +1,54 @@ -import { DxcParagraph, DxcBulletedList, DxcFlex } from "@dxc-technology/halstack-react"; +import { DxcParagraph, DxcBulletedList, DxcFlex, DxcTable } from "@dxc-technology/halstack-react"; import QuickNavContainer from "@/common/QuickNavContainer"; -// import Figure from "@/common/Figure"; import DocFooter from "@/common/DocFooter"; -// import Image from "@/common/Image"; +import Image from "@/common/Image"; +import anatomy from "./images/amount_input_anatomy.png"; +import Code from "@/common/Code"; const sections = [ { title: "Introduction", - content: <DxcParagraph>Introduction</DxcParagraph>, + content: ( + <> + <DxcParagraph> + Distinct from the standard number input, the amount input is optimized for values where{" "} + <strong>numeric formatting is required</strong> (ex. currency, financial values, percentages, and + measurements). It can present values using grouping, decimal separators, and symbols to provide contextual + information to users. + </DxcParagraph> + <DxcParagraph> + This makes the component particularly useful for financial forms, payments, budgets, transactions, quotations, + and other experiences where users enter financial or values requiring specific units and formatting. + </DxcParagraph> + </> + ), }, { title: "Anatomy", content: ( <> - {/* <Image src={anatomy} alt="Amount input anatomy" /> */} + <Image src={anatomy} alt="Amount input anatomy" /> <DxcBulletedList type="number"> <DxcBulletedList.Item> - <strong>Label</strong> <em>(Optional)</em>: a descriptive text that helps users understand what information - is expected in the amount input field. It should be clear, concise, and placed near the input for better - readability. - </DxcBulletedList.Item> - <DxcBulletedList.Item> - <strong>Optional indicator</strong> <em>(Optional)</em>: a small indicator that signals the input field is - not mandatory. It helps users know they can leave the field empty without causing validation errors. + <strong>Label</strong> <em>(Optional)</em>: a descriptive text that identifies the amount users are expected + to enter. Labels should be concise and should communicate the purpose of the value rather than its + formatting. </DxcBulletedList.Item> <DxcBulletedList.Item> - <strong>Clear action</strong> <em>(Optional)</em>: a small button, represented by an "X" icon, that allows - users to clear the entered text quickly without manually deleting it. + <strong>Optional indicator</strong> <em>(Optional)</em>: indicates that providing an amount is not required. </DxcBulletedList.Item> <DxcBulletedList.Item> - <strong>Helper text</strong> <em>(Optional)</em>: additional text placed below the input field that provides - guidance, examples, or explanations to assist users in filling out the field correctly. + <strong>Helper text</strong> <em>(Optional)</em>: provides additional information about the expected amount, + currency, restrictions, or other requirements. </DxcBulletedList.Item> <DxcBulletedList.Item> - <strong>Container:</strong> the visual wrapper around the input field that provides structure, ensures - accessibility, and helps differentiate the input from other UI elements. + <strong>Container:</strong> the visual wrapper for the input. It establishes the interactive area and + communicates states such as hover, focus, error, disabled, and read-only. </DxcBulletedList.Item> <DxcBulletedList.Item> - <strong>Placeholder/Value:</strong> a short hint displayed inside the input field before any text is - entered, offering a brief example or instruction on what type of data is expected. It disappears when the - user starts typing. The value represents the actual content entered by the user. Unlike the placeholder, the - value persists during interaction and is what gets submitted with the form. + <strong>Placeholder/Value:</strong> provides an example or hint before a value is entered. The value + represents the number provided by the user and can be automatically formatted based on currency, percentage, + or unit settings. </DxcBulletedList.Item> </DxcBulletedList> </> @@ -51,14 +59,13 @@ const sections = [ content: ( <> <DxcParagraph> - Form inputs are essential UI elements that allow users to interact with digital products by{" "} - <strong>entering or selecting data</strong>. Choosing the right input type and structure is key to designing - efficient, user-friendly forms that support task completion and data accuracy. + Form inputs allow users to enter or select data. Choosing an input that matches the type of information being + collected helps improve task completion and data accuracy. </DxcParagraph> <DxcParagraph> - A form input (also known as a form field) is used to capture user data. Common input types include text - fields, date pickers, number fields, radio buttons, checkboxes, toggles, and dropdowns. Forms should always - include a submission method, such as a submit button, link, or keyboard trigger, to complete the interaction. + Amount input should be used when the numeric information being collected has value and formatting-specific + presentation requirements. For numeric data where rigid formatting is unnecessary, use the more general number + input instead. </DxcParagraph> </> ), @@ -67,29 +74,16 @@ const sections = [ title: "Shared input characteristics", content: ( <> - <DxcParagraph> - Although input fields vary in type and purpose, they often share a common set of features: - </DxcParagraph> + <DxcParagraph>Amount input shares the common characteristics of other Halstack form inputs:</DxcParagraph> <DxcBulletedList> <DxcBulletedList.Item> - <strong>Placeholder:</strong> a short hint displayed inside the input field that describes its expected - value or purpose. + <strong>Placeholder:</strong> provides a hint or example of the expected value. </DxcBulletedList.Item> <DxcBulletedList.Item> - <strong>Size and max length:</strong> inputs can have both a visual size (width of the field) and a - character limit that defines how much text can be entered. + <strong>Helper text:</strong> provides instructions or additional information about the expected amount. </DxcBulletedList.Item> <DxcBulletedList.Item> - <strong>Prefix or suffix:</strong> some inputs include a visual element before or after the user input, - like currency symbols or units, to help clarify the expected data. - </DxcBulletedList.Item> - <DxcBulletedList.Item> - <strong>Helper text:</strong> additional information displayed below the field to guide the user in - providing the correct input. - </DxcBulletedList.Item> - <DxcBulletedList.Item> - <strong>Optional label:</strong> inputs that are not mandatory can be marked with an "Optional" tag to - set clear expectations. + <strong>Optional label:</strong> communicates that entering a value is not mandatory. </DxcBulletedList.Item> </DxcBulletedList> </> @@ -120,6 +114,150 @@ const sections = [ }, ], }, + { + title: "Using amount inputs", + content: ( + <DxcParagraph> + Amount inputs should be used whenever users need to enter monetary values or other numeric values where{" "} + <strong>amount formatting and readability are important</strong>. + </DxcParagraph> + ), + subSections: [ + { + title: "Amount Input vs Number Input vs Text Input", + content: ( + <> + <DxcBulletedList> + <DxcBulletedList.Item> + Use <strong>amount input</strong> when the value represents an amount and requires currency-specific, + percentage, or measurement unit formatting. + </DxcBulletedList.Item> + <DxcBulletedList.Item> + Use <strong>number input</strong> for discrete, countable quantities like Item counts, guests, age, or + ratings where the numeric value itself is calculated or compared. + </DxcBulletedList.Item> + <DxcBulletedList.Item> + Use <strong>text input</strong> for general numeric values that need more flexibility or a combination + of numbers and letters. These can include location information like address, contact number, and zip + code. + </DxcBulletedList.Item> + </DxcBulletedList> + <DxcTable> + <thead> + <tr> + <th>Need</th> + <th>Component</th> + </tr> + </thead> + <tbody> + <tr> + <td>Address, phone number, zip code</td> + <td>Text Input</td> + </tr> + <tr> + <td>Quantities that Increment/decrement with a defined step (ex. age, object count, ratings)</td> + <td>Number Input</td> + </tr> + <tr> + <td>Currency or locale-formatted values</td> + <td>Amount Input</td> + </tr> + <tr> + <td> + Price, cost, payment or financial amounts that require specific digits, separators, decimals, or + formatting + </td> + <td>Amount Input</td> + </tr> + <tr> + <td>Quantities with units(percent, weight, distance, volume)</td> + <td>Amount Input</td> + </tr> + </tbody> + </DxcTable> + </> + ), + }, + ], + }, + { + title: "Formatting", + content: ( + <> + <DxcParagraph> + Users should be able to type an amount directly into the field using familiar numeric input conventions. + </DxcParagraph> + <DxcParagraph> + The component should distinguish between a user's <strong>editing state</strong> and the{" "} + <strong>formatted representation</strong> of the final value. This prevents formatting from interfering + unnecessarily while users are entering or correcting an amount. + </DxcParagraph> + <DxcParagraph>For example, a user typing:</DxcParagraph> + <div> + <Code>1234567.89</Code> + </div> + <DxcParagraph>may ultimately see:</DxcParagraph> + <div> + <Code>1,234,567.89</Code> + </div> + <DxcParagraph>after the value has been accepted and formatted.</DxcParagraph> + <DxcParagraph>Common use cases and corresponding amount input formatting examples:</DxcParagraph> + <DxcTable> + <thead> + <tr> + <th>Use case</th> + <th>Example</th> + </tr> + </thead> + <tbody> + <tr> + <td>Currency</td> + <td> + $ 2,532.50 + <br /> + 123.456,79 €<br /> + -3,500.00 US dollars + </td> + </tr> + <tr> + <td>Units</td> + <td> + 1,000 km + <br /> + 58.2 litres + </td> + </tr> + <tr> + <td>Percentage</td> + <td> + 97.999 % + <br /> + 2.5% + </td> + </tr> + <tr> + <td>Digit grouping and separators</td> + <td> + R$ 1.250.500,75 + <br /> + 1 250 500,75 € + <br /> + ₹12,50,500.75 + </td> + </tr> + <tr> + <td>Decimal values</td> + <td> + 0.00075 + <br /> + 9.81 + </td> + </tr> + </tbody> + </DxcTable> + </> + ), + }, { title: "Best practices", subSections: [ @@ -128,68 +266,56 @@ const sections = [ content: ( <DxcBulletedList> <DxcBulletedList.Item> - <strong>Always use clear labels:</strong> ensure every text input has a visible, descriptive label that - doesn't disappear as users begin typing. Avoid relying solely on placeholder text. + <strong>Always use clear labels:</strong> describe what the amount represents rather than relying on its + formatting or currency symbol alone. </DxcBulletedList.Item> <DxcBulletedList.Item> - <strong>Use placeholders as hints only:</strong> placeholders should provide examples or expected formats - (e.g., "e.g., johndoe@email.com"), not serve as the primary field descriptor. + <strong>Make currency clear:</strong> when the value represents money, users should be able to determine + which currency applies without relying on context elsewhere on the page. </DxcBulletedList.Item> <DxcBulletedList.Item> - <strong>Clarify field requirements:</strong> use an "Optional" tag next to labels to indicate when a field - isn't mandatory, reducing user uncertainty. + <strong>Use helper text when necessary:</strong> explain constraints, expected values, or other + requirements that cannot be inferred from the label. </DxcBulletedList.Item> <DxcBulletedList.Item> - <strong>Provide helper text when needed:</strong> include contextual guidance below the input to help - users provide the correct information, especially for complex or specific inputs. - </DxcBulletedList.Item> - <DxcBulletedList.Item> - <strong>Support various states consistently:</strong> reflect focus, disabled, error, and read-only states - with distinct, accessible visual cues. - </DxcBulletedList.Item> - <DxcBulletedList.Item> - <strong>Apply appropiate alignment:</strong> It is recommended to use left alignment in general, except - when there is a specific need for right alignment, such as in currency inputs or numeric fields, generally - using a suffix. + <strong>Indicate optional fields:</strong> use the standard Halstack optional indicator when entering an + amount is not mandatory. </DxcBulletedList.Item> </DxcBulletedList> ), }, { - title: "Actions", + title: "Formatting", content: ( <DxcBulletedList> <DxcBulletedList.Item> - <strong>Provide a way to clear content:</strong> allow users to easily clear the input with a clear icon - or button, especially useful for fields like search or filters. - </DxcBulletedList.Item> - <DxcBulletedList.Item> - <strong>Use custom action icons appropriately:</strong> if adding custom icons inside the input (e.g., a - calendar icon for date inputs or a search icon), ensure they're meaningful, accessible, and do not - interfere with user input. + <strong>Format for readability, not decoration:</strong> thousand/grouping separators are especially + useful for large values making them easier to read. Alignment also plays a significant role in improving + the readability of multiple values, particularly those with fixed decimal digits. </DxcBulletedList.Item> <DxcBulletedList.Item> - <strong>Avoid distracting behaviors:</strong> don't introduce actions that reset, redirect, or submit - forms unexpectedly from within a text field. + <strong>Consider locale carefully and communicate it clearly with users:</strong> Decimal and grouping + separators differ between locales. For example, <Code>1,234.56</Code> and <Code>1.234,56</Code> can + represent the same amount under different conventions. </DxcBulletedList.Item> </DxcBulletedList> ), }, { - title: "Prefix/suffix", + title: "Validation", content: ( <DxcBulletedList> <DxcBulletedList.Item> - <strong>Use prefixes and suffixes to add clarity:</strong> add visual cues like currency symbols (€), - units (kg), or domain suffixes (.com) to help users understand the context of their input. + <strong>Provide useful validation messages:</strong> explain why an amount is invalid and, where possible, + what users need to do to correct it. </DxcBulletedList.Item> <DxcBulletedList.Item> - <strong>Do not confuse with input content:</strong> ensure prefixes/suffixes are visually distinct and not - editable to avoid confusion with the actual value being typed. + <strong>Explain constraints in human-readable terms:</strong> for example, prefer “Enter an amount between + $100 and $1,000” over a generic “Invalid value.” </DxcBulletedList.Item> <DxcBulletedList.Item> - <strong>Keep it minimal and functional:</strong> avoid decorative or unnecessary additions. Prefixes and - suffixes should always serve a clear purpose. + <strong>Preserve user input when displaying an error:</strong> so users can correct the value rather than + entering it again. </DxcBulletedList.Item> </DxcBulletedList> ), diff --git a/apps/website/screens/components/amount-input/overview/images/amount_input_anatomy.png b/apps/website/screens/components/amount-input/overview/images/amount_input_anatomy.png new file mode 100644 index 0000000000000000000000000000000000000000..1c40273a41bf948e856fff5f98bda4acc4793377 GIT binary patch literal 20432 zcmeIaXIN8P@HZNjBX$phBGMF8L_kDAdO0>ks(^rWK@I}aJ0S@+qzI@;hXj?5fJkqN zB1J)o(n3vy2%(2il0ZVZYsYi${lDMdd*3hj!`aVsj@#_L*P1mmYi52kvy3(|(%rl3 z$SxQRwpZ`kWm6c8Hv$IR`hCZC@Qbg2XEOL>r_Z%p{xH~~6VQKK^h}R0f*-f|o9bSK zm3E0tgTL^&{$=<V3|5}7n|=Ea@b`TISF8fey#EdezU}7%yXxlZc^h4x><oh$>+4<q z%RFSu+$iFiolDjfi#Pu473E_EqN0h{o*dW~cRe-nTII`Uu<NoDSGJlRxIZ<rZS2~y z!#}%J4)1)Z62|j#d}_j_>+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yj%~0mAglW*m$v*RYN{$`;_3)5>?2X5Aa0V2~{wv(-IFWcS=4U~S zJpy-DN$lnniL3UoyQOfTdD%|0%AWCZ30j8;`BKhuTAZ&8=h;PUZNOyi-EUo&;e~x` zthSHyv~n`O<-<3B6j0mcvV>Oaq%RY3+lIjau<SyvP!A1Xjen~O69h~Nw%^o`#sN-7 zot{$(k^t`jRpyH4(4{xJ>WLpb%FinC5xNXV=nYA^7VLQnzMYB=spY?4{LY2y46XV5 zo!OyzdK|bb_&8TcQ7bz=0=QTFR~-+j=rvW2ffIZyuDVtM4Sn|<6mk|ArgbCce|B|M z5fDiB>t(1e7|~Y2)mOu`0ng^T`UazLOE$zAQz%gc>s?^zY8{NNIR7JdeS75icjhoO z@w5BT;hO9q407!2%vw`Zjz*6wDv+z=@1bM)5kpDR!=t3N8!PF$Mx2%zSMbfzgAfH% zF|U5)tGUk8W0qva#Z<W!k~DyQU^;}CQ$xG?YAw-RcDet%vZ>d_uI=M^636|mY}M<G zjx?Oh!N9bukcNJ~28nzjYGSP}mECcTGPHN2A*g+Ew`=Aav`upU{zDN|uyj}U?rD8R ztMPDXwar6zdTVIWrDzavyv99j=F^@e{d3R^-#XHXiz<4#*gzhL?kaBN1uxVJa|y$r zIu>$!=35A5rO+xfD|)j%xrya8On%~gccowvnrI}DD_g0g!z1-RTBXLuS7*z-1GVHG z>evp9mAzgG9A0`$+kMs>6ahVO!Ow~dp%&aBjf5_p0}RN_K$kQ$A@|bz?+*4K4`BcC j0PKeU^x*#&JYe%S*kM<)JnlY)ER^0Aqsyfi9UuH(Pe7IB literal 0 HcmV?d00001 From 143186905c45f30a5dd728614cba5eb0a138b0ec Mon Sep 17 00:00:00 2001 From: jialecl <jialestrabajos@gmail.com> Date: Fri, 20 Nov 2026 12:43:12 +0100 Subject: [PATCH 6/8] Added location documentation --- .../amount-input/code/AmountInputCodePage.tsx | 1 - .../localization/LocalizationPage.tsx | 34 +++++++++++++++++++ .../localization/examples/localization.tsx | 19 ++++++++++- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/apps/website/screens/components/amount-input/code/AmountInputCodePage.tsx b/apps/website/screens/components/amount-input/code/AmountInputCodePage.tsx index 520c578ee..4a45f70b1 100644 --- a/apps/website/screens/components/amount-input/code/AmountInputCodePage.tsx +++ b/apps/website/screens/components/amount-input/code/AmountInputCodePage.tsx @@ -1,7 +1,6 @@ import { DxcFlex, DxcLink, DxcTable } from "@dxc-technology/halstack-react"; import QuickNavContainer from "@/common/QuickNavContainer"; import DocFooter from "@/common/DocFooter"; -// import Example from "@/common/example/Example"; import Code, { TableCode, ExtendedTableCode } from "@/common/Code"; import controlled from "./examples/controlled"; import Example from "@/common/example/Example"; diff --git a/apps/website/screens/guidelines/localization/LocalizationPage.tsx b/apps/website/screens/guidelines/localization/LocalizationPage.tsx index a546d8564..fce7cf9b1 100644 --- a/apps/website/screens/guidelines/localization/LocalizationPage.tsx +++ b/apps/website/screens/guidelines/localization/LocalizationPage.tsx @@ -167,6 +167,40 @@ const sections = [ </DxcTable> ), }, + { + title: "amountInput", + content: ( + <DxcTable> + <thead> + <tr> + <th>Label Name</th> + <th>Default value</th> + <th>Details</th> + </tr> + </thead> + <tbody> + <tr> + <td> + <Code>valueGreaterThanOrEqualToErrorMessage</Code> + </td> + <td> + Value must be greater than or equal to <Code>value</Code>. + </td> + <td>It is a function that receives one parameter (value) and returns the text with that parameter.</td> + </tr> + <tr> + <td> + <Code>valueLessThanOrEqualToErrorMessage</Code> + </td> + <td> + Value must be less than or equal to <Code>value</Code>. + </td> + <td>It is a function that receives one parameter (value) and returns the text with that parameter.</td> + </tr> + </tbody> + </DxcTable> + ), + }, { title: "calendar", content: ( diff --git a/apps/website/screens/guidelines/localization/examples/localization.tsx b/apps/website/screens/guidelines/localization/examples/localization.tsx index 9475e15ca..accd24bc7 100644 --- a/apps/website/screens/guidelines/localization/examples/localization.tsx +++ b/apps/website/screens/guidelines/localization/examples/localization.tsx @@ -1,4 +1,11 @@ -import { DxcDateInput, DxcTimeInput, HalstackProvider, DxcInset, DxcFlex } from "@dxc-technology/halstack-react"; +import { + DxcAmountInput, + DxcDateInput, + DxcTimeInput, + HalstackProvider, + DxcInset, + DxcFlex, +} from "@dxc-technology/halstack-react"; const code = `() => { @@ -21,6 +28,15 @@ const labels = { label="Time" optional /> + <DxcAmountInput + label="Amount" + optional + config={{ + currencyConfig: { + currency: "EUR", + }, + }} + /> </DxcFlex> </DxcInset> </HalstackProvider> @@ -31,6 +47,7 @@ const scope = { DxcFlex, DxcTimeInput, DxcDateInput, + DxcAmountInput, HalstackProvider, DxcInset, }; From d9184d83b5966598630b1216c17c43b996c37a3a Mon Sep 17 00:00:00 2001 From: jialecl <jialestrabajos@gmail.com> Date: Mon, 23 Nov 2026 13:48:14 +0100 Subject: [PATCH 7/8] Documentation errors fixed and console.log removed --- apps/website/screens/common/componentsList.json | 2 +- .../amount-input/code/AmountInputCodePage.tsx | 6 +++++- .../overview/AmountInputOverviewPage.tsx | 2 +- .../lib/src/amount-input/AmountInput.test.tsx | 16 ++++++++++++++++ packages/lib/src/amount-input/AmountInput.tsx | 1 - packages/lib/src/amount-input/utils.ts | 10 +++++----- 6 files changed, 28 insertions(+), 9 deletions(-) diff --git a/apps/website/screens/common/componentsList.json b/apps/website/screens/common/componentsList.json index 624b9e7cd..f1ad92c84 100644 --- a/apps/website/screens/common/componentsList.json +++ b/apps/website/screens/common/componentsList.json @@ -127,7 +127,7 @@ "label": "Amount input", "path": "/components/amount-input", "status": "experimental", - "icon": "smart_button" + "icon": "money_range" }, { "label": "Button", diff --git a/apps/website/screens/components/amount-input/code/AmountInputCodePage.tsx b/apps/website/screens/components/amount-input/code/AmountInputCodePage.tsx index 4a45f70b1..37fa1e093 100644 --- a/apps/website/screens/components/amount-input/code/AmountInputCodePage.tsx +++ b/apps/website/screens/components/amount-input/code/AmountInputCodePage.tsx @@ -84,7 +84,11 @@ const sections = [ and decimal separators and the position of the currency symbol. <Code>currencyConfig</Code> and{" "} <Code>unitsConfig</Code> are mutually exclusive. To better understand the allowed values for currencies and units, please refer to the{" "} - <Link href="/theme-generator/user-guide" legacyBehavior passHref> + <Link + href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/supportedValuesOf" + legacyBehavior + passHref + > <DxcLink newWindow>respective documentation.</DxcLink> </Link> </td> diff --git a/apps/website/screens/components/amount-input/overview/AmountInputOverviewPage.tsx b/apps/website/screens/components/amount-input/overview/AmountInputOverviewPage.tsx index dd39e0cd5..b1b07d904 100644 --- a/apps/website/screens/components/amount-input/overview/AmountInputOverviewPage.tsx +++ b/apps/website/screens/components/amount-input/overview/AmountInputOverviewPage.tsx @@ -170,7 +170,7 @@ const sections = [ <td>Amount Input</td> </tr> <tr> - <td>Quantities with units(percent, weight, distance, volume)</td> + <td>Quantities with units (percent, weight, distance, volume)</td> <td>Amount Input</td> </tr> </tbody> diff --git a/packages/lib/src/amount-input/AmountInput.test.tsx b/packages/lib/src/amount-input/AmountInput.test.tsx index a5015d5f0..c485e6e32 100644 --- a/packages/lib/src/amount-input/AmountInput.test.tsx +++ b/packages/lib/src/amount-input/AmountInput.test.tsx @@ -52,6 +52,22 @@ describe("Amount input component", () => { expect(input.value).toBe("1,234.5"); }); + test("limits integer digits without counting the negative sign", async () => { + const user = userEvent.setup(); + const onChange = jest.fn(); + const { getByLabelText } = render(<AmountInput label="Amount" numberOfIntegers={3} onChange={onChange} />); + const input = getByLabelText("Amount") as HTMLInputElement; + + await user.type(input, "-1234"); + + expect(onChange).toHaveBeenLastCalledWith({ value: "-123", error: undefined }); + expect(input.value).toBe("-123"); + + fireEvent.change(input, { target: { value: "-1234.56" } }); + expect(onChange).toHaveBeenLastCalledWith({ value: "-123.56", error: undefined }); + expect(input.value).toBe("-123.56"); + }); + test("reports an error when the value exceeds the maximum", async () => { const user = userEvent.setup(); const onChange = jest.fn(); diff --git a/packages/lib/src/amount-input/AmountInput.tsx b/packages/lib/src/amount-input/AmountInput.tsx index 1a65625fe..b63d06359 100644 --- a/packages/lib/src/amount-input/AmountInput.tsx +++ b/packages/lib/src/amount-input/AmountInput.tsx @@ -70,7 +70,6 @@ const AmountInput = ({ const handleChange = (event: { value: string; error?: string }) => { const sanitizedValue = sanitizeAmount(event.value, numberOfDecimals, numberOfIntegers); - console.log("onChange Sanitized value:", sanitizedValue); if (!isControlled.current) { setInternalValue(sanitizedValue); } diff --git a/packages/lib/src/amount-input/utils.ts b/packages/lib/src/amount-input/utils.ts index 6b449186a..6f2a18ccb 100644 --- a/packages/lib/src/amount-input/utils.ts +++ b/packages/lib/src/amount-input/utils.ts @@ -9,13 +9,13 @@ export const sanitizeAmount = ( numberOfIntegers?: number ): string => { if (!value) return ""; + const isNegativeAccounting = value.includes("(") && value.includes(")"); value = value.replace(/[^\d.-]/g, ""); if (value.startsWith("-")) { value = "-" + value.slice(1).replace(/-/g, ""); } else { value = value.replace(/-/g, ""); } - const isNegative = value.includes("(") && value.includes(")"); const decimalSeparatorCount = (value.match(new RegExp(`\\.`, "g")) || []).length; if (decimalSeparatorCount > 1) { const firstIndex = value.indexOf("."); @@ -31,10 +31,12 @@ export const sanitizeAmount = ( if (numberOfIntegers !== undefined && numberOfIntegers >= 0) { const [integerPart, decimalPart] = value.split("."); if (integerPart) { - value = `${integerPart.slice(0, numberOfIntegers)}${decimalPart ? `.${decimalPart}` : ""}`; + const sign = integerPart.startsWith("-") ? "-" : ""; + const digits = sign ? integerPart.slice(1) : integerPart; + value = `${sign}${digits.slice(0, numberOfIntegers)}${decimalPart ? `.${decimalPart}` : ""}`; } } - return isNegative && value ? `-${value}` : value; + return isNegativeAccounting && value ? `-${value}` : value; }; export const formatString = (value: string, locale: string | undefined, config?: ConfigType): string => { @@ -56,8 +58,6 @@ export const formatString = (value: string, locale: string | undefined, config?: } let formattedParts = formatter.formatToParts(parseFloat(value)); - console.log(formattedParts); - if ( config?.symbolPosition === "before" && formattedParts.some((part) => part.type === "currency" || part.type === "unit") From 715fda28970269839a0e5a43941b3c2ebe1265e3 Mon Sep 17 00:00:00 2001 From: Jiale <jialestrabajos@gmail.com> Date: Mon, 23 Nov 2026 14:01:05 +0100 Subject: [PATCH 8/8] Change icon for Amount input component --- apps/website/screens/common/componentsList.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/website/screens/common/componentsList.json b/apps/website/screens/common/componentsList.json index f1ad92c84..054c44f9f 100644 --- a/apps/website/screens/common/componentsList.json +++ b/apps/website/screens/common/componentsList.json @@ -127,7 +127,7 @@ "label": "Amount input", "path": "/components/amount-input", "status": "experimental", - "icon": "money_range" + "icon": "universal_currency_alt" }, { "label": "Button",