This repository has been archived by the owner on May 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathindex.jsx
91 lines (84 loc) · 2.84 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import React, { Component } from "react";
import PropTypes from "prop-types";
import "./style.less";
import Tooltip from "../Tooltip";
class TextOverflowWrapper extends Component {
constructor() {
super();
this.uniqueId = "overflowTooltip-" + (Date.now() * Math.random());
this.state = {
itemWidth: 0
};
this.overflowTooltipRef = React.createRef();
}
getStyle() {
const {props} = this;
return Object.assign({ maxWidth: props.maxWidth }, props.style);
}
componentDidMount() {
//Set time out to ensure calculation happens after render
this.timerId = setTimeout(() => {
let input = this.overflowTooltipRef;
if (typeof input !== "undefined" && input.current.getBoundingClientRect()) {
let inputRect = input.current.getBoundingClientRect();
this.setState({
itemWidth: inputRect.width
});
} else {
this.setState({
itemWidth: this.props.maxWidth
});
}
}, 500);
}
componentWillUnmount() {
clearTimeout(this.timerId);
}
render() {
const {props, state} = this;
return (
<div
className={"dnn-text-overflow-wrapper" + (props.className ? " " + props.className : "")}
style={this.getStyle()}
ref={this.overflowTooltipRef}
data-tip
data-for={this.uniqueId}
title={props.doNotUseTitleAttribute ? "" : props.text}>
{!props.isAnchor && props.text}
{props.isAnchor && <a href={props.href} target={props.target}>{props.text}</a>}
{props.doNotUseTitleAttribute && state.itemWidth >= props.maxWidth && <Tooltip
key={this.uniqueId}
tooltipPlace={props.place}
type={props.type}
className={"overflow-tooltip" + (props.tooltipClassName ? " " + props.tooltipClassName : "")}
messages={[props.text]}
style={props.style}
tooltipStyle={props.tooltipStyle}
/>
}
</div>
);
}
}
TextOverflowWrapper.propTypes = {
text: PropTypes.string,
maxWidth: PropTypes.number,
style: PropTypes.object,
effect: PropTypes.string,
type: PropTypes.string,
place: PropTypes.string,
tooltipClassName: PropTypes.string,
multiline: PropTypes.bool,
doNotUseTitleAttribute: PropTypes.bool,
isAnchor: PropTypes.bool,
href: PropTypes.string,
target: PropTypes.string
};
TextOverflowWrapper.defaultProps = {
maxWidth: 200,
effect: "solid",
place: "top",
type: "info",
multiline: true
};
export default TextOverflowWrapper;