1
0

index.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import React, { PureComponent, ReactNode, CSSProperties } from 'react';
  2. import cls from 'classnames';
  3. import PropTypes from 'prop-types';
  4. import { cssClasses } from '@douyinfe/semi-foundation/skeleton/constants';
  5. import '@douyinfe/semi-foundation/skeleton/skeleton.scss';
  6. import { Avatar, Image, Title, Button, Paragraph } from './item';
  7. export { ParagraphProps, AvatarProps, GenericProps } from './item';
  8. const prefixCls = cssClasses.PREFIX;
  9. export interface SkeletonProps {
  10. active?: boolean;
  11. children?: ReactNode;
  12. className?: string;
  13. loading?: boolean;
  14. placeholder?: ReactNode;
  15. style?: CSSProperties;
  16. }
  17. class Skeleton extends PureComponent<SkeletonProps> {
  18. static Avatar = Avatar;
  19. static Title = Title;
  20. static Button = Button;
  21. static Paragraph = Paragraph;
  22. static Image = Image;
  23. static defaultProps = {
  24. loading: true,
  25. };
  26. static propTypes = {
  27. active: PropTypes.bool,
  28. placeholder: PropTypes.node,
  29. style: PropTypes.object,
  30. className: PropTypes.string,
  31. loading: PropTypes.bool,
  32. children: PropTypes.node,
  33. };
  34. render(): ReactNode {
  35. const { placeholder, active, children, className, loading, style, ...others } = this.props;
  36. const skCls = cls(prefixCls,
  37. {
  38. [`${prefixCls}-active`]: Boolean(active),
  39. },
  40. className);
  41. let content;
  42. if (loading) {
  43. content = (
  44. <div className={skCls} style={style} {...others}>
  45. {placeholder}
  46. </div>
  47. );
  48. } else {
  49. content = children;
  50. }
  51. return content;
  52. }
  53. }
  54. export default Skeleton;