index.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import React from 'react';
  2. import BaseComponent, { BaseProps } from '../_base/baseComponent';
  3. import { cssClasses } from '@douyinfe/semi-foundation/scrollList/constants';
  4. import classnames from 'classnames';
  5. import propTypes from 'prop-types';
  6. import ScrollItem from './scrollItem';
  7. import Foundation from '@douyinfe/semi-foundation/scrollList/foundation';
  8. import '@douyinfe/semi-foundation/scrollList/scrollList.scss';
  9. export type { ScrollItemProps } from './scrollItem';
  10. export interface ScrollListProps extends BaseProps {
  11. header?: React.ReactNode;
  12. footer?: React.ReactNode;
  13. children?: React.ReactNode;
  14. bodyHeight?: number | string;
  15. prefixCls?: string
  16. }
  17. // eslint-disable-next-line @typescript-eslint/ban-types
  18. class ScrollList extends BaseComponent<ScrollListProps, {}> {
  19. static Item = ScrollItem;
  20. static propTypes = {
  21. className: propTypes.string,
  22. header: propTypes.node,
  23. footer: propTypes.node,
  24. children: propTypes.node,
  25. bodyHeight: propTypes.oneOfType([propTypes.number, propTypes.string]),
  26. };
  27. constructor(props: ScrollListProps) {
  28. super(props);
  29. this.foundation = new Foundation(this.adapter);
  30. }
  31. render() {
  32. const { children, header, footer, prefixCls, bodyHeight, className, style } = this.props;
  33. const clsWrapper = classnames(className, {
  34. [prefixCls || cssClasses.PREFIX]: true,
  35. });
  36. const clsHeader = classnames({
  37. [`${prefixCls || cssClasses.PREFIX}-header`]: true,
  38. });
  39. return (
  40. <div className={clsWrapper} style={style}>
  41. {header ? (
  42. <div className={clsHeader}>
  43. <div
  44. className={`${clsHeader}-title`}
  45. x-semi-prop={this.props['x-semi-header-alias'] || "header"}
  46. >
  47. {header}
  48. </div>
  49. <div className={`${clsWrapper}-line`} />
  50. </div>
  51. ) : null}
  52. <div
  53. className={`${clsWrapper}-body`}
  54. style={{ height: bodyHeight ? bodyHeight : '' }}
  55. x-semi-prop="children"
  56. >
  57. {children}
  58. </div>
  59. {footer ? (
  60. <div
  61. className={`${clsWrapper}-footer`}
  62. x-semi-prop={this.props['x-semi-footer-alias'] || "footer"}
  63. >
  64. {footer}
  65. </div>
  66. ) : null}
  67. </div>
  68. );
  69. }
  70. }
  71. export default ScrollList;