@@ -2,35 +2,40 @@ import React, { forwardRef, HTMLAttributes, ReactNode } from 'react'
22import PropTypes from 'prop-types'
33import classNames from 'classnames'
44
5- import { Colors , Shapes , colorPropType , shapePropType } from '../Types'
5+ import { Colors , Shapes } from '../Types'
66
7- import { CFormControl } from './CFormControl'
87import { CFormLabel } from './CFormLabel'
98
10- export interface CFormCheckProps extends HTMLAttributes < HTMLInputElement > {
11- button ?: boolean
9+ export type ButtonObject = {
1210 /**
1311 * Sets the color context of the component to one of CoreUI’s themed colors. [docs]
1412 *
1513 * @type 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'dark' | 'light' | string
1614 */
17- buttonColor ?: Colors
15+ color ?: Colors
1816 /**
1917 * Select the shape of the component. [docs]
2018 *
2119 * @type 'rounded' | 'rounded-top' | 'rounded-end' | 'rounded-bottom' | 'rounded-start' | 'rounded-circle' | 'rounded-pill' | 'rounded-0' | 'rounded-1' | 'rounded-2' | 'rounded-3' | string
2220 */
23- buttonShape ?: Shapes
21+ shape ?: Shapes
2422 /**
2523 * Size the component small or large. [docs]
2624 *
2725 * @type 'sm' | 'lg'
2826 */
29- buttonSize ?: 'sm' | 'lg'
27+ size ?: 'sm' | 'lg'
3028 /**
3129 * Set the button variant to an outlined button or a ghost button. [docs]
3230 */
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
3439 /**
3540 * A string of all className you want applied to the component. [docs]
3641 */
@@ -51,16 +56,6 @@ export interface CFormCheckProps extends HTMLAttributes<HTMLInputElement> {
5156 * The element represents a caption for a component. [docs]
5257 */
5358 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
6459 /**
6560 * Specifies the type of component. [docs]
6661 *
@@ -75,31 +70,10 @@ export interface CFormCheckProps extends HTMLAttributes<HTMLInputElement> {
7570}
7671
7772export 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 ) => {
9874 const _className = classNames (
9975 'form-check' ,
10076 {
101- 'form-switch' : _switch ,
102- [ `form-switch-${ size } ` ] : size ,
10377 'form-check-inline' : inline ,
10478 'is-invalid' : invalid ,
10579 'is-valid' : valid ,
@@ -115,35 +89,28 @@ export const CFormCheck = forwardRef<HTMLInputElement, CFormCheckProps>(
11589 button
11690 ? classNames (
11791 'btn' ,
118- buttonVariant ? `btn-${ buttonVariant } -${ buttonColor } ` : `btn-${ buttonColor } ` ,
92+ button . variant ? `btn-${ button . variant } -${ button . color } ` : `btn-${ button . color } ` ,
11993 {
120- [ `btn-${ buttonSize } ` ] : buttonSize ,
121- buttonShape,
94+ [ `btn-${ button . size } ` ] : button . size ,
12295 } ,
96+ `${ button . shape } ` ,
12397 )
12498 : 'form-check-label' ,
12599 )
126100
127101 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 } />
131103 }
132104
133105 const formLabel = ( ) => {
134106 return (
135- < CFormLabel classNameParent = { labelClassName } { ...( id && { htmlFor : id } ) } >
107+ < CFormLabel customClassName = { labelClassName } { ...( id && { htmlFor : id } ) } >
136108 { label }
137109 </ CFormLabel >
138110 )
139111 }
140112
141- return _switch ? (
142- < div className = { _className } >
143- { formControl ( ) }
144- { label && formLabel ( ) }
145- </ div >
146- ) : button ? (
113+ return button ? (
147114 < >
148115 { formControl ( ) }
149116 { label && formLabel ( ) }
@@ -160,18 +127,12 @@ export const CFormCheck = forwardRef<HTMLInputElement, CFormCheckProps>(
160127)
161128
162129CFormCheck . 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 ,
168131 className : PropTypes . string ,
169132 id : PropTypes . string ,
170133 inline : PropTypes . bool ,
171134 invalid : PropTypes . bool ,
172135 label : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . node ] ) ,
173- size : PropTypes . oneOf ( [ 'lg' , 'xl' ] ) ,
174- switch : PropTypes . bool ,
175136 type : PropTypes . oneOf ( [ 'checkbox' , 'radio' ] ) ,
176137 valid : PropTypes . bool ,
177138}
0 commit comments