@coreui/react-pro 4.9.0-next.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 (133) 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/utils.d.ts +0 -1
  7. package/dist/components/callout/CCallout.d.ts +1 -1
  8. package/dist/components/card/CCard.d.ts +1 -1
  9. package/dist/components/date-range-picker/CDateRangePicker.d.ts +1 -1
  10. package/dist/components/date-range-picker/utils.d.ts +1 -0
  11. package/dist/components/dropdown/CDropdown.d.ts +1 -1
  12. package/dist/components/dropdown/CDropdownToggle.d.ts +1 -1
  13. package/dist/components/form/CFormCheck.d.ts +1 -1
  14. package/dist/components/list-group/CListGroupItem.d.ts +4 -5
  15. package/dist/components/multi-select/CMultiSelect.d.ts +1 -13
  16. package/dist/components/multi-select/CMultiSelectNativeSelect.d.ts +1 -1
  17. package/dist/components/multi-select/CMultiSelectOptions.d.ts +1 -1
  18. package/dist/components/multi-select/CMultiSelectSelection.d.ts +1 -1
  19. package/dist/components/multi-select/types.d.ts +14 -0
  20. package/dist/components/multi-select/utils.d.ts +6 -0
  21. package/dist/components/navbar/CNavbar.d.ts +1 -1
  22. package/dist/components/picker/CPicker.d.ts +1 -1
  23. package/dist/components/placeholder/CPlaceholder.d.ts +1 -1
  24. package/dist/components/popover/CPopover.d.ts +1 -1
  25. package/dist/components/progress/CProgressBar.d.ts +1 -1
  26. package/dist/components/smart-table/CSmartTableHead.d.ts +1 -1
  27. package/dist/components/smart-table/CSmartTableInterface.d.ts +8 -0
  28. package/dist/components/smart-table/types.d.ts +1 -1
  29. package/dist/components/spinner/CSpinner.d.ts +1 -1
  30. package/dist/components/table/CTable.d.ts +2 -18
  31. package/dist/components/table/CTableBody.d.ts +1 -1
  32. package/dist/components/table/CTableDataCell.d.ts +1 -1
  33. package/dist/components/table/CTableFoot.d.ts +1 -1
  34. package/dist/components/table/CTableHead.d.ts +1 -1
  35. package/dist/components/table/CTableHeaderCell.d.ts +1 -1
  36. package/dist/components/table/CTableRow.d.ts +1 -1
  37. package/dist/components/table/types.d.ts +17 -0
  38. package/dist/components/table/utils.d.ts +5 -0
  39. package/dist/components/toast/CToast.d.ts +1 -1
  40. package/dist/components/toast/CToastClose.d.ts +1 -1
  41. package/dist/components/tooltip/CTooltip.d.ts +1 -1
  42. package/dist/components/virtual-scroller/CVirtualScroller.d.ts +0 -8
  43. package/dist/components/widgets/CWidgetStatsA.d.ts +1 -1
  44. package/dist/components/widgets/CWidgetStatsB.d.ts +1 -1
  45. package/dist/components/widgets/CWidgetStatsC.d.ts +1 -1
  46. package/dist/components/widgets/CWidgetStatsD.d.ts +1 -1
  47. package/dist/components/widgets/CWidgetStatsF.d.ts +1 -1
  48. package/dist/index.es.js +216 -225
  49. package/dist/index.es.js.map +1 -1
  50. package/dist/index.js +216 -225
  51. package/dist/index.js.map +1 -1
  52. package/dist/props.d.ts +8 -0
  53. package/dist/types.d.ts +7 -0
  54. package/dist/utils/index.d.ts +1 -3
  55. package/package.json +1 -1
  56. package/src/components/accordion/CAccordionBody.tsx +1 -0
  57. package/src/components/accordion/CAccordionCollapse.tsx +1 -0
  58. package/src/components/alert/CAlert.tsx +2 -1
  59. package/src/components/avatar/CAvatar.tsx +2 -8
  60. package/src/components/backdrop/CBackdrop.tsx +1 -1
  61. package/src/components/badge/CBadge.tsx +2 -10
  62. package/src/components/button/CButton.tsx +3 -1
  63. package/src/components/calendar/utils.ts +0 -46
  64. package/src/components/callout/CCallout.tsx +2 -1
  65. package/src/components/card/CCard.tsx +2 -1
  66. package/src/components/date-range-picker/CDateRangePicker.tsx +2 -2
  67. package/src/components/date-range-picker/utils.ts +49 -0
  68. package/src/components/dropdown/CDropdown.tsx +2 -1
  69. package/src/components/dropdown/CDropdownItem.tsx +1 -2
  70. package/src/components/dropdown/CDropdownMenu.tsx +2 -1
  71. package/src/components/dropdown/CDropdownToggle.tsx +5 -4
  72. package/src/components/form/CFormCheck.tsx +3 -3
  73. package/src/components/form/CFormControlValidation.tsx +0 -1
  74. package/src/components/form/CFormControlWrapper.tsx +0 -1
  75. package/src/components/form/CFormInput.tsx +8 -4
  76. package/src/components/form/CFormRange.tsx +1 -2
  77. package/src/components/form/CFormSelect.tsx +1 -2
  78. package/src/components/form/CFormTextarea.tsx +1 -2
  79. package/src/components/list-group/CListGroupItem.tsx +8 -8
  80. package/src/components/list-group/CListGroupItem.tsx~HEAD +3 -1
  81. package/src/components/modal/CModal.tsx +2 -2
  82. package/src/components/modal/CModalHeader.tsx +3 -2
  83. package/src/components/multi-select/CMultiSelect.tsx +15 -74
  84. package/src/components/multi-select/CMultiSelectNativeSelect.tsx +1 -1
  85. package/src/components/multi-select/CMultiSelectOptions.tsx +2 -2
  86. package/src/components/multi-select/CMultiSelectSelection.tsx +1 -1
  87. package/src/components/multi-select/types.ts +15 -0
  88. package/src/components/multi-select/utils.ts +92 -0
  89. package/src/components/nav/CNavItem.tsx +1 -0
  90. package/src/components/nav/CNavLink.tsx +3 -3
  91. package/src/components/navbar/CNavbar.tsx +2 -1
  92. package/src/components/offcanvas/COffcanvas.tsx +4 -3
  93. package/src/components/picker/CPicker.tsx +1 -1
  94. package/src/components/placeholder/CPlaceholder.tsx +2 -1
  95. package/src/components/popover/CPopover.tsx +2 -1
  96. package/src/components/progress/CProgress.tsx +1 -0
  97. package/src/components/progress/CProgressBar.tsx +2 -1
  98. package/src/components/sidebar/CSidebar.tsx +2 -1
  99. package/src/components/smart-table/CSmartTable.tsx +1 -1
  100. package/src/components/smart-table/CSmartTableBody.tsx +82 -81
  101. package/src/components/smart-table/CSmartTableHead.tsx +5 -2
  102. package/src/components/smart-table/CSmartTableInterface.tsx +8 -0
  103. package/src/components/smart-table/{utils.tsx → utils.ts} +1 -1
  104. package/src/components/spinner/CSpinner.tsx +2 -1
  105. package/src/components/table/CTable.tsx +25 -59
  106. package/src/components/table/CTableBody.tsx +2 -1
  107. package/src/components/table/CTableDataCell.tsx +2 -1
  108. package/src/components/table/CTableFoot.tsx +2 -1
  109. package/src/components/table/CTableHead.tsx +2 -1
  110. package/src/components/table/CTableHeaderCell.tsx +2 -1
  111. package/src/components/table/CTableRow.tsx +2 -1
  112. package/src/components/table/types.ts +20 -0
  113. package/src/components/table/utils.ts +29 -0
  114. package/src/components/tabs/CTabPane.tsx +1 -0
  115. package/src/components/time-picker/CTimePicker.tsx +2 -4
  116. package/src/components/toast/CToast.tsx +3 -3
  117. package/src/components/toast/CToastClose.tsx +2 -2
  118. package/src/components/toast/CToaster.tsx +2 -1
  119. package/src/components/tooltip/CTooltip.tsx +3 -2
  120. package/src/components/virtual-scroller/CVirtualScroller.tsx +31 -54
  121. package/src/components/widgets/CWidgetStatsA.tsx +3 -3
  122. package/src/components/widgets/CWidgetStatsB.tsx +4 -4
  123. package/src/components/widgets/CWidgetStatsC.tsx +4 -4
  124. package/src/components/widgets/CWidgetStatsD.tsx +4 -5
  125. package/src/components/widgets/CWidgetStatsE.tsx +1 -2
  126. package/src/components/widgets/CWidgetStatsF.tsx +3 -4
  127. package/src/{components/Types.tsx → props.ts} +1 -68
  128. package/src/types.ts +68 -0
  129. package/src/utils/index.ts +1 -3
  130. package/src/components/multi-select/CMultiSelectCleaner.tsx +0 -18
  131. package/src/utils/getNextSibling.ts +0 -18
  132. package/src/utils/getPreviousSibling.ts +0 -18
  133. package/src/components/smart-table/{types.tsx → types.ts} +1 -1
@@ -0,0 +1,8 @@
1
+ import PropTypes from 'prop-types';
2
+ import type { Placements, Triggers } from './types';
3
+ export declare const colorPropType: PropTypes.Requireable<string>;
4
+ export declare const gradientsPropType: PropTypes.Requireable<string>;
5
+ export declare const placementPropType: PropTypes.Requireable<Placements>;
6
+ export declare const shapePropType: PropTypes.Requireable<string>;
7
+ export declare const textColorsPropType: PropTypes.Requireable<string>;
8
+ export declare const triggerPropType: PropTypes.Requireable<Triggers>;
@@ -0,0 +1,7 @@
1
+ export type Breakpoints = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl';
2
+ export type Colors = 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'dark' | 'light' | string;
3
+ export type Gradients = 'primary-gradient' | 'secondary-gradient' | 'success-gradient' | 'danger-gradient' | 'warning-gradient' | 'info-gradient' | 'dark-gradient' | 'light-gradient';
4
+ export type Placements = 'auto' | 'auto-start' | 'auto-end' | 'top-end' | 'top' | 'top-start' | 'bottom-end' | 'bottom' | 'bottom-start' | 'right-start' | 'right' | 'right-end' | 'left-start' | 'left' | 'left-end' | undefined;
5
+ export type Shapes = 'rounded' | 'rounded-top' | 'rounded-end' | 'rounded-bottom' | 'rounded-start' | 'rounded-circle' | 'rounded-pill' | 'rounded-0' | 'rounded-1' | 'rounded-2' | 'rounded-3' | string;
6
+ export type TextColors = Colors | 'white' | 'muted' | 'high-emphasis' | 'medium-emphasis' | 'disabled' | 'high-emphasis-inverse' | 'medium-emphasis-inverse' | 'disabled-inverse' | string;
7
+ export type Triggers = 'hover' | 'focus' | 'click';
@@ -1,5 +1,3 @@
1
- import getNextSibling from './getNextSibling';
2
- import getPreviousSibling from './getPreviousSibling';
3
1
  import isInViewport from './isInViewport';
4
2
  import isObjectInArray from './isObjectInArray';
5
- export { getNextSibling, getPreviousSibling, isInViewport, isObjectInArray };
3
+ export { isInViewport, isObjectInArray };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coreui/react-pro",
3
- "version": "4.9.0-next.0",
3
+ "version": "4.9.0-next.1",
4
4
  "description": "UI Components Library for React.js",
5
5
  "keywords": [
6
6
  "react",
@@ -5,6 +5,7 @@ import classNames from 'classnames'
5
5
  import { CAccordionItemContext } from './CAccordionItem'
6
6
 
7
7
  import { CCollapse } from './../collapse/CCollapse'
8
+
8
9
  export interface CAccordionBodyProps extends HTMLAttributes<HTMLDivElement> {
9
10
  /**
10
11
  * A string of all className you want applied to the base component.
@@ -1,5 +1,6 @@
1
1
  import React, { forwardRef } from 'react'
2
2
  import PropTypes from 'prop-types'
3
+
3
4
  import { CCollapse, CCollapseProps } from '../collapse/CCollapse'
4
5
 
5
6
  export const CAccordionCollapse = forwardRef<HTMLDivElement, Omit<CCollapseProps, 'horizontal'>>(
@@ -3,10 +3,11 @@ import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
  import { Transition } from 'react-transition-group'
5
5
 
6
- import { Colors, colorPropType } from '../Types'
7
6
  import { CCloseButton } from '../close-button/CCloseButton'
8
7
 
9
8
  import { useForkedRef } from '../../hooks'
9
+ import { colorPropType } from '../../props'
10
+ import type { Colors } from '../../types'
10
11
 
11
12
  export interface CAlertProps extends HTMLAttributes<HTMLDivElement> {
12
13
  /**
@@ -2,14 +2,8 @@ import React, { forwardRef, HTMLAttributes } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import {
6
- Colors,
7
- Shapes,
8
- TextColors,
9
- colorPropType,
10
- shapePropType,
11
- textColorsPropType,
12
- } from '../Types'
5
+ import { colorPropType, shapePropType, textColorsPropType } from '../../props'
6
+ import type { Colors, Shapes, TextColors } from '../../types'
13
7
 
14
8
  export interface CAvatarProps extends HTMLAttributes<HTMLDivElement> {
15
9
  /**
@@ -1,7 +1,7 @@
1
1
  import React, { forwardRef, HTMLAttributes, useRef } from 'react'
2
- import { Transition } from 'react-transition-group'
3
2
  import PropTypes from 'prop-types'
4
3
  import classNames from 'classnames'
4
+ import { Transition } from 'react-transition-group'
5
5
 
6
6
  import { useForkedRef } from '../../hooks'
7
7
 
@@ -2,16 +2,8 @@ import React, { ElementType, forwardRef, HTMLAttributes } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import {
6
- Colors,
7
- Gradients,
8
- Shapes,
9
- TextColors,
10
- colorPropType,
11
- gradientsPropType,
12
- shapePropType,
13
- textColorsPropType,
14
- } from '../Types'
5
+ import { colorPropType, gradientsPropType, shapePropType, textColorsPropType } from '../../props'
6
+ import type { Colors, Gradients, Shapes, TextColors } from '../../types'
15
7
 
16
8
  export interface CBadgeProps extends HTMLAttributes<HTMLDivElement | HTMLSpanElement> {
17
9
  /**
@@ -2,9 +2,11 @@ import React, { ElementType, forwardRef } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import { Colors, Shapes, colorPropType } from '../Types'
6
5
  import { CLink, CLinkProps } from '../link/CLink'
7
6
 
7
+ import { colorPropType } from '../../props'
8
+ import type { Colors, Shapes } from '../../types'
9
+
8
10
  export interface CButtonProps extends Omit<CLinkProps, 'size'> {
9
11
  /**
10
12
  * Toggle the active state for the component.
@@ -15,52 +15,6 @@ export const getCurrentYear = () => new Date().getFullYear()
15
15
 
16
16
  export const getCurrentMonth = () => new Date().getMonth()
17
17
 
18
- export const getLocalDateFromString = (string: string, locale: string, time?: boolean) => {
19
- const date = new Date(2013, 11, 31, 17, 19, 22)
20
- let regex = time ? date.toLocaleString(locale) : date.toLocaleDateString(locale)
21
- regex = regex
22
- .replace('2013', '(?<year>[0-9]{2,4})')
23
- .replace('12', '(?<month>[0-9]{1,2})')
24
- .replace('31', '(?<day>[0-9]{1,2})')
25
-
26
- if (time) {
27
- regex = regex
28
- .replace('5', '(?<hour>[0-9]{1,2})')
29
- .replace('17', '(?<hour>[0-9]{1,2})')
30
- .replace('19', '(?<minute>[0-9]{1,2})')
31
- .replace('22', '(?<second>[0-9]{1,2})')
32
- .replace('PM', '(?<ampm>[A-Z]{2})')
33
- }
34
-
35
- const rgx = RegExp(`${regex}`)
36
- const partials = string.match(rgx)
37
-
38
- if (partials === null) return
39
-
40
- const newDate =
41
- partials.groups &&
42
- (time
43
- ? new Date(
44
- Number(partials.groups['year']),
45
- Number(partials.groups['month']) - 1,
46
- Number(partials.groups['day']),
47
- partials.groups['ampm']
48
- ? partials.groups['ampm'] === 'PM'
49
- ? Number(partials.groups['hour']) + 12
50
- : Number(partials.groups['hour'])
51
- : Number(partials.groups['hour']),
52
- Number(partials.groups['minute']),
53
- Number(partials.groups['second']),
54
- )
55
- : new Date(
56
- Number(partials.groups['year']),
57
- Number(partials.groups['month']) - 1,
58
- Number(partials.groups['day']),
59
- ))
60
-
61
- return newDate
62
- }
63
-
64
18
  export const getMonthName = (month: number, locale: string) => {
65
19
  const d = new Date()
66
20
  d.setDate(1)
@@ -2,7 +2,8 @@ import React, { forwardRef, HTMLAttributes } 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 { colorPropType } from '../../props'
6
+ import type { Colors } from '../../types'
6
7
 
7
8
  export interface CCalloutProps extends HTMLAttributes<HTMLDivElement> {
8
9
  /**
@@ -2,7 +2,8 @@ import React, { forwardRef, HTMLAttributes } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import { Colors, Gradients, colorPropType, gradientsPropType } from '../Types'
5
+ import { colorPropType, gradientsPropType } from '../../props'
6
+ import type { Colors, Gradients } from '../../types'
6
7
 
7
8
  export interface CCardProps extends HTMLAttributes<HTMLDivElement> {
8
9
  /**
@@ -12,9 +12,9 @@ import { CFormControlWrapper, CFormControlWrapperProps } from '../form/CFormCont
12
12
  import { CPicker, CPickerProps } from '../picker/CPicker'
13
13
  import { CTimePicker } from '../time-picker/CTimePicker'
14
14
 
15
- import { getLocalDateFromString } from '../calendar/utils'
15
+ import { getLocalDateFromString } from './utils'
16
16
 
17
- import { Colors } from '../Types'
17
+ import { Colors } from '../../types'
18
18
  export interface CDateRangePickerProps
19
19
  extends Omit<CFormControlWrapperProps, 'floatingLabel'>,
20
20
  Omit<CPickerProps, 'autoClose' | 'component' | 'dark' | 'placeholder' | 'variant'>,
@@ -0,0 +1,49 @@
1
+ export const getLocalDateFromString = (string: string, locale: string, time?: boolean) => {
2
+ if (!isNaN(Date.parse(string))) {
3
+ return new Date(Date.parse(string))
4
+ }
5
+
6
+ const date = new Date(2013, 11, 31, 17, 19, 22)
7
+ let regex = time ? date.toLocaleString(locale) : date.toLocaleDateString(locale)
8
+ regex = regex
9
+ .replace('2013', '(?<year>[0-9]{2,4})')
10
+ .replace('12', '(?<month>[0-9]{1,2})')
11
+ .replace('31', '(?<day>[0-9]{1,2})')
12
+
13
+ if (time) {
14
+ regex = regex
15
+ .replace('5', '(?<hour>[0-9]{1,2})')
16
+ .replace('17', '(?<hour>[0-9]{1,2})')
17
+ .replace('19', '(?<minute>[0-9]{1,2})')
18
+ .replace('22', '(?<second>[0-9]{1,2})')
19
+ .replace('PM', '(?<ampm>[A-Z]{2})')
20
+ }
21
+
22
+ const rgx = RegExp(`${regex}`)
23
+ const partials = string.match(rgx)
24
+
25
+ if (partials === null) return
26
+
27
+ const newDate =
28
+ partials.groups &&
29
+ (time
30
+ ? new Date(
31
+ Number(partials.groups['year']),
32
+ Number(partials.groups['month']) - 1,
33
+ Number(partials.groups['day']),
34
+ partials.groups['ampm']
35
+ ? partials.groups['ampm'] === 'PM'
36
+ ? Number(partials.groups['hour']) + 12
37
+ : Number(partials.groups['hour'])
38
+ : Number(partials.groups['hour']),
39
+ Number(partials.groups['minute']),
40
+ Number(partials.groups['second']),
41
+ )
42
+ : new Date(
43
+ Number(partials.groups['year']),
44
+ Number(partials.groups['month']) - 1,
45
+ Number(partials.groups['day']),
46
+ ))
47
+
48
+ return newDate
49
+ }
@@ -12,8 +12,9 @@ import PropTypes from 'prop-types'
12
12
  import classNames from 'classnames'
13
13
  import { Manager } from 'react-popper'
14
14
 
15
- import { Placements, placementPropType } from '../Types'
16
15
  import { useForkedRef } from '../../hooks'
16
+ import { placementPropType } from '../../props'
17
+ import type { Placements } from '../../types'
17
18
 
18
19
  export type Directions = 'start' | 'end'
19
20
 
@@ -2,8 +2,7 @@ import React, { ElementType, forwardRef } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import { CLinkProps } from '../link/CLink'
6
- import { CLink } from '../link/CLink'
5
+ import { CLink, CLinkProps } from '../link/CLink'
7
6
 
8
7
  export interface CDropdownItemProps extends CLinkProps {
9
8
  /**
@@ -3,9 +3,10 @@ import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
  import { Popper, PopperChildrenProps } from 'react-popper'
5
5
 
6
- import { Placements } from '../Types'
7
6
  import { Alignments, CDropdownContext } from './CDropdown'
8
7
 
8
+ import type { Placements } from '../../types'
9
+
9
10
  export interface CDropdownMenuProps
10
11
  extends HTMLAttributes<HTMLDivElement | HTMLUListElement>,
11
12
  Omit<
@@ -3,13 +3,14 @@ import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
  import { Reference } from 'react-popper'
5
5
 
6
- import { useForkedRef } from '../../hooks'
7
-
8
- import { Triggers, triggerPropType } from '../Types'
9
-
10
6
  import { CButton, CButtonProps } from '../button/CButton'
7
+
11
8
  import { CDropdownContext } from './CDropdown'
12
9
 
10
+ import { useForkedRef } from '../../hooks'
11
+ import { triggerPropType } from '../../props'
12
+ import type { Triggers } from '../../types'
13
+
13
14
  export interface CDropdownToggleProps extends Omit<CButtonProps, 'type'> {
14
15
  /**
15
16
  * Enables pseudo element caret on toggler.
@@ -2,12 +2,12 @@ import React, { forwardRef, InputHTMLAttributes, ReactNode, useEffect, useRef }
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import { useForkedRef } from '../../hooks'
6
- import { Colors, Shapes } from '../Types'
7
-
8
5
  import { CFormControlValidation, CFormControlValidationProps } from './CFormControlValidation'
9
6
  import { CFormLabel } from './CFormLabel'
10
7
 
8
+ import { useForkedRef } from '../../hooks'
9
+ import type { Colors, Shapes } from '../../types'
10
+
11
11
  export type ButtonObject = {
12
12
  /**
13
13
  * Sets the color context of the component to one of CoreUI’s themed colors.
@@ -1,5 +1,4 @@
1
1
  import React, { FC, ReactNode } from 'react'
2
-
3
2
  import PropTypes from 'prop-types'
4
3
 
5
4
  import { CFormFeedback } from './CFormFeedback'
@@ -1,5 +1,4 @@
1
1
  import React, { FC, ReactNode } from 'react'
2
-
3
2
  import PropTypes from 'prop-types'
4
3
 
5
4
  import { CFormControlValidation, CFormControlValidationProps } from './CFormControlValidation'
@@ -1,10 +1,14 @@
1
- import React, { ChangeEventHandler, forwardRef, InputHTMLAttributes, useState } from 'react'
2
-
3
- import classNames from 'classnames'
1
+ import React, {
2
+ ChangeEventHandler,
3
+ forwardRef,
4
+ InputHTMLAttributes,
5
+ useEffect,
6
+ useState,
7
+ } from 'react'
4
8
  import PropTypes from 'prop-types'
9
+ import classNames from 'classnames'
5
10
 
6
11
  import { CFormControlWrapper, CFormControlWrapperProps } from './CFormControlWrapper'
7
- import { useEffect } from 'react'
8
12
 
9
13
  export interface CFormInputProps
10
14
  extends CFormControlWrapperProps,
@@ -1,7 +1,6 @@
1
1
  import React, { ChangeEventHandler, forwardRef, InputHTMLAttributes, ReactNode } from 'react'
2
-
3
- import classNames from 'classnames'
4
2
  import PropTypes from 'prop-types'
3
+ import classNames from 'classnames'
5
4
 
6
5
  import { CFormLabel } from './CFormLabel'
7
6
  export interface CFormRangeProps extends InputHTMLAttributes<HTMLInputElement> {
@@ -1,7 +1,6 @@
1
1
  import React, { ChangeEventHandler, forwardRef, InputHTMLAttributes } from 'react'
2
-
3
- import classNames from 'classnames'
4
2
  import PropTypes from 'prop-types'
3
+ import classNames from 'classnames'
5
4
 
6
5
  import { CFormControlWrapper, CFormControlWrapperProps } from './CFormControlWrapper'
7
6
 
@@ -1,7 +1,6 @@
1
1
  import React, { ChangeEventHandler, forwardRef, TextareaHTMLAttributes } from 'react'
2
-
3
- import classNames from 'classnames'
4
2
  import PropTypes from 'prop-types'
3
+ import classNames from 'classnames'
5
4
 
6
5
  import { CFormControlWrapper, CFormControlWrapperProps } from './CFormControlWrapper'
7
6
 
@@ -1,12 +1,14 @@
1
- import React, { ElementType, HTMLAttributes, forwardRef } from 'react'
1
+ import React, { ElementType, AnchorHTMLAttributes, forwardRef } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import { Colors, colorPropType } from '../Types'
6
5
  import { CLink } from '../link/CLink'
7
6
 
7
+ import { colorPropType } from '../../props'
8
+ import type { Colors } from '../../types'
9
+
8
10
  export interface CListGroupItemProps
9
- extends HTMLAttributes<HTMLLIElement | HTMLAnchorElement | HTMLButtonElement | HTMLLinkElement> {
11
+ extends AnchorHTMLAttributes<HTMLLIElement | HTMLAnchorElement | HTMLButtonElement> {
10
12
  /**
11
13
  * Toggle the active state for the component.
12
14
  */
@@ -29,13 +31,12 @@ export interface CListGroupItemProps
29
31
  * Component used for the root node. Either a string to use a HTML element or a component.
30
32
  */
31
33
  component?: string | ElementType
32
- href?: string
33
34
  }
34
35
 
35
36
  export const CListGroupItem = forwardRef<
36
- HTMLLIElement | HTMLAnchorElement | HTMLButtonElement | HTMLLinkElement,
37
+ HTMLLIElement | HTMLAnchorElement | HTMLButtonElement,
37
38
  CListGroupItemProps
38
- >(({ children, active, className, disabled, href, color, component = 'li', ...rest }, ref) => {
39
+ >(({ children, active, className, disabled, color, component = 'li', ...rest }, ref) => {
39
40
  const _className = classNames(
40
41
  'list-group-item',
41
42
  {
@@ -52,9 +53,8 @@ export const CListGroupItem = forwardRef<
52
53
  rest = {
53
54
  ...((component === 'a' || component === 'button') && {
54
55
  active,
55
- component,
56
56
  disabled,
57
- href: href,
57
+ component,
58
58
  ref: ref,
59
59
  }),
60
60
  ...(active && { 'aria-current': true }),
@@ -2,9 +2,11 @@ import React, { ElementType, AnchorHTMLAttributes, forwardRef } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import classNames from 'classnames'
4
4
 
5
- import { Colors, colorPropType } from '../Types'
6
5
  import { CLink } from '../link/CLink'
7
6
 
7
+ import { colorPropType } from '../../props'
8
+ import type { Colors } from '../../types'
9
+
8
10
  export interface CListGroupItemProps
9
11
  extends AnchorHTMLAttributes<HTMLLIElement | HTMLAnchorElement | HTMLButtonElement> {
10
12
  /**
@@ -13,12 +13,12 @@ import PropTypes from 'prop-types'
13
13
  import classNames from 'classnames'
14
14
  import { Transition } from 'react-transition-group'
15
15
 
16
- import { useForkedRef } from '../../hooks'
17
-
18
16
  import { CBackdrop } from '../backdrop/CBackdrop'
19
17
  import { CModalContent } from './CModalContent'
20
18
  import { CModalDialog } from './CModalDialog'
21
19
 
20
+ import { useForkedRef } from '../../hooks'
21
+
22
22
  export interface CModalProps extends HTMLAttributes<HTMLDivElement> {
23
23
  /**
24
24
  * Align the modal in the center or top of the screen.
@@ -1,9 +1,10 @@
1
1
  import React, { forwardRef, HTMLAttributes, useContext } from 'react'
2
2
  import PropTypes from 'prop-types'
3
- import { CModalContext } from './CModal'
4
- import { CCloseButton } from '../close-button/CCloseButton'
5
3
  import classNames from 'classnames'
6
4
 
5
+ import { CCloseButton } from '../close-button/CCloseButton'
6
+ import { CModalContext } from './CModal'
7
+
7
8
  export interface CModalHeaderProps extends HTMLAttributes<HTMLDivElement> {
8
9
  /**
9
10
  * A string of all className you want applied to the base component.
@@ -16,11 +16,13 @@ import PropTypes from 'prop-types'
16
16
  import { CFormControlWrapper, CFormControlWrapperProps } from './../form/CFormControlWrapper'
17
17
  import { CPicker } from '../picker/CPicker'
18
18
 
19
- import { CMultiSelectCleaner } from './CMultiSelectCleaner'
20
19
  import { CMultiSelectNativeSelect } from './CMultiSelectNativeSelect'
21
20
  import { CMultiSelectOptions } from './CMultiSelectOptions'
22
21
  import { CMultiSelectSelection } from './CMultiSelectSelection'
23
22
 
23
+ import { filterOptionsList, flattenArray, selectOptions } from './utils'
24
+ import type { Option, SelectedOption } from './types'
25
+
24
26
  export interface CMultiSelectProps
25
27
  extends Omit<CFormControlWrapperProps, 'floatingClassName' | 'floatingLabel'>,
26
28
  Omit<HTMLAttributes<HTMLDivElement>, 'onChange'> {
@@ -113,29 +115,6 @@ export interface CMultiSelectProps
113
115
  visibleItems?: number
114
116
  }
115
117
 
116
- export interface Option {
117
- disabled?: boolean
118
- label?: string
119
- options?: Option[]
120
- selected?: boolean
121
- // TODO: change to label
122
- text?: string
123
- value?: number | string
124
- }
125
-
126
- export interface SelectedOption {
127
- disabled?: boolean
128
- text: string
129
- value: number | string
130
- }
131
-
132
- const flattenArray = (options: Option[]): Option[] =>
133
- options.reduce(
134
- (acc: Option[], val: Option) =>
135
- acc.concat(Array.isArray(val.options) ? flattenArray(val.options) : val),
136
- [],
137
- )
138
-
139
118
  export const CMultiSelect = forwardRef<HTMLDivElement, CMultiSelectProps>(
140
119
  (
141
120
  {
@@ -181,30 +160,6 @@ export const CMultiSelect = forwardRef<HTMLDivElement, CMultiSelectProps>(
181
160
  const [_visible, setVisible] = useState(visible)
182
161
  const [selected, setSelected] = useState<SelectedOption[]>([])
183
162
 
184
- const selectOptions = (options: Option[], deselected?: Option[]) => {
185
- let _selected = [...selected, ...options]
186
-
187
- if (deselected) {
188
- _selected = _selected.filter(
189
- (selectedOption) =>
190
- !deselected.some((deselectedOption) => deselectedOption.value === selectedOption.value),
191
- )
192
- }
193
-
194
- const deduplicated = _selected.reduce((unique: Option[], option) => {
195
- if (!unique.some((obj) => obj.value === option.value)) {
196
- unique.push({
197
- value: option.value,
198
- text: option.text,
199
- ...(option.disabled && { disabled: option.disabled }),
200
- })
201
- }
202
- return unique
203
- }, []) as SelectedOption[]
204
-
205
- setSelected(deduplicated)
206
- }
207
-
208
163
  useMemo(() => {
209
164
  setOptions(options)
210
165
  const _selected =
@@ -227,7 +182,7 @@ export const CMultiSelect = forwardRef<HTMLDivElement, CMultiSelectProps>(
227
182
  return
228
183
  })
229
184
 
230
- _selected && selectOptions(_selected, deselected)
185
+ _selected && setSelected(selectOptions(_selected, selected, deselected))
231
186
  }, [JSON.stringify(options)])
232
187
 
233
188
  useEffect(() => {
@@ -254,29 +209,6 @@ export const CMultiSelect = forwardRef<HTMLDivElement, CMultiSelectProps>(
254
209
  isInitialMount.current = false
255
210
  }, [])
256
211
 
257
- const filterOptionsList = (search: string, options: Option[]) => {
258
- return search.length
259
- ? options &&
260
- options.reduce((acc: Option[], val: Option) => {
261
- const options =
262
- val.options &&
263
- val.options.filter(
264
- (element) =>
265
- element.text && element.text.toLowerCase().includes(search.toLowerCase()),
266
- )
267
-
268
- if (
269
- (val.text && val.text.toLowerCase().includes(search.toLowerCase())) ||
270
- (options && options.length)
271
- ) {
272
- acc.push(Object.assign({}, val, options && options.length && { options }))
273
- }
274
-
275
- return acc
276
- }, [])
277
- : _options
278
- }
279
-
280
212
  const handleSearchChange = (event: FormEvent<HTMLInputElement>) => {
281
213
  const target = event.target as HTMLInputElement
282
214
  if (search !== 'external') {
@@ -315,7 +247,12 @@ export const CMultiSelect = forwardRef<HTMLDivElement, CMultiSelectProps>(
315
247
  }
316
248
 
317
249
  const handleSelectAll = () => {
318
- selectOptions(flattenArray(options).filter((option: Option) => !option.disabled))
250
+ setSelected(
251
+ selectOptions(
252
+ flattenArray(options).filter((option: Option) => !option.disabled),
253
+ selected,
254
+ ),
255
+ )
319
256
  }
320
257
 
321
258
  const handleDeselectAll = () => {
@@ -366,7 +303,11 @@ export const CMultiSelect = forwardRef<HTMLDivElement, CMultiSelectProps>(
366
303
  selectionTypeCounterText={selectionTypeCounterText}
367
304
  />
368
305
  {multiple && cleaner && selected.length > 0 && (
369
- <CMultiSelectCleaner onClick={() => handleDeselectAll()} />
306
+ <button
307
+ type="button"
308
+ className="form-multi-select-selection-cleaner"
309
+ onClick={() => handleDeselectAll()}
310
+ ></button>
370
311
  )}
371
312
  {search && (
372
313
  <input
@@ -1,7 +1,7 @@
1
1
  import React, { forwardRef, HTMLAttributes } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
 
4
- import { Option } from './CMultiSelect'
4
+ import type { Option } from './types'
5
5
 
6
6
  export interface CMultiSelectNativeSelectProps
7
7
  extends Omit<HTMLAttributes<HTMLSelectElement>, 'options'> {