aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/mixin/CommonMixin.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/mixin/CommonMixin.js')
-rw-r--r--src/mixin/CommonMixin.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/mixin/CommonMixin.js b/src/mixin/CommonMixin.js
new file mode 100644
index 0000000..4203a9e
--- /dev/null
+++ b/src/mixin/CommonMixin.js
@@ -0,0 +1,46 @@
1import {PropTypes} from 'react';
2import enUs from '../locale/en_US';
3import {getFormatter} from '../util/index';
4
5export default {
6 propTypes: {
7 prefixCls: PropTypes.string,
8 locale: PropTypes.object,
9 },
10
11 getDefaultProps() {
12 return {
13 prefixCls: 'rc-timepicker',
14 locale: enUs,
15 };
16 },
17
18 getFormatter() {
19 const formatter = this.props.formatter;
20 const locale = this.props.locale;
21 if (formatter) {
22 if (formatter === this.lastFormatter) {
23 return this.normalFormatter;
24 }
25 this.normalFormatter = getFormatter(formatter, locale);
26 this.lastFormatter = formatter;
27 return this.normalFormatter;
28 }
29 if (!this.showSecond) {
30 if (!this.notShowSecondFormatter) {
31 this.notShowSecondFormatter = getFormatter('HH:mm', locale);
32 }
33 return this.notShowSecondFormatter;
34 }
35 if (!this.showHour) {
36 if (!this.notShowHourFormatter) {
37 this.notShowHourFormatter = getFormatter('mm:ss', locale);
38 }
39 return this.notShowHourFormatter;
40 }
41 if (!this.normalFormatter) {
42 this.normalFormatter = getFormatter('HH:mm:ss', locale);
43 }
44 return this.normalFormatter;
45 },
46};