@coreui/react-pro 4.10.0 → 4.11.0-next.1

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,33 +1,50 @@
1
1
  import type { Option, SelectedOption } from './types'
2
2
 
3
- export const filterOptionsList = (search: string, _options: Option[]) => {
4
- return search.length > 0
3
+ export const createOption = (text: string, options: Option[]) => {
4
+ const value = text.toLowerCase().replace(/\s/g, '-')
5
+ let uniqueValue = value
6
+ let i = 1
7
+
8
+ while (options.find((option) => String(option.value) === uniqueValue)) {
9
+ uniqueValue = `${value}-${i}`
10
+ i++
11
+ }
12
+
13
+ return [
14
+ {
15
+ value: uniqueValue,
16
+ text,
17
+ custom: true,
18
+ },
19
+ ]
20
+ }
21
+
22
+ export const filterOptionsList = (search: string, _options: Option[]) =>
23
+ search.length > 0
5
24
  ? _options &&
6
- _options.reduce((acc: Option[], val: Option) => {
7
- const options =
8
- val.options &&
9
- val.options.filter(
10
- (element) =>
11
- element.text && element.text.toLowerCase().includes(search.toLowerCase()),
12
- )
13
-
14
- if (
15
- (val.text && val.text.toLowerCase().includes(search.toLowerCase())) ||
16
- (options && options.length > 0)
17
- ) {
18
- acc.push(Object.assign({}, val, options && options.length > 0 && { options }))
19
- }
20
-
21
- return acc
22
- }, [])
25
+ _options.reduce((acc: Option[], val: Option) => {
26
+ const options =
27
+ val.options &&
28
+ val.options.filter(
29
+ (element) => element.text && element.text.toLowerCase().includes(search.toLowerCase()),
30
+ )
31
+ if (
32
+ (val.text && val.text.toLowerCase().includes(search.toLowerCase())) ||
33
+ (options && options.length > 0)
34
+ ) {
35
+ acc.push(Object.assign({}, val, options && options.length > 0 && { options }))
36
+ }
37
+
38
+ return acc
39
+ }, [])
23
40
  : _options
24
- }
25
41
 
26
- export const flattenArray = (options: Option[]): Option[] => {
27
- return options.reduce((acc: Option[], val: Option) => {
28
- return acc.concat(Array.isArray(val.options) ? flattenArray(val.options) : val)
29
- }, [])
30
- }
42
+ export const flattenArray = (options: Option[]): Option[] =>
43
+ options.reduce(
44
+ (acc: Option[], val: Option) =>
45
+ acc.concat(Array.isArray(val.options) ? flattenArray(val.options) : val),
46
+ [],
47
+ )
31
48
 
32
49
  export const getNextSibling = (elem: HTMLElement, selector?: string) => {
33
50
  // Get the next sibling element
@@ -121,7 +121,7 @@ export interface CSmartTableProps extends HTMLAttributes<HTMLDivElement> {
121
121
  */
122
122
  itemsPerPageSelect?: boolean | ItemsPerPageSelect
123
123
  /**
124
- * When set, table will have loading style: loading spinner and reduced opacity. When 'small' prop is enabled spinner will be also smaller.
124
+ * When set, table will have loading style: loading spinner and reduced opacity.
125
125
  */
126
126
  loading?: boolean
127
127
  /**
@@ -43,17 +43,17 @@ export const CVirtualScroller = forwardRef<HTMLDivElement, CVirtualScrollerProps
43
43
  })
44
44
 
45
45
  useEffect(() => {
46
- setItemsNumber(itemsNumber || React.Children.count(children))
47
- }, [children, itemsNumber])
46
+ setItemsNumber(React.Children.count(children))
47
+ }, [children])
48
48
 
49
49
  useEffect(() => {
50
- setViewportHeight(visibleItems * itemHeight + 2 * viewportPadding)
51
- }, [viewportPadding, visibleItems, itemHeight])
50
+ setViewportHeight(Math.min(visibleItems, itemsNumber) * itemHeight + 2 * viewportPadding)
51
+ }, [itemHeight, itemsNumber, viewportPadding, visibleItems])
52
52
 
53
53
  useEffect(() => {
54
- setMaxHeight(itemsNumber * itemHeight + 2 * viewportPadding)
54
+ setMaxHeight(itemsNumber * itemHeight)
55
55
  virtualScrollRef.current && virtualScrollRef.current.scrollTop
56
- }, [itemsNumber, itemHeight])
56
+ }, [itemHeight, itemsNumber])
57
57
 
58
58
  useEffect(() => {
59
59
  setBuffer(Math.floor(visibleItems / 2))
@@ -73,7 +73,8 @@ export const CVirtualScroller = forwardRef<HTMLDivElement, CVirtualScrollerProps
73
73
  }
74
74
  ref={forkedRef}
75
75
  style={{
76
- height: maxHeight > viewportHeight ? viewportHeight : maxHeight,
76
+ // height: maxHeight > viewportHeight ? viewportHeight : maxHeight,
77
+ height: viewportHeight,
77
78
  overflowY: 'auto',
78
79
  }}
79
80
  >