@axa-fr/design-system-apollo-react 3.0.0 → 3.0.1-alpha.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1,8 @@
1
1
  export declare const formatInputDateValue: (value?: Date | string) => string | undefined;
2
+ export declare const isValidDayDecimal: (char: string, index: number) => boolean;
3
+ export declare const isValidDay: (day: number, index: number) => boolean;
4
+ export declare const isValidMonthDecimal: (char: string, index: number) => boolean;
5
+ export declare const isValidMonth: (month: number, index: number) => boolean;
6
+ export declare const isValidMillennium: (char: string, index: number) => boolean;
7
+ export declare const isValidDigit: (char: string, index: number, currentCleanValue: string[]) => boolean;
8
+ export declare const formatDateTextValue: (value?: string) => string;
@@ -1 +1,23 @@
1
1
  export const formatInputDateValue = (value) => value instanceof Date ? value.toISOString().split("T")[0] : value;
2
+ export const isValidDayDecimal = (char, index) => (index === 0 && Number(char) <= 3) || index !== 0;
3
+ export const isValidDay = (day, index) => (index === 1 && day <= 31 && day > 0) || index !== 1;
4
+ export const isValidMonthDecimal = (char, index) => (index === 2 && Number(char) <= 1) || index !== 2;
5
+ export const isValidMonth = (month, index) => (index === 3 && month <= 12 && month > 0) || index !== 3;
6
+ export const isValidMillennium = (char, index) => (index === 4 && Number(char) > 0) || index !== 4;
7
+ export const isValidDigit = (char, index, currentCleanValue) => Number.isInteger(Number(char)) &&
8
+ isValidDayDecimal(char, index) &&
9
+ isValidDay(Number(`${Number(currentCleanValue[0])}${Number(char)}`), index) &&
10
+ isValidMonthDecimal(char, index) &&
11
+ isValidMonth(Number(`${Number(currentCleanValue[2])}${Number(char)}`), index) &&
12
+ isValidMillennium(char, index);
13
+ export const formatDateTextValue = (value) => {
14
+ if (!value) {
15
+ return "";
16
+ }
17
+ return value
18
+ .split("")
19
+ .filter((char) => char !== "/")
20
+ .filter((char, index, currentCleanValue) => isValidDigit(char, index, currentCleanValue))
21
+ .map((char, index) => (index === 2 || index === 4 ? `/${char}` : char))
22
+ .join("");
23
+ };
@@ -0,0 +1,9 @@
1
+ import { type ComponentPropsWithRef } from "react";
2
+ export type InputDateAtomProps = Omit<ComponentPropsWithRef<"input">, "value" | "min" | "max"> & {
3
+ defaultValue?: Date | string;
4
+ value?: Date | string;
5
+ min?: Date | string;
6
+ max?: Date | string;
7
+ };
8
+ declare const InputDateAtom: import("react").ForwardRefExoticComponent<Omit<InputDateAtomProps, "ref"> & import("react").RefAttributes<HTMLInputElement>>;
9
+ export { InputDateAtom };
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef } from "react";
3
+ import { formatInputDateValue } from "./InputDate.helper";
4
+ const InputDateAtom = forwardRef(({ defaultValue, value, min, max, ...otherProps }, inputRef) => (_jsx("input", { ...otherProps, type: "date", ref: inputRef, defaultValue: formatInputDateValue(defaultValue), value: formatInputDateValue(value), min: formatInputDateValue(min), max: formatInputDateValue(max) })));
5
+ InputDateAtom.displayName = "InputDateAtom";
6
+ export { InputDateAtom };
@@ -18,7 +18,7 @@ export type InputDateProps = Omit<ComponentPropsWithRef<"input">, "value" | "min
18
18
  success?: string;
19
19
  hidePicker?: boolean;
20
20
  label: ItemLabelProps["label"];
21
- } & Partial<ItemLabelProps & ItemMessageProps>;
21
+ } & Partial<Omit<ItemLabelProps, "onChange"> & ItemMessageProps>;
22
22
  type InputDateCommonProps = InputDateProps & {
23
23
  ItemLabelComponent: ComponentType<Omit<ComponentProps<typeof ItemLabelCommon>, "ButtonComponent">>;
24
24
  ItemMessageComponent: ComponentType<ComponentProps<typeof ItemMessage>>;
@@ -1,41 +1,26 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { forwardRef, useEffect, useId, useImperativeHandle, useRef, } from "react";
2
+ import { forwardRef, useId, } from "react";
3
3
  import { getComponentClassName } from "../../utilities/getComponentClassName";
4
- import { formatInputDateValue } from "./InputDate.helper";
5
- const InputDateCommon = forwardRef(({ className, classModifier = "", defaultValue, value, helper, error, success, message, messageType, label, description, buttonLabel, onButtonClick, ItemLabelComponent, ItemMessageComponent, required, min, max, hidePicker, ...otherProps }, ref) => {
6
- const componentClassName = getComponentClassName("af-form__input-date", className ?? "", `${classModifier}${hidePicker ? " no-picker" : ""}`);
4
+ import { InputDateAtom } from "./InputDateAtom";
5
+ import { InputDateTextAtom } from "./InputDateTextAtom";
6
+ const InputDateCommon = forwardRef(({ className, classModifier = "", helper, error, success, message, messageType, label, description, buttonLabel, onButtonClick, ItemLabelComponent, ItemMessageComponent, required, hidePicker, max, min, ...otherProps }, inputRef) => {
7
+ const componentClassName = getComponentClassName("af-form__input-date", className ?? "", classModifier);
7
8
  let inputId = useId();
8
9
  inputId = otherProps.id ?? inputId;
9
10
  const idMessage = useId();
10
11
  const idHelp = useId();
11
- const inputRef = useRef(null);
12
- useImperativeHandle(ref, () => inputRef.current);
13
- const ariaDescribedby = [helper && idHelp, success && idMessage].filter(Boolean);
14
- /* Stop space keydown, enter keydown for non webkit browsers and click events targeting the input element when picker is disabled */
15
- useEffect(() => {
16
- function handleKeydown(event) {
17
- if (hidePicker &&
18
- (event.keyCode === 32 ||
19
- (event.keyCode === 13 &&
20
- !window.navigator?.userAgent?.includes("WebKit"))) &&
21
- event.target === inputRef.current) {
22
- event.preventDefault();
23
- }
24
- }
25
- function handleClick(event) {
26
- if (hidePicker && event.target === inputRef.current) {
27
- event.preventDefault();
28
- }
29
- }
30
- window.addEventListener("keydown", handleKeydown);
31
- window.addEventListener("click", handleClick);
32
- return () => {
33
- window.removeEventListener("keydown", handleKeydown);
34
- window.removeEventListener("click", handleClick);
35
- };
36
- }, [hidePicker]);
12
+ const ariaDescribedbyIds = [
13
+ helper && idHelp,
14
+ ((Boolean(message) && messageType === "success") || Boolean(success)) &&
15
+ idMessage,
16
+ ].filter(Boolean);
17
+ const ariaDescribedby = ariaDescribedbyIds.length
18
+ ? ariaDescribedbyIds.join(" ")
19
+ : undefined;
37
20
  const hasError = (Boolean(message) && messageType === "error") || Boolean(error);
38
- return (_jsxs("div", { className: "af-form__input-container", children: [_jsx(ItemLabelComponent, { label: label, description: description, buttonLabel: buttonLabel, onButtonClick: onButtonClick, required: required, inputId: inputId }), _jsx("input", { ...otherProps, id: inputId, className: componentClassName, type: "date", ref: inputRef, defaultValue: formatInputDateValue(defaultValue), value: formatInputDateValue(value), "aria-errormessage": hasError ? idMessage : undefined, "aria-invalid": hasError || undefined, "aria-describedby": ariaDescribedby.length > 0 ? ariaDescribedby.join(" ") : undefined, required: required, min: formatInputDateValue(min), max: formatInputDateValue(max) }), helper ? (_jsx("span", { id: idHelp, className: "af-form__input-helper", children: helper })) : null, _jsx(ItemMessageComponent, { id: idMessage, message: message || error || success, messageType: messageType || (error ? "error" : "success") })] }));
21
+ const ariaErrormessage = hasError ? idMessage : undefined;
22
+ const ariaInvalid = hasError || undefined;
23
+ return (_jsxs("div", { className: "af-form__input-container", children: [_jsx(ItemLabelComponent, { label: label, description: description, buttonLabel: buttonLabel, onButtonClick: onButtonClick, required: required, inputId: inputId }), hidePicker ? (_jsx(InputDateTextAtom, { ...otherProps, id: inputId, className: componentClassName, ref: inputRef, "aria-errormessage": ariaErrormessage, "aria-invalid": ariaInvalid, "aria-describedby": ariaDescribedby, required: required })) : (_jsx(InputDateAtom, { ...otherProps, id: inputId, className: componentClassName, ref: inputRef, "aria-errormessage": ariaErrormessage, "aria-invalid": ariaInvalid, "aria-describedby": ariaDescribedby, required: required, max: max, min: min })), helper ? (_jsx("span", { id: idHelp, className: "af-form__input-helper", children: helper })) : null, _jsx(ItemMessageComponent, { id: idMessage, message: message || error || success, messageType: messageType || (error ? "error" : "success") })] }));
39
24
  });
40
25
  InputDateCommon.displayName = "InputDate";
41
26
  export { InputDateCommon };
@@ -0,0 +1,9 @@
1
+ import { type ComponentProps } from "react";
2
+ import { InputTextAtom } from "../InputTextAtom/InputTextAtomCommon";
3
+ export type InputDateTextAtomProps = Omit<ComponentProps<typeof InputTextAtom>, "value"> & {
4
+ value?: Date | string;
5
+ defaultValue?: Date | string;
6
+ onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
7
+ };
8
+ declare const InputDateTextAtom: import("react").ForwardRefExoticComponent<Omit<InputDateTextAtomProps, "ref"> & import("react").RefAttributes<HTMLInputElement>>;
9
+ export { InputDateTextAtom };
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef } from "react";
3
+ import { InputTextAtom } from "../InputTextAtom/InputTextAtomCommon";
4
+ import { formatDateTextValue, formatInputDateValue } from "./InputDate.helper";
5
+ const InputDateTextAtom = forwardRef(({ onChange, value, defaultValue, ...otherProps }, inputRef) => {
6
+ const handleChange = (e) => {
7
+ const formattedValue = formatDateTextValue(e.target.value);
8
+ onChange?.({
9
+ ...e,
10
+ target: { ...e.target, value: formattedValue },
11
+ });
12
+ };
13
+ return (_jsx(InputTextAtom, { pattern: "\\d{0,2}/?\\d{0,2}/?\\d{0,4}", maxLength: 10, ref: inputRef, inputMode: "numeric", onChange: handleChange, value: formatInputDateValue(value), defaultValue: formatInputDateValue(defaultValue), ...otherProps }));
14
+ });
15
+ InputDateTextAtom.displayName = "InputDateText";
16
+ export { InputDateTextAtom };
@@ -1,11 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { forwardRef, useId, } from "react";
3
3
  import { getComponentClassName } from "../../utilities/getComponentClassName";
4
- const InputTextAtom = forwardRef(({ unit, className, classModifier = "", error, required, idMessage, idHelp, "aria-errormessage": ariaErrormessage, type = "text", ...otherProps }, inputRef) => {
4
+ const InputTextAtom = forwardRef(({ unit, className, classModifier = "", error, required, idMessage, idHelp, "aria-errormessage": ariaErrormessage, "aria-describedby": ariaDescribedby, type = "text", ...otherProps }, inputRef) => {
5
5
  const componentClassName = getComponentClassName("af-form__input-text", className, classModifier + (error || ariaErrormessage ? " error" : ""));
6
6
  let inputId = useId();
7
7
  inputId = otherProps.id || inputId;
8
- return (_jsxs("div", { className: "af-form__input-variant", children: [_jsx("input", { id: inputId, className: componentClassName, type: type, required: required, ref: inputRef, "aria-errormessage": ariaErrormessage ?? idMessage, "aria-invalid": Boolean(error || ariaErrormessage), "aria-describedby": idHelp, ...otherProps }), unit] }));
8
+ return (_jsxs("div", { className: "af-form__input-variant", children: [_jsx("input", { id: inputId, className: componentClassName, type: type, required: required, ref: inputRef, "aria-errormessage": ariaErrormessage ?? idMessage, "aria-invalid": Boolean(error || ariaErrormessage), "aria-describedby": ariaDescribedby ?? idHelp, ...otherProps }), unit] }));
9
9
  });
10
10
  InputTextAtom.displayName = "InputTextAtom";
11
11
  export { InputTextAtom };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axa-fr/design-system-apollo-react",
3
- "version": "3.0.0",
3
+ "version": "3.0.1-alpha.12",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -46,10 +46,10 @@
46
46
  },
47
47
  "homepage": "https://github.com/AxaFrance/design-system#readme",
48
48
  "peerDependencies": {
49
- "@axa-fr/design-system-apollo-css": "3.0.0",
49
+ "@axa-fr/design-system-apollo-css": "3.0.1-alpha.12",
50
50
  "@material-symbols/svg-400": ">= 0.19.0",
51
51
  "react": ">= 18",
52
- "@axa-fr/design-system-look-and-feel-css": "3.0.0"
52
+ "@axa-fr/design-system-look-and-feel-css": "3.0.1-alpha.12"
53
53
  },
54
54
  "peerDependenciesMeta": {
55
55
  "@material-symbols/svg-400": {