@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.
- package/README.md +1 -1
- package/dist/components/alert/CAlert.d.ts +1 -1
- package/dist/components/avatar/CAvatar.d.ts +1 -1
- package/dist/components/badge/CBadge.d.ts +1 -1
- package/dist/components/button/CButton.d.ts +1 -1
- package/dist/components/calendar/index.d.ts +2 -0
- package/dist/components/calendar/utils.d.ts +22 -0
- package/dist/components/callout/CCallout.d.ts +1 -1
- package/dist/components/card/CCard.d.ts +1 -1
- package/dist/components/date-picker/CDatePicker.d.ts +1 -1
- package/dist/components/date-range-picker/CDateRangePicker.d.ts +3 -3
- package/dist/components/date-range-picker/utils.d.ts +1 -0
- package/dist/components/dropdown/CDropdown.d.ts +1 -1
- package/dist/components/dropdown/CDropdownToggle.d.ts +1 -1
- package/dist/components/element-cover/CElementCover.d.ts +0 -4
- package/dist/components/element-cover/index.d.ts +2 -0
- package/dist/components/form/CFormCheck.d.ts +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/list-group/CListGroupItem.d.ts +4 -5
- package/dist/components/multi-select/CMultiSelect.d.ts +1 -13
- package/dist/components/multi-select/CMultiSelectNativeSelect.d.ts +1 -1
- package/dist/components/multi-select/CMultiSelectOptions.d.ts +1 -1
- package/dist/components/multi-select/CMultiSelectSelection.d.ts +1 -1
- package/dist/components/multi-select/types.d.ts +14 -0
- package/dist/components/multi-select/utils.d.ts +6 -0
- package/dist/components/navbar/CNavbar.d.ts +1 -1
- package/dist/components/offcanvas/COffcanvas.d.ts +7 -1
- package/dist/components/picker/CPicker.d.ts +1 -1
- package/dist/components/placeholder/CPlaceholder.d.ts +1 -1
- package/dist/components/popover/CPopover.d.ts +1 -1
- package/dist/components/progress/CProgressBar.d.ts +1 -1
- package/dist/components/smart-table/CSmartTableBody.d.ts +6 -5
- package/dist/components/smart-table/CSmartTableHead.d.ts +6 -3
- package/dist/components/smart-table/CSmartTableInterface.d.ts +38 -59
- package/dist/components/smart-table/types.d.ts +53 -0
- package/dist/components/smart-table/utils.d.ts +16 -0
- package/dist/components/spinner/CSpinner.d.ts +1 -1
- package/dist/components/table/CTable.d.ts +2 -18
- package/dist/components/table/CTableBody.d.ts +1 -1
- package/dist/components/table/CTableDataCell.d.ts +1 -1
- package/dist/components/table/CTableFoot.d.ts +1 -1
- package/dist/components/table/CTableHead.d.ts +1 -1
- package/dist/components/table/CTableHeaderCell.d.ts +1 -1
- package/dist/components/table/CTableRow.d.ts +1 -1
- package/dist/components/table/types.d.ts +17 -0
- package/dist/components/table/utils.d.ts +5 -0
- package/dist/components/time-picker/types.d.ts +15 -0
- package/dist/components/time-picker/utils.d.ts +23 -0
- package/dist/components/toast/CToast.d.ts +1 -1
- package/dist/components/toast/CToastClose.d.ts +1 -1
- package/dist/components/tooltip/CTooltip.d.ts +1 -1
- package/dist/components/virtual-scroller/CVirtualScroller.d.ts +0 -8
- package/dist/components/widgets/CWidgetStatsA.d.ts +1 -1
- package/dist/components/widgets/CWidgetStatsB.d.ts +1 -1
- package/dist/components/widgets/CWidgetStatsC.d.ts +1 -1
- package/dist/components/widgets/CWidgetStatsD.d.ts +1 -1
- package/dist/components/widgets/CWidgetStatsF.d.ts +1 -1
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/useForkedRef.d.ts +7 -0
- package/dist/hooks/useStateWithCallback.d.ts +2 -0
- package/dist/index.es.js +1171 -1109
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +1171 -1108
- package/dist/index.js.map +1 -1
- package/dist/props.d.ts +8 -0
- package/dist/types.d.ts +7 -0
- package/dist/utils/index.d.ts +2 -3
- package/dist/utils/isObjectInArray.d.ts +2 -0
- package/package.json +11 -11
- package/src/components/accordion/CAccordionBody.tsx +1 -0
- package/src/components/accordion/CAccordionCollapse.tsx +1 -0
- package/src/components/alert/CAlert.tsx +3 -2
- package/src/components/avatar/CAvatar.tsx +2 -8
- package/src/components/backdrop/CBackdrop.tsx +2 -2
- package/src/components/badge/CBadge.tsx +2 -10
- package/src/components/button/CButton.tsx +3 -1
- package/src/components/calendar/CCalendar.tsx +351 -240
- package/src/components/calendar/index.ts +3 -0
- package/src/{utils/calendar.ts → components/calendar/utils.ts} +1 -47
- package/src/components/callout/CCallout.tsx +2 -1
- package/src/components/card/CCard.tsx +2 -1
- package/src/components/carousel/CCarousel.tsx +1 -1
- package/src/components/carousel/CCarouselItem.tsx +1 -1
- package/src/components/collapse/CCollapse.tsx +1 -1
- package/src/components/date-picker/CDatePicker.tsx +1 -1
- package/src/components/date-range-picker/CDateRangePicker.tsx +4 -4
- package/src/components/date-range-picker/utils.ts +49 -0
- package/src/components/dropdown/CDropdown.tsx +3 -2
- package/src/components/dropdown/CDropdownItem.tsx +1 -2
- package/src/components/dropdown/CDropdownMenu.tsx +2 -1
- package/src/components/dropdown/CDropdownToggle.tsx +5 -4
- package/src/components/element-cover/CElementCover.tsx +16 -22
- package/src/components/element-cover/index.ts +3 -0
- package/src/components/form/CFormCheck.tsx +3 -3
- package/src/components/form/CFormControlValidation.tsx +0 -1
- package/src/components/form/CFormControlWrapper.tsx +0 -1
- package/src/components/form/CFormInput.tsx +8 -4
- package/src/components/form/CFormRange.tsx +1 -2
- package/src/components/form/CFormSelect.tsx +1 -2
- package/src/components/form/CFormTextarea.tsx +1 -2
- package/src/components/index.ts +1 -0
- package/src/components/list-group/CListGroupItem.tsx +8 -8
- package/src/components/list-group/CListGroupItem.tsx~HEAD +3 -1
- package/src/components/modal/CModal.tsx +2 -2
- package/src/components/modal/CModalHeader.tsx +3 -2
- package/src/components/multi-select/CMultiSelect.tsx +15 -74
- package/src/components/multi-select/CMultiSelectNativeSelect.tsx +1 -1
- package/src/components/multi-select/CMultiSelectOptions.tsx +2 -2
- package/src/components/multi-select/CMultiSelectSelection.tsx +1 -1
- package/src/components/multi-select/types.ts +15 -0
- package/src/components/multi-select/utils.ts +92 -0
- package/src/components/nav/CNavItem.tsx +1 -0
- package/src/components/nav/CNavLink.tsx +4 -3
- package/src/components/navbar/CNavbar.tsx +2 -1
- package/src/components/offcanvas/COffcanvas.tsx +38 -19
- package/src/components/picker/CPicker.tsx +1 -1
- package/src/components/placeholder/CPlaceholder.tsx +2 -1
- package/src/components/popover/CPopover.tsx +2 -1
- package/src/components/progress/CProgress.tsx +1 -0
- package/src/components/progress/CProgressBar.tsx +2 -1
- package/src/components/sidebar/CSidebar.tsx +3 -2
- package/src/components/smart-table/CSmartTable.tsx +263 -257
- package/src/components/smart-table/CSmartTableBody.tsx +98 -107
- package/src/components/smart-table/CSmartTableCleaner.tsx +1 -1
- package/src/components/smart-table/CSmartTableFilter.tsx +1 -3
- package/src/components/smart-table/CSmartTableHead.tsx +56 -103
- package/src/components/smart-table/CSmartTableInterface.tsx +49 -71
- package/src/components/smart-table/CSmartTableItemsPerPageSelector.tsx +1 -2
- package/src/components/smart-table/types.ts +65 -0
- package/src/components/smart-table/utils.ts +199 -0
- package/src/components/spinner/CSpinner.tsx +2 -1
- package/src/components/table/CTable.tsx +25 -59
- package/src/components/table/CTableBody.tsx +2 -1
- package/src/components/table/CTableDataCell.tsx +2 -1
- package/src/components/table/CTableFoot.tsx +2 -1
- package/src/components/table/CTableHead.tsx +2 -1
- package/src/components/table/CTableHeaderCell.tsx +2 -1
- package/src/components/table/CTableRow.tsx +2 -1
- package/src/components/table/types.ts +20 -0
- package/src/components/table/utils.ts +29 -0
- package/src/components/tabs/CTabPane.tsx +2 -1
- package/src/components/time-picker/CTimePicker.tsx +48 -23
- package/src/components/time-picker/CTimePickerRollCol.tsx +1 -1
- package/src/components/time-picker/types.ts +15 -0
- package/src/{utils/time.ts → components/time-picker/utils.ts} +43 -2
- package/src/components/toast/CToast.tsx +4 -4
- package/src/components/toast/CToastClose.tsx +2 -2
- package/src/components/toast/CToaster.tsx +2 -1
- package/src/components/tooltip/CTooltip.tsx +3 -2
- package/src/components/virtual-scroller/CVirtualScroller.tsx +32 -55
- package/src/components/widgets/CWidgetStatsA.tsx +3 -3
- package/src/components/widgets/CWidgetStatsB.tsx +4 -4
- package/src/components/widgets/CWidgetStatsC.tsx +4 -4
- package/src/components/widgets/CWidgetStatsD.tsx +4 -5
- package/src/components/widgets/CWidgetStatsE.tsx +1 -2
- package/src/components/widgets/CWidgetStatsF.tsx +3 -4
- package/src/{components/Types.tsx → props.ts} +1 -68
- package/src/types.ts +68 -0
- package/src/utils/index.ts +2 -3
- package/src/utils/isObjectInArray.ts +14 -0
- package/src/components/multi-select/CMultiSelectCleaner.tsx +0 -18
- package/src/utils/getNextSibling.ts +0 -18
- package/src/utils/getPreviousSibling.ts +0 -18
- /package/src/{utils/hooks → hooks}/index.ts +0 -0
- /package/src/{utils/hooks → hooks}/useForkedRef.ts +0 -0
- /package/src/{utils/hooks → hooks}/useStateWithCallback.ts +0 -0
|
@@ -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
|
-
|
|
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
|
-
<
|
|
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 './
|
|
4
|
+
import type { Option } from './types'
|
|
5
5
|
|
|
6
6
|
export interface CMultiSelectNativeSelectProps
|
|
7
7
|
extends Omit<HTMLAttributes<HTMLSelectElement>, 'options'> {
|
|
@@ -2,10 +2,10 @@ import React, { forwardRef, Fragment, HTMLAttributes, ReactNode } from 'react'
|
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import classNames from 'classnames'
|
|
4
4
|
|
|
5
|
-
import { Option } from './CMultiSelect'
|
|
6
5
|
import { CVirtualScroller } from './../virtual-scroller'
|
|
7
6
|
|
|
8
|
-
import { getNextSibling, getPreviousSibling } from '
|
|
7
|
+
import { getNextSibling, getPreviousSibling } from './utils'
|
|
8
|
+
import type { Option } from './types'
|
|
9
9
|
|
|
10
10
|
export interface CMultiSelectOptionsProps extends HTMLAttributes<HTMLDivElement> {
|
|
11
11
|
handleOptionOnClick?: (option: Option) => void
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { forwardRef, HTMLAttributes } from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
|
|
4
|
-
import type { SelectedOption } from './
|
|
4
|
+
import type { SelectedOption } from './types'
|
|
5
5
|
|
|
6
6
|
export interface CMultiSelectSelectionProps extends HTMLAttributes<HTMLSpanElement> {
|
|
7
7
|
multiple?: boolean
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type Option = {
|
|
2
|
+
disabled?: boolean
|
|
3
|
+
label?: string
|
|
4
|
+
options?: Option[]
|
|
5
|
+
order?: number
|
|
6
|
+
selected?: boolean
|
|
7
|
+
text: string
|
|
8
|
+
value: number | string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type SelectedOption = {
|
|
12
|
+
disabled?: boolean
|
|
13
|
+
text: string
|
|
14
|
+
value: number | string
|
|
15
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { Option, SelectedOption } from './types'
|
|
2
|
+
|
|
3
|
+
export const filterOptionsList = (search: string, _options: Option[]) => {
|
|
4
|
+
return search.length
|
|
5
|
+
? _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)
|
|
17
|
+
) {
|
|
18
|
+
acc.push(Object.assign({}, val, options && options.length && { options }))
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return acc
|
|
22
|
+
}, [])
|
|
23
|
+
: _options
|
|
24
|
+
}
|
|
25
|
+
|
|
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
|
+
}
|
|
31
|
+
|
|
32
|
+
export const getNextSibling = (elem: HTMLElement, selector?: string) => {
|
|
33
|
+
// Get the next sibling element
|
|
34
|
+
let sibling = elem.nextElementSibling
|
|
35
|
+
|
|
36
|
+
// If there's no selector, return the first sibling
|
|
37
|
+
if (!selector) return sibling
|
|
38
|
+
|
|
39
|
+
// If the sibling matches our selector, use it
|
|
40
|
+
// If not, jump to the next sibling and continue the loop
|
|
41
|
+
while (sibling) {
|
|
42
|
+
if (sibling.matches(selector)) return sibling
|
|
43
|
+
sibling = sibling.nextElementSibling
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const getPreviousSibling = (elem: HTMLElement, selector?: string) => {
|
|
50
|
+
// Get the next sibling element
|
|
51
|
+
let sibling = elem.previousElementSibling
|
|
52
|
+
|
|
53
|
+
// If there's no selector, return the first sibling
|
|
54
|
+
if (!selector) return sibling
|
|
55
|
+
|
|
56
|
+
// If the sibling matches our selector, use it
|
|
57
|
+
// If not, jump to the next sibling and continue the loop
|
|
58
|
+
while (sibling) {
|
|
59
|
+
if (sibling.matches(selector)) return sibling
|
|
60
|
+
sibling = sibling.previousElementSibling
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const selectOptions = (
|
|
67
|
+
options: Option[],
|
|
68
|
+
selected: SelectedOption[],
|
|
69
|
+
deselected?: Option[],
|
|
70
|
+
) => {
|
|
71
|
+
let _selected = [...selected, ...options]
|
|
72
|
+
|
|
73
|
+
if (deselected) {
|
|
74
|
+
_selected = _selected.filter(
|
|
75
|
+
(selectedOption) =>
|
|
76
|
+
!deselected.some((deselectedOption) => deselectedOption.value === selectedOption.value),
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const deduplicated = _selected.reduce((unique: Option[], option) => {
|
|
81
|
+
if (!unique.some((obj) => obj.value === option.value)) {
|
|
82
|
+
unique.push({
|
|
83
|
+
value: option.value,
|
|
84
|
+
text: option.text,
|
|
85
|
+
...(option.disabled && { disabled: option.disabled }),
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
return unique
|
|
89
|
+
}, []) as SelectedOption[]
|
|
90
|
+
|
|
91
|
+
return deduplicated
|
|
92
|
+
}
|
|
@@ -2,10 +2,11 @@ import React, { ElementType, forwardRef, useContext, useEffect, useRef } from 'r
|
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import classNames from 'classnames'
|
|
4
4
|
|
|
5
|
-
import { useForkedRef } from '../../utils/hooks'
|
|
6
|
-
|
|
7
|
-
import { CNavContext } from '../sidebar/CSidebarNav'
|
|
8
5
|
import { CLinkProps, CLink } from '../link/CLink'
|
|
6
|
+
import { CNavContext } from '../sidebar/CSidebarNav'
|
|
7
|
+
|
|
8
|
+
import { useForkedRef } from '../../hooks'
|
|
9
|
+
|
|
9
10
|
export interface CNavLinkProps extends Omit<CLinkProps, 'idx'> {
|
|
10
11
|
/**
|
|
11
12
|
* Toggle the active state for the component.
|
|
@@ -2,7 +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 {
|
|
5
|
+
import { colorPropType } from '../../props'
|
|
6
|
+
import type { Colors } from '../../types'
|
|
6
7
|
|
|
7
8
|
export interface CNavbarProps extends HTMLAttributes<HTMLDivElement> {
|
|
8
9
|
/**
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import PropTypes from 'prop-types'
|
|
2
1
|
import React, { forwardRef, HTMLAttributes, useCallback, useEffect, useRef, useState } from 'react'
|
|
3
2
|
import { createPortal } from 'react-dom'
|
|
4
|
-
import
|
|
3
|
+
import PropTypes from 'prop-types'
|
|
5
4
|
import classNames from 'classnames'
|
|
5
|
+
import { Transition } from 'react-transition-group'
|
|
6
6
|
|
|
7
|
-
import { useForkedRef } from '../../utils/hooks'
|
|
8
7
|
import { CBackdrop } from '../backdrop/CBackdrop'
|
|
9
8
|
|
|
9
|
+
import { useForkedRef } from '../../hooks'
|
|
10
|
+
|
|
10
11
|
export interface COffcanvasProps extends HTMLAttributes<HTMLDivElement> {
|
|
11
12
|
/**
|
|
12
13
|
* Apply a backdrop on body while offcanvas is open.
|
|
13
14
|
*/
|
|
14
|
-
backdrop?: boolean
|
|
15
|
+
backdrop?: boolean | 'static'
|
|
15
16
|
/**
|
|
16
17
|
* A string of all className you want applied to the base component.
|
|
17
18
|
*/
|
|
@@ -36,6 +37,12 @@ export interface COffcanvasProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
36
37
|
* Generates modal using createPortal.
|
|
37
38
|
*/
|
|
38
39
|
portal?: boolean
|
|
40
|
+
/**
|
|
41
|
+
* Responsive offcanvas property hide content outside the viewport from a specified breakpoint and down.
|
|
42
|
+
*
|
|
43
|
+
* @since 4.6.0
|
|
44
|
+
*/
|
|
45
|
+
responsive?: boolean | 'sm' | 'md' | 'lg' | 'xl' | 'xxl'
|
|
39
46
|
/**
|
|
40
47
|
* Allow body scrolling while offcanvas is open
|
|
41
48
|
*/
|
|
@@ -56,7 +63,8 @@ export const COffcanvas = forwardRef<HTMLDivElement, COffcanvasProps>(
|
|
|
56
63
|
onHide,
|
|
57
64
|
onShow,
|
|
58
65
|
placement,
|
|
59
|
-
portal =
|
|
66
|
+
portal = false,
|
|
67
|
+
responsive = true,
|
|
60
68
|
scroll = false,
|
|
61
69
|
visible = false,
|
|
62
70
|
...rest
|
|
@@ -86,26 +94,34 @@ export const COffcanvas = forwardRef<HTMLDivElement, COffcanvasProps>(
|
|
|
86
94
|
}
|
|
87
95
|
}, [_visible])
|
|
88
96
|
|
|
97
|
+
const getTransitionClass = (state: string) => {
|
|
98
|
+
return state === 'entering'
|
|
99
|
+
? 'showing'
|
|
100
|
+
: state === 'entered'
|
|
101
|
+
? 'show'
|
|
102
|
+
: state === 'exiting'
|
|
103
|
+
? 'show hiding'
|
|
104
|
+
: ''
|
|
105
|
+
}
|
|
106
|
+
|
|
89
107
|
const _className = classNames(
|
|
90
|
-
'offcanvas',
|
|
91
108
|
{
|
|
109
|
+
[`offcanvas${typeof responsive !== 'boolean' ? '-' + responsive : ''}`]: responsive,
|
|
92
110
|
[`offcanvas-${placement}`]: placement,
|
|
93
|
-
show: _visible,
|
|
94
111
|
},
|
|
95
112
|
className,
|
|
96
113
|
)
|
|
97
114
|
|
|
98
|
-
const transitionStyles = {
|
|
99
|
-
entering: { visibility: 'visible' },
|
|
100
|
-
entered: { visibility: 'visible' },
|
|
101
|
-
exiting: { visibility: 'visible' },
|
|
102
|
-
exited: { visibility: 'hidden' },
|
|
103
|
-
}
|
|
104
|
-
|
|
105
115
|
const handleDismiss = () => {
|
|
106
116
|
setVisible(false)
|
|
107
117
|
}
|
|
108
118
|
|
|
119
|
+
const handleBackdropDismiss = () => {
|
|
120
|
+
if (backdrop !== 'static') {
|
|
121
|
+
setVisible(false)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
109
125
|
const handleKeyDown = useCallback(
|
|
110
126
|
(event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
111
127
|
if (event.key === 'Escape' && keyboard) {
|
|
@@ -119,9 +135,8 @@ export const COffcanvas = forwardRef<HTMLDivElement, COffcanvasProps>(
|
|
|
119
135
|
return (
|
|
120
136
|
<>
|
|
121
137
|
<div
|
|
122
|
-
className={_className}
|
|
138
|
+
className={classNames(_className, getTransitionClass(state))}
|
|
123
139
|
role="dialog"
|
|
124
|
-
style={{ ...transitionStyles[state] }}
|
|
125
140
|
tabIndex={-1}
|
|
126
141
|
onKeyDown={handleKeyDown}
|
|
127
142
|
{...rest}
|
|
@@ -154,7 +169,7 @@ export const COffcanvas = forwardRef<HTMLDivElement, COffcanvasProps>(
|
|
|
154
169
|
createPortal(
|
|
155
170
|
<CBackdrop
|
|
156
171
|
className="offcanvas-backdrop"
|
|
157
|
-
onClick={
|
|
172
|
+
onClick={handleBackdropDismiss}
|
|
158
173
|
visible={_visible}
|
|
159
174
|
/>,
|
|
160
175
|
document.body,
|
|
@@ -162,7 +177,7 @@ export const COffcanvas = forwardRef<HTMLDivElement, COffcanvasProps>(
|
|
|
162
177
|
: backdrop && (
|
|
163
178
|
<CBackdrop
|
|
164
179
|
className="offcanvas-backdrop"
|
|
165
|
-
onClick={
|
|
180
|
+
onClick={handleBackdropDismiss}
|
|
166
181
|
visible={_visible}
|
|
167
182
|
/>
|
|
168
183
|
)}
|
|
@@ -172,7 +187,7 @@ export const COffcanvas = forwardRef<HTMLDivElement, COffcanvasProps>(
|
|
|
172
187
|
)
|
|
173
188
|
|
|
174
189
|
COffcanvas.propTypes = {
|
|
175
|
-
backdrop: PropTypes.bool,
|
|
190
|
+
backdrop: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf<'static'>(['static'])]),
|
|
176
191
|
children: PropTypes.node,
|
|
177
192
|
className: PropTypes.string,
|
|
178
193
|
keyboard: PropTypes.bool,
|
|
@@ -181,6 +196,10 @@ COffcanvas.propTypes = {
|
|
|
181
196
|
placement: PropTypes.oneOf<'start' | 'end' | 'top' | 'bottom'>(['start', 'end', 'top', 'bottom'])
|
|
182
197
|
.isRequired,
|
|
183
198
|
portal: PropTypes.bool,
|
|
199
|
+
responsive: PropTypes.oneOfType([
|
|
200
|
+
PropTypes.bool,
|
|
201
|
+
PropTypes.oneOf<'sm' | 'md' | 'lg' | 'xl' | 'xxl'>(['sm', 'md', 'lg', 'xl', 'xxl']),
|
|
202
|
+
]),
|
|
184
203
|
scroll: PropTypes.bool,
|
|
185
204
|
visible: PropTypes.bool,
|
|
186
205
|
}
|
|
@@ -7,7 +7,7 @@ import { CDropdown, CDropdownProps } from '../dropdown/CDropdown'
|
|
|
7
7
|
import { CDropdownMenu } from '../dropdown/CDropdownMenu'
|
|
8
8
|
import { CDropdownToggle } from '../dropdown/CDropdownToggle'
|
|
9
9
|
|
|
10
|
-
import { Colors } from '
|
|
10
|
+
import { Colors } from '../../types'
|
|
11
11
|
|
|
12
12
|
export interface CPickerProps extends Omit<CDropdownProps, 'variant'> {
|
|
13
13
|
/**
|
|
@@ -2,7 +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 {
|
|
5
|
+
import { colorPropType } from '../../props'
|
|
6
|
+
import type { Colors } from '../../types'
|
|
6
7
|
|
|
7
8
|
export interface CPlaceholderProps extends HTMLAttributes<HTMLSpanElement> {
|
|
8
9
|
/**
|
|
@@ -5,7 +5,8 @@ import classNames from 'classnames'
|
|
|
5
5
|
import { usePopper } from 'react-popper'
|
|
6
6
|
import { Transition } from 'react-transition-group'
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { triggerPropType } from '../../props'
|
|
9
|
+
import type { Triggers } from '../../types'
|
|
9
10
|
|
|
10
11
|
export interface CPopoverProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
|
|
11
12
|
/**
|
|
@@ -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 {
|
|
5
|
+
import { colorPropType, gradientsPropType } from '../../props'
|
|
6
|
+
import type { Colors, Gradients } from '../../types'
|
|
6
7
|
|
|
7
8
|
export interface CProgressBarProps extends HTMLAttributes<HTMLDivElement> {
|
|
8
9
|
/**
|
|
@@ -3,10 +3,11 @@ import { createPortal } from 'react-dom'
|
|
|
3
3
|
import PropTypes from 'prop-types'
|
|
4
4
|
import classNames from 'classnames'
|
|
5
5
|
|
|
6
|
-
import { isInViewport } from '../../utils'
|
|
7
|
-
import { useForkedRef } from '../../utils/hooks'
|
|
8
6
|
import { CBackdrop } from '../backdrop/CBackdrop'
|
|
9
7
|
|
|
8
|
+
import { isInViewport } from '../../utils'
|
|
9
|
+
import { useForkedRef } from '../../hooks'
|
|
10
|
+
|
|
10
11
|
export interface CSidebarProps extends HTMLAttributes<HTMLDivElement> {
|
|
11
12
|
/**
|
|
12
13
|
* A string of all className you want applied to the component.
|