@rsuci/shared-form-components 1.0.76 → 1.0.77

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 @@
1
- {"version":3,"file":"PhoneInput.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/PhoneInput.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIxE,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,kBAAkB,GAAG;QAAE,QAAQ,EAAE,OAAO,CAAA;KAAE,CAAC;IACrD,KAAK,EAAE,aAAa,CAAC;IACrB,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IACzC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,QAAA,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CA+BzC,CAAC;AAEF,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"PhoneInput.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/PhoneInput.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAgC,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIxE,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,kBAAkB,GAAG;QAAE,QAAQ,EAAE,OAAO,CAAA;KAAE,CAAC;IACrD,KAAK,EAAE,aAAa,CAAC;IACrB,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IACzC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,QAAA,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CA8DzC,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -3,7 +3,8 @@
3
3
  * RSU v2 - Moteur de Rendu des Formulaires d'Enquête
4
4
  */
5
5
  'use client';
6
- import { jsx as _jsx } from "react/jsx-runtime";
6
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
7
+ import { useState, useCallback } from 'react';
7
8
  import { applyComponentStyle } from '../../utils/styleUtils';
8
9
  import { isComponentReadonly, readonlyClasses } from '../../utils/componentStateUtils';
9
10
  const PhoneInput = ({ variable, value, onChange, onBlur, error, disabled, isConsultationMode = false }) => {
@@ -11,16 +12,40 @@ const PhoneInput = ({ variable, value, onChange, onBlur, error, disabled, isCons
11
12
  const { textStyle, containerStyle } = applyComponentStyle(variable.componentStyle);
12
13
  // Déterminer si le composant est en lecture seule
13
14
  const isReadonly = isComponentReadonly(variable, isConsultationMode);
15
+ const [localError, setLocalError] = useState(null);
16
+ const validate = useCallback((val) => {
17
+ if (!val)
18
+ return null;
19
+ if (val.length !== 10) {
20
+ return 'Le numéro doit contenir exactement 10 chiffres';
21
+ }
22
+ const prefix2 = val.slice(0, 2);
23
+ const firstDigit = val[0];
24
+ if (!['07', '05', '01'].includes(prefix2) && firstDigit !== '2') {
25
+ return 'Le numéro doit commencer par 07, 05, 01 ou 2';
26
+ }
27
+ return null;
28
+ }, []);
29
+ const handleChange = (e) => {
30
+ const raw = e.target.value.replace(/\D/g, '').slice(0, 10);
31
+ setLocalError(validate(raw));
32
+ onChange(raw);
33
+ };
34
+ const handleBlur = () => {
35
+ setLocalError(validate(stringValue));
36
+ onBlur?.();
37
+ };
14
38
  // Générer les classes CSS
39
+ const displayError = error || localError;
15
40
  const getInputClasses = () => {
16
41
  const baseClasses = 'w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-green-500 focus:border-transparent text-gray-900';
17
- const errorClasses = error ? 'border-red-500' : 'border-gray-300';
42
+ const errorClasses = displayError ? 'border-red-500' : 'border-gray-300';
18
43
  if (disabled)
19
44
  return `${baseClasses} ${errorClasses} bg-gray-100 cursor-not-allowed text-gray-500`;
20
45
  if (isReadonly)
21
46
  return `${baseClasses} ${errorClasses} ${readonlyClasses.readonly}`;
22
47
  return `${baseClasses} ${errorClasses} bg-white`;
23
48
  };
24
- return (_jsx("div", { style: containerStyle, children: _jsx("input", { type: "tel", value: stringValue, onChange: (e) => onChange(e.target.value), onBlur: onBlur, placeholder: variable.proprietes?.placeholder || "+225 XX XX XX XX", disabled: disabled, readOnly: isReadonly, style: textStyle, className: getInputClasses() }) }));
49
+ return (_jsxs("div", { style: containerStyle, children: [_jsx("input", { type: "tel", value: stringValue, onChange: handleChange, onBlur: handleBlur, placeholder: variable.proprietes?.placeholder || "07 XX XX XX XX", disabled: disabled, readOnly: isReadonly, maxLength: 10, style: textStyle, className: getInputClasses() }), displayError && (_jsx("p", { className: "mt-1 text-sm text-red-600", children: displayError }))] }));
25
50
  };
26
51
  export default PhoneInput;
@@ -429,7 +429,7 @@ export class VariableValueConverter {
429
429
  case 'HOUR':
430
430
  return /^([01]?[0-9]|2[0-3]):[0-5][0-9]$/.test(value);
431
431
  case 'PHONE':
432
- return /^\+?[1-9]\d{1,14}$/.test(value.replace(/\s/g, ''));
432
+ return /^(0[157]|2)\d{8}$/.test(value.replace(/\s/g, ''));
433
433
  case 'GPS':
434
434
  try {
435
435
  const parsed = JSON.parse(value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsuci/shared-form-components",
3
- "version": "1.0.76",
3
+ "version": "1.0.77",
4
4
  "description": "Composants partagés de rendu de formulaires RSU v2 - Package local pour frontend Admin et Public",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",