|
| 1 | +import React from 'react'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | +import classNames from 'classnames'; |
| 4 | + |
| 5 | +import Skeleton, { SkeletonTheme } from 'react-loading-skeleton'; |
| 6 | +import 'react-loading-skeleton/dist/skeleton.css'; |
| 7 | + |
| 8 | +import colors from '../Styles/colors/palette'; |
| 9 | + |
| 10 | +const LoadingSkeleton = ({ className, ...props }) => ( |
| 11 | + <SkeletonTheme baseColor={colors.UX_GRAY_300}> |
| 12 | + <Skeleton |
| 13 | + className={classNames('LoadingSkeleton', className)} |
| 14 | + {...props} |
| 15 | + /> |
| 16 | + </SkeletonTheme> |
| 17 | +); |
| 18 | + |
| 19 | +LoadingSkeleton.propTypes = { |
| 20 | + /** |
| 21 | + The border radius of the skeleton. |
| 22 | + */ |
| 23 | + borderRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), |
| 24 | + /** |
| 25 | + Makes the skeleton circular by setting border-radius to 50%. |
| 26 | + */ |
| 27 | + circle: PropTypes.bool, |
| 28 | + className: PropTypes.string, |
| 29 | + /** |
| 30 | + A custom class name for the `<span>` that wraps the individual skeleton elements. |
| 31 | + */ |
| 32 | + containerClassName: PropTypes.string, |
| 33 | + /** |
| 34 | + A string that is added to the container element as a data-testid attribute. |
| 35 | + Use it with screen.getByTestId('...') from React Testing Library. |
| 36 | + */ |
| 37 | + containerTestId: PropTypes.string, |
| 38 | + /** |
| 39 | + The number of lines of skeletons to render. If count is a decimal number like 3.5, |
| 40 | + three full skeletons and one half-width skeleton will be rendered. |
| 41 | + */ |
| 42 | + count: PropTypes.number, |
| 43 | + /** |
| 44 | + The height of the skeleton. |
| 45 | + */ |
| 46 | + height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), |
| 47 | + /** |
| 48 | + By default, a `<br />` is inserted after each skeleton so that each skeleton gets its own line. |
| 49 | + When inline is true, no line breaks are inserted. |
| 50 | + */ |
| 51 | + inline: PropTypes.bool, |
| 52 | + /** |
| 53 | + The width of the skeleton. |
| 54 | + */ |
| 55 | + width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), |
| 56 | +}; |
| 57 | + |
| 58 | +LoadingSkeleton.defaultProps = { |
| 59 | + borderRadius: '0.25rem', |
| 60 | + className: undefined, |
| 61 | + circle: false, |
| 62 | + containerClassName: undefined, |
| 63 | + containerTestId: undefined, |
| 64 | + count: 1, |
| 65 | + height: undefined, |
| 66 | + inline: false, |
| 67 | + width: '100%', |
| 68 | +}; |
| 69 | + |
| 70 | +export default LoadingSkeleton; |
0 commit comments