@coreui/react-pro 4.8.0 → 4.9.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.
Files changed (166) hide show
  1. package/README.md +1 -1
  2. package/dist/components/alert/CAlert.d.ts +1 -1
  3. package/dist/components/avatar/CAvatar.d.ts +1 -1
  4. package/dist/components/badge/CBadge.d.ts +1 -1
  5. package/dist/components/button/CButton.d.ts +1 -1
  6. package/dist/components/calendar/index.d.ts +2 -0
  7. package/dist/components/calendar/utils.d.ts +22 -0
  8. package/dist/components/callout/CCallout.d.ts +1 -1
  9. package/dist/components/card/CCard.d.ts +1 -1
  10. package/dist/components/date-picker/CDatePicker.d.ts +1 -1
  11. package/dist/components/date-range-picker/CDateRangePicker.d.ts +3 -3
  12. package/dist/components/date-range-picker/utils.d.ts +1 -0
  13. package/dist/components/dropdown/CDropdown.d.ts +1 -1
  14. package/dist/components/dropdown/CDropdownToggle.d.ts +1 -1
  15. package/dist/components/element-cover/CElementCover.d.ts +0 -4
  16. package/dist/components/element-cover/index.d.ts +2 -0
  17. package/dist/components/form/CFormCheck.d.ts +1 -1
  18. package/dist/components/index.d.ts +1 -0
  19. package/dist/components/list-group/CListGroupItem.d.ts +4 -5
  20. package/dist/components/multi-select/CMultiSelect.d.ts +1 -13
  21. package/dist/components/multi-select/CMultiSelectNativeSelect.d.ts +1 -1
  22. package/dist/components/multi-select/CMultiSelectOptions.d.ts +1 -1
  23. package/dist/components/multi-select/CMultiSelectSelection.d.ts +1 -1
  24. package/dist/components/multi-select/types.d.ts +14 -0
  25. package/dist/components/multi-select/utils.d.ts +6 -0
  26. package/dist/components/navbar/CNavbar.d.ts +1 -1
  27. package/dist/components/offcanvas/COffcanvas.d.ts +7 -1
  28. package/dist/components/picker/CPicker.d.ts +1 -1
  29. package/dist/components/placeholder/CPlaceholder.d.ts +1 -1
  30. package/dist/components/popover/CPopover.d.ts +1 -1
  31. package/dist/components/progress/CProgressBar.d.ts +1 -1
  32. package/dist/components/smart-table/CSmartTableBody.d.ts +6 -5
  33. package/dist/components/smart-table/CSmartTableHead.d.ts +6 -3
  34. package/dist/components/smart-table/CSmartTableInterface.d.ts +38 -59
  35. package/dist/components/smart-table/types.d.ts +53 -0
  36. package/dist/components/smart-table/utils.d.ts +16 -0
  37. package/dist/components/spinner/CSpinner.d.ts +1 -1
  38. package/dist/components/table/CTable.d.ts +2 -18
  39. package/dist/components/table/CTableBody.d.ts +1 -1
  40. package/dist/components/table/CTableDataCell.d.ts +1 -1
  41. package/dist/components/table/CTableFoot.d.ts +1 -1
  42. package/dist/components/table/CTableHead.d.ts +1 -1
  43. package/dist/components/table/CTableHeaderCell.d.ts +1 -1
  44. package/dist/components/table/CTableRow.d.ts +1 -1
  45. package/dist/components/table/types.d.ts +17 -0
  46. package/dist/components/table/utils.d.ts +5 -0
  47. package/dist/components/time-picker/types.d.ts +15 -0
  48. package/dist/components/time-picker/utils.d.ts +23 -0
  49. package/dist/components/toast/CToast.d.ts +1 -1
  50. package/dist/components/toast/CToastClose.d.ts +1 -1
  51. package/dist/components/tooltip/CTooltip.d.ts +1 -1
  52. package/dist/components/virtual-scroller/CVirtualScroller.d.ts +0 -8
  53. package/dist/components/widgets/CWidgetStatsA.d.ts +1 -1
  54. package/dist/components/widgets/CWidgetStatsB.d.ts +1 -1
  55. package/dist/components/widgets/CWidgetStatsC.d.ts +1 -1
  56. package/dist/components/widgets/CWidgetStatsD.d.ts +1 -1
  57. package/dist/components/widgets/CWidgetStatsF.d.ts +1 -1
  58. package/dist/hooks/index.d.ts +3 -0
  59. package/dist/hooks/useForkedRef.d.ts +7 -0
  60. package/dist/hooks/useStateWithCallback.d.ts +2 -0
  61. package/dist/index.es.js +1171 -1109
  62. package/dist/index.es.js.map +1 -1
  63. package/dist/index.js +1171 -1108
  64. package/dist/index.js.map +1 -1
  65. package/dist/props.d.ts +8 -0
  66. package/dist/types.d.ts +7 -0
  67. package/dist/utils/index.d.ts +2 -3
  68. package/dist/utils/isObjectInArray.d.ts +2 -0
  69. package/package.json +11 -11
  70. package/src/components/accordion/CAccordionBody.tsx +1 -0
  71. package/src/components/accordion/CAccordionCollapse.tsx +1 -0
  72. package/src/components/alert/CAlert.tsx +3 -2
  73. package/src/components/avatar/CAvatar.tsx +2 -8
  74. package/src/components/backdrop/CBackdrop.tsx +2 -2
  75. package/src/components/badge/CBadge.tsx +2 -10
  76. package/src/components/button/CButton.tsx +3 -1
  77. package/src/components/calendar/CCalendar.tsx +351 -240
  78. package/src/components/calendar/index.ts +3 -0
  79. package/src/{utils/calendar.ts → components/calendar/utils.ts} +1 -47
  80. package/src/components/callout/CCallout.tsx +2 -1
  81. package/src/components/card/CCard.tsx +2 -1
  82. package/src/components/carousel/CCarousel.tsx +1 -1
  83. package/src/components/carousel/CCarouselItem.tsx +1 -1
  84. package/src/components/collapse/CCollapse.tsx +1 -1
  85. package/src/components/date-picker/CDatePicker.tsx +1 -1
  86. package/src/components/date-range-picker/CDateRangePicker.tsx +4 -4
  87. package/src/components/date-range-picker/utils.ts +49 -0
  88. package/src/components/dropdown/CDropdown.tsx +3 -2
  89. package/src/components/dropdown/CDropdownItem.tsx +1 -2
  90. package/src/components/dropdown/CDropdownMenu.tsx +2 -1
  91. package/src/components/dropdown/CDropdownToggle.tsx +5 -4
  92. package/src/components/element-cover/CElementCover.tsx +16 -22
  93. package/src/components/element-cover/index.ts +3 -0
  94. package/src/components/form/CFormCheck.tsx +3 -3
  95. package/src/components/form/CFormControlValidation.tsx +0 -1
  96. package/src/components/form/CFormControlWrapper.tsx +0 -1
  97. package/src/components/form/CFormInput.tsx +8 -4
  98. package/src/components/form/CFormRange.tsx +1 -2
  99. package/src/components/form/CFormSelect.tsx +1 -2
  100. package/src/components/form/CFormTextarea.tsx +1 -2
  101. package/src/components/index.ts +1 -0
  102. package/src/components/list-group/CListGroupItem.tsx +8 -8
  103. package/src/components/list-group/CListGroupItem.tsx~HEAD +3 -1
  104. package/src/components/modal/CModal.tsx +2 -2
  105. package/src/components/modal/CModalHeader.tsx +3 -2
  106. package/src/components/multi-select/CMultiSelect.tsx +15 -74
  107. package/src/components/multi-select/CMultiSelectNativeSelect.tsx +1 -1
  108. package/src/components/multi-select/CMultiSelectOptions.tsx +2 -2
  109. package/src/components/multi-select/CMultiSelectSelection.tsx +1 -1
  110. package/src/components/multi-select/types.ts +15 -0
  111. package/src/components/multi-select/utils.ts +92 -0
  112. package/src/components/nav/CNavItem.tsx +1 -0
  113. package/src/components/nav/CNavLink.tsx +4 -3
  114. package/src/components/navbar/CNavbar.tsx +2 -1
  115. package/src/components/offcanvas/COffcanvas.tsx +38 -19
  116. package/src/components/picker/CPicker.tsx +1 -1
  117. package/src/components/placeholder/CPlaceholder.tsx +2 -1
  118. package/src/components/popover/CPopover.tsx +2 -1
  119. package/src/components/progress/CProgress.tsx +1 -0
  120. package/src/components/progress/CProgressBar.tsx +2 -1
  121. package/src/components/sidebar/CSidebar.tsx +3 -2
  122. package/src/components/smart-table/CSmartTable.tsx +263 -257
  123. package/src/components/smart-table/CSmartTableBody.tsx +98 -107
  124. package/src/components/smart-table/CSmartTableCleaner.tsx +1 -1
  125. package/src/components/smart-table/CSmartTableFilter.tsx +1 -3
  126. package/src/components/smart-table/CSmartTableHead.tsx +56 -103
  127. package/src/components/smart-table/CSmartTableInterface.tsx +49 -71
  128. package/src/components/smart-table/CSmartTableItemsPerPageSelector.tsx +1 -2
  129. package/src/components/smart-table/types.ts +65 -0
  130. package/src/components/smart-table/utils.ts +199 -0
  131. package/src/components/spinner/CSpinner.tsx +2 -1
  132. package/src/components/table/CTable.tsx +25 -59
  133. package/src/components/table/CTableBody.tsx +2 -1
  134. package/src/components/table/CTableDataCell.tsx +2 -1
  135. package/src/components/table/CTableFoot.tsx +2 -1
  136. package/src/components/table/CTableHead.tsx +2 -1
  137. package/src/components/table/CTableHeaderCell.tsx +2 -1
  138. package/src/components/table/CTableRow.tsx +2 -1
  139. package/src/components/table/types.ts +20 -0
  140. package/src/components/table/utils.ts +29 -0
  141. package/src/components/tabs/CTabPane.tsx +2 -1
  142. package/src/components/time-picker/CTimePicker.tsx +48 -23
  143. package/src/components/time-picker/CTimePickerRollCol.tsx +1 -1
  144. package/src/components/time-picker/types.ts +15 -0
  145. package/src/{utils/time.ts → components/time-picker/utils.ts} +43 -2
  146. package/src/components/toast/CToast.tsx +4 -4
  147. package/src/components/toast/CToastClose.tsx +2 -2
  148. package/src/components/toast/CToaster.tsx +2 -1
  149. package/src/components/tooltip/CTooltip.tsx +3 -2
  150. package/src/components/virtual-scroller/CVirtualScroller.tsx +32 -55
  151. package/src/components/widgets/CWidgetStatsA.tsx +3 -3
  152. package/src/components/widgets/CWidgetStatsB.tsx +4 -4
  153. package/src/components/widgets/CWidgetStatsC.tsx +4 -4
  154. package/src/components/widgets/CWidgetStatsD.tsx +4 -5
  155. package/src/components/widgets/CWidgetStatsE.tsx +1 -2
  156. package/src/components/widgets/CWidgetStatsF.tsx +3 -4
  157. package/src/{components/Types.tsx → props.ts} +1 -68
  158. package/src/types.ts +68 -0
  159. package/src/utils/index.ts +2 -3
  160. package/src/utils/isObjectInArray.ts +14 -0
  161. package/src/components/multi-select/CMultiSelectCleaner.tsx +0 -18
  162. package/src/utils/getNextSibling.ts +0 -18
  163. package/src/utils/getPreviousSibling.ts +0 -18
  164. /package/src/{utils/hooks → hooks}/index.ts +0 -0
  165. /package/src/{utils/hooks → hooks}/useForkedRef.ts +0 -0
  166. /package/src/{utils/hooks → hooks}/useStateWithCallback.ts +0 -0
@@ -3,7 +3,8 @@ import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
  import { Transition } from 'react-transition-group'
5
5
 
6
- import { useForkedRef } from '../../utils/hooks'
6
+ import { useForkedRef } from '../../hooks'
7
+
7
8
  export interface CTabPaneProps extends HTMLAttributes<HTMLDivElement> {
8
9
  /**
9
10
  * A string of all className you want applied to the base component.
@@ -4,22 +4,21 @@ import classNames from 'classnames'
4
4
 
5
5
  import { CFormInput, CFormSelect, CInputGroup, CInputGroupText } from '../form'
6
6
  import { CFormControlWrapper, CFormControlWrapperProps } from '../form/CFormControlWrapper'
7
+ import { CPicker, CPickerProps } from './../picker/CPicker'
7
8
 
8
9
  import { CTimePickerRollCol } from './CTimePickerRollCol'
9
- import { CPicker, CPickerProps } from './../picker/CPicker'
10
10
  import {
11
11
  convert12hTo24h,
12
12
  convertTimeToDate,
13
13
  getAmPm,
14
- getListOfHours,
15
- getListOfMinutes,
16
- getListOfSeconds,
14
+ getLocalizedTimePartials,
17
15
  getSelectedHour,
18
16
  getSelectedMinutes,
19
17
  getSelectedSeconds,
20
- isAmPm,
21
18
  isValidTime,
22
- } from '../../utils/time'
19
+ } from './utils'
20
+
21
+ import type { LocalizedTimePartials } from './types'
23
22
 
24
23
  export interface CTimePickerProps
25
24
  extends Omit<CFormControlWrapperProps, 'floatingLabel'>,
@@ -121,15 +120,24 @@ export const CTimePicker = forwardRef<HTMLDivElement | HTMLLIElement, CTimePicke
121
120
  const [_ampm, setAmPm] = useState<'am' | 'pm'>(date ? getAmPm(new Date(date), locale) : 'am')
122
121
  const [_visible, setVisible] = useState(visible)
123
122
 
123
+ const [localizedTimePartials, setLocalizedTimePartials] = useState<LocalizedTimePartials>({
124
+ listOfHours: [],
125
+ listOfMinutes: [],
126
+ listOfSeconds: [],
127
+ hour12: false,
128
+ })
129
+
124
130
  useEffect(() => {
125
131
  setDate(convertTimeToDate(time))
126
132
  }, [time])
127
133
 
128
134
  useEffect(() => {
135
+ setLocalizedTimePartials(getLocalizedTimePartials(locale, ampm))
136
+
129
137
  if (inputRef.current) {
130
138
  inputRef.current.value = date
131
139
  ? date.toLocaleTimeString(locale, {
132
- hour12: (ampm === 'auto' && isAmPm(locale)) || (typeof ampm === 'boolean' && ampm),
140
+ hour12: localizedTimePartials && localizedTimePartials.hour12,
133
141
  ...(!seconds && { timeStyle: 'short' }),
134
142
  })
135
143
  : ''
@@ -157,7 +165,7 @@ export const CTimePicker = forwardRef<HTMLDivElement | HTMLLIElement, CTimePicke
157
165
  }
158
166
 
159
167
  if (set === 'hours') {
160
- if ((ampm === 'auto' && isAmPm(locale)) || ampm === true) {
168
+ if (localizedTimePartials && localizedTimePartials.hour12) {
161
169
  _date.setHours(convert12hTo24h(_ampm, parseInt(value)))
162
170
  } else {
163
171
  _date.setHours(parseInt(value))
@@ -224,12 +232,15 @@ export const CTimePicker = forwardRef<HTMLDivElement | HTMLLIElement, CTimePicke
224
232
  <span className="time-picker-inline-icon" />
225
233
  <CFormSelect
226
234
  disabled={disabled}
227
- options={getListOfHours(locale).map((option) => {
228
- return {
229
- value: option.value.toString(),
230
- label: option.label,
231
- }
232
- })}
235
+ options={
236
+ localizedTimePartials &&
237
+ localizedTimePartials.listOfHours?.map((option) => {
238
+ return {
239
+ value: option.value.toString(),
240
+ label: option.label,
241
+ }
242
+ })
243
+ }
233
244
  onChange={(event: React.ChangeEvent<HTMLSelectElement>) =>
234
245
  handleTimeChange('hours', event.target.value)
235
246
  }
@@ -238,8 +249,15 @@ export const CTimePicker = forwardRef<HTMLDivElement | HTMLLIElement, CTimePicke
238
249
  <>:</>
239
250
  <CFormSelect
240
251
  disabled={disabled}
241
- // @ts-expect-error the getListOfMinutes function returns corect type
242
- options={getListOfMinutes(locale, true)}
252
+ options={
253
+ localizedTimePartials &&
254
+ localizedTimePartials.listOfMinutes.map((option) => {
255
+ return {
256
+ value: option.value.toString(),
257
+ label: option.label,
258
+ }
259
+ })
260
+ }
243
261
  onChange={(event: React.ChangeEvent<HTMLSelectElement>) =>
244
262
  handleTimeChange('minutes', event.target.value)
245
263
  }
@@ -250,8 +268,15 @@ export const CTimePicker = forwardRef<HTMLDivElement | HTMLLIElement, CTimePicke
250
268
  <>:</>
251
269
  <CFormSelect
252
270
  disabled={disabled}
253
- // @ts-expect-error the getListOfSeconds function returns corect type
254
- options={getListOfSeconds(locale, true)}
271
+ options={
272
+ localizedTimePartials &&
273
+ localizedTimePartials.listOfSeconds.map((option) => {
274
+ return {
275
+ value: option.value.toString(),
276
+ label: option.label,
277
+ }
278
+ })
279
+ }
255
280
  onChange={(event: React.ChangeEvent<HTMLSelectElement>) =>
256
281
  handleTimeChange('seconds', event.target.value)
257
282
  }
@@ -259,7 +284,7 @@ export const CTimePicker = forwardRef<HTMLDivElement | HTMLLIElement, CTimePicke
259
284
  />
260
285
  </>
261
286
  )}
262
- {isAmPm(locale) && (
287
+ {localizedTimePartials && localizedTimePartials.hour12 && (
263
288
  <CFormSelect
264
289
  disabled={disabled}
265
290
  options={[
@@ -279,23 +304,23 @@ export const CTimePicker = forwardRef<HTMLDivElement | HTMLLIElement, CTimePicke
279
304
  const TimePickerRoll = () => (
280
305
  <>
281
306
  <CTimePickerRollCol
282
- elements={getListOfHours(locale, ampm)}
307
+ elements={localizedTimePartials && localizedTimePartials.listOfHours}
283
308
  onClick={(index: number) => handleTimeChange('hours', index.toString())}
284
309
  selected={getSelectedHour(date, locale, ampm)}
285
310
  />
286
311
  <CTimePickerRollCol
287
- elements={getListOfMinutes(locale)}
312
+ elements={localizedTimePartials && localizedTimePartials.listOfMinutes}
288
313
  onClick={(index: number) => handleTimeChange('minutes', index.toString())}
289
314
  selected={getSelectedMinutes(date)}
290
315
  />
291
316
  {seconds && (
292
317
  <CTimePickerRollCol
293
- elements={getListOfSeconds(locale)}
318
+ elements={localizedTimePartials && localizedTimePartials.listOfSeconds}
294
319
  onClick={(index: number) => handleTimeChange('seconds', index.toString())}
295
320
  selected={getSelectedSeconds(date)}
296
321
  />
297
322
  )}
298
- {((ampm === 'auto' && isAmPm(locale)) || ampm === true) && (
323
+ {localizedTimePartials && localizedTimePartials.hour12 && (
299
324
  <CTimePickerRollCol
300
325
  elements={[
301
326
  { value: 'am', label: 'AM' },
@@ -2,7 +2,7 @@ import React, { forwardRef, useEffect, useRef } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import { useForkedRef } from '../../utils/hooks'
5
+ import { useForkedRef } from '../../hooks'
6
6
 
7
7
  export interface Element {
8
8
  value: number | string
@@ -0,0 +1,15 @@
1
+ export type LocalizedTimePartials = {
2
+ listOfHours: {
3
+ value: number
4
+ label: string
5
+ }[]
6
+ listOfMinutes: {
7
+ value: number
8
+ label: string
9
+ }[]
10
+ listOfSeconds: {
11
+ value: number
12
+ label: string
13
+ }[]
14
+ hour12: boolean
15
+ }
@@ -1,3 +1,5 @@
1
+ import type { LocalizedTimePartials } from './types'
2
+
1
3
  export const convert12hTo24h = (abbr: 'am' | 'pm', hour: number) => {
2
4
  if (abbr === 'am' && hour === 12) {
3
5
  return 0
@@ -26,6 +28,7 @@ export const getAmPm = (date: Date, locale: string) => {
26
28
  return date.getHours() >= 12 ? 'pm' : 'am'
27
29
  }
28
30
 
31
+ // TODO: clean-up
29
32
  export const getListOfHours = (locale: string, ampm: 'auto' | boolean = 'auto') =>
30
33
  Array.from({ length: (ampm === 'auto' && isAmPm(locale)) || ampm === true ? 12 : 24 }, (_, i) => {
31
34
  return {
@@ -36,6 +39,7 @@ export const getListOfHours = (locale: string, ampm: 'auto' | boolean = 'auto')
36
39
  }
37
40
  })
38
41
 
42
+ // TODO: clean-up
39
43
  export const getListOfMinutes = (locale: string, valueAsString = false) =>
40
44
  Array.from({ length: 60 }, (_, i) => {
41
45
  const d = new Date()
@@ -47,10 +51,11 @@ export const getListOfMinutes = (locale: string, valueAsString = false) =>
47
51
  minute: '2-digit',
48
52
  second: '2-digit',
49
53
  })
50
- .split(/[^A-Za-z0-9]/)[0],
54
+ .split(/[^A-Za-z0-9\u06F0-\u06F90-9]/)[0],
51
55
  }
52
56
  })
53
57
 
58
+ // TODO: clean-up
54
59
  export const getListOfSeconds = (locale: string, valueAsString = false) =>
55
60
  Array.from({ length: 60 }, (_, i) => {
56
61
  const d = new Date()
@@ -62,10 +67,46 @@ export const getListOfSeconds = (locale: string, valueAsString = false) =>
62
67
  minute: '2-digit',
63
68
  second: '2-digit',
64
69
  })
65
- .split(/[^A-Za-z0-9]/)[1],
70
+ .split(/[^A-Za-z0-9\u06F0-\u06F90-9]/)[0],
71
+ }
72
+ })
73
+
74
+ export const getLocalizedTimePartials = (
75
+ locale: string,
76
+ ampm: 'auto' | boolean = 'auto',
77
+ ): LocalizedTimePartials => {
78
+ const date = new Date()
79
+ const hour12 = ['am', 'AM', 'pm', 'PM'].some((el) => date.toLocaleString(locale).includes(el))
80
+ const listOfHours = Array.from(
81
+ { length: (ampm === 'auto' && hour12) || ampm === true ? 12 : 24 },
82
+ (_, i) => {
83
+ return {
84
+ value: (ampm === 'auto' && hour12) || ampm === true ? i + 1 : i,
85
+ label: ((ampm === 'auto' && hour12) || ampm === true ? i + 1 : i).toLocaleString(locale),
86
+ }
87
+ },
88
+ )
89
+ const listOfMinutesSeconds = Array.from({ length: 60 }, (_, i) => {
90
+ date.setMinutes(i)
91
+ return {
92
+ value: i,
93
+ label: date
94
+ .toLocaleTimeString(locale, {
95
+ minute: '2-digit',
96
+ second: '2-digit',
97
+ })
98
+ .split(/[^A-Za-z0-9\u06F0-\u06F90-9]/)[0],
66
99
  }
67
100
  })
68
101
 
102
+ return {
103
+ listOfHours,
104
+ listOfMinutes: listOfMinutesSeconds,
105
+ listOfSeconds: listOfMinutesSeconds,
106
+ hour12,
107
+ }
108
+ }
109
+
69
110
  export const getSelectedHour = (
70
111
  date: Date | null,
71
112
  locale: string,
@@ -6,13 +6,13 @@ import React, {
6
6
  useRef,
7
7
  useState,
8
8
  } from 'react'
9
- import { Transition } from 'react-transition-group'
10
9
  import PropTypes from 'prop-types'
11
10
  import classNames from 'classnames'
11
+ import { Transition } from 'react-transition-group'
12
12
 
13
- import { Colors, colorPropType } from '../Types'
14
-
15
- import { useForkedRef } from '../../utils/hooks'
13
+ import { useForkedRef } from '../../hooks'
14
+ import { colorPropType } from '../../props'
15
+ import type { Colors } from '../../types'
16
16
 
17
17
  export interface CToastProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
18
18
  /**
@@ -1,9 +1,9 @@
1
1
  import React, { ElementType, forwardRef, useContext } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import { CToastContext } from './CToast'
4
- import { CCloseButton, CCloseButtonProps } from '../close-button/CCloseButton'
5
4
 
6
- import type { CButtonProps } from '../button/CButton'
5
+ import { CButtonProps } from '../button/CButton'
6
+ import { CCloseButton, CCloseButtonProps } from '../close-button/CCloseButton'
7
7
 
8
8
  type CombineButtonProps = CCloseButtonProps & CButtonProps
9
9
  export interface CToastCloseProps extends CombineButtonProps {
@@ -1,7 +1,8 @@
1
1
  import React, { forwardRef, HTMLAttributes, useEffect, useState, useRef, ReactElement } from 'react'
2
- import PropTypes from 'prop-types'
3
2
  import { createPortal } from 'react-dom'
3
+ import PropTypes from 'prop-types'
4
4
  import classNames from 'classnames'
5
+
5
6
  export interface CToasterProps extends HTMLAttributes<HTMLDivElement> {
6
7
  /**
7
8
  * A string of all className you want applied to the base component.
@@ -1,11 +1,12 @@
1
1
  import React, { FC, HTMLAttributes, ReactNode, useEffect, useRef, useState } from 'react'
2
2
  import { createPortal } from 'react-dom'
3
- import classNames from 'classnames'
4
3
  import PropTypes from 'prop-types'
4
+ import classNames from 'classnames'
5
5
  import { usePopper } from 'react-popper'
6
6
  import { Transition } from 'react-transition-group'
7
7
 
8
- import { Triggers, triggerPropType } from '../Types'
8
+ import { triggerPropType } from '../../props'
9
+ import type { Triggers } from '../../types'
9
10
 
10
11
  export interface CTooltipProps extends HTMLAttributes<HTMLDivElement> {
11
12
  /**
@@ -2,21 +2,13 @@ import React, { forwardRef, HTMLAttributes, UIEvent, useEffect, useRef, useState
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import { useForkedRef } from '../../utils/hooks'
5
+ import { useForkedRef } from '../../hooks'
6
6
 
7
7
  export interface CVirtualScrollerProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onScroll'> {
8
8
  /**
9
9
  * A string of all className you want applied to the base component.
10
10
  */
11
11
  className?: string
12
- /**
13
- * Single item height.
14
- */
15
- itemHeight?: number | 'auto'
16
- /**
17
- * Number of items.
18
- */
19
- itemsNumber?: number
20
12
  /**
21
13
  * Event fires when the component has been scrolled.
22
14
  */
@@ -28,23 +20,20 @@ export interface CVirtualScrollerProps extends Omit<HTMLAttributes<HTMLDivElemen
28
20
  }
29
21
 
30
22
  export const CVirtualScroller = forwardRef<HTMLDivElement, CVirtualScrollerProps>(
31
- ({ children, className, itemHeight = 'auto', visibleItems, itemsNumber, onScroll }, ref) => {
23
+ ({ children, className, visibleItems, onScroll }, ref) => {
32
24
  const virtualScrollRef = useRef<HTMLDivElement>(null)
33
25
  const virtualScrollContentRef = useRef<HTMLDivElement>(null)
34
26
  const forkedRef = useForkedRef(ref, virtualScrollRef)
35
27
 
36
- const [currentItemIndex, setCurrentItemIndex] = useState(0)
37
- const [_itemHeight, setItemHeight] = useState<number>(itemHeight === 'auto' ? 0 : itemHeight)
38
- const [_itemsNumber, setItemsNumber] = useState(itemsNumber || React.Children.count(children))
28
+ const [buffer, setBuffer] = useState(Math.floor(visibleItems / 2))
29
+ const [currentItemIndex, setCurrentItemIndex] = useState(1)
30
+ const [itemHeight, setItemHeight] = useState(0)
31
+ const [itemsNumber, setItemsNumber] = useState(React.Children.count(children))
39
32
  const [viewportPadding, setViewportPadding] = useState(0)
40
33
  const [viewportHeight, setViewportHeight] = useState(
41
- visibleItems * _itemHeight + 2 * viewportPadding,
34
+ visibleItems * itemHeight + 2 * viewportPadding,
42
35
  )
43
- const [maxHeight, setMaxHeight] = useState(_itemsNumber * _itemHeight + 2 * viewportPadding)
44
- const [topPadding, setTopPadding] = useState(0)
45
- const [bottomPadding, setBottomPadding] = useState(0)
46
-
47
- const [contentHeight, setContentHeight] = useState(0)
36
+ const [maxHeight, setMaxHeight] = useState(itemsNumber * itemHeight + 2 * viewportPadding)
48
37
 
49
38
  useEffect(() => {
50
39
  virtualScrollRef.current && virtualScrollRef.current.scrollTop
@@ -58,33 +47,20 @@ export const CVirtualScroller = forwardRef<HTMLDivElement, CVirtualScrollerProps
58
47
  }, [children, itemsNumber])
59
48
 
60
49
  useEffect(() => {
61
- setViewportHeight(visibleItems * _itemHeight + 2 * viewportPadding)
62
- }, [viewportPadding, visibleItems, _itemHeight])
50
+ setViewportHeight(visibleItems * itemHeight + 2 * viewportPadding)
51
+ }, [viewportPadding, visibleItems, itemHeight])
63
52
 
64
53
  useEffect(() => {
65
- setMaxHeight(_itemsNumber * _itemHeight + 2 * viewportPadding)
54
+ setMaxHeight(itemsNumber * itemHeight + 2 * viewportPadding)
66
55
  virtualScrollRef.current && virtualScrollRef.current.scrollTop
67
- setTopPadding(0)
68
- }, [_itemsNumber, _itemHeight])
56
+ }, [itemsNumber, itemHeight])
69
57
 
70
- const handleScroll = (scrollTop: number) => {
71
- const _currentItemIndex = Math.min(
72
- Math.max(
73
- 1 +
74
- Math.max(Math.floor(scrollTop / _itemHeight), 0) -
75
- Math.min(
76
- Math.floor(visibleItems / 2) - (Math.floor(visibleItems / 2) - currentItemIndex) - 1,
77
- Math.floor(visibleItems / 2),
78
- ),
79
- 1,
80
- ),
81
- _itemsNumber - visibleItems + 1,
82
- )
58
+ useEffect(() => {
59
+ setBuffer(Math.floor(visibleItems / 2))
60
+ }, [visibleItems])
83
61
 
84
- virtualScrollContentRef.current &&
85
- setContentHeight(virtualScrollContentRef.current.offsetHeight)
86
- setTopPadding(Math.max(_currentItemIndex * _itemHeight - _itemHeight, 0))
87
- setBottomPadding(Math.max(maxHeight - topPadding - contentHeight, 0))
62
+ const handleScroll = (scrollTop: number) => {
63
+ const _currentItemIndex = itemHeight && Math.max(Math.ceil(scrollTop / itemHeight), 1)
88
64
  setCurrentItemIndex(_currentItemIndex)
89
65
  onScroll && onScroll(_currentItemIndex)
90
66
  }
@@ -103,23 +79,31 @@ export const CVirtualScroller = forwardRef<HTMLDivElement, CVirtualScrollerProps
103
79
  overflowY: 'auto',
104
80
  }}
105
81
  >
106
- <div style={{ height: topPadding }} />
107
- <div className="virtual-scroller-content" ref={virtualScrollContentRef}>
82
+ <div
83
+ className="virtual-scroller-content"
84
+ style={{
85
+ height: maxHeight,
86
+ }}
87
+ ref={virtualScrollContentRef}
88
+ >
108
89
  {React.Children.map(children, (child, index) => {
109
- const _index = index + 1
110
90
  if (
111
91
  React.isValidElement(child) &&
112
- _index >= Math.max(currentItemIndex - Math.floor(visibleItems / 2), 0) &&
113
- _index <= currentItemIndex + visibleItems + Math.floor(visibleItems / 2)
92
+ index + 1 > Math.max(currentItemIndex - buffer, 0) &&
93
+ index + 1 <= currentItemIndex + visibleItems + buffer
114
94
  ) {
115
95
  return React.cloneElement(child as React.ReactElement<any>, {
116
96
  className: classNames(child.props.className, {
117
97
  'virtual-scroller-item-preload':
118
- _index > currentItemIndex + visibleItems || _index < currentItemIndex,
98
+ index + 1 > currentItemIndex + visibleItems || index + 1 < currentItemIndex,
119
99
  }),
120
100
  key: index,
101
+ style: {
102
+ ...(currentItemIndex > buffer && {
103
+ transform: `translateY(${(currentItemIndex - buffer) * itemHeight}px)`,
104
+ }),
105
+ },
121
106
  ref: (node: HTMLElement) =>
122
- itemHeight === 'auto' &&
123
107
  node &&
124
108
  node.offsetHeight &&
125
109
  setItemHeight(
@@ -132,19 +116,12 @@ export const CVirtualScroller = forwardRef<HTMLDivElement, CVirtualScrollerProps
132
116
  return
133
117
  })}
134
118
  </div>
135
- <div
136
- style={{
137
- height: bottomPadding,
138
- }}
139
- />
140
119
  </div>
141
120
  )
142
121
  },
143
122
  )
144
123
 
145
124
  CVirtualScroller.propTypes = {
146
- itemHeight: PropTypes.number,
147
- itemsNumber: PropTypes.number,
148
125
  onScroll: PropTypes.func,
149
126
  visibleItems: PropTypes.number.isRequired,
150
127
  }
@@ -2,10 +2,10 @@ import React, { forwardRef, HTMLAttributes, ReactNode } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import { Colors, colorPropType } from '../Types'
5
+ import { CCard, CCardBody } from '../card'
6
6
 
7
- import { CCard } from '../card/CCard'
8
- import { CCardBody } from '../card/CCardBody'
7
+ import { colorPropType } from '../../props'
8
+ import type { Colors } from '../../types'
9
9
 
10
10
  export interface CWidgetStatsAProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
11
11
  /**
@@ -1,12 +1,12 @@
1
1
  import React, { forwardRef, HTMLAttributes, ReactNode } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
 
4
- import { Colors, colorPropType } from '../Types'
5
-
6
- import { CCard } from '../card/CCard'
7
- import { CCardBody } from '../card/CCardBody'
4
+ import { CCard, CCardBody } from '../card'
8
5
  import { CProgress, CProgressProps } from '../progress/CProgress'
9
6
 
7
+ import { colorPropType } from '../../props'
8
+ import type { Colors } from '../../types'
9
+
10
10
  export interface CWidgetStatsBProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
11
11
  /**
12
12
  * A string of all className you want applied to the base component.
@@ -1,12 +1,12 @@
1
1
  import React, { forwardRef, HTMLAttributes, ReactNode } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
 
4
- import { Colors, colorPropType } from '../Types'
5
-
6
- import { CCard } from '../card/CCard'
7
- import { CCardBody } from '../card/CCardBody'
4
+ import { CCard, CCardBody } from '../card'
8
5
  import { CProgress, CProgressProps } from '../progress/CProgress'
9
6
 
7
+ import { colorPropType } from '../../props'
8
+ import type { Colors } from '../../types'
9
+
10
10
  export interface CWidgetStatsCProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
11
11
  /**
12
12
  * A string of all className you want applied to the base component.
@@ -2,13 +2,12 @@ import React, { forwardRef, HTMLAttributes, ReactNode } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import { Colors, colorPropType } from '../Types'
6
-
7
- import { CCard } from '../card/CCard'
8
- import { CCardBody } from '../card/CCardBody'
9
- import { CCardHeader } from '../card/CCardHeader'
5
+ import { CCard, CCardBody, CCardHeader } from '../card'
10
6
  import { CCol } from '../grid/CCol'
11
7
 
8
+ import { colorPropType } from '../../props'
9
+ import type { Colors } from '../../types'
10
+
12
11
  type Value = {
13
12
  title?: string | ReactNode
14
13
  value?: number | string | ReactNode
@@ -2,8 +2,7 @@ import React, { forwardRef, HTMLAttributes, ReactNode } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import { CCard } from '../card/CCard'
6
- import { CCardBody } from '../card/CCardBody'
5
+ import { CCard, CCardBody } from '../card'
7
6
 
8
7
  export interface CWidgetStatsEProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
9
8
  /**
@@ -2,11 +2,10 @@ import React, { forwardRef, HTMLAttributes, ReactNode } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import { Colors, colorPropType } from '../Types'
5
+ import { CCard, CCardBody, CCardFooter } from '../card'
6
6
 
7
- import { CCard } from '../card/CCard'
8
- import { CCardBody } from '../card/CCardBody'
9
- import { CCardFooter } from '../card/CCardFooter'
7
+ import { colorPropType } from '../../props'
8
+ import type { Colors } from '../../types'
10
9
 
11
10
  export interface CWidgetStatsFProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
12
11
  /**