]> git.immae.eu Git - github/fretlink/time-picker.git/blobdiff - src/mixin/CommonMixin.js
release 0.1.0
[github/fretlink/time-picker.git] / src / mixin / CommonMixin.js
diff --git a/src/mixin/CommonMixin.js b/src/mixin/CommonMixin.js
new file mode 100644 (file)
index 0000000..4203a9e
--- /dev/null
@@ -0,0 +1,46 @@
+import {PropTypes} from 'react';
+import enUs from '../locale/en_US';
+import {getFormatter} from '../util/index';
+
+export default {
+  propTypes: {
+    prefixCls: PropTypes.string,
+    locale: PropTypes.object,
+  },
+
+  getDefaultProps() {
+    return {
+      prefixCls: 'rc-timepicker',
+      locale: enUs,
+    };
+  },
+
+  getFormatter() {
+    const formatter = this.props.formatter;
+    const locale = this.props.locale;
+    if (formatter) {
+      if (formatter === this.lastFormatter) {
+        return this.normalFormatter;
+      }
+      this.normalFormatter = getFormatter(formatter, locale);
+      this.lastFormatter = formatter;
+      return this.normalFormatter;
+    }
+    if (!this.showSecond) {
+      if (!this.notShowSecondFormatter) {
+        this.notShowSecondFormatter = getFormatter('HH:mm', locale);
+      }
+      return this.notShowSecondFormatter;
+    }
+    if (!this.showHour) {
+      if (!this.notShowHourFormatter) {
+        this.notShowHourFormatter = getFormatter('mm:ss', locale);
+      }
+      return this.notShowHourFormatter;
+    }
+    if (!this.normalFormatter) {
+      this.normalFormatter = getFormatter('HH:mm:ss', locale);
+    }
+    return this.normalFormatter;
+  },
+};