odaptos_design_system 2.0.71 → 2.0.72

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,4 +1,8 @@
1
1
  import React from 'react';
2
+ interface OptionType {
3
+ label: string;
4
+ value: string;
5
+ }
2
6
  interface MultiSelectProps {
3
7
  label: string;
4
8
  placeholder?: string;
@@ -12,7 +16,7 @@ interface MultiSelectProps {
12
16
  disabled?: boolean;
13
17
  required?: boolean;
14
18
  defaultValue: any[];
15
- options: any[];
19
+ options: OptionType[];
16
20
  error?: boolean;
17
21
  helperText?: string;
18
22
  errorText?: string;
@@ -22,9 +26,11 @@ interface MultiSelectProps {
22
26
  deleteOption: (value: any) => void;
23
27
  limitTags?: number;
24
28
  onBlur?: () => void;
29
+ loadMoreOptions?: () => Promise<OptionType[]>;
30
+ initialLoadCount?: number;
25
31
  }
26
32
  /**
27
33
  * Use this component for multiselection !!
28
34
  */
29
- export declare const MultiSelect: ({ options, label, placeholder, name, className, onChange, disabled, defaultValue, topLabel, topLabelWeight, topLabelSize, id, inputId, required, error, helperText, errorText, canAddNewOption, deleteOption, disableCloseOnSelect, limitTags, onBlur, ...props }: MultiSelectProps) => React.JSX.Element;
35
+ export declare const MultiSelect: ({ options: initialOptions, loadMoreOptions, initialLoadCount, label, placeholder, name, className, onChange, disabled, defaultValue, topLabel, topLabelWeight, topLabelSize, id, inputId, required, error, helperText, errorText, canAddNewOption, deleteOption, disableCloseOnSelect, limitTags, onBlur, ...props }: MultiSelectProps) => React.JSX.Element;
30
36
  export {};
@@ -1,4 +1,8 @@
1
1
  import React from 'react';
2
+ interface OptionType {
3
+ label: string;
4
+ value: string;
5
+ }
2
6
  interface SingleSelectProps {
3
7
  label: string;
4
8
  placeholder?: string;
@@ -16,12 +20,14 @@ interface SingleSelectProps {
16
20
  errorText?: string;
17
21
  canAddNewOption?: boolean;
18
22
  defaultValue: any;
19
- options: any[];
23
+ options: OptionType[];
20
24
  onChange: (value: any) => void;
21
25
  onBlur?: () => void;
26
+ loadMoreOptions?: () => Promise<OptionType[]>;
27
+ initialLoadCount?: number;
22
28
  }
23
29
  /**
24
30
  * Use this component for single selection !!
25
31
  */
26
- export declare const SingleSelect: ({ options, label, placeholder, name, className, onChange, disabled, defaultValue, topLabel, topLabelWeight, topLabelSize, id, inputId, required, error, helperText, errorText, canAddNewOption, onBlur, ...props }: SingleSelectProps) => React.JSX.Element;
32
+ export declare const SingleSelect: ({ options: initialOptions, loadMoreOptions, initialLoadCount, label, placeholder, name, className, onChange, disabled, defaultValue, topLabel, topLabelWeight, topLabelSize, id, inputId, required, error, helperText, errorText, canAddNewOption, onBlur, ...props }: SingleSelectProps) => React.JSX.Element;
27
33
  export {};
@@ -13340,11 +13340,21 @@ const CssTextField$1 = /*#__PURE__*/styles$15.styled(material.TextField)({
13340
13340
  }
13341
13341
  }
13342
13342
  });
13343
+ // Fonction utilitaire de debounce
13344
+ const debounce = (func, delay) => {
13345
+ let timeoutId;
13346
+ return (...args) => {
13347
+ clearTimeout(timeoutId);
13348
+ timeoutId = setTimeout(() => func(...args), delay);
13349
+ };
13350
+ };
13343
13351
  /**
13344
13352
  * Use this component for multiselection !!
13345
13353
  */
13346
13354
  const MultiSelect = ({
13347
- options,
13355
+ options: initialOptions,
13356
+ loadMoreOptions,
13357
+ initialLoadCount = 50,
13348
13358
  label,
13349
13359
  placeholder,
13350
13360
  name,
@@ -13368,8 +13378,28 @@ const MultiSelect = ({
13368
13378
  onBlur,
13369
13379
  ...props
13370
13380
  }) => {
13381
+ const [options, setOptions] = React.useState(initialOptions.slice(0, initialLoadCount));
13382
+ const [loading, setLoading] = React.useState(false);
13383
+ const [hasMore, setHasMore] = React.useState(initialOptions.length > initialLoadCount);
13371
13384
  const [value, setValue] = React.useState(defaultValue === undefined ? [] : defaultValue);
13372
13385
  const [inputValue, setInputValue] = React__default.useState('');
13386
+ const loadMore = React.useCallback(async () => {
13387
+ if (loading || !hasMore) return;
13388
+ setLoading(true);
13389
+ if (loadMoreOptions) {
13390
+ const newOptions = await loadMoreOptions();
13391
+ setOptions(prevOptions => [...prevOptions, ...newOptions]);
13392
+ setHasMore(newOptions.length > 0);
13393
+ } else {
13394
+ const currentLength = options.length;
13395
+ const nextOptions = initialOptions.slice(currentLength, currentLength + initialLoadCount);
13396
+ setOptions(prevOptions => [...prevOptions, ...nextOptions]);
13397
+ setHasMore(currentLength + nextOptions.length < initialOptions.length);
13398
+ }
13399
+ setLoading(false);
13400
+ }, [loading, hasMore, loadMoreOptions, initialOptions, options.length, initialLoadCount]);
13401
+ // Création d'une version debounced de loadMore
13402
+ const debouncedLoadMore = React.useRef(debounce(loadMore, 300)).current;
13373
13403
  React.useEffect(() => {
13374
13404
  setValue(defaultValue === undefined ? [] : defaultValue);
13375
13405
  }, [defaultValue]);
@@ -13397,11 +13427,7 @@ const MultiSelect = ({
13397
13427
  setValue(newValue);
13398
13428
  onChange(newValue);
13399
13429
  },
13400
- options: options ? options : [{
13401
- label: 'Loading...',
13402
- value: 0,
13403
- year: 100
13404
- }],
13430
+ options: options,
13405
13431
  multiple: true,
13406
13432
  autoComplete: options.length > 10,
13407
13433
  size: "small",
@@ -13447,6 +13473,12 @@ const MultiSelect = ({
13447
13473
  renderOption: (props, option, {
13448
13474
  selected
13449
13475
  }) => {
13476
+ if (option.value === 'load-more') {
13477
+ return /*#__PURE__*/React__default.createElement(material.ListSubheader, {
13478
+ key: "load-more",
13479
+ component: "div"
13480
+ }, loading ? 'Chargement...' : 'Charger plus');
13481
+ }
13450
13482
  return /*#__PURE__*/React__default.createElement("li", Object.assign({}, props, {
13451
13483
  id: option.value,
13452
13484
  key: `${props.id}`,
@@ -13484,6 +13516,14 @@ const MultiSelect = ({
13484
13516
  });
13485
13517
  }
13486
13518
  return filtered;
13519
+ },
13520
+ ListboxProps: {
13521
+ onScroll: event => {
13522
+ const listboxNode = event.currentTarget;
13523
+ if (listboxNode.scrollTop + listboxNode.clientHeight >= listboxNode.scrollHeight - 50) {
13524
+ debouncedLoadMore();
13525
+ }
13526
+ }
13487
13527
  }
13488
13528
  }, props)), errorText && /*#__PURE__*/React__default.createElement(Text, {
13489
13529
  size: "xs",
@@ -14996,6 +15036,14 @@ var css_248z$J = ".SingleSelect-modules_newAutocomplete__eqYQo{min-width:16rem;w
14996
15036
  var styles$J = {"newAutocomplete":"SingleSelect-modules_newAutocomplete__eqYQo","MuiAutocomplete-endAdornment":"SingleSelect-modules_MuiAutocomplete-endAdornment__8EaFU","tags-container":"SingleSelect-modules_tags-container__ohLVa","input_top_label":"SingleSelect-modules_input_top_label__duzAQ","MuiOutlinedInput-root":"SingleSelect-modules_MuiOutlinedInput-root__bpVWQ","MuiInputBase-root":"SingleSelect-modules_MuiInputBase-root__FVaHT","MuiInputBase-formControl":"SingleSelect-modules_MuiInputBase-formControl__lYoNJ","text_below":"SingleSelect-modules_text_below__6l3Mu","icon":"SingleSelect-modules_icon__-dAuA"};
14997
15037
  styleInject(css_248z$J);
14998
15038
 
15039
+ // Fonction utilitaire de debounce
15040
+ const debounce$1 = (func, delay) => {
15041
+ let timeoutId;
15042
+ return (...args) => {
15043
+ clearTimeout(timeoutId);
15044
+ timeoutId = setTimeout(() => func(...args), delay);
15045
+ };
15046
+ };
14999
15047
  const filter$2 = /*#__PURE__*/Autocomplete.createFilterOptions();
15000
15048
  const CssTextField$6 = /*#__PURE__*/styles$15.styled(material.TextField)({
15001
15049
  '& .MuiInputBase-input': {
@@ -15088,7 +15136,9 @@ const CssTextField$6 = /*#__PURE__*/styles$15.styled(material.TextField)({
15088
15136
  * Use this component for single selection !!
15089
15137
  */
15090
15138
  const SingleSelect = ({
15091
- options,
15139
+ options: initialOptions,
15140
+ loadMoreOptions,
15141
+ initialLoadCount = 50,
15092
15142
  label,
15093
15143
  placeholder,
15094
15144
  name,
@@ -15111,9 +15161,29 @@ const SingleSelect = ({
15111
15161
  }) => {
15112
15162
  const [value, setValue] = React.useState(defaultValue === undefined ? null : defaultValue);
15113
15163
  const [inputValue, setInputValue] = React__default.useState('');
15164
+ const [options, setOptions] = React.useState(initialOptions.slice(0, initialLoadCount));
15165
+ const [loading, setLoading] = React.useState(false);
15166
+ const [hasMore, setHasMore] = React.useState(initialOptions.length > initialLoadCount);
15114
15167
  React.useEffect(() => {
15115
15168
  setValue(defaultValue === undefined ? null : defaultValue);
15116
15169
  }, [defaultValue]);
15170
+ const loadMore = React.useCallback(async () => {
15171
+ if (loading || !hasMore) return;
15172
+ setLoading(true);
15173
+ if (loadMoreOptions) {
15174
+ const newOptions = await loadMoreOptions();
15175
+ setOptions(prevOptions => [...prevOptions, ...newOptions]);
15176
+ setHasMore(newOptions.length > 0);
15177
+ } else {
15178
+ const currentLength = options.length;
15179
+ const nextOptions = initialOptions.slice(currentLength, currentLength + initialLoadCount);
15180
+ setOptions(prevOptions => [...prevOptions, ...nextOptions]);
15181
+ setHasMore(currentLength + nextOptions.length < initialOptions.length);
15182
+ }
15183
+ setLoading(false);
15184
+ }, [loading, hasMore, loadMoreOptions, initialOptions, options.length, initialLoadCount]);
15185
+ // Création d'une version debounced de loadMore
15186
+ const debouncedLoadMore = React.useRef(debounce$1(loadMore, 300)).current;
15117
15187
  return /*#__PURE__*/React__default.createElement("div", {
15118
15188
  className: `${className && className}`,
15119
15189
  style: {
@@ -15175,6 +15245,12 @@ const SingleSelect = ({
15175
15245
  }),
15176
15246
  className: `${styles$J.newAutocomplete}`,
15177
15247
  renderOption: (props, option) => {
15248
+ if (option.value === 'load-more') {
15249
+ return /*#__PURE__*/React__default.createElement(material.ListSubheader, {
15250
+ key: "load-more",
15251
+ component: "div"
15252
+ }, loading ? 'Chargement...' : 'Charger plus');
15253
+ }
15178
15254
  return /*#__PURE__*/React__default.createElement("li", Object.assign({}, props, {
15179
15255
  key: option.value,
15180
15256
  id: option.value
@@ -15183,6 +15259,14 @@ const SingleSelect = ({
15183
15259
  size: "sm"
15184
15260
  }));
15185
15261
  },
15262
+ ListboxProps: {
15263
+ onScroll: event => {
15264
+ const listboxNode = event.currentTarget;
15265
+ if (listboxNode.scrollTop + listboxNode.clientHeight >= listboxNode.scrollHeight - 50) {
15266
+ debouncedLoadMore();
15267
+ }
15268
+ }
15269
+ },
15186
15270
  filterOptions: (options, params) => {
15187
15271
  const filtered = filter$2(options, params);
15188
15272
  const {