8000 feat(CFormRange): automatically add a label to component; syntax impr… · athulchandroth/coreui-react@ed7ed62 · GitHub
[go: up one dir, main page]

Skip to content

Commit ed7ed62

Browse files
committed
feat(CFormRange): automatically add a label to component; syntax improvement
1 parent 3f87b21 commit ed7ed62

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

packages/coreui-react/src/components/form/CFormRange.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import React, { ChangeEventHandler, forwardRef, InputHTMLAttributes } from 'react'
2-
import PropTypes from 'prop-types'
1+
import React, { ChangeEventHandler, forwardRef, InputHTMLAttributes, ReactNode } from 'react'
2+
33
import classNames from 'classnames'
4+
import PropTypes from 'prop-types'
45

6+
import { CFormLabel } from './CFormLabel'
57
export interface CFormRangeProps extends InputHTMLAttributes<HTMLInputElement> {
68
/**
79
* A string of all className you want applied to the component.
@@ -11,6 +13,12 @@ export interface CFormRangeProps extends InputHTMLAttributes<HTMLInputElement> {
1113
* Toggle the disabled state for the component.
1214
*/
1315
disabled?: boolean
16+
/**
17+
* Add a caption for a component.
18+
*
19+
* @since 4.2.0
20+
*/
21+
label?: ReactNode | string
1422
/**
1523
* Specifies the maximum value for the component.
1624
*/
@@ -40,14 +48,20 @@ export interface CFormRangeProps extends InputHTMLAttributes<HTMLInputElement> {
4048
}
4149

4250
export const CFormRange = forwardRef<HTMLInputElement, CFormRangeProps>(
43-
({ className, ...rest }, ref) => {
51+
({ className, label, ...rest }, ref) => {
4452
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+
)
4659
},
4760
)
4861

4962
CFormRange.propTypes = {
5063
className: PropTypes.string,
64+
label: PropTypes.oneOfType([PropTypes.node, PropTypes.string]),
5165
}
5266

5367
CFormRange.displayName = 'CFormRange'

0 commit comments

Comments
 (0)
0