@coreui/react 4.0.0 → 4.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coreui/react",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "UI Components Library for React.js",
5
5
  "keywords": [
6
6
  "react",
@@ -26,7 +26,7 @@
26
26
  "main": "dist/index.js",
27
27
  "module": "dist/index.es.js",
28
28
  "jsnext:main": "dist/index.es.js",
29
- "typings": "dist/index.d.ts",
29
+ "types": "dist/index.d.ts",
30
30
  "files": [
31
31
  "dist/",
32
32
  "src/"
@@ -39,18 +39,18 @@
39
39
  "@rollup/plugin-commonjs": "^21.0.1",
40
40
  "@rollup/plugin-node-resolve": "^13.0.6",
41
41
  "@rollup/plugin-typescript": "^8.3.0",
42
- "@testing-library/jest-dom": "^5.14.1",
42
+ "@testing-library/jest-dom": "^5.15.0",
43
43
  "@testing-library/react": "^12.1.2",
44
- "@types/react": "^17.0.31",
45
- "@types/react-dom": "^17.0.10",
46
- "@types/react-transition-group": "^4.4.3",
44
+ "@types/react": "^17.0.34",
45
+ "@types/react-dom": "^17.0.11",
46
+ "@types/react-transition-group": "^4.4.4",
47
47
  "classnames": "^2.3.1",
48
48
  "prop-types": "^15.7.2",
49
49
  "react": "^17.0.2",
50
50
  "react-dom": "^17.0.2",
51
51
  "react-popper": "^2.2.5",
52
52
  "react-transition-group": "^4.4.2",
53
- "rollup": "^2.58.0",
53
+ "rollup": "^2.59.0",
54
54
  "rollup-plugin-peer-deps-external": "^2.2.4",
55
55
  "typescript": "^4.4.4"
56
56
  },
@@ -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
- { className, button, hitArea, id, inline, invalid, label, type = 'checkbox', valid, ...rest },
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={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]),
@@ -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
- {children}
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
  }