---
+0.3.0 / 2015-11-17
+------------------
+
+`update` remove TimePanel and merge it to TimePicker.
+
0.2.0 / 2015-11-16
------------------
API
---
-### TimePanel
+### TimePicker
| Name | Type | Default | Description |
|---------------|----------------------------|-----------------------------------------------|-----------------------------------------------|
| prefixCls | String | | prefixCls of this component |
| locale | Object | import from 'rc-time-picker/lib/locale/en_US' | |
-| defaultValue | GregorianCalendar | null | defaultValue like input's defaultValue |
+| disabled | Boolean | false | whether picker is disabled |
+| open | Boolean | false | current open state of picker. controlled prop |
+| value | GregorianCalendar | null | current value like input's value |
| placeholder | String | '' | time input's placeholder |
| formatter | GregorianCalendarFormatter | HH:mm:ss or HH:mm or mm:ss | |
| hourOptions | Array<String> | hour options | |
| minuteOptions | Array<String> | minute options | |
| secondOptions | Array<String> | second options | |
-| onChange | Function | null | called when input or select a different value |
-
-### TimePicker
-
-| Name | Type | Default | Description |
-|-----------|-------------------------|---------|-----------------------------------------------|
-| prefixCls | String | | prefixCls of this component |
-| panel | TimePanel React Element | | |
-| disabled | Boolean | false | whether picker is disabled |
-| open | Boolean | false | current open state of picker. controlled prop |
-| value | GregorianCalendar | null | current value like input's value |
-| onChange | Function | null | called when select a different value |
-| onOpen | Function | null | called when open picker |
-| onClose | Function | null | called when close picker |
+| onChange | Function | null | called when select a different value |
+| onOpen | Function | null | called when open picker |
+| onClose | Function | null | called when close picker |
License
-------
import zhCn from 'gregorian-calendar/lib/locale/zh_CN';
import TimePicker from 'rc-time-picker/src/TimePicker';
-import TimePanel from 'rc-time-picker/src/TimePanel';
import TimePickerLocale from 'rc-time-picker/src/locale/zh_CN';
const formatter = new DateTimeFormat('HH:mm:ss');
const now = new GregorianCalendar(zhCn);
now.setTime(Date.now());
-const timePanel = (
- <TimePanel
- defaultValue={now}
- locale={TimePickerLocale}
- formatter={formatter}
- minuteOptions={[0, 30]}
- />
-);
-
ReactDom.render(
- <TimePicker panel={timePanel} value={now}>
- {
- ({value}) => {
- return <input type="text" placeholder="请选择时间" readOnly value={value && formatter.format(value)} />;
- }
- }
- </TimePicker>,
+ <TimePicker formatter={formatter} locale={TimePickerLocale} value={now} />,
document.getElementById('__react-content')
);
{
"name": "rc-time-picker",
- "version": "0.2.0",
+ "version": "0.3.0",
"description": "React TimePicker",
"keywords": [
"react",
import ReactDOM from 'react-dom';
import Trigger from 'rc-trigger';
import {createChainedFunction} from 'rc-util';
+import Panel from 'rc-time-picker/src/module/Panel';
import placements from './util/placements';
import CommonMixin from './mixin/CommonMixin';
const Picker = React.createClass({
propTypes: {
prefixCls: PropTypes.string,
- panel: PropTypes.element,
+ locale: PropTypes.object,
children: PropTypes.func,
disabled: PropTypes.bool,
value: PropTypes.object,
align: PropTypes.object,
placement: PropTypes.any,
transitionName: PropTypes.string,
+ placeholder: PropTypes.string,
+ formatter: PropTypes.object,
+ hourOptions: PropTypes.array,
+ minuteOptions: PropTypes.array,
+ secondOptions: PropTypes.array,
onChange: PropTypes.func,
onOpen: PropTypes.func,
onClose: PropTypes.func,
},
onPanelClear() {
- this.setOpen(false, this.focus);
+ this.setOpen(false);
},
onVisibleChange(open) {
this.setOpen(open, () => {
if (open) {
+ ReactDOM.findDOMNode(this.refs.picker).blur();
ReactDOM.findDOMNode(this.panelInstance).focus();
}
});
},
+ getPanel() {
+ const { value, locale, formatter, placeholder, hourOptions, minuteOptions, secondOptions } = this.props;
+ return (
+ <Panel
+ defaultValue={value}
+ locale={locale}
+ formatter={formatter}
+ placeholder={placeholder}
+ hourOptions={hourOptions}
+ minuteOptions={minuteOptions}
+ secondOptions={secondOptions}
+ />
+ );
+ },
+
getPanelElement() {
- const panel = this.props.panel;
+ const panel = this.getPanel();
const extraProps = {
ref: this.savePanelRef,
defaultValue: this.state.value || panel.props.defaultValue,
}
},
- focus() {
- if (!this.state.open) {
- ReactDOM.findDOMNode(this).focus();
- }
- },
-
render() {
- const state = this.state;
- const props = this.props;
- const { prefixCls, placement, align, disabled, transitionName, children } = props;
+ const { prefixCls, placement, align, disabled, transitionName, children, formatter } = this.props;
+ const { open, value } = this.state;
+
return (
<Trigger
prefixCls={prefixCls}
action={disabled ? [] : ['click']}
destroyPopupOnHide
popupTransitionName={transitionName}
- popupVisible={state.open}
+ popupVisible={open}
onPopupVisibleChange={this.onVisibleChange}
>
<span className={`${prefixCls}-picker`}>
- {children(state, props)}
+ <input ref="picker" type="text" placeholder="请选择时间" readOnly disabled={disabled} value={value && formatter.format(value)} />
</span>
</Trigger>
);
import React, {PropTypes} from 'react';
import classnames from 'classnames';
-import CommonMixin from './mixin/CommonMixin';
-import Header from './module/Header';
-import Combobox from './module/Combobox';
+import GregorianCalendar from 'gregorian-calendar';
+import zhCn from 'gregorian-calendar/lib/locale/zh_CN';
+
+import CommonMixin from '../mixin/CommonMixin';
+import Header from './Header';
+import Combobox from './Combobox';
function noop() {
}
});
}
-const TimePanel = React.createClass({
+const Panel = React.createClass({
propTypes: {
prefixCls: PropTypes.string,
defaultValue: PropTypes.object,
},
getInitialState() {
+ let defaultValue = this.props.defaultValue;
+ if (!defaultValue) {
+ defaultValue = new GregorianCalendar(zhCn);
+ defaultValue.setTime(Date.now());
+ }
return {
- value: this.props.defaultValue,
+ value: defaultValue,
};
},
<div className={`${prefixCls}-panel ${cls}`}>
<Header
prefixCls={prefixCls}
- gregorianTimePickerLocale={defaultValue.locale}
+ gregorianTimePickerLocale={value.locale}
locale={locale}
value={value}
formatter={this.getFormatter()}
},
});
-export default TimePanel;
+export default Panel;