@rolster/react-components 18.10.5 → 18.10.7
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.
- package/dist/cjs/index.js +57 -41
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.js +57 -41
- package/dist/es/index.js.map +1 -1
- package/dist/esm/components/organisms/AutocompleteField/AutocompleteFieldHook.d.ts +3 -3
- package/dist/esm/components/organisms/AutocompleteField/AutocompleteFieldHook.js +28 -19
- package/dist/esm/components/organisms/AutocompleteField/AutocompleteFieldHook.js.map +1 -1
- package/dist/esm/components/organisms/SelectField/SelectFieldHook.js +23 -13
- package/dist/esm/components/organisms/SelectField/SelectFieldHook.js.map +1 -1
- package/dist/esm/hooks/ListControlHook.d.ts +2 -2
- package/dist/esm/hooks/ListControlHook.js +5 -8
- package/dist/esm/hooks/ListControlHook.js.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1127,7 +1127,7 @@ const ELEMENT_SIZE_REM = 4;
|
|
|
1127
1127
|
const BASE_SIZE_PX = 16;
|
|
1128
1128
|
const ELEMENT_SIZE_PX = BASE_SIZE_PX * ELEMENT_SIZE_REM;
|
|
1129
1129
|
const MAZ_LIST_SIZE_PX = BASE_SIZE_PX * LIST_SIZE_REM;
|
|
1130
|
-
function useListControl({ suggestions, formControl, withHigher = false }) {
|
|
1130
|
+
function useListControl({ suggestions, formControl, higher: withHigher = false }) {
|
|
1131
1131
|
const boxContentRef = react.useRef(null);
|
|
1132
1132
|
const listRef = react.useRef(null);
|
|
1133
1133
|
const inputRef = react.useRef(null);
|
|
@@ -1219,10 +1219,7 @@ function useListControl({ suggestions, formControl, withHigher = false }) {
|
|
|
1219
1219
|
setPositionElement(0);
|
|
1220
1220
|
elements.item(0).focus();
|
|
1221
1221
|
setTimeout(() => {
|
|
1222
|
-
listRef?.current?.scroll({
|
|
1223
|
-
top: 0,
|
|
1224
|
-
behavior: 'smooth'
|
|
1225
|
-
});
|
|
1222
|
+
listRef?.current?.scroll({ top: 0, behavior: 'smooth' });
|
|
1226
1223
|
}, 100);
|
|
1227
1224
|
}
|
|
1228
1225
|
}
|
|
@@ -1254,19 +1251,19 @@ function useListControl({ suggestions, formControl, withHigher = false }) {
|
|
|
1254
1251
|
higher,
|
|
1255
1252
|
inputRef,
|
|
1256
1253
|
listRef,
|
|
1257
|
-
value,
|
|
1258
|
-
visible,
|
|
1259
1254
|
navigationElement,
|
|
1260
1255
|
navigationInput,
|
|
1261
1256
|
setFocused,
|
|
1262
1257
|
setValue,
|
|
1263
|
-
setVisible
|
|
1258
|
+
setVisible,
|
|
1259
|
+
value,
|
|
1260
|
+
visible
|
|
1264
1261
|
};
|
|
1265
1262
|
}
|
|
1266
1263
|
|
|
1267
1264
|
const DURATION_ANIMATION$1 = 240;
|
|
1268
1265
|
const MAX_ELEMENTS = 6;
|
|
1269
|
-
function useAutocompleteField({
|
|
1266
|
+
function useAutocompleteField({ disabled, formControl, onSelect, onValue, suggestions }) {
|
|
1270
1267
|
const [pattern, setPattern] = react.useState('');
|
|
1271
1268
|
const [coincidences, setCoincidences] = react.useState([]);
|
|
1272
1269
|
const [store, setStore] = react.useState({
|
|
@@ -1277,26 +1274,37 @@ function useAutocompleteField({ suggestions, disabled, formControl, onSelect, on
|
|
|
1277
1274
|
const listControl = useListControl({
|
|
1278
1275
|
suggestions,
|
|
1279
1276
|
formControl,
|
|
1280
|
-
|
|
1277
|
+
higher: true
|
|
1281
1278
|
});
|
|
1282
|
-
const { collection, inputRef,
|
|
1279
|
+
const { collection, inputRef, navigationElement, navigationInput, setFocused, setValue, setVisible } = listControl;
|
|
1283
1280
|
const [changeInternal, setChangeInternal] = react.useState(false);
|
|
1284
1281
|
react.useEffect(() => filterSuggestions(pattern, true), [suggestions]);
|
|
1285
1282
|
react.useEffect(() => filterSuggestions(pattern), [pattern]);
|
|
1286
1283
|
react.useEffect(() => {
|
|
1287
|
-
changeInternal ? setChangeInternal(false) : resetState();
|
|
1284
|
+
changeInternal ? setChangeInternal(false) : resetState(formControl?.state);
|
|
1288
1285
|
}, [formControl?.state]);
|
|
1289
|
-
react.useEffect(() =>
|
|
1290
|
-
function
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1286
|
+
react.useEffect(() => resetCollection(collection, formControl?.state), [collection]);
|
|
1287
|
+
function setFormState(value) {
|
|
1288
|
+
setChangeInternal(true);
|
|
1289
|
+
formControl?.setState(value);
|
|
1290
|
+
}
|
|
1291
|
+
function resetCollection(collection, state) {
|
|
1292
|
+
if (state) {
|
|
1293
|
+
const element = collection.find(state);
|
|
1294
|
+
if (element) {
|
|
1295
|
+
setValue(element.description);
|
|
1296
|
+
}
|
|
1297
|
+
else {
|
|
1298
|
+
setValue('');
|
|
1299
|
+
setFormState(undefined);
|
|
1300
|
+
}
|
|
1299
1301
|
}
|
|
1302
|
+
else {
|
|
1303
|
+
setValue('');
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
function resetState(state) {
|
|
1307
|
+
setValue(state ? collection.find(state)?.description || '' : '');
|
|
1300
1308
|
}
|
|
1301
1309
|
function onClickControl() {
|
|
1302
1310
|
if (!disabled) {
|
|
@@ -1327,8 +1335,7 @@ function useAutocompleteField({ suggestions, disabled, formControl, onSelect, on
|
|
|
1327
1335
|
setVisible(false);
|
|
1328
1336
|
setValue('');
|
|
1329
1337
|
if (formControl) {
|
|
1330
|
-
|
|
1331
|
-
formControl.setState(undefined);
|
|
1338
|
+
setFormState(undefined);
|
|
1332
1339
|
}
|
|
1333
1340
|
if (onValue) {
|
|
1334
1341
|
onValue(undefined);
|
|
@@ -1361,8 +1368,7 @@ function useAutocompleteField({ suggestions, disabled, formControl, onSelect, on
|
|
|
1361
1368
|
}
|
|
1362
1369
|
else {
|
|
1363
1370
|
if (formControl) {
|
|
1364
|
-
|
|
1365
|
-
formControl.setState(value);
|
|
1371
|
+
setFormState(value);
|
|
1366
1372
|
}
|
|
1367
1373
|
setValue(description);
|
|
1368
1374
|
}
|
|
@@ -1416,7 +1422,6 @@ function useAutocompleteField({ suggestions, disabled, formControl, onSelect, on
|
|
|
1416
1422
|
return {
|
|
1417
1423
|
coincidences,
|
|
1418
1424
|
listControl,
|
|
1419
|
-
pattern,
|
|
1420
1425
|
onBlurInput,
|
|
1421
1426
|
onClickAction,
|
|
1422
1427
|
onClickBackdrop,
|
|
@@ -1425,6 +1430,7 @@ function useAutocompleteField({ suggestions, disabled, formControl, onSelect, on
|
|
|
1425
1430
|
onFocusInput,
|
|
1426
1431
|
onKeydownElement,
|
|
1427
1432
|
onKeydownInput,
|
|
1433
|
+
pattern,
|
|
1428
1434
|
setPattern
|
|
1429
1435
|
};
|
|
1430
1436
|
}
|
|
@@ -1888,22 +1894,33 @@ function RlsFormNavigation({ children, visible, rlsTheme }) {
|
|
|
1888
1894
|
|
|
1889
1895
|
function useSelectField({ suggestions, formControl, onSelect, onValue }) {
|
|
1890
1896
|
const listControl = useListControl({ suggestions, formControl });
|
|
1891
|
-
const { collection, inputRef, visible,
|
|
1897
|
+
const { collection, inputRef, visible, navigationElement, navigationInput, setFocused, setValue, setVisible } = listControl;
|
|
1892
1898
|
const [changeInternal, setChangeInternal] = react.useState(false);
|
|
1893
1899
|
react.useEffect(() => {
|
|
1894
|
-
changeInternal ? setChangeInternal(false) : resetState();
|
|
1900
|
+
changeInternal ? setChangeInternal(false) : resetState(formControl?.state);
|
|
1895
1901
|
}, [formControl?.state]);
|
|
1896
|
-
react.useEffect(() =>
|
|
1897
|
-
function
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1902
|
+
react.useEffect(() => resetCollection(collection, formControl?.state), [collection]);
|
|
1903
|
+
function setFormState(value) {
|
|
1904
|
+
setChangeInternal(true);
|
|
1905
|
+
formControl?.setState(value);
|
|
1906
|
+
}
|
|
1907
|
+
function resetCollection(collection, state) {
|
|
1908
|
+
if (state) {
|
|
1909
|
+
const element = collection.find(state);
|
|
1910
|
+
if (element) {
|
|
1911
|
+
setValue(element.description);
|
|
1912
|
+
}
|
|
1913
|
+
else {
|
|
1914
|
+
setValue('');
|
|
1915
|
+
setFormState(undefined);
|
|
1916
|
+
}
|
|
1906
1917
|
}
|
|
1918
|
+
else {
|
|
1919
|
+
setValue('');
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
function resetState(state) {
|
|
1923
|
+
setValue(state ? collection.find(state)?.description || '' : '');
|
|
1907
1924
|
}
|
|
1908
1925
|
function onFocusInput() {
|
|
1909
1926
|
setFocused(true);
|
|
@@ -1968,8 +1985,7 @@ function useSelectField({ suggestions, formControl, onSelect, onValue }) {
|
|
|
1968
1985
|
}
|
|
1969
1986
|
else {
|
|
1970
1987
|
if (formControl) {
|
|
1971
|
-
|
|
1972
|
-
formControl.setState(value);
|
|
1988
|
+
setFormState(value);
|
|
1973
1989
|
}
|
|
1974
1990
|
setValue(description);
|
|
1975
1991
|
}
|