1
1
/**
2
- * Copyright IBM Corp. 2016, 2023
2
+ * Copyright IBM Corp. 2016, 2025
3
3
*
4
4
* This source code is licensed under the Apache-2.0 license found in the
5
5
* LICENSE file in the root directory of this source tree.
6
6
*/
7
+
7
8
import PropTypes from 'prop-types' ;
8
- import React from 'react' ;
9
+ import React , { useContext } from 'react' ;
9
10
import cx from 'classnames' ;
10
11
import { PrefixContext } from '../../internal/usePrefix' ;
11
12
@@ -21,70 +22,61 @@ export interface ToggleSmallSkeletonProps {
21
22
id ?: string ;
22
23
/**
23
24
* Provide the text that will be read by a screen reader when visiting this
24
- * control
25
- * `aria-label` is always required but will be null if `labelText` is also
26
- * provided
25
+ * control. `aria-label` is always required but will be `null` if `labelText`
26
+ * is also provided.
27
27
*/
28
28
labelText ?: string ;
29
29
}
30
30
31
- class ToggleSmallSkeleton extends React . Component < ToggleSmallSkeletonProps > {
32
- static propTypes = {
33
- [ 'aria-label' ] : PropTypes . string . isRequired ,
34
- /**
35
- * Specify an optional className to add to the form item wrapper.
36
- */
37
- className : PropTypes . string ,
38
- /**
39
- * Provide an id that unique represents the underlying `<input>`
40
- */
41
- id : PropTypes . string ,
42
- /**
43
- * Provide the text that will be read by a screen reader when visiting this
44
- * control
45
- * `aria-label` is always required but will be null if `labelText` is also
46
- * provided
47
- */
48
- labelText : PropTypes . string ,
49
- } ;
31
+ export const ToggleSmallSkeleton = ( {
32
+ id,
33
+ labelText,
34
+ className,
35
+ ...rest
36
+ } : ToggleSmallSkeletonProps ) => {
37
+ const prefix = useContext ( PrefixContext ) ;
50
38
51
- render ( ) {
52
- const { id, labelText, className, ...rest } = this . props ;
53
- return (
54
- < PrefixContext . Consumer >
55
- { ( prefix ) => {
56
- return (
57
- < div className = { cx ( `${ prefix } --form-item` , className ) } { ...rest } >
58
- < input
59
- type = "checkbox"
60
- id = { id }
61
- className = { `${ prefix } --toggle ${ prefix } --toggle--small ${ prefix } --skeleton` }
62
- />
63
- < label
64
- className = { `${ prefix } --toggle__label ${ prefix } --skeleton` }
65
- htmlFor = { id } >
66
- { labelText && (
67
- < span className = { `${ prefix } --toggle__label-text` } >
68
- { labelText }
69
- </ span >
70
- ) }
71
- < span className = { `${ prefix } --toggle__appearance` } >
72
- < svg
73
- className = { `${ prefix } --toggle__check` }
74
- width = "6px"
75
- height = "5px"
76
- viewBox = "0 0 6 5" >
77
- < path d = "M2.2403 2.7299L4.9245 0 6 1.1117 2.2384 5 0 2.6863 1.0612 1.511z" />
78
- </ svg >
79
- </ span >
80
- </ label >
81
- </ div >
82
- ) ;
83
- } }
84
- </ PrefixContext . Consumer >
85
- ) ;
86
- }
87
- }
39
+ return (
40
+ < div className = { cx ( `${ prefix } --form-item` , className ) } { ...rest } >
41
+ < input
42
+ type = "checkbox"
43
+ id = { id }
44
+ className = { `${ prefix } --toggle ${ prefix } --toggle--small ${ prefix } --skeleton` }
45
+ />
46
+ < label
47
+ className = { `${ prefix } --toggle__label ${ prefix } --skeleton` }
48
+ htmlFor = { id } >
49
+ { labelText && (
50
+ < span className = { `${ prefix } --toggle__label-text` } > { labelText } </ span >
51
+ ) }
52
+ < span className = { `${ prefix } --toggle__appearance` } >
53
+ < svg
54
+ className = { `${ prefix } --toggle__check` }
55
+ width = "6px"
56
+ height = "5px"
57
+ viewBox = "0 0 6 5" >
58
+ < path d = "M2.2403 2.7299L4.9245 0 6 1.1117 2.2384 5 0 2.6863 1.0612 1.511z" />
59
+ </ svg >
60
+ </ span >
61
+ </ label >
62
+ </ div >
63
+ ) ;
64
+ } ;
88
65
89
- export default ToggleSmallSkeleton ;
90
- export { ToggleSmallSkeleton } ;
66
+ ToggleSmallSkeleton . propTypes = {
67
+ [ 'aria-label' ] : PropTypes . string . isRequired ,
68
+ /**
69
+ * Specify an optional className to add to the form item wrapper.
70
+ */
71
+ className : PropTypes . string ,
72
+ /**
73
+ * Provide an id that unique represents the underlying `<input>`
74
+ */
75
+ id : PropTypes . string ,
76
+ /**
77
+ * Provide the text that will be read by a screen reader when visiting this
78
+ * control. `aria-label` is always required but will be `null` if `labelText`
79
+ * is also provided.
80
+ */
81
+ labelText : PropTypes . string ,
82
+ } ;
0 commit comments