Skip to content

Commit c4e8bcd

Browse files
committed
refactor(code-snippet): update CodeSnippet.Skeleton to hooks
1 parent 918003f commit c4e8bcd

File tree

1 file changed

+46
-49
lines changed

1 file changed

+46
-49
lines changed

packages/react/src/components/CodeSnippet/CodeSnippet.Skeleton.js

Lines changed: 46 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,61 +5,58 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import PropTypes from 'prop-types';
9-
import React, { Component } from 'react';
10-
import classNames from 'classnames';
118
import { settings } from 'carbon-components';
9+
import cx from 'classnames';
10+
import PropTypes from 'prop-types';
11+
import React from 'react';
1212

1313
const { prefix } = settings;
1414

15-
export default class CodeSnippetSkeleton extends Component {
16-
static propTypes = {
17-
/**
18-
* The type of code snippet
19-
* can be single or multi
20-
*/
21-
type: PropTypes.oneOf(['single', 'multi']),
22-
23-
/**
24-
* Specify an optional className to be applied to the container node
25-
*/
26-
className: PropTypes.string,
27-
};
28-
29-
static defaultProps = {
30-
type: 'single',
31-
};
32-
33-
render() {
34-
const { className, type, ...other } = this.props;
35-
36-
const codeSnippetClasses = classNames(className, {
37-
[`${prefix}--snippet`]: true,
38-
[`${prefix}--skeleton`]: true,
39-
[`${prefix}--snippet--single`]: type === 'single',
40-
[`${prefix}--snippet--multi`]: type === 'multi',
41-
});
42-
43-
if (type === 'single') {
44-
return (
45-
<div className={codeSnippetClasses} {...other}>
46-
<div className={`${prefix}--snippet-container`}>
47-
<span />
48-
</div>
15+
function CodeSnippetSkeleton({
16+
className: containerClassName,
17+
type = 'single',
18+
...rest
19+
}) {
20+
const className = cx(containerClassName, {
21+
[`${prefix}--snippet`]: true,
22+
[`${prefix}--skeleton`]: true,
23+
[`${prefix}--snippet--single`]: type === 'single',
24+
[`${prefix}--snippet--multi`]: type === 'multi',
25+
});
26+
27+
if (type === 'single') {
28+
return (
29+
<div className={className} {...rest}>
30+
<div className={`${prefix}--snippet-container`}>
31+
<span />
4932
</div>
50-
);
51-
}
33+
</div>
34+
);
35+
}
5236

53-
if (type === 'multi') {
54-
return (
55-
<div className={codeSnippetClasses} {...other}>
56-
<div className={`${prefix}--snippet-container`}>
57-
<span />
58-
<span />
59-
<span />
60-
</div>
37+
if (type === 'multi') {
38+
return (
39+
<div className={className} {...rest}>
40+
<div className={`${prefix}--snippet-container`}>
41+
<span />
42+
<span />
43+
<span />
6144
</div>
62-
);
63-
}
45+
</div>
46+
);
6447
}
6548
}
49+
50+
CodeSnippetSkeleton.propTypes = {
51+
/**
52+
* The type of the code snippet, including single or multi
53+
*/
54+
type: PropTypes.oneOf(['single', 'multi']),
55+
56+
/**
57+
* Specify an optional className to be applied to the container node
58+
*/
59+
className: PropTypes.string,
60+
};
61+
62+
export default CodeSnippetSkeleton;

0 commit comments

Comments
 (0)