@coreui/react 4.0.0-rc.5 → 4.0.2
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/LICENSE +21 -0
- package/README.md +157 -0
- package/dist/components/form/CFormCheck.d.ts +4 -0
- package/dist/components/form/CFormLabel.d.ts +2 -2
- package/dist/components/form/CFormSelect.d.ts +13 -0
- package/dist/index.es.js +18 -4
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +18 -4
- package/dist/index.js.map +1 -1
- package/package.json +31 -35
- package/src/components/form/CFormCheck.tsx +30 -3
- package/src/components/form/CFormLabel.tsx +2 -2
- package/src/components/form/CFormSelect.tsx +28 -2
- package/src/components/form/__tests__/CFormLabel.spec.tsx +8 -0
- package/src/components/form/__tests__/__snapshots__/CFormLabel.spec.tsx.snap +11 -0
- package/tsconfig.json +0 -25
package/package.json
CHANGED
|
@@ -1,65 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coreui/react",
|
|
3
|
+
"version": "4.0.2",
|
|
3
4
|
"description": "UI Components Library for React.js",
|
|
4
|
-
"
|
|
5
|
+
"keywords": [
|
|
6
|
+
"react",
|
|
7
|
+
"react-component",
|
|
8
|
+
"react component",
|
|
9
|
+
"react bootstrap",
|
|
10
|
+
"bootstrap react",
|
|
11
|
+
"ui library",
|
|
12
|
+
"ui components",
|
|
13
|
+
"component library",
|
|
14
|
+
"components"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://coreui.io/react/",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/coreui/coreui-react/issues"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/coreui/coreui-react.git"
|
|
23
|
+
},
|
|
5
24
|
"license": "MIT",
|
|
25
|
+
"author": "The CoreUI Team (https://github.com/orgs/coreui/people)",
|
|
6
26
|
"main": "dist/index.js",
|
|
7
27
|
"module": "dist/index.es.js",
|
|
8
28
|
"jsnext:main": "dist/index.es.js",
|
|
9
|
-
"
|
|
29
|
+
"types": "dist/index.d.ts",
|
|
10
30
|
"files": [
|
|
11
31
|
"dist/",
|
|
12
|
-
"src/
|
|
13
|
-
"src/utils/",
|
|
14
|
-
"src/index.ts",
|
|
15
|
-
"tsconfig.json",
|
|
16
|
-
"package.json"
|
|
32
|
+
"src/"
|
|
17
33
|
],
|
|
18
34
|
"scripts": {
|
|
19
|
-
"build": "rollup -c"
|
|
20
|
-
"lint": "eslint \"src/components/**/*.{js,ts,tsx}\"",
|
|
21
|
-
"test": "jest --coverage",
|
|
22
|
-
"test:update": "jest --coverage --updateSnapshot"
|
|
35
|
+
"build": "rollup -c"
|
|
23
36
|
},
|
|
24
37
|
"devDependencies": {
|
|
25
38
|
"@popperjs/core": "^2.10.2",
|
|
26
|
-
"@rollup/plugin-commonjs": "^21.0.
|
|
27
|
-
"@rollup/plugin-node-resolve": "^13.0.
|
|
39
|
+
"@rollup/plugin-commonjs": "^21.0.1",
|
|
40
|
+
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
28
41
|
"@rollup/plugin-typescript": "^8.3.0",
|
|
29
|
-
"@testing-library/jest-dom": "^5.
|
|
42
|
+
"@testing-library/jest-dom": "^5.15.0",
|
|
30
43
|
"@testing-library/react": "^12.1.2",
|
|
31
|
-
"@types/react": "^17.0.
|
|
32
|
-
"@types/react-dom": "^17.0.
|
|
33
|
-
"@types/react-transition-group": "^4.4.
|
|
34
|
-
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
35
|
-
"@typescript-eslint/parser": "^5.0.0",
|
|
44
|
+
"@types/react": "^17.0.34",
|
|
45
|
+
"@types/react-dom": "^17.0.11",
|
|
46
|
+
"@types/react-transition-group": "^4.4.4",
|
|
36
47
|
"classnames": "^2.3.1",
|
|
37
|
-
"eslint": "^7.32.0",
|
|
38
|
-
"eslint-config-prettier": "^8.3.0",
|
|
39
|
-
"eslint-plugin-prettier": "^4.0.0",
|
|
40
|
-
"eslint-plugin-react": "^7.26.1",
|
|
41
|
-
"eslint-plugin-react-hooks": "^4.2.0",
|
|
42
|
-
"jest": "^27.2.5",
|
|
43
|
-
"prettier": "^2.4.1",
|
|
44
48
|
"prop-types": "^15.7.2",
|
|
45
49
|
"react": "^17.0.2",
|
|
46
50
|
"react-dom": "^17.0.2",
|
|
47
51
|
"react-popper": "^2.2.5",
|
|
48
52
|
"react-transition-group": "^4.4.2",
|
|
49
|
-
"rollup": "^2.
|
|
53
|
+
"rollup": "^2.60.0",
|
|
50
54
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
51
|
-
"ts-jest": "^27.0.7",
|
|
52
55
|
"typescript": "^4.4.4"
|
|
53
56
|
},
|
|
54
57
|
"peerDependencies": {
|
|
55
58
|
"react": "^17",
|
|
56
59
|
"react-dom": "^17"
|
|
57
|
-
},
|
|
58
|
-
"jest": {
|
|
59
|
-
"preset": "ts-jest",
|
|
60
|
-
"testEnvironment": "jsdom",
|
|
61
|
-
"testPathIgnorePatterns": [
|
|
62
|
-
"dist/"
|
|
63
|
-
]
|
|
64
60
|
}
|
|
65
61
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import React, { forwardRef, InputHTMLAttributes, ReactNode } from 'react'
|
|
1
|
+
import React, { forwardRef, InputHTMLAttributes, ReactNode, 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
6
|
import { Colors, Shapes } from '../Types'
|
|
6
7
|
|
|
7
8
|
import { CFormLabel } from './CFormLabel'
|
|
@@ -46,6 +47,10 @@ export interface CFormCheckProps extends InputHTMLAttributes<HTMLInputElement> {
|
|
|
46
47
|
* The id global attribute defines an identifier (ID) that must be unique in the whole document.
|
|
47
48
|
*/
|
|
48
49
|
id?: string
|
|
50
|
+
/**
|
|
51
|
+
* Input Checkbox indeterminate Property.
|
|
52
|
+
*/
|
|
53
|
+
indeterminate?: boolean
|
|
49
54
|
/**
|
|
50
55
|
* Group checkboxes or radios on the same horizontal row by adding.
|
|
51
56
|
*/
|
|
@@ -70,9 +75,30 @@ export interface CFormCheckProps extends InputHTMLAttributes<HTMLInputElement> {
|
|
|
70
75
|
|
|
71
76
|
export const CFormCheck = forwardRef<HTMLInputElement, CFormCheckProps>(
|
|
72
77
|
(
|
|
73
|
-
{
|
|
78
|
+
{
|
|
79
|
+
className,
|
|
80
|
+
button,
|
|
81
|
+
hitArea,
|
|
82
|
+
id,
|
|
83
|
+
indeterminate,
|
|
84
|
+
inline,
|
|
85
|
+
invalid,
|
|
86
|
+
label,
|
|
87
|
+
type = 'checkbox',
|
|
88
|
+
valid,
|
|
89
|
+
...rest
|
|
90
|
+
},
|
|
74
91
|
ref,
|
|
75
92
|
) => {
|
|
93
|
+
const inputRef = useRef<HTMLInputElement>(null)
|
|
94
|
+
const forkedRef = useForkedRef(ref, inputRef)
|
|
95
|
+
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
if (inputRef.current && indeterminate) {
|
|
98
|
+
inputRef.current.indeterminate = indeterminate
|
|
99
|
+
}
|
|
100
|
+
}, [indeterminate])
|
|
101
|
+
|
|
76
102
|
const _className = classNames(
|
|
77
103
|
'form-check',
|
|
78
104
|
{
|
|
@@ -102,7 +128,7 @@ export const CFormCheck = forwardRef<HTMLInputElement, CFormCheckProps>(
|
|
|
102
128
|
)
|
|
103
129
|
|
|
104
130
|
const formControl = () => {
|
|
105
|
-
return <input type={type} className={inputClassName} id={id} {...rest} ref={
|
|
131
|
+
return <input type={type} className={inputClassName} id={id} {...rest} ref={forkedRef} />
|
|
106
132
|
}
|
|
107
133
|
|
|
108
134
|
const formLabel = () => {
|
|
@@ -141,6 +167,7 @@ CFormCheck.propTypes = {
|
|
|
141
167
|
className: PropTypes.string,
|
|
142
168
|
hitArea: PropTypes.oneOf(['full']),
|
|
143
169
|
id: PropTypes.string,
|
|
170
|
+
indeterminate: PropTypes.bool,
|
|
144
171
|
inline: PropTypes.bool,
|
|
145
172
|
invalid: PropTypes.bool,
|
|
146
173
|
label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React, { forwardRef,
|
|
1
|
+
import React, { forwardRef, AllHTMLAttributes } from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import classNames from 'classnames'
|
|
4
4
|
|
|
5
|
-
export interface CFormLabelProps extends
|
|
5
|
+
export interface CFormLabelProps extends AllHTMLAttributes<HTMLLabelElement> {
|
|
6
6
|
/**
|
|
7
7
|
* A string of all className you want applied to the component.
|
|
8
8
|
*/
|
|
@@ -2,6 +2,11 @@ import React, { ChangeEventHandler, forwardRef, InputHTMLAttributes } from 'reac
|
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import classNames from 'classnames'
|
|
4
4
|
|
|
5
|
+
type Option = {
|
|
6
|
+
disabled?: boolean
|
|
7
|
+
label?: string
|
|
8
|
+
value?: string
|
|
9
|
+
}
|
|
5
10
|
export interface CFormSelectProps extends Omit<InputHTMLAttributes<HTMLSelectElement>, 'size'> {
|
|
6
11
|
/**
|
|
7
12
|
* A string of all className you want applied to the component.
|
|
@@ -19,6 +24,13 @@ export interface CFormSelectProps extends Omit<InputHTMLAttributes<HTMLSelectEle
|
|
|
19
24
|
* Method called immediately after the `value` prop changes.
|
|
20
25
|
*/
|
|
21
26
|
onChange?: ChangeEventHandler<HTMLSelectElement>
|
|
27
|
+
/**
|
|
28
|
+
* Options list of the select component. Available keys: `label`, `value`, `disabled`.
|
|
29
|
+
* Examples:
|
|
30
|
+
* - `options={[{ value: 'js', label: 'JavaScript' }, { value: 'html', label: 'HTML', disabled: true }]}`
|
|
31
|
+
* - `options={['js', 'html']}`
|
|
32
|
+
*/
|
|
33
|
+
options?: Option[] | string[]
|
|
22
34
|
/**
|
|
23
35
|
* Size the component small or large.
|
|
24
36
|
*/
|
|
@@ -36,7 +48,7 @@ export interface CFormSelectProps extends Omit<InputHTMLAttributes<HTMLSelectEle
|
|
|
36
48
|
}
|
|
37
49
|
|
|
38
50
|
export const CFormSelect = forwardRef<HTMLSelectElement, CFormSelectProps>(
|
|
39
|
-
({ children, className, htmlSize, invalid, size, valid, ...rest }, ref) => {
|
|
51
|
+
({ children, className, htmlSize, invalid, options, size, valid, ...rest }, ref) => {
|
|
40
52
|
const _className = classNames(
|
|
41
53
|
'form-select',
|
|
42
54
|
{
|
|
@@ -48,7 +60,20 @@ export const CFormSelect = forwardRef<HTMLSelectElement, CFormSelectProps>(
|
|
|
48
60
|
)
|
|
49
61
|
return (
|
|
50
62
|
<select className={_className} size={htmlSize} {...rest} ref={ref}>
|
|
51
|
-
{
|
|
63
|
+
{options
|
|
64
|
+
? options.map((option, index) => {
|
|
65
|
+
return (
|
|
66
|
+
<option
|
|
67
|
+
{...(typeof option === 'object' &&
|
|
68
|
+
option.disabled && { disabled: option.disabled })}
|
|
69
|
+
{...(typeof option === 'object' && option.value && { value: option.value })}
|
|
70
|
+
key={index}
|
|
71
|
+
>
|
|
72
|
+
{typeof option === 'string' ? option : option.label}
|
|
73
|
+
</option>
|
|
74
|
+
)
|
|
75
|
+
})
|
|
76
|
+
: children}
|
|
52
77
|
</select>
|
|
53
78
|
)
|
|
54
79
|
},
|
|
@@ -59,6 +84,7 @@ CFormSelect.propTypes = {
|
|
|
59
84
|
className: PropTypes.string,
|
|
60
85
|
htmlSize: PropTypes.number,
|
|
61
86
|
invalid: PropTypes.bool,
|
|
87
|
+
options: PropTypes.array,
|
|
62
88
|
size: PropTypes.oneOf(['sm', 'lg']),
|
|
63
89
|
valid: PropTypes.bool,
|
|
64
90
|
}
|
|
@@ -15,3 +15,11 @@ test('CFormLabel customize className', async () => {
|
|
|
15
15
|
expect(container.firstChild).toHaveClass('form-label')
|
|
16
16
|
expect(container.firstChild).toHaveTextContent('Test')
|
|
17
17
|
})
|
|
18
|
+
|
|
19
|
+
test('CFormLabel customize htmlFor', async () => {
|
|
20
|
+
const { container } = render(<CFormLabel htmlFor="bazinga">Test</CFormLabel>)
|
|
21
|
+
expect(container).toMatchSnapshot()
|
|
22
|
+
expect(container.firstChild).toHaveAttribute('for', 'bazinga')
|
|
23
|
+
expect(container.firstChild).toHaveClass('form-label')
|
|
24
|
+
expect(container.firstChild).toHaveTextContent('Test')
|
|
25
|
+
})
|
|
@@ -10,6 +10,17 @@ exports[`CFormLabel customize className 1`] = `
|
|
|
10
10
|
</div>
|
|
11
11
|
`;
|
|
12
12
|
|
|
13
|
+
exports[`CFormLabel customize htmlFor 1`] = `
|
|
14
|
+
<div>
|
|
15
|
+
<label
|
|
16
|
+
class="form-label"
|
|
17
|
+
for="bazinga"
|
|
18
|
+
>
|
|
19
|
+
Test
|
|
20
|
+
</label>
|
|
21
|
+
</div>
|
|
22
|
+
`;
|
|
23
|
+
|
|
13
24
|
exports[`loads and displays CFormLabel component 1`] = `
|
|
14
25
|
<div>
|
|
15
26
|
<label
|
package/tsconfig.json
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"jsx": "react",
|
|
4
|
-
"outDir": "dist",
|
|
5
|
-
"module": "esnext",
|
|
6
|
-
"target": "es5",
|
|
7
|
-
"lib": ["es6", "dom", "es2016", "es2017"],
|
|
8
|
-
"sourceMap": true,
|
|
9
|
-
"allowJs": false,
|
|
10
|
-
"declaration": true,
|
|
11
|
-
"declarationDir": ".",
|
|
12
|
-
"moduleResolution": "node",
|
|
13
|
-
"forceConsistentCasingInFileNames": true,
|
|
14
|
-
"noImplicitReturns": true,
|
|
15
|
-
"noImplicitThis": true,
|
|
16
|
-
"noImplicitAny": true,
|
|
17
|
-
"strictNullChecks": true,
|
|
18
|
-
"suppressImplicitAnyIndexErrors": true,
|
|
19
|
-
"noUnusedLocals": true,
|
|
20
|
-
"noUnusedParameters": true,
|
|
21
|
-
"esModuleInterop": true
|
|
22
|
-
},
|
|
23
|
-
"include": ["src"],
|
|
24
|
-
"exclude": ["**/node_modules", "dist"]
|
|
25
|
-
}
|