paragraph.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import React, { PureComponent } from 'react';
  2. import PropTypes from 'prop-types';
  3. import cls from 'classnames';
  4. import { strings, cssClasses } from '@douyinfe/semi-foundation/typography/constants';
  5. import Base from './base';
  6. import {
  7. Ellipsis,
  8. TypographyBaseSize,
  9. TypographyBaseSpacing,
  10. TypographyBaseType,
  11. OmitTypographyProps
  12. } from './interface';
  13. import { CopyableConfig, LinkType } from './title';
  14. type OmitParagraphProps = OmitTypographyProps;
  15. export interface ParagraphProps extends Omit<React.HTMLAttributes<HTMLParagraphElement>, OmitParagraphProps>{
  16. className?: string;
  17. component?: React.ElementType;
  18. copyable?: CopyableConfig | boolean;
  19. delete?: boolean;
  20. disabled?: boolean;
  21. ellipsis?: Ellipsis | boolean;
  22. link?: LinkType;
  23. mark?: boolean;
  24. size?: TypographyBaseSize;
  25. spacing?: TypographyBaseSpacing;
  26. strong?: boolean;
  27. style?: React.CSSProperties;
  28. type?: TypographyBaseType;
  29. underline?: boolean;
  30. }
  31. const prefixCls = cssClasses.PREFIX;
  32. export default class Paragraph extends PureComponent<ParagraphProps> {
  33. static propTypes = {
  34. copyable: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]),
  35. delete: PropTypes.bool,
  36. disabled: PropTypes.bool,
  37. // editable: PropTypes.bool,
  38. ellipsis: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]),
  39. mark: PropTypes.bool,
  40. link: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]),
  41. underline: PropTypes.bool,
  42. strong: PropTypes.bool,
  43. type: PropTypes.oneOf(strings.TYPE),
  44. size: PropTypes.oneOf(strings.SIZE),
  45. spacing: PropTypes.oneOf(strings.SPACING),
  46. style: PropTypes.object,
  47. className: PropTypes.string,
  48. component: PropTypes.string,
  49. };
  50. static defaultProps = {
  51. copyable: false,
  52. delete: false,
  53. disabled: false,
  54. // editable: false,
  55. ellipsis: false,
  56. mark: false,
  57. underline: false,
  58. strong: false,
  59. link: false,
  60. type: 'primary',
  61. size: 'normal',
  62. spacing: 'normal',
  63. style: {},
  64. className: '',
  65. };
  66. render() {
  67. const { className } = this.props;
  68. const paragraphCls = cls(className, `${prefixCls}-paragraph`);
  69. return <Base component={'p'} {...this.props} className={paragraphCls} />;
  70. }
  71. }