@@ -2,35 +2,40 @@ import React, { forwardRef, HTMLAttributes, ReactNode } from 'react'
2
2
import PropTypes from 'prop-types'
3
3
import classNames from 'classnames'
4
4
5
- import { Colors , Shapes , colorPropType , shapePropType } from '../Types'
5
+ import { Colors , Shapes } from '../Types'
6
6
7
- import { CFormControl } from './CFormControl'
8
7
import { CFormLabel } from './CFormLabel'
9
8
10
- export interface CFormCheckProps extends HTMLAttributes < HTMLInputElement > {
11
- button ?: boolean
9
+ export type ButtonObject = {
12
10
/**
13
11
* Sets the color context of the component to one of CoreUI’s themed colors. [docs]
14
12
*
15
13
* @type 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'dark' | 'light' | string
16
14
*/
17
- buttonColor ?: Colors
15
+ color ?: Colors
18
16
/**
19
17
* Select the shape of the component. [docs]
20
18
*
21
19
* @type 'rounded' | 'rounded-top' | 'rounded-end' | 'rounded-bottom' | 'rounded-start' | 'rounded-circle' | 'rounded-pill' | 'rounded-0' | 'rounded-1' | 'rounded-2' | 'rounded-3' | string
22
20
*/
23
- buttonShape ?: Shapes
21
+ shape ?: Shapes
24
22
/**
25
23
* Size the component small or large. [docs]
26
24
*
27
25
* @type 'sm' | 'lg'
28
26
*/
29
- buttonSize ?: 'sm' | 'lg'
27
+ size ?: 'sm' | 'lg'
30
28
/**
31
29
* Set the button variant to an outlined button or a ghost button. [docs]
32
30
*/
33
- buttonVariant ?: 'outline' | 'ghost'
31
+ variant ?: 'outline' | 'ghost'
32
+ }
33
+
34
+ export interface CFormCheckProps extends HTMLAttributes < HTMLInputElement > {
35
+ /**
36
+ * Create button-like checkboxes and radio buttons
37
+ */
38
+ button ?: ButtonObject
34
39
/**
35
40
* A string of all className you want applied to the component. [docs]
36
41
*/
@@ -51,16 +56,6 @@ export interface CFormCheckProps extends HTMLAttributes<HTMLInputElement> {
51
56
* The element represents a caption for a component. [docs]
52
57
*/
53
58
label ?: string | ReactNode
54
- /**
55
- * Size the component large or extra large. Works only with `switch` [docs]
56
- *
57
- * @type 'lg' | 'xl'
58
- */
59
- size ?: 'lg' | 'xl'
60
- /**
61
- * Render component as a toggle switch. [docs]
62
- */
63
- switch ?: boolean
64
59
/**
65
60
* Specifies the type of component. [docs]
66
61
*
@@ -75,31 +70,10 @@ export interface CFormCheckProps extends HTMLAttributes<HTMLInputElement> {
75
70
}
76
71
77
72
export const CFormCheck = forwardRef < HTMLInputElement , CFormCheckProps > (
78
- (
79
- {
80
- className,
81
- button,
82
- buttonColor = 'primary' ,
83
- buttonSize,
84
- buttonShape,
85
- buttonVariant,
86
- id,
87
- inline,
88
- invalid,
89
- label,
90
- size,
91
- switch : _switch ,
92
- type = 'checkbox' ,
93
- valid,
94
- ...rest
95
- } ,
96
- ref ,
97
- ) => {
73
+ ( { className, button, id, inline, invalid, label, type = 'checkbox' , valid, ...rest } , ref ) => {
98
74
const _className = classNames (
99
75
'form-check' ,
100
76
{
101
- 'form-switch' : _switch ,
102
- [ `form-switch-${ size } ` ] : size ,
103
77
'form-check-inline' : inline ,
104
78
'is-invalid' : invalid ,
105
79
'is-valid' : valid ,
@@ -115,35 +89,28 @@ export const CFormCheck = forwardRef<HTMLInputElement, CFormCheckProps>(
115
89
button
116
90
? classNames (
117
91
'btn' ,
118
- buttonVariant ? `btn-${ buttonVariant } -${ buttonColor } ` : `btn-${ buttonColor } ` ,
92
+ button . variant ? `btn-${ button . variant } -${ button . color } ` : `btn-${ button . color } ` ,
119
93
{
120
- [ `btn-${ buttonSize } ` ] : buttonSize ,
121
- buttonShape,
94
+ [ `btn-${ button . size } ` ] : button . size ,
122
95
} ,
96
+ `${ button . shape } ` ,
123
97
)
124
98
: 'form-check-label' ,
125
99
)
126
100
127
101
const formControl = ( ) => {
128
- return (
129
- < CFormControl type = { type } classNameParent = { inputClassName } id = { id } { ...rest } ref = { ref } />
130
- )
102
+ return < input type = { type } className = { inputClassName } id = { id } { ...rest } ref = { ref } />
131
103
}
132
104
133
105
const formLabel = ( ) => {
134
106
return (
135
- < CFormLabel classNameParent = { labelClassName } { ...( id && { htmlFor : id } ) } >
107
+ < CFormLabel customClassName = { labelClassName } { ...( id && { htmlFor : id } ) } >
136
108
{ label }
137
109
</ CFormLabel >
138
110
)
139
111
}
140
112
141
- return _switch ? (
142
- < div className = { _className } >
143
- { formControl ( ) }
144
- { label && formLabel ( ) }
145
- </ div >
146
- ) : button ? (
113
+ return button ? (
147
114
< >
148
115
{ formControl ( ) }
149
116
{ label && formLabel ( ) }
@@ -160,18 +127,12 @@ export const CFormCheck = forwardRef<HTMLInputElement, CFormCheckProps>(
160
127
)
161
128
162
129
CFormCheck . propTypes = {
163
- button : PropTypes . bool ,
164
- buttonColor : colorPropType ,
165
- buttonShape : shapePropType ,
166
- buttonSize : PropTypes . oneOf ( [ 'sm' , 'lg' ] ) ,
167
- buttonVariant : PropTypes . oneOf ( [ 'outline' , 'ghost' ] ) ,
130
+ button : PropTypes . object ,
168
131
className : PropTypes . string ,
169
132
id : PropTypes . string ,
170
133
inline : PropTypes . bool ,
171
134
invalid : PropTypes . bool ,
172
135
label : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . node ] ) ,
173
- size : PropTypes . oneOf ( [ 'lg' , 'xl' ] ) ,
174
- switch : PropTypes . bool ,
175
136
type : PropTypes . oneOf ( [ 'checkbox' , 'radio' ] ) ,
176
137
valid : PropTypes . bool ,
177
138
}
0 commit comments