cardGroup.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import React, { PureComponent } from 'react';
  2. import PropTypes from 'prop-types';
  3. import { cssClasses, strings } from '@douyinfe/semi-foundation/card/constants';
  4. import cls from 'classnames';
  5. import Space from '../space';
  6. const prefixcls = cssClasses.PREFIX;
  7. export type CardGroupType = 'grid';
  8. export interface CardGroupProps {
  9. /** Card group style class name */
  10. className?: string;
  11. /** Card Spacing */
  12. spacing?: number | number[];
  13. /** Card group inline style */
  14. style?: React.CSSProperties;
  15. /** Card set type */
  16. type?: CardGroupType;
  17. }
  18. class CardGroup extends PureComponent<CardGroupProps> {
  19. static propTypes = {
  20. children: PropTypes.node,
  21. className: PropTypes.string,
  22. spacing: PropTypes.oneOfType([PropTypes.number, PropTypes.array]),
  23. style: PropTypes.object,
  24. type: PropTypes.oneOf(strings.TYPE)
  25. };
  26. static defaultProps = {
  27. spacing: 16
  28. };
  29. render() {
  30. const {
  31. children,
  32. className,
  33. spacing,
  34. style,
  35. type,
  36. ...others
  37. } = this.props;
  38. const isGrid = type === 'grid';
  39. const cardGroupCls = cls(`${prefixcls}-group`, className, {
  40. [`${prefixcls}-group-grid`]: isGrid
  41. });
  42. return (
  43. <Space
  44. spacing={isGrid ? 0 : spacing}
  45. wrap={true}
  46. className={cardGroupCls}
  47. style={style}
  48. {...others}
  49. >
  50. {children}
  51. </Space>
  52. );
  53. }
  54. }
  55. export default CardGroup;