text.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import React, { PureComponent } from 'react';
  2. import PropTypes from 'prop-types';
  3. import { strings } from '@douyinfe/semi-foundation/typography/constants';
  4. import Base from './base';
  5. import { Ellipsis, TypographyBaseSize, TypographyBaseType, OmitTypographyProps } from './interface';
  6. import { CopyableConfig, LinkType } from './title';
  7. type OmitTextProps = OmitTypographyProps;
  8. export interface TextProps extends Omit<React.HTMLAttributes<HTMLSpanElement>, OmitTextProps> {
  9. children?: React.ReactNode;
  10. className?: string;
  11. code?: boolean;
  12. component?: React.ElementType;
  13. copyable?: CopyableConfig | boolean;
  14. delete?: boolean;
  15. disabled?: boolean;
  16. ellipsis?: Ellipsis | boolean;
  17. icon?: React.ReactNode | string;
  18. link?: LinkType;
  19. mark?: boolean;
  20. size?: TypographyBaseSize;
  21. strong?: boolean;
  22. style?: React.CSSProperties;
  23. type?: TypographyBaseType;
  24. underline?: boolean;
  25. }
  26. export default class Text extends PureComponent<TextProps> {
  27. static propTypes = {
  28. copyable: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]),
  29. delete: PropTypes.bool,
  30. disabled: PropTypes.bool,
  31. icon: PropTypes.oneOfType([PropTypes.node, PropTypes.string]),
  32. ellipsis: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]),
  33. mark: PropTypes.bool,
  34. underline: PropTypes.bool,
  35. link: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]),
  36. strong: PropTypes.bool,
  37. type: PropTypes.oneOf(strings.TYPE),
  38. size: PropTypes.oneOf(strings.SIZE),
  39. style: PropTypes.object,
  40. className: PropTypes.string,
  41. code: PropTypes.bool,
  42. component: PropTypes.string,
  43. };
  44. static defaultProps = {
  45. copyable: false,
  46. delete: false,
  47. disabled: false,
  48. icon: '',
  49. // editable: false,
  50. ellipsis: false,
  51. mark: false,
  52. underline: false,
  53. strong: false,
  54. link: false,
  55. type: 'primary',
  56. style: {},
  57. size: 'normal',
  58. className: '',
  59. };
  60. render() {
  61. return <Base component={'span'} {...this.props} />;
  62. }
  63. }