UNPKG

1.33 kBJavaScriptView Raw
1import React from 'react';
2import PropTypes from 'prop-types';
3import classNames from 'classnames';
4import { mapToCssModules, tagPropType } from './utils';
5import Col, { getColumnClasses } from './Col';
6
7const propTypes = {
8 ...Col.propTypes,
9 /** Add custom color to the placeholder */
10 color: PropTypes.string,
11 /** Add custom tag. */
12 tag: tagPropType,
13 /** Apply either `glow` or `wave` animation. */
14 animation: PropTypes.oneOf(['glow', 'wave']),
15 innerRef: PropTypes.oneOfType([
16 PropTypes.object,
17 PropTypes.func,
18 PropTypes.string,
19 ]),
20 /** Make the size larger */
21 size: PropTypes.oneOf(['lg', 'sm', 'xs']),
22};
23
24function Placeholder(props) {
25 let {
26 className,
27 cssModule,
28 color,
29 innerRef,
30 tag: Tag = 'span',
31 animation,
32 size,
33 widths,
34 ...attributes
35 } = props;
36
37 let { modifiedAttributes, colClasses } = getColumnClasses(
38 attributes,
39 cssModule,
40 widths,
41 );
42
43 const classes = mapToCssModules(
44 classNames(
45 className,
46 colClasses,
47 'placeholder' + (animation ? '-' + animation : ''),
48 size ? 'placeholder-' + size : false,
49 color ? 'bg-' + color : false,
50 ),
51 cssModule,
52 );
53
54 return <Tag {...modifiedAttributes} className={classes} ref={innerRef} />;
55}
56
57Placeholder.propTypes = propTypes;
58
59export default Placeholder;
60
\No newline at end of file