-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathTip.jsx.js
More file actions
152 lines (146 loc) · 5.98 KB
/
Copy pathTip.jsx.js
File metadata and controls
152 lines (146 loc) · 5.98 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/**
* 提示
* @author Brian Li
* @email lbxxlht@163.com
* @version 0.0.2.2
*/
define(function (require) {
var React = require('react');
var util = require('./core/util');
var Layer = require('./Layer.jsx');
var cTools = require('./core/componentTools');
return React.createClass({
/**
* @properties
* @param {Import|Properties} src\core\componentTools.js skin className style disabled
* @param {String} title 弹出提示的标题
* @param {String} content 弹出提示的内容,可以含有html标签
* @param {String} icon 提示组件外部显示的图标,具体见src/css/icon/variable.less
* @param {ReactClass} renderer Tip内部渲染的组件,如果指定,icon属性无效
* @param {Object} renderProps Tip内部组件渲染的属性集
* @param {String} layerLocation 浮层的定位配置,具体见src\core\layerTools.js
* @param {Function} contentFactory 浮层展开前,可以通过此属性方法获取新的content
* @param {Function} onOffset 浮层位置修正回调
* @param {Function} layerClassName 浮层的自定义样式
*/
/**
* @fire Import src\Layer.jsx.js layer onOffset
*/
// @override
contextTypes: {
appSkin: React.PropTypes.string
},
// @override
getDefaultProps: function () {
return {
// base
skin: '',
className: '',
style: {},
disabled: false,
// self
title: '',
content: '',
icon: 'fcui2-icon fcui2-icon-question',
renderer: null,
renderProps: {},
layerLocation: 'right left top bottom',
contentFactory: null,
onOffset: null,
layerClassName: ''
};
},
getInitialState: function () {
return {
layerOpen: false,
mouseenter: false,
outerContent: null
};
},
onMouseEnter: function () {
if (typeof this.props.contentFactory === 'function' && this.state.outerContent == null) {
var result = this.props.contentFactory(this);
if (typeof result === 'string' && result.length) {
this.setState({
outerContent: result,
mouseenter: true,
layerOpen: true
});
return;
}
if (result && typeof result.then === 'function') {
var me = this;
result.then(function (content) {
me.setState({
outerContent: typeof content === 'string' && content.length ? content : null,
mouseenter: true,
layerOpen: true
});
});
return;
}
}
this.setState({
mouseenter: true,
layerOpen: true
});
},
onMouseLeave: function () {
this.setState({mouseenter: false});
cTools.closeLayerHandlerFactory(this, 'layerOpen')();
},
offsetLayerPosition: function (result) {
if (typeof this.props.onOffset === 'function') {
this.props.onOffset(result);
return;
}
if (typeof this.props.renderer === 'function') return;
result.left += '1_6_'.indexOf(result.clockPosition + '_') > -1 ? 25 : -15;
result.top += '12_1_'.indexOf(result.clockPosition + '_') > -1 ? -8 : 10;
},
render: function () {
var containerProp = cTools.containerBaseProps('tip', this, {
merge: {
onMouseEnter: this.onMouseEnter,
onMouseLeave: this.onMouseLeave
},
style: (this.props.title || this.props.content) ? undefined : {display: 'none'}
});
var skin = (this.context.appSkin ? this.context.appSkin + '-' : '')
+ (this.props.skin ? this.props.skin : 'normal');
var content = this.props.content;
content = this.state.outerContent == null ? content : this.state.outerContent;
var layerProp = {
ref: 'layer',
isOpen: this.state.layerOpen && (this.props.title || content) && !this.props.disabled,
anchor: this.refs.container,
location: this.props.layerLocation,
onOffset: this.offsetLayerPosition,
onMouseLeave: this.onMouseLeave,
skin: skin === 'oneux3-normal' ? 'normal' : skin
};
var Renderer = this.props.renderer;
containerProp.className += typeof Renderer === 'function' ? '' : ' font-icon ' + this.props.icon;
var layerClassName = [
'fcui2-tip-layer',
'fcui2-tip-layer-' + skin,
this.props.layerClassName ? this.props.layerClassName : ''
].join(' ');
return (
<div {...containerProp}>
{typeof Renderer === 'function' ? <Renderer {...this.props.renderProps}/> : null}
<Layer {...layerProp}>
<div className={layerClassName}>
{this.props.title ? <div className="tip-title">{this.props.title}</div> : null}
{
content
? <div className="tip-content" dangerouslySetInnerHTML={{__html: content}}></div>
: null
}
</div>
</Layer>
</div>
);
}
});
});