textLineComponent.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import * as React from "react";
  2. interface ITextLineComponentProps {
  3. label?: string;
  4. value?: string;
  5. color?: string;
  6. underline?: boolean;
  7. onLink?: () => void;
  8. url?: string;
  9. ignoreValue?: boolean;
  10. additionalClass?: string;
  11. }
  12. export class TextLineComponent extends React.Component<ITextLineComponentProps> {
  13. constructor(props: ITextLineComponentProps) {
  14. super(props);
  15. }
  16. onLink() {
  17. if (this.props.url) {
  18. window.open(this.props.url, '_blank');
  19. return;
  20. }
  21. if (!this.props.onLink) {
  22. return;
  23. }
  24. this.props.onLink();
  25. }
  26. renderContent() {
  27. if (this.props.ignoreValue) {
  28. return null;
  29. }
  30. if (this.props.onLink || this.props.url) {
  31. return (
  32. <div className="link-value" title={this.props.value} onClick={() => this.onLink()}>
  33. {this.props.url ? "doc" : (this.props.value || "no name")}
  34. </div>
  35. )
  36. }
  37. return (
  38. <div className="value" title={this.props.value} style={{ color: this.props.color ? this.props.color : "" }}>
  39. {this.props.value || "no name"}
  40. </div>
  41. )
  42. }
  43. render() {
  44. return (
  45. <div className={this.props.underline ? "textLine underline" : "textLine" + (this.props.additionalClass ? " " + this.props.additionalClass : "")}>
  46. <div className="label" title={this.props.label ?? ""}>
  47. {this.props.label ?? ""}
  48. </div>
  49. {this.renderContent()}
  50. </div>
  51. );
  52. }
  53. }