4
4
* See the accompanying LICENSE file for terms.
5
5
*/
6
6
7
- import React , { Component , PropTypes } from 'react' ;
7
+ import { Component , PropTypes , createElement } from 'react' ;
8
8
import { intlShape , dateTimeFormatPropTypes } from '../types' ;
9
9
import { invariantIntlContext , shouldIntlComponentUpdate } from '../utils' ;
10
10
@@ -20,15 +20,20 @@ export default class FormattedDate extends Component {
20
20
21
21
render ( ) {
22
22
const { formatDate} = this . context . intl ;
23
- const { value, children} = this . props ;
23
+ const { value,
24
+ children,
25
+ tagName,
26
+ tagProps,
27
+ } = this . props ;
24
28
25
29
let formattedDate = formatDate ( value , this . props ) ;
26
30
27
31
if ( typeof children === 'function' ) {
28
32
return children ( formattedDate ) ;
29
33
}
30
34
31
- return < span > { formattedDate } </ span > ;
35
+ return createElement ( tagName , tagProps , formattedDate ) ;
36
+
32
37
}
33
38
}
34
39
@@ -40,7 +45,17 @@ FormattedDate.contextTypes = {
40
45
41
46
FormattedDate . propTypes = {
42
47
...dateTimeFormatPropTypes ,
43
- value : PropTypes . any . isRequired ,
44
- format : PropTypes . string ,
45
48
children : PropTypes . func ,
49
+ format : PropTypes . string ,
50
+ tagName : PropTypes . oneOfType ( [
51
+ PropTypes . string ,
52
+ PropTypes . func ,
53
+ ] ) ,
54
+ tagProps : PropTypes . object ,
55
+ value : PropTypes . any . isRequired ,
56
+ } ;
57
+
58
+ FormattedDate . defaultProps = {
59
+ tagName : 'span' ,
60
+ tagProps : null ,
46
61
} ;
0 commit comments