Skip to content

Commit c3c0efb

Browse files
authored
feat: upgrade bootstrap italia
1 parent a8405ce commit c3c0efb

File tree

7 files changed

+1891
-1790
lines changed

7 files changed

+1891
-1790
lines changed

src/Autocomplete/Autocomplete.tsx

+69-18
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
1-
import React, { FC } from 'react';
1+
import React, { FC, useEffect } from 'react';
22
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
33
// @ts-ignore non ci sono i types
4-
import BaseAutocomplete from 'accessible-autocomplete/react'; // Reference to https://www.npmjs.com/package/accessible-autocomplete
4+
import BaseAutocomplete from 'accessible-autocomplete/react';
5+
// Reference to https://www.npmjs.com/package/accessible-autocomplete
6+
// Implementation example: https://github.com/alphagov/accessible-autocomplete/blob/main/examples/react/index.html
57

68
export interface AutocompleteAttributes {
79
/** Identificativo */
8-
id?: string;
10+
id: string;
11+
/** Label */
12+
label: string;
13+
/** Valori all'interno della select */
14+
source: (query: string, syncResults: () => void) => void;
915
/** Valori chiave - valore all'interno della select */
10-
source: { value: string; label: string }[];
16+
onConfirm?: (value: string) => void;
1117
/** Placeholder (default: ``) */
1218
placeholder?: string;
1319
/** Valore di default (default: ``) */
1420
defaultValue?: string;
1521
/** Modalità display menu (default: `inline`) */
1622
displayMenu?: string;
23+
/** Utilizzare per mostrare il successo nella validazione del valore nel campo Input */
24+
valid?: boolean;
25+
/** Testo di validazione per l'elemento del moduleo form. */
26+
validationText?: string;
1727
/** Funzione ritornante stringa in caso di nessun risultato */
1828
tNoResults?: () => string;
1929
/** Funzione ritornante stringa di suggerimento */
@@ -60,22 +70,63 @@ export const Autocomplete: FC<AutocompleteAttributes> = ({
6070
defaultValue = '',
6171
displayMenu = 'inline',
6272
source,
73+
validationText,
74+
onConfirm,
6375
...attributes
6476
}) => {
77+
const { id, valid } = attributes;
78+
const validityCheck = valid === true || valid === false;
79+
80+
useEffect(() => {
81+
const inputElement: HTMLInputElement = document.getElementById(id) as HTMLInputElement;
82+
const labelElement = inputElement?.parentElement?.parentElement?.getElementsByTagName('label')[0];
83+
84+
if (inputElement.value !== '') {
85+
labelElement?.classList.add('active');
86+
}
87+
88+
inputElement?.addEventListener('focus', () => {
89+
labelElement?.classList.add('active');
90+
});
91+
inputElement?.addEventListener('blur', () => {
92+
if (inputElement.value === '') {
93+
labelElement?.classList.remove('active');
94+
}
95+
if (onConfirm) {
96+
onConfirm(inputElement.value);
97+
}
98+
});
99+
}, [id]);
100+
65101
return (
66-
<BaseAutocomplete
67-
id='autocomplete'
68-
source={source}
69-
placeholder={placeholder}
70-
defaultValue={defaultValue}
71-
displayMenu={displayMenu}
72-
tAssistiveHint={tAssistiveHint}
73-
tNoResults={tNoResults}
74-
tStatusQueryTooShort={tStatusQueryTooShort}
75-
tStatusNoResults={tStatusNoResults}
76-
tStatusSelectedOption={tStatusSelectedOption}
77-
tStatusResults={tStatusResults}
78-
{...attributes}
79-
/>
102+
<>
103+
<label htmlFor={attributes.id}>{attributes.label}</label>
104+
<BaseAutocomplete
105+
source={source}
106+
placeholder={placeholder}
107+
defaultValue={defaultValue}
108+
displayMenu={displayMenu}
109+
tAssistiveHint={tAssistiveHint}
110+
tNoResults={tNoResults}
111+
tStatusQueryTooShort={tStatusQueryTooShort}
112+
tStatusNoResults={tStatusNoResults}
113+
tStatusSelectedOption={tStatusSelectedOption}
114+
tStatusResults={tStatusResults}
115+
onConfirm={onConfirm}
116+
inputClasses={`form-control ${validityCheck && (valid === false ? 'is-invalid' : 'just-validate-success-field')}`}
117+
showNoOptionsFound={true}
118+
hintClasses='app-hint'
119+
autoselect={false}
120+
showAllValues={false}
121+
templates={undefined}
122+
confirmOnBlur={false}
123+
menuAttributes={null}
124+
menuClasses={null}
125+
{...attributes}
126+
/>
127+
<div className='form-feedback just-validate-error-label form-text form-feedback just-validate-error-label'>
128+
{!valid && validationText}
129+
</div>
130+
</>
80131
);
81132
};

src/Input/Input.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
6262
decrementLabel?: string | ReactNode;
6363
/** Testo di esempio da utilizzare per il campo. */
6464
placeholder?: string;
65-
/** Testo di validazione per l'elemento del moduleo form. */
65+
/** Testo di validazione per l'elemento del modulo form. */
6666
validationText?: string;
6767
/** Testo di aiuto per l'elemento del moduleo form. Richiede che il componente `Input` abbia la prop `id` impostata. */
6868
infoText?: string;

0 commit comments

Comments
 (0)