Skip to content

Commit 8382893

Browse files
authored
refactor: convert ToggleSmallSkeleton to functional component (#19114)
1 parent a6eb265 commit 8382893

File tree

2 files changed

+56
-64
lines changed

2 files changed

+56
-64
lines changed

packages/react/src/components/ModalWrapper/ModalWrapper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default class ModalWrapper extends React.Component<
5454
if(isDev) {
5555
warning(
5656
didWarnAboutDeprecation,
57-
'`<ModalWrapper>` has been deprecated in favor of `<ComposedModal/>` and will be removed in the next major version, `@carbon/react@v2.x`'
57+
'`<ModalWrapper>` has been deprecated in favor of `<ComposedModal/>` and will be removed in the next major version, `@carbon/react@v12.x`'
5858
);
5959
didWarnAboutDeprecation = true;
6060
}
Lines changed: 55 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/**
2-
* Copyright IBM Corp. 2016, 2023
2+
* Copyright IBM Corp. 2016, 2025
33
*
44
* This source code is licensed under the Apache-2.0 license found in the
55
* LICENSE file in the root directory of this source tree.
66
*/
7+
78
import PropTypes from 'prop-types';
8-
import React from 'react';
9+
import React, { useContext } from 'react';
910
import cx from 'classnames';
1011
import { PrefixContext } from '../../internal/usePrefix';
1112

@@ -21,70 +22,61 @@ export interface ToggleSmallSkeletonProps {
2122
id?: string;
2223
/**
2324
* 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.
2727
*/
2828
labelText?: string;
2929
}
3030

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);
5038

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+
};
8865

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

Comments
 (0)