@coreui/react-pro 4.11.2 → 4.12.0-alpha.0
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/date-range-picker/CDateRangePicker copy.d.ts +114 -0
- package/dist/components/date-range-picker/CDateRangePicker.d.ts +49 -1
- package/dist/components/multi-select/CMultiSelect.d.ts +34 -3
- package/dist/components/multi-select/CMultiSelectNativeSelect.d.ts +4 -5
- package/dist/components/multi-select/CMultiSelectOptions.d.ts +4 -2
- package/dist/components/multi-select/CMultiSelectSelection.d.ts +1 -0
- package/dist/components/multi-select/types.d.ts +7 -3
- package/dist/components/multi-select/utils.d.ts +5 -5
- package/dist/components/multi-select-new/CMultiSelect.d.ts +133 -0
- package/dist/components/multi-select-new/CMultiSelectNativeSelect.d.ts +7 -0
- package/dist/components/multi-select-new/CMultiSelectNew.d.ts +121 -0
- package/dist/components/multi-select-new/CMultiSelectOptions.d.ts +16 -0
- package/dist/components/multi-select-new/CMultiSelectSelection.d.ts +11 -0
- package/dist/components/multi-select-new/index.d.ts +2 -0
- package/dist/components/multi-select-new/types.d.ts +15 -0
- package/dist/components/multi-select-new/utils.d.ts +11 -0
- package/dist/components/picker/CPicker copy.d.ts +82 -0
- package/dist/components/picker/CPicker.d.ts +14 -56
- package/dist/components/picker copy/CPicker.d.ts +82 -0
- package/dist/components/popover/CPopover.d.ts +1 -1
- package/dist/components/time-picker/CTimePicker.d.ts +41 -1
- package/dist/components/tooltip/CTooltip.d.ts +3 -3
- package/dist/index.es.js +2200 -2074
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +2199 -2073
- package/dist/index.js.map +1 -1
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/isRTL.d.ts +2 -0
- package/package.json +7 -7
- package/src/components/calendar/__tests__/__snapshots__/CCalendar.spec.tsx.snap +601 -555
- package/src/components/date-picker/__tests__/__snapshots__/CDatePicker.spec.tsx.snap +599 -561
- package/src/components/date-range-picker/CDateRangePicker.tsx +198 -97
- package/src/components/date-range-picker/__tests__/__snapshots__/CDateRangePicker.spec.tsx.snap +1197 -1121
- package/src/components/dropdown/CDropdownMenu.tsx +5 -4
- package/src/components/dropdown/__tests__/__snapshots__/CDropdown.spec.tsx.snap +1 -1
- package/src/components/element-cover/CElementCover.tsx +1 -0
- package/src/components/multi-select/CMultiSelect.tsx +200 -79
- package/src/components/multi-select/CMultiSelectNativeSelect.tsx +34 -24
- package/src/components/multi-select/CMultiSelectOptions.tsx +25 -23
- package/src/components/multi-select/CMultiSelectSelection.tsx +36 -7
- package/src/components/multi-select/__tests__/CMultiSelect.spec.tsx +25 -14
- package/src/components/multi-select/__tests__/CMultiSelectNativeSelect.spec.tsx +1 -1
- package/src/components/multi-select/__tests__/CMultiSelectOptions.spec.tsx +4 -4
- package/src/components/multi-select/__tests__/CMultiSelectSelection.spec.tsx +0 -1
- package/src/components/multi-select/__tests__/__snapshots__/CMultiSelect.spec.tsx.snap +136 -30
- package/src/components/multi-select/__tests__/__snapshots__/CMultiSelectNativeSelect.spec.tsx.snap +2 -0
- package/src/components/multi-select/__tests__/__snapshots__/CMultiSelectOptions.spec.tsx.snap +3 -1
- package/src/components/multi-select/__tests__/__snapshots__/CMultiSelectSelection.spec.tsx.snap +2 -2
- package/src/components/multi-select/types.ts +9 -4
- package/src/components/multi-select/utils.ts +56 -39
- package/src/components/picker/CPicker.tsx +113 -138
- package/src/components/popover/CPopover.tsx +62 -26
- package/src/components/smart-table/CSmartTable.tsx +5 -1
- package/src/components/smart-table/__tests__/CSmartTable.spec.tsx +1 -1
- package/src/components/smart-table/__tests__/__snapshots__/CSmartTable.spec.tsx.snap +580 -0
- package/src/components/time-picker/CTimePicker.tsx +182 -82
- package/src/components/time-picker/__tests__/__snapshots__/CTimePicker.spec.tsx.snap +1078 -0
- package/src/components/tooltip/CTooltip.tsx +66 -31
- package/src/components/virtual-scroller/CVirtualScroller.tsx +0 -1
- package/src/utils/index.ts +2 -1
- package/src/utils/isRTL.ts +13 -0
- package/src/components/multi-select/__tests__/CMultiSelectCleaner.spec.tsx +0 -15
- package/src/components/multi-select/__tests__/CMultiSelectSearchInput.spec.tsx +0 -17
- package/src/components/multi-select/__tests__/CMultiSelectSelectAllButton.spec.tsx +0 -21
- package/src/components/multi-select/__tests__/__snapshots__/CMultiSelectCleaner.spec.tsx.snap +0 -19
- package/src/components/multi-select/__tests__/__snapshots__/CMultiSelectSearchInput.spec.tsx.snap +0 -20
- package/src/components/multi-select/__tests__/__snapshots__/CMultiSelectSelectAllButton.spec.tsx.snap +0 -24
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import React, { FC, HTMLAttributes, ReactNode,
|
|
1
|
+
import React, { FC, HTMLAttributes, ReactNode, useRef, useEffect, useState } from 'react'
|
|
2
2
|
import { createPortal } from 'react-dom'
|
|
3
|
-
import PropTypes from 'prop-types'
|
|
4
3
|
import classNames from 'classnames'
|
|
5
|
-
import
|
|
4
|
+
import PropTypes from 'prop-types'
|
|
6
5
|
import { Transition } from 'react-transition-group'
|
|
6
|
+
import { createPopper, Instance, Placement } from '@popperjs/core'
|
|
7
7
|
|
|
8
8
|
import { triggerPropType } from '../../props'
|
|
9
9
|
import type { Triggers } from '../../types'
|
|
10
|
+
import { isRTL } from '../../utils'
|
|
10
11
|
|
|
11
|
-
export interface CTooltipProps extends HTMLAttributes<HTMLDivElement> {
|
|
12
|
+
export interface CTooltipProps extends Omit<HTMLAttributes<HTMLDivElement>, 'content'> {
|
|
12
13
|
/**
|
|
13
14
|
* A string of all className you want applied to the component.
|
|
14
15
|
*/
|
|
@@ -18,7 +19,7 @@ export interface CTooltipProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
18
19
|
*/
|
|
19
20
|
content: ReactNode | string
|
|
20
21
|
/**
|
|
21
|
-
* Offset of the
|
|
22
|
+
* Offset of the tooltip relative to its target.
|
|
22
23
|
*/
|
|
23
24
|
offset?: [number, number]
|
|
24
25
|
/**
|
|
@@ -40,16 +41,31 @@ export interface CTooltipProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
40
41
|
*/
|
|
41
42
|
placement?: 'auto' | 'top' | 'right' | 'bottom' | 'left'
|
|
42
43
|
/**
|
|
43
|
-
* Toggle the visibility of
|
|
44
|
+
* Toggle the visibility of tooltip component.
|
|
44
45
|
*/
|
|
45
46
|
visible?: boolean
|
|
46
47
|
}
|
|
47
48
|
|
|
49
|
+
const getPlacement = (placement: string, element: HTMLDivElement | null): Placement => {
|
|
50
|
+
console.log(element)
|
|
51
|
+
switch (placement) {
|
|
52
|
+
case 'right': {
|
|
53
|
+
return isRTL(element) ? 'left' : 'right'
|
|
54
|
+
}
|
|
55
|
+
case 'left': {
|
|
56
|
+
return isRTL(element) ? 'right' : 'left'
|
|
57
|
+
}
|
|
58
|
+
default: {
|
|
59
|
+
return placement as Placement
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
48
64
|
export const CTooltip: FC<CTooltipProps> = ({
|
|
49
65
|
children,
|
|
50
66
|
className,
|
|
51
67
|
content,
|
|
52
|
-
offset = [0,
|
|
68
|
+
offset = [0, 6],
|
|
53
69
|
onHide,
|
|
54
70
|
onShow,
|
|
55
71
|
placement = 'top',
|
|
@@ -57,33 +73,53 @@ export const CTooltip: FC<CTooltipProps> = ({
|
|
|
57
73
|
visible,
|
|
58
74
|
...rest
|
|
59
75
|
}) => {
|
|
60
|
-
const tooltipRef = useRef()
|
|
76
|
+
const tooltipRef = useRef(null)
|
|
77
|
+
const togglerRef = useRef(null)
|
|
78
|
+
const popper = useRef<Instance>()
|
|
61
79
|
const [_visible, setVisible] = useState(visible)
|
|
62
80
|
|
|
63
|
-
const [referenceElement, setReferenceElement] = useState(null)
|
|
64
|
-
const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null)
|
|
65
|
-
const [arrowElement, setArrowElement] = useState<HTMLDivElement | null>(null)
|
|
66
|
-
const { styles, attributes } = usePopper(referenceElement, popperElement, {
|
|
67
|
-
modifiers: [
|
|
68
|
-
{ name: 'arrow', options: { element: arrowElement } },
|
|
69
|
-
{
|
|
70
|
-
name: 'offset',
|
|
71
|
-
options: {
|
|
72
|
-
offset: offset,
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
placement: placement,
|
|
77
|
-
})
|
|
78
|
-
|
|
79
81
|
useEffect(() => {
|
|
80
82
|
setVisible(visible)
|
|
81
83
|
}, [visible])
|
|
82
84
|
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (_visible) {
|
|
87
|
+
initPopper()
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return () => {
|
|
91
|
+
destroyPopper()
|
|
92
|
+
}
|
|
93
|
+
}, [_visible])
|
|
94
|
+
|
|
95
|
+
const initPopper = () => {
|
|
96
|
+
if (togglerRef.current && tooltipRef.current) {
|
|
97
|
+
popper.current = createPopper(togglerRef.current, tooltipRef.current, {
|
|
98
|
+
modifiers: [
|
|
99
|
+
{
|
|
100
|
+
name: 'offset',
|
|
101
|
+
options: {
|
|
102
|
+
offset: offset,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
placement: getPlacement(placement, togglerRef.current),
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const destroyPopper = () => {
|
|
112
|
+
if (popper.current) {
|
|
113
|
+
popper.current.destroy()
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
popper.current = undefined
|
|
117
|
+
}
|
|
118
|
+
|
|
83
119
|
return (
|
|
84
120
|
<>
|
|
85
121
|
{React.cloneElement(children as React.ReactElement<any>, {
|
|
86
|
-
ref:
|
|
122
|
+
ref: togglerRef,
|
|
87
123
|
...((trigger === 'click' || trigger.includes('click')) && {
|
|
88
124
|
onClick: () => setVisible(!_visible),
|
|
89
125
|
}),
|
|
@@ -101,7 +137,6 @@ export const CTooltip: FC<CTooltipProps> = ({
|
|
|
101
137
|
<Transition
|
|
102
138
|
in={_visible}
|
|
103
139
|
mountOnEnter
|
|
104
|
-
nodeRef={tooltipRef}
|
|
105
140
|
onEnter={onShow}
|
|
106
141
|
onExit={onHide}
|
|
107
142
|
timeout={{
|
|
@@ -114,20 +149,20 @@ export const CTooltip: FC<CTooltipProps> = ({
|
|
|
114
149
|
<div
|
|
115
150
|
className={classNames(
|
|
116
151
|
'tooltip',
|
|
117
|
-
`bs-
|
|
152
|
+
`bs-tooltip-${getPlacement(placement, togglerRef.current)
|
|
153
|
+
.replace('left', 'start')
|
|
154
|
+
.replace('right', 'end')}`,
|
|
118
155
|
'fade',
|
|
119
156
|
{
|
|
120
157
|
show: state === 'entered',
|
|
121
158
|
},
|
|
122
159
|
className,
|
|
123
160
|
)}
|
|
124
|
-
ref={
|
|
161
|
+
ref={tooltipRef}
|
|
125
162
|
role="tooltip"
|
|
126
|
-
style={styles.popper}
|
|
127
|
-
{...attributes.popper}
|
|
128
163
|
{...rest}
|
|
129
164
|
>
|
|
130
|
-
<div className="tooltip-arrow"
|
|
165
|
+
<div data-popper-arrow className="tooltip-arrow"></div>
|
|
131
166
|
<div className="tooltip-inner">{content}</div>
|
|
132
167
|
</div>
|
|
133
168
|
)}
|
package/src/utils/index.ts
CHANGED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import * as React from 'react'
|
|
2
|
-
import { render } from '@testing-library/react'
|
|
3
|
-
import '@testing-library/jest-dom/extend-expect'
|
|
4
|
-
import { CMultiSelectCleaner } from '../CMultiSelectCleaner'
|
|
5
|
-
|
|
6
|
-
test('loads and displays CMultiSelectCleaner component', async () => {
|
|
7
|
-
const { container } = render(<CMultiSelectCleaner />)
|
|
8
|
-
expect(container).toMatchSnapshot()
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
test('CMultiSelectCleaner customize', async () => {
|
|
12
|
-
const { container } = render(<CMultiSelectCleaner />)
|
|
13
|
-
expect(container).toMatchSnapshot()
|
|
14
|
-
expect(container.firstChild).toHaveClass('form-multi-select-selection-cleaner')
|
|
15
|
-
})
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import * as React from 'react'
|
|
2
|
-
import { render } from '@testing-library/react'
|
|
3
|
-
import '@testing-library/jest-dom/extend-expect'
|
|
4
|
-
import { CMultiSelectSearchInput } from '../CMultiSelectSearchInput'
|
|
5
|
-
|
|
6
|
-
test('loads and displays CMultiSelectSearchInput component', async () => {
|
|
7
|
-
const { container } = render(<CMultiSelectSearchInput />)
|
|
8
|
-
expect(container).toMatchSnapshot()
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
test('CMultiSelectSearchInput customize', async () => {
|
|
12
|
-
const { container } = render(<CMultiSelectSearchInput placeholder="some placeholder" />)
|
|
13
|
-
expect(container).toMatchSnapshot()
|
|
14
|
-
expect(container.firstChild).toHaveClass('form-multi-select-search')
|
|
15
|
-
expect(container.firstChild).toHaveAttribute('type', 'text')
|
|
16
|
-
expect(container.firstChild).toHaveAttribute('placeholder', 'some placeholder')
|
|
17
|
-
})
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import * as React from 'react'
|
|
2
|
-
import { render } from '@testing-library/react'
|
|
3
|
-
import '@testing-library/jest-dom/extend-expect'
|
|
4
|
-
import { CMultiSelectSelectAllButton } from '../CMultiSelectSelectAllButton'
|
|
5
|
-
|
|
6
|
-
test('loads and displays CMultiSelectSelectAllButton component', async () => {
|
|
7
|
-
const { container } = render(<CMultiSelectSelectAllButton>text</CMultiSelectSelectAllButton>)
|
|
8
|
-
expect(container).toMatchSnapshot()
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
test('CMultiSelectSelectAllButton customize', async () => {
|
|
12
|
-
const { container } = render(
|
|
13
|
-
<CMultiSelectSelectAllButton placeholder="some placeholder">
|
|
14
|
-
bazinga
|
|
15
|
-
</CMultiSelectSelectAllButton>,
|
|
16
|
-
)
|
|
17
|
-
expect(container).toMatchSnapshot()
|
|
18
|
-
expect(container.firstChild).toHaveClass('form-multi-select-all')
|
|
19
|
-
expect(container.firstChild).toHaveAttribute('type', 'button')
|
|
20
|
-
expect(container.firstChild).toHaveTextContent('bazinga')
|
|
21
|
-
})
|
package/src/components/multi-select/__tests__/__snapshots__/CMultiSelectCleaner.spec.tsx.snap
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`CMultiSelectCleaner customize 1`] = `
|
|
4
|
-
<div>
|
|
5
|
-
<button
|
|
6
|
-
class="form-multi-select-selection-cleaner"
|
|
7
|
-
type="button"
|
|
8
|
-
/>
|
|
9
|
-
</div>
|
|
10
|
-
`;
|
|
11
|
-
|
|
12
|
-
exports[`loads and displays CMultiSelectCleaner component 1`] = `
|
|
13
|
-
<div>
|
|
14
|
-
<button
|
|
15
|
-
class="form-multi-select-selection-cleaner"
|
|
16
|
-
type="button"
|
|
17
|
-
/>
|
|
18
|
-
</div>
|
|
19
|
-
`;
|
package/src/components/multi-select/__tests__/__snapshots__/CMultiSelectSearchInput.spec.tsx.snap
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`CMultiSelectSearchInput customize 1`] = `
|
|
4
|
-
<div>
|
|
5
|
-
<input
|
|
6
|
-
class="form-multi-select-search"
|
|
7
|
-
placeholder="some placeholder"
|
|
8
|
-
type="text"
|
|
9
|
-
/>
|
|
10
|
-
</div>
|
|
11
|
-
`;
|
|
12
|
-
|
|
13
|
-
exports[`loads and displays CMultiSelectSearchInput component 1`] = `
|
|
14
|
-
<div>
|
|
15
|
-
<input
|
|
16
|
-
class="form-multi-select-search"
|
|
17
|
-
type="text"
|
|
18
|
-
/>
|
|
19
|
-
</div>
|
|
20
|
-
`;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`CMultiSelectSelectAllButton customize 1`] = `
|
|
4
|
-
<div>
|
|
5
|
-
<button
|
|
6
|
-
class="form-multi-select-all"
|
|
7
|
-
placeholder="some placeholder"
|
|
8
|
-
type="button"
|
|
9
|
-
>
|
|
10
|
-
bazinga
|
|
11
|
-
</button>
|
|
12
|
-
</div>
|
|
13
|
-
`;
|
|
14
|
-
|
|
15
|
-
exports[`loads and displays CMultiSelectSelectAllButton component 1`] = `
|
|
16
|
-
<div>
|
|
17
|
-
<button
|
|
18
|
-
class="form-multi-select-all"
|
|
19
|
-
type="button"
|
|
20
|
-
>
|
|
21
|
-
text
|
|
22
|
-
</button>
|
|
23
|
-
</div>
|
|
24
|
-
`;
|