Section.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import React from 'react';
  2. import { BareProps } from '@polkadot/react-components/types';
  3. import styled from 'styled-components';
  4. const Header = styled.div`
  5. display: flex;
  6. width: 100%;
  7. justify-content: space-between;
  8. align-items: flex-end;
  9. margin-bottom: ${(props: { withPagination: boolean }) => props.withPagination ? '1rem' : 0};
  10. flex-wrap: wrap;
  11. `;
  12. const Title = styled.div`
  13. flex-grow: 1;
  14. `;
  15. const ResponsivePagination = styled.div`
  16. @media screen and (max-width: 767px) {
  17. & a[type=firstItem],
  18. & a[type=lastItem] {
  19. display: none !important;
  20. }
  21. & a {
  22. font-size: 0.8rem !important;
  23. }
  24. }
  25. `;
  26. const TopPagination = styled(ResponsivePagination)`
  27. margin-left: auto;
  28. `;
  29. const BottomPagination = styled(ResponsivePagination)`
  30. display: flex;
  31. justify-content: flex-end;
  32. `;
  33. type Props = BareProps & {
  34. className?: string;
  35. title?: JSX.Element | string;
  36. level?: number;
  37. pagination?: JSX.Element;
  38. };
  39. export default class Section extends React.PureComponent<Props> {
  40. render () {
  41. let { className, children, pagination } = this.props;
  42. className = (className || '') + ' JoySection';
  43. return (
  44. <section className={className}>
  45. <Header withPagination={ Boolean(pagination) }>
  46. <Title>{this.renderTitle()}</Title>
  47. { pagination && <TopPagination>{ pagination }</TopPagination> }
  48. </Header>
  49. <div>{children}</div>
  50. { pagination && <BottomPagination>{ pagination }</BottomPagination> }
  51. </section>
  52. );
  53. }
  54. private renderTitle = () => {
  55. const { title, level = 2, pagination } = this.props;
  56. if (!title) return null;
  57. const className = 'JoySection-title';
  58. const style = pagination ? { margin: '0' } : {};
  59. return React.createElement(
  60. `h${level}`,
  61. { className, style },
  62. title
  63. );
  64. }
  65. }