|
5 | 5 | * LICENSE file in the root directory of this source tree.
|
6 | 6 | */
|
7 | 7 |
|
8 |
| -import PropTypes from 'prop-types'; |
9 |
| -import React, { Component } from 'react'; |
10 |
| -import classNames from 'classnames'; |
11 | 8 | import { settings } from 'carbon-components';
|
| 9 | +import cx from 'classnames'; |
| 10 | +import PropTypes from 'prop-types'; |
| 11 | +import React from 'react'; |
12 | 12 |
|
13 | 13 | const { prefix } = settings;
|
14 | 14 |
|
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 /> |
49 | 32 | </div>
|
50 |
| - ); |
51 |
| - } |
| 33 | + </div> |
| 34 | + ); |
| 35 | + } |
52 | 36 |
|
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 /> |
61 | 44 | </div>
|
62 |
| - ); |
63 |
| - } |
| 45 | + </div> |
| 46 | + ); |
64 | 47 | }
|
65 | 48 | }
|
| 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