1
- import React , { ChangeEventHandler , forwardRef , InputHTMLAttributes } from 'react'
2
- import PropTypes from 'prop-types'
1
+ import React , { ChangeEventHandler , forwardRef , InputHTMLAttributes , ReactNode } from 'react'
2
+
3
3
import classNames from 'classnames'
4
+ import PropTypes from 'prop-types'
4
5
6
+ import { CFormLabel } from './CFormLabel'
5
7
export interface CFormRangeProps extends InputHTMLAttributes < HTMLInputElement > {
6
8
/**
7
9
* A string of all className you want applied to the component.
@@ -11,6 +13,12 @@ export interface CFormRangeProps extends InputHTMLAttributes<HTMLInputElement> {
11
13
* Toggle the disabled state for the component.
12
14
*/
13
15
disabled ?: boolean
16
+ /**
17
+ * Add a caption for a component.
18
+ *
19
+ * @since 4.2.0
20
+ */
21
+ label ?: ReactNode | string
14
22
/**
15
23
* Specifies the maximum value for the component.
16
24
*/
@@ -40,14 +48,20 @@ export interface CFormRangeProps extends InputHTMLAttributes<HTMLInputElement> {
40
48
}
41
49
42
50
export const CFormRange = forwardRef < HTMLInputElement , CFormRangeProps > (
43
- ( { className, ...rest } , ref ) => {
51
+ ( { className, label , ...rest } , ref ) => {
44
52
const _className = classNames ( 'form-range' , className )
45
- return < input type = "range" className = { _className } { ...rest } ref = { ref } />
53
+ return (
54
+ < >
55
+ { label && < CFormLabel htmlFor = { rest . id } > { label } </ CFormLabel > }
56
+ < input type = "range" className = { _className } { ...rest } ref = { ref } />
57
+ </ >
58
+ )
46
59
} ,
47
60
)
48
61
49
62
CFormRange . propTypes = {
50
63
className : PropTypes . string ,
64
+ label : PropTypes . oneOfType ( [ PropTypes . node , PropTypes . string ] ) ,
51
65
}
52
66
53
67
CFormRange . displayName = 'CFormRange'
0 commit comments