@rsuci/shared-form-components 1.0.2 → 1.0.3

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.
@@ -9,6 +9,7 @@ export { default as DepartementInput } from './geographic/DepartementInput';
9
9
  export { default as SousPrefectureInput } from './geographic/SousPrefectureInput';
10
10
  export { default as QuartierInput } from './geographic/QuartierInput';
11
11
  export { default as VillageInput } from './geographic/VillageInput';
12
+ export { default as SearchableSelect } from './inputs/SearchableSelect';
12
13
  export { default as GeographicCascadeInput } from './inputs/GeographicCascadeInput';
13
14
  export { default as StringInput } from './inputs/StringInput';
14
15
  export { default as NumberInput } from './inputs/NumberInput';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAI3D,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAGjE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGpE,OAAO,EAAE,OAAO,IAA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,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG1D,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAG9D,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAGnE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,wBAAwB,CAAC"}
@@ -14,6 +14,7 @@ export { default as SousPrefectureInput } from './geographic/SousPrefectureInput
14
14
  export { default as QuartierInput } from './geographic/QuartierInput';
15
15
  export { default as VillageInput } from './geographic/VillageInput';
16
16
  // Input Components
17
+ export { default as SearchableSelect } from './inputs/SearchableSelect';
17
18
  export { default as GeographicCascadeInput } from './inputs/GeographicCascadeInput';
18
19
  export { default as StringInput } from './inputs/StringInput';
19
20
  export { default as NumberInput } from './inputs/NumberInput';
@@ -2,6 +2,7 @@
2
2
  * Composant unifié pour la sélection géographique en cascade
3
3
  * S'adapte automatiquement selon le type de variable (DISTRICT, REGION, DEPARTEMENT, etc.)
4
4
  * Gère la cascade via le champ variable.valeur (ex: "${G_01}")
5
+ * Utilise SearchableSelect pour une meilleure UX avec recherche intégrée
5
6
  */
6
7
  import React from 'react';
7
8
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"GeographicCascadeInput.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/GeographicCascadeInput.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAA2C,MAAM,OAAO,CAAC;AAShE;;GAEG;AACH,UAAU,SAAS;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AAWD,UAAU,2BAA2B;IACnC,QAAQ,EAAE,GAAG,CAAC;IACd,KAAK,EAAE,GAAG,CAAC;IACX,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,KAAK,IAAI,CAAC;IAC5C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,2BAA2B,CAiLxE,CAAC;AAEF,eAAe,sBAAsB,CAAC"}
1
+ {"version":3,"file":"GeographicCascadeInput.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/GeographicCascadeInput.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAA2C,MAAM,OAAO,CAAC;AAUhE;;GAEG;AACH,UAAU,SAAS;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AAWD,UAAU,2BAA2B;IACnC,QAAQ,EAAE,GAAG,CAAC;IACd,KAAK,EAAE,GAAG,CAAC;IACX,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,KAAK,IAAI,CAAC;IAC5C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,2BAA2B,CA+KxE,CAAC;AAEF,eAAe,sBAAsB,CAAC"}
@@ -3,8 +3,10 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  * Composant unifié pour la sélection géographique en cascade
4
4
  * S'adapte automatiquement selon le type de variable (DISTRICT, REGION, DEPARTEMENT, etc.)
5
5
  * Gère la cascade via le champ variable.valeur (ex: "${G_01}")
6
+ * Utilise SearchableSelect pour une meilleure UX avec recherche intégrée
6
7
  */
7
8
  import { useEffect, useState, useCallback } from 'react';
9
+ import SearchableSelect from './SearchableSelect';
8
10
  import { resolveParentValue, getApiEndpoint, getParentLabel, requiresParent } from '../../utils/variableDependencyResolver';
9
11
  export const GeographicCascadeInput = ({ variable, value, onChange, reponses, disabled = false, required = false, className = '' }) => {
10
12
  const [items, setItems] = useState([]);
@@ -71,22 +73,18 @@ export const GeographicCascadeInput = ({ variable, value, onChange, reponses, di
71
73
  }
72
74
  }, [parentValue, needsParent, value]);
73
75
  // 7. Gérer le changement de valeur
74
- const handleChange = (e) => {
75
- const selectedId = e.target.value;
76
- if (!selectedId || selectedId === '') {
76
+ const handleChange = (option) => {
77
+ if (!option) {
77
78
  onChange(null);
78
79
  return;
79
80
  }
80
- const parsedId = parseInt(selectedId, 10);
81
- if (isNaN(parsedId)) {
82
- onChange(null);
83
- return;
84
- }
85
- const selected = items.find(item => item.id === parsedId);
86
- if (selected) {
87
- // Stocker l'objet complet SelectDto
88
- onChange(selected);
89
- }
81
+ // Convertir SelectOption vers SelectDto
82
+ const selectDto = {
83
+ id: typeof option.id === 'string' ? parseInt(option.id, 10) : option.id,
84
+ code: option.code || '',
85
+ designation: option.designation
86
+ };
87
+ onChange(selectDto);
90
88
  };
91
89
  // 8. Déterminer si le champ est désactivé
92
90
  const isDisabled = disabled || loading || (needsParent && !parentValue);
@@ -94,8 +92,6 @@ export const GeographicCascadeInput = ({ variable, value, onChange, reponses, di
94
92
  const getPlaceholder = () => {
95
93
  if (loading)
96
94
  return 'Chargement...';
97
- if (error)
98
- return error;
99
95
  if (needsParent && !parentValue) {
100
96
  return `Sélectionnez d'abord ${getParentLabel(variable.type)}`;
101
97
  }
@@ -104,9 +100,24 @@ export const GeographicCascadeInput = ({ variable, value, onChange, reponses, di
104
100
  }
105
101
  return `Sélectionner ${variable.libelle || 'un élément'}...`;
106
102
  };
107
- // 10. Rendu du composant
108
- return (_jsxs("div", { className: "w-full", children: [_jsxs("select", { value: value?.id || '', onChange: handleChange, disabled: isDisabled, required: required, className: `w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-colors ${error ? 'border-red-300 bg-red-50' : 'border-gray-300'} ${isDisabled
109
- ? 'bg-gray-100 cursor-not-allowed text-gray-500'
110
- : 'bg-white text-gray-900'} ${className}`, title: isDisabled && needsParent && !parentValue ? `Sélectionnez d'abord ${getParentLabel(variable.type)}` : '', children: [_jsx("option", { value: "", children: getPlaceholder() }), items.map((item) => (_jsx("option", { value: item.id, children: item.designation }, item.id)))] }), error && !loading && (_jsxs("p", { className: "mt-1 text-sm text-red-600 flex items-center", children: [_jsx("svg", { className: "w-4 h-4 mr-1", fill: "currentColor", viewBox: "0 0 20 20", children: _jsx("path", { fillRule: "evenodd", d: "M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z", clipRule: "evenodd" }) }), error] })), needsParent && !parentValue && !loading && !error && (_jsxs("p", { className: "mt-1 text-sm text-gray-500 flex items-center", children: [_jsx("svg", { className: "w-4 h-4 mr-1", fill: "currentColor", viewBox: "0 0 20 20", children: _jsx("path", { fillRule: "evenodd", d: "M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z", clipRule: "evenodd" }) }), "Veuillez d'abord s\u00E9lectionner ", getParentLabel(variable.type)] })), loading && (_jsxs("p", { className: "mt-1 text-sm text-blue-600 flex items-center", children: [_jsxs("svg", { className: "animate-spin h-4 w-4 mr-1", fill: "none", viewBox: "0 0 24 24", children: [_jsx("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }), _jsx("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })] }), "Chargement des donn\u00E9es..."] }))] }));
103
+ // 10. Convertir les items en SelectOption pour SearchableSelect
104
+ const options = items.map(item => ({
105
+ id: item.id,
106
+ code: item.code,
107
+ designation: item.designation
108
+ }));
109
+ // 11. Convertir la valeur actuelle en SelectOption
110
+ const currentValue = value ? {
111
+ id: value.id,
112
+ code: value.code,
113
+ designation: value.designation
114
+ } : null;
115
+ // 12. Rendu du composant
116
+ return (_jsxs("div", { className: "w-full", children: [_jsx(SearchableSelect, { options: options, value: currentValue, onChange: handleChange, placeholder: getPlaceholder(), searchPlaceholder: "Rechercher...", disabled: isDisabled, required: required, loading: loading, error: error || undefined, className: className, noOptionsMessage: needsParent && !parentValue
117
+ ? `Veuillez d'abord sélectionner ${getParentLabel(variable.type)}`
118
+ : `Aucun(e) ${variable.libelle?.toLowerCase() || 'élément'} disponible`, formatOptionLabel: (option) => {
119
+ // Formater le label avec le code si disponible
120
+ return option.code ? `${option.code} ${option.designation}` : option.designation;
121
+ } }), needsParent && !parentValue && !loading && !error && (_jsxs("p", { className: "mt-1 text-sm text-gray-500 flex items-center", children: [_jsx("svg", { className: "w-4 h-4 mr-1", fill: "currentColor", viewBox: "0 0 20 20", children: _jsx("path", { fillRule: "evenodd", d: "M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z", clipRule: "evenodd" }) }), "Veuillez d'abord s\u00E9lectionner ", getParentLabel(variable.type)] })), loading && (_jsxs("p", { className: "mt-1 text-sm text-blue-600 flex items-center", children: [_jsxs("svg", { className: "animate-spin h-4 w-4 mr-1", fill: "none", viewBox: "0 0 24 24", children: [_jsx("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }), _jsx("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })] }), "Chargement des donn\u00E9es..."] }))] }));
111
122
  };
112
123
  export default GeographicCascadeInput;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Composant de sélection avec recherche intégrée
3
+ * Inspiré du design de production avec champ de filtre
4
+ */
5
+ import React from 'react';
6
+ export interface SelectOption {
7
+ id: number | string;
8
+ code?: string;
9
+ designation: string;
10
+ [key: string]: any;
11
+ }
12
+ interface SearchableSelectProps {
13
+ options: SelectOption[];
14
+ value?: SelectOption | null;
15
+ onChange: (option: SelectOption | null) => void;
16
+ placeholder?: string;
17
+ searchPlaceholder?: string;
18
+ disabled?: boolean;
19
+ required?: boolean;
20
+ loading?: boolean;
21
+ error?: string;
22
+ className?: string;
23
+ noOptionsMessage?: string;
24
+ formatOptionLabel?: (option: SelectOption) => string;
25
+ }
26
+ export declare const SearchableSelect: React.FC<SearchableSelectProps>;
27
+ export default SearchableSelect;
28
+ //# sourceMappingURL=SearchableSelect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SearchableSelect.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/SearchableSelect.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAsC,MAAM,OAAO,CAAC;AAE3D,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,UAAU,qBAAqB;IAC7B,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,KAAK,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;IAC5B,QAAQ,EAAE,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,KAAK,IAAI,CAAC;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,iBAAiB,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,MAAM,CAAC;CACtD;AAED,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CA+L5D,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,71 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * Composant de sélection avec recherche intégrée
4
+ * Inspiré du design de production avec champ de filtre
5
+ */
6
+ import { useState, useRef, useEffect } from 'react';
7
+ export const SearchableSelect = ({ options, value, onChange, placeholder = 'Sélectionner...', searchPlaceholder = 'Rechercher...', disabled = false, required = false, loading = false, error, className = '', noOptionsMessage = 'Aucune option disponible', formatOptionLabel }) => {
8
+ const [isOpen, setIsOpen] = useState(false);
9
+ const [searchTerm, setSearchTerm] = useState('');
10
+ const dropdownRef = useRef(null);
11
+ const searchInputRef = useRef(null);
12
+ // Fermer le dropdown quand on clique à l'extérieur
13
+ useEffect(() => {
14
+ const handleClickOutside = (event) => {
15
+ if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
16
+ setIsOpen(false);
17
+ setSearchTerm('');
18
+ }
19
+ };
20
+ document.addEventListener('mousedown', handleClickOutside);
21
+ return () => document.removeEventListener('mousedown', handleClickOutside);
22
+ }, []);
23
+ // Focus sur le champ de recherche quand le dropdown s'ouvre
24
+ useEffect(() => {
25
+ if (isOpen && searchInputRef.current) {
26
+ searchInputRef.current.focus();
27
+ }
28
+ }, [isOpen]);
29
+ // Filtrer les options selon le terme de recherche
30
+ const filteredOptions = options.filter(option => {
31
+ const label = formatOptionLabel ? formatOptionLabel(option) : option.designation;
32
+ const searchLower = searchTerm.toLowerCase();
33
+ return (label.toLowerCase().includes(searchLower) ||
34
+ (option.code && option.code.toLowerCase().includes(searchLower)));
35
+ });
36
+ // Gérer la sélection d'une option
37
+ const handleSelect = (option) => {
38
+ onChange(option);
39
+ setIsOpen(false);
40
+ setSearchTerm('');
41
+ };
42
+ // Gérer l'ouverture/fermeture du dropdown
43
+ const toggleDropdown = () => {
44
+ if (!disabled && !loading) {
45
+ setIsOpen(!isOpen);
46
+ if (!isOpen) {
47
+ setSearchTerm('');
48
+ }
49
+ }
50
+ };
51
+ // Formater le label d'une option
52
+ const getOptionLabel = (option) => {
53
+ if (formatOptionLabel) {
54
+ return formatOptionLabel(option);
55
+ }
56
+ return option.code ? `${option.code} ${option.designation}` : option.designation;
57
+ };
58
+ // Obtenir le label de la valeur sélectionnée
59
+ const getSelectedLabel = () => {
60
+ if (!value)
61
+ return placeholder;
62
+ return getOptionLabel(value);
63
+ };
64
+ return (_jsxs("div", { className: `relative w-full ${className}`, ref: dropdownRef, children: [_jsx("button", { type: "button", onClick: toggleDropdown, disabled: disabled || loading, className: `w-full px-3 py-2 text-left border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-colors ${error ? 'border-red-300 bg-red-50' : 'border-gray-300'} ${disabled || loading
65
+ ? 'bg-gray-100 cursor-not-allowed text-gray-500'
66
+ : 'bg-white text-gray-900 hover:border-gray-400'} ${isOpen ? 'ring-2 ring-blue-500 border-transparent' : ''}`, children: _jsxs("div", { className: "flex items-center justify-between", children: [_jsx("span", { className: value ? 'text-gray-900' : 'text-gray-500', children: loading ? 'Chargement...' : getSelectedLabel() }), _jsx("svg", { className: `w-5 h-5 text-gray-400 transition-transform ${isOpen ? 'transform rotate-180' : ''}`, fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M19 9l-7 7-7-7" }) })] }) }), isOpen && !disabled && !loading && (_jsxs("div", { className: "absolute z-50 w-full mt-1 bg-white border border-gray-300 rounded-lg shadow-lg max-h-80 overflow-hidden", children: [_jsx("div", { className: "p-2 border-b border-gray-200 bg-gray-50", children: _jsxs("div", { className: "relative", children: [_jsx("svg", { className: "absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-gray-400", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" }) }), _jsx("input", { ref: searchInputRef, type: "text", value: searchTerm, onChange: (e) => setSearchTerm(e.target.value), placeholder: searchPlaceholder, className: "w-full pl-10 pr-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-transparent text-sm" })] }) }), _jsx("div", { className: "overflow-y-auto max-h-60", children: filteredOptions.length === 0 ? (_jsx("div", { className: "px-4 py-3 text-sm text-gray-500 text-center", children: searchTerm ? `Aucun résultat pour "${searchTerm}"` : noOptionsMessage })) : (_jsx("ul", { className: "py-1", children: filteredOptions.map((option) => {
67
+ const isSelected = value?.id === option.id;
68
+ return (_jsx("li", { children: _jsx("button", { type: "button", onClick: () => handleSelect(option), className: `w-full px-4 py-2 text-left text-sm hover:bg-blue-50 transition-colors ${isSelected ? 'bg-blue-100 text-blue-900 font-medium' : 'text-gray-900'}`, children: getOptionLabel(option) }) }, option.id));
69
+ }) })) })] })), error && (_jsxs("p", { className: "mt-1 text-sm text-red-600 flex items-center", children: [_jsx("svg", { className: "w-4 h-4 mr-1", fill: "currentColor", viewBox: "0 0 20 20", children: _jsx("path", { fillRule: "evenodd", d: "M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z", clipRule: "evenodd" }) }), error] })), required && !value && (_jsx("p", { className: "mt-1 text-xs text-gray-500", children: "Ce champ est obligatoire" }))] }));
70
+ };
71
+ export default SearchableSelect;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Composant SelectInput - Liste de sélection avec recherche et pagination
2
+ * Composant SelectInput - Liste de sélection avec recherche intégrée
3
3
  * RSU v2 - Moteur de Rendu des Formulaires d'Enquête
4
4
  */
5
5
  import React from 'react';
@@ -1 +1 @@
1
- {"version":3,"file":"SelectInput.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/SelectInput.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAmB,MAAM,OAAO,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGxE,MAAM,WAAW,gBAAgB;IAC/B,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;CACpB;AAED,QAAA,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAkI3C,CAAC;AAEF,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"SelectInput.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/SelectInput.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIxE,MAAM,WAAW,gBAAgB;IAC/B,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;CACpB;AAED,QAAA,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAuF3C,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -1,15 +1,12 @@
1
1
  /**
2
- * Composant SelectInput - Liste de sélection avec recherche et pagination
2
+ * Composant SelectInput - Liste de sélection avec recherche intégrée
3
3
  * RSU v2 - Moteur de Rendu des Formulaires d'Enquête
4
4
  */
5
5
  'use client';
6
6
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
7
- import { useState } from 'react';
8
7
  import { VariableValueConverter } from '../../lib/utils/variableValueConverter';
8
+ import SearchableSelect from './SearchableSelect';
9
9
  const SelectInput = ({ variable, value, onChange, onBlur, error, disabled }) => {
10
- const [searchTerm, setSearchTerm] = useState('');
11
- const [currentPage, setCurrentPage] = useState(1);
12
- const itemsPerPage = 10;
13
10
  // Récupérer les options depuis la propriété valeur OU valeurDefaut (format: "Code1#Designation1|Code2#Designation2")
14
11
  const optionsSource = variable.proprietes?.valeur || variable.valeurDefaut;
15
12
  const allOptions = optionsSource && typeof optionsSource === 'string'
@@ -18,22 +15,30 @@ const SelectInput = ({ variable, value, onChange, onBlur, error, disabled }) =>
18
15
  code: opt.value.toString(),
19
16
  designation: opt.label
20
17
  }));
21
- // Filtrage par recherche
22
- const filteredOptions = allOptions.filter(option => option.designation.toLowerCase().includes(searchTerm.toLowerCase()) ||
23
- option.code.toLowerCase().includes(searchTerm.toLowerCase()));
24
- // Pagination
25
- const totalPages = Math.ceil(filteredOptions.length / itemsPerPage);
26
- const startIndex = (currentPage - 1) * itemsPerPage;
27
- const paginatedOptions = filteredOptions.slice(startIndex, startIndex + itemsPerPage);
28
18
  const selectedValue = value || '';
29
- // Affichage radio pour peu d'options
30
- if (allOptions.length <= 5 && !searchTerm) {
19
+ // Affichage radio pour peu d'options (≤5)
20
+ if (allOptions.length <= 5) {
31
21
  return (_jsx("div", { className: "space-y-2", children: allOptions.map((option) => (_jsxs("label", { className: "flex items-center space-x-2 cursor-pointer", children: [_jsx("input", { type: "radio", name: variable.code, value: option.code, checked: selectedValue === option.code, onChange: (e) => onChange(e.target.value), onBlur: onBlur, disabled: disabled, className: `w-4 h-4 text-green-600 border-gray-300 focus:ring-green-500 ${disabled ? 'cursor-not-allowed' : 'cursor-pointer'}` }), _jsx("span", { className: `text-sm ${disabled ? 'text-gray-400' : 'text-gray-700'}`, children: option.designation })] }, option.code))) }));
32
22
  }
33
- // Affichage avec recherche et pagination pour beaucoup d'options
34
- return (_jsxs("div", { className: "space-y-3", children: [allOptions.length > 10 && (_jsx("div", { className: "relative", children: _jsx("input", { type: "text", placeholder: "Rechercher...", value: searchTerm, onChange: (e) => {
35
- setSearchTerm(e.target.value.toUpperCase());
36
- setCurrentPage(1); // Reset à la première page lors de la recherche
37
- }, disabled: disabled, className: "w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-green-500 focus:border-transparent text-sm text-gray-900 bg-white" }) })), _jsxs("select", { value: selectedValue, onChange: (e) => onChange(e.target.value || ''), onBlur: onBlur, disabled: disabled, className: `w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-green-500 focus:border-transparent text-gray-900 ${error ? 'border-red-500' : 'border-gray-300'} ${disabled ? 'bg-gray-100 cursor-not-allowed text-gray-500' : 'bg-white'}`, children: [_jsx("option", { value: "", children: "S\u00E9lectionner..." }), paginatedOptions.map((option) => (_jsxs("option", { value: option.code, children: [option.code, " - ", option.designation] }, option.code)))] }), totalPages > 1 && (_jsxs("div", { className: "flex items-center justify-between text-sm text-gray-600", children: [_jsxs("div", { children: ["Page ", currentPage, " sur ", totalPages, " (", filteredOptions.length, " \u00E9l\u00E9ments)"] }), _jsxs("div", { className: "flex space-x-2", children: [_jsx("button", { type: "button", onClick: () => setCurrentPage(Math.max(1, currentPage - 1)), disabled: currentPage === 1 || disabled, className: "px-2 py-1 border border-gray-300 rounded text-xs hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed", children: "Pr\u00E9c\u00E9dent" }), _jsx("button", { type: "button", onClick: () => setCurrentPage(Math.min(totalPages, currentPage + 1)), disabled: currentPage === totalPages || disabled, className: "px-2 py-1 border border-gray-300 rounded text-xs hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed", children: "Suivant" })] })] })), selectedValue && (_jsx("div", { className: "p-2 bg-green-50 border border-green-200 rounded text-sm", children: _jsxs("span", { className: "text-green-800", children: ["S\u00E9lectionn\u00E9: ", allOptions.find(opt => opt.code === selectedValue)?.designation || selectedValue] }) }))] }));
23
+ // Convertir les options au format SelectOption pour SearchableSelect
24
+ const selectOptions = allOptions.map(opt => ({
25
+ id: opt.code,
26
+ code: opt.code,
27
+ designation: opt.designation
28
+ }));
29
+ // Trouver l'option sélectionnée
30
+ const selectedOption = selectOptions.find(opt => opt.code === selectedValue) || null;
31
+ // Gérer le changement de sélection
32
+ const handleChange = (option) => {
33
+ onChange(option?.code || '');
34
+ if (onBlur)
35
+ onBlur();
36
+ };
37
+ // Format d'affichage: "Code - Designation"
38
+ const formatOptionLabel = (option) => {
39
+ return `${option.code} - ${option.designation}`;
40
+ };
41
+ // Affichage avec SearchableSelect pour beaucoup d'options (>5)
42
+ return (_jsxs("div", { className: "space-y-2", children: [_jsx(SearchableSelect, { options: selectOptions, value: selectedOption, onChange: handleChange, placeholder: "S\u00E9lectionner...", searchPlaceholder: "Rechercher...", disabled: disabled, required: variable.estObligatoire, error: error, formatOptionLabel: formatOptionLabel, noOptionsMessage: "Aucune option trouv\u00E9e" }), selectedValue && selectedOption && (_jsx("div", { className: "p-2 bg-green-50 border border-green-200 rounded text-sm", children: _jsxs("span", { className: "text-green-800", children: ["S\u00E9lectionn\u00E9: ", selectedOption.designation] }) }))] }));
38
43
  };
39
44
  export default SelectInput;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsuci/shared-form-components",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
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",
package/.gitattributes DELETED
@@ -1,2 +0,0 @@
1
- # Auto detect text files and perform LF normalization
2
- * text=auto