@coreui/react 4.9.0-alpha.1 → 4.9.0-beta.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/accordion/index.d.ts +1 -1
- package/dist/hooks/index.d.ts +2 -1
- package/dist/hooks/useColorModes.d.ts +6 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +67 -200
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +68 -199
- package/dist/index.js.map +1 -1
- package/dist/props.d.ts +1 -1
- package/package.json +9 -9
- package/src/components/accordion/index.ts +1 -7
- package/src/components/form/CFormSelect.tsx +3 -1
- package/src/components/modal/CModal.tsx +2 -0
- package/src/components/popover/CPopover.tsx +0 -1
- package/src/components/popover/__tests__/__snapshots__/CPopover.spec.tsx.snap +2 -1
- package/src/components/progress/CProgress.tsx +1 -0
- package/src/components/sidebar/CSidebar.tsx +2 -2
- package/src/components/spinner/CSpinner.tsx +4 -2
- package/src/components/spinner/__tests__/__snapshots__/CSpinner.spec.tsx.snap +2 -2
- package/src/components/table/CTable.tsx +2 -1
- package/src/components/tooltip/CTooltip.tsx +0 -1
- package/src/components/tooltip/__tests__/CTooltip.spec.tsx +1 -1
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useColorModes.ts +55 -0
- package/src/hooks/useForkedRef.ts +1 -1
- package/src/index.ts +1 -0
- package/src/props.ts +4 -1
- package/src/utils/isRTL.ts +1 -1
- package/src/components/accordion/__tests__/__snapshots__/CAccordionCollapse.spec.tsx.snap +0 -11
package/dist/props.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export declare const colorPropType: PropTypes.Requireable<string>;
|
|
|
4
4
|
export declare const placementPropType: PropTypes.Requireable<Placements>;
|
|
5
5
|
export declare const shapePropType: PropTypes.Requireable<string>;
|
|
6
6
|
export declare const textColorsPropType: PropTypes.Requireable<string>;
|
|
7
|
-
export declare const triggerPropType: PropTypes.Requireable<Triggers
|
|
7
|
+
export declare const triggerPropType: PropTypes.Requireable<NonNullable<Triggers | NonNullable<Triggers>[] | null | undefined>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coreui/react",
|
|
3
|
-
"version": "4.9.0-
|
|
3
|
+
"version": "4.9.0-beta.0",
|
|
4
4
|
"description": "UI Components Library for React.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -37,13 +37,13 @@
|
|
|
37
37
|
"test:update": "jest --coverage --updateSnapshot"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@popperjs/core": "^2.11.
|
|
41
|
-
"@rollup/plugin-commonjs": "^
|
|
42
|
-
"@rollup/plugin-node-resolve": "^15.0
|
|
43
|
-
"@rollup/plugin-typescript": "^11.1.
|
|
40
|
+
"@popperjs/core": "^2.11.8",
|
|
41
|
+
"@rollup/plugin-commonjs": "^25.0.1",
|
|
42
|
+
"@rollup/plugin-node-resolve": "^15.1.0",
|
|
43
|
+
"@rollup/plugin-typescript": "^11.1.1",
|
|
44
44
|
"@testing-library/jest-dom": "^5.16.5",
|
|
45
45
|
"@testing-library/react": "^14.0.0",
|
|
46
|
-
"@types/react": "18.2.
|
|
46
|
+
"@types/react": "18.2.11",
|
|
47
47
|
"@types/react-dom": "^18.2.4",
|
|
48
48
|
"@types/react-transition-group": "^4.4.6",
|
|
49
49
|
"classnames": "^2.3.2",
|
|
@@ -54,13 +54,13 @@
|
|
|
54
54
|
"react-dom": "^18.2.0",
|
|
55
55
|
"react-popper": "^2.3.0",
|
|
56
56
|
"react-transition-group": "^4.4.5",
|
|
57
|
-
"rollup": "^3.
|
|
58
|
-
"tslib": "^2.5.
|
|
57
|
+
"rollup": "^3.25.0",
|
|
58
|
+
"tslib": "^2.5.3",
|
|
59
59
|
"ts-jest": "^29.1.0",
|
|
60
60
|
"typescript": "^4.9.5"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"@coreui/coreui": "4.3.0-
|
|
63
|
+
"@coreui/coreui": "4.3.0-beta.0",
|
|
64
64
|
"react": ">=17",
|
|
65
65
|
"react-dom": ">=17"
|
|
66
66
|
}
|
|
@@ -4,10 +4,4 @@ import { CAccordionButton } from './CAccordionButton'
|
|
|
4
4
|
import { CAccordionHeader } from './CAccordionHeader'
|
|
5
5
|
import { CAccordionItem } from './CAccordionItem'
|
|
6
6
|
|
|
7
|
-
export {
|
|
8
|
-
CAccordion,
|
|
9
|
-
CAccordionBody,
|
|
10
|
-
CAccordionButton,
|
|
11
|
-
CAccordionHeader,
|
|
12
|
-
CAccordionItem,
|
|
13
|
-
}
|
|
7
|
+
export { CAccordion, CAccordionBody, CAccordionButton, CAccordionHeader, CAccordionItem }
|
|
@@ -9,6 +9,7 @@ type Option = {
|
|
|
9
9
|
label?: string
|
|
10
10
|
value?: string
|
|
11
11
|
}
|
|
12
|
+
|
|
12
13
|
export interface CFormSelectProps
|
|
13
14
|
extends CFormControlWrapperProps,
|
|
14
15
|
Omit<InputHTMLAttributes<HTMLSelectElement>, 'size'> {
|
|
@@ -102,7 +103,8 @@ export const CFormSelect = forwardRef<HTMLSelectElement, CFormSelectProps>(
|
|
|
102
103
|
<option
|
|
103
104
|
{...(typeof option === 'object' &&
|
|
104
105
|
option.disabled && { disabled: option.disabled })}
|
|
105
|
-
{...(typeof option === 'object' &&
|
|
106
|
+
{...(typeof option === 'object' &&
|
|
107
|
+
option.value !== undefined && { value: option.value })}
|
|
106
108
|
key={index}
|
|
107
109
|
>
|
|
108
110
|
{typeof option === 'string' ? option : option.label}
|
|
@@ -142,6 +142,7 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
|
|
|
142
142
|
return setStaticBackdrop(true)
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
+
setVisible(false)
|
|
145
146
|
return onClose && onClose()
|
|
146
147
|
}
|
|
147
148
|
|
|
@@ -174,6 +175,7 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
|
|
|
174
175
|
document.body.style.removeProperty('padding-right')
|
|
175
176
|
}
|
|
176
177
|
}
|
|
178
|
+
|
|
177
179
|
return () => {
|
|
178
180
|
document.body.classList.remove('modal-open')
|
|
179
181
|
if (backdrop) {
|
|
@@ -51,7 +51,6 @@ export interface CPopoverProps extends Omit<HTMLAttributes<HTMLDivElement>, 'tit
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
const getPlacement = (placement: string, element: HTMLDivElement | null): Placement => {
|
|
54
|
-
console.log(element)
|
|
55
54
|
switch (placement) {
|
|
56
55
|
case 'right': {
|
|
57
56
|
return isRTL(element) ? 'left' : 'right'
|
|
@@ -11,10 +11,11 @@ exports[`CPopover customize 1`] = `
|
|
|
11
11
|
<div
|
|
12
12
|
class="popover bs-popover-end fade"
|
|
13
13
|
role="tooltip"
|
|
14
|
-
style="position: absolute; left: 0px; top: 0px;"
|
|
14
|
+
style="position: absolute; left: 0px; top: 0px; margin: 0px;"
|
|
15
15
|
>
|
|
16
16
|
<div
|
|
17
17
|
class="popover-arrow"
|
|
18
|
+
data-popper-arrow="true"
|
|
18
19
|
style="position: absolute;"
|
|
19
20
|
/>
|
|
20
21
|
<div
|
|
@@ -29,6 +29,7 @@ export interface CProgressProps
|
|
|
29
29
|
white?: boolean
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
// TODO: update markup and add '.progress-stacked' in v5
|
|
32
33
|
export const CProgress = forwardRef<HTMLDivElement, CProgressProps>(
|
|
33
34
|
({ children, className, height, thin, value = 0, white, ...rest }, ref) => {
|
|
34
35
|
return (
|
|
@@ -98,7 +98,7 @@ export const CSidebar = forwardRef<HTMLDivElement, CSidebarProps>(
|
|
|
98
98
|
sidebarRef.current && setMobile(isOnMobile(sidebarRef.current))
|
|
99
99
|
sidebarRef.current && setInViewport(isInViewport(sidebarRef.current))
|
|
100
100
|
|
|
101
|
-
window.addEventListener('resize',
|
|
101
|
+
window.addEventListener('resize', handleResize)
|
|
102
102
|
window.addEventListener('mouseup', handleClickOutside)
|
|
103
103
|
window.addEventListener('keyup', handleKeyup)
|
|
104
104
|
|
|
@@ -108,7 +108,7 @@ export const CSidebar = forwardRef<HTMLDivElement, CSidebarProps>(
|
|
|
108
108
|
})
|
|
109
109
|
|
|
110
110
|
return () => {
|
|
111
|
-
window.removeEventListener('resize',
|
|
111
|
+
window.removeEventListener('resize', handleResize)
|
|
112
112
|
window.removeEventListener('mouseup', handleClickOutside)
|
|
113
113
|
window.removeEventListener('keyup', handleKeyup)
|
|
114
114
|
|
|
@@ -51,8 +51,10 @@ export const CSpinner = forwardRef<HTMLDivElement | HTMLSpanElement, CSpinnerPro
|
|
|
51
51
|
<Component
|
|
52
52
|
className={classNames(
|
|
53
53
|
`spinner-${variant}`,
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
{
|
|
55
|
+
[`spinner-${variant}-${size}`]: size,
|
|
56
|
+
[`text-${color}`]: color,
|
|
57
|
+
},
|
|
56
58
|
className,
|
|
57
59
|
)}
|
|
58
60
|
role="status"
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
exports[`CSpinner customize 1`] = `
|
|
4
4
|
<div>
|
|
5
5
|
<h3
|
|
6
|
-
class="spinner-grow
|
|
6
|
+
class="spinner-grow spinner-grow-sm text-warning bazinga"
|
|
7
7
|
role="status"
|
|
8
8
|
>
|
|
9
9
|
<span
|
|
@@ -18,7 +18,7 @@ exports[`CSpinner customize 1`] = `
|
|
|
18
18
|
exports[`loads and displays CSpinner component 1`] = `
|
|
19
19
|
<div>
|
|
20
20
|
<div
|
|
21
|
-
class="spinner-border
|
|
21
|
+
class="spinner-border"
|
|
22
22
|
role="status"
|
|
23
23
|
>
|
|
24
24
|
<span
|
|
@@ -201,7 +201,8 @@ export const CTable = forwardRef<HTMLTableElement, CTableProps>(
|
|
|
201
201
|
<CTableRow {...(item._props && { ...item._props })} key={index}>
|
|
202
202
|
{columnNames &&
|
|
203
203
|
columnNames.map((colName: string, index: number) => {
|
|
204
|
-
|
|
204
|
+
// eslint-disable-next-line unicorn/no-negated-condition
|
|
205
|
+
return item[colName] !== undefined ? (
|
|
205
206
|
<CTableDataCell
|
|
206
207
|
{...(item._cellProps && {
|
|
207
208
|
...(item._cellProps['all'] && { ...item._cellProps['all'] }),
|
|
@@ -47,7 +47,6 @@ export interface CTooltipProps extends Omit<HTMLAttributes<HTMLDivElement>, 'con
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
const getPlacement = (placement: string, element: HTMLDivElement | null): Placement => {
|
|
50
|
-
console.log(element)
|
|
51
50
|
switch (placement) {
|
|
52
51
|
case 'right': {
|
|
53
52
|
return isRTL(element) ? 'left' : 'right'
|
package/src/hooks/index.ts
CHANGED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
interface UseColorModesOutput {
|
|
4
|
+
getColorMode: () => string
|
|
5
|
+
setColorMode: (mode: string) => void
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const getStoredTheme = (localStorageItemName: string) => localStorage.getItem(localStorageItemName)
|
|
9
|
+
const setStoredTheme = (localStorageItemName: string, colorMode: string) =>
|
|
10
|
+
localStorage.setItem(localStorageItemName, colorMode)
|
|
11
|
+
|
|
12
|
+
const getPreferredColorScheme = (localStorageItemName: string) => {
|
|
13
|
+
const storedTheme = getStoredTheme(localStorageItemName)
|
|
14
|
+
|
|
15
|
+
if (storedTheme) {
|
|
16
|
+
return storedTheme
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const setTheme = (colorMode: string) => {
|
|
23
|
+
document.documentElement.dataset.coreuiTheme =
|
|
24
|
+
colorMode === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
25
|
+
? 'dark'
|
|
26
|
+
: colorMode
|
|
27
|
+
|
|
28
|
+
const event = new Event('ColorSchemeChange')
|
|
29
|
+
document.documentElement.dispatchEvent(event)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const useColorModes = (
|
|
33
|
+
localStorageItemName = 'coreui-react-color-scheme',
|
|
34
|
+
): UseColorModesOutput => {
|
|
35
|
+
const [colorMode, setColorMode] = useState<string>(getPreferredColorScheme(localStorageItemName))
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
setStoredTheme(localStorageItemName, colorMode)
|
|
39
|
+
setTheme(colorMode)
|
|
40
|
+
}, [colorMode])
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
|
|
44
|
+
const storedTheme = getStoredTheme(localStorageItemName)
|
|
45
|
+
if (storedTheme !== 'light' && storedTheme !== 'dark') {
|
|
46
|
+
setTheme(colorMode)
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
}, [])
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
getColorMode: () => colorMode,
|
|
53
|
+
setColorMode: (mode: string) => setColorMode(mode),
|
|
54
|
+
}
|
|
55
|
+
}
|
package/src/index.ts
CHANGED
package/src/props.ts
CHANGED
|
@@ -57,4 +57,7 @@ export const textColorsPropType = PropTypes.oneOfType([
|
|
|
57
57
|
PropTypes.string,
|
|
58
58
|
])
|
|
59
59
|
|
|
60
|
-
export const triggerPropType = PropTypes.
|
|
60
|
+
export const triggerPropType = PropTypes.oneOfType([
|
|
61
|
+
PropTypes.arrayOf(PropTypes.oneOf<Triggers>(['hover', 'focus', 'click']).isRequired),
|
|
62
|
+
PropTypes.oneOf<Triggers>(['hover', 'focus', 'click']),
|
|
63
|
+
])
|
package/src/utils/isRTL.ts
CHANGED