cardGroup.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. children?: React.ReactNode;
  12. /** Card Spacing */
  13. spacing?: number | number[];
  14. /** Card group inline style */
  15. style?: React.CSSProperties;
  16. /** Card set type */
  17. type?: CardGroupType;
  18. }
  19. class CardGroup extends PureComponent<CardGroupProps> {
  20. static propTypes = {
  21. children: PropTypes.node,
  22. className: PropTypes.string,
  23. spacing: PropTypes.oneOfType([PropTypes.number, PropTypes.array]),
  24. style: PropTypes.object,
  25. type: PropTypes.oneOf(strings.TYPE)
  26. };
  27. static defaultProps = {
  28. spacing: 16
  29. };
  30. render() {
  31. const {
  32. children,
  33. className,
  34. spacing,
  35. style,
  36. type,
  37. ...others
  38. } = this.props;
  39. const isGrid = type === 'grid';
  40. const cardGroupCls = cls(`${prefixcls}-group`, className, {
  41. [`${prefixcls}-group-grid`]: isGrid
  42. });
  43. return (
  44. <Space
  45. spacing={isGrid ? 0 : spacing}
  46. wrap={true}
  47. className={cardGroupCls}
  48. style={style}
  49. {...others}
  50. >
  51. {children}
  52. </Space>
  53. );
  54. }
  55. }
  56. export default CardGroup;