From 04de55f8a50f58575ccda435ba62edfca1d4a5e4 Mon Sep 17 00:00:00 2001 From: yiminghe Date: Wed, 13 Jul 2016 20:21:06 +0800 Subject: add default prefixCls for panel --- src/TimePicker.jsx | 1 + src/mixin/CommonMixin.js | 1 - src/module/Panel.jsx | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/TimePicker.jsx b/src/TimePicker.jsx index 350eeb2..86faa71 100644 --- a/src/TimePicker.jsx +++ b/src/TimePicker.jsx @@ -45,6 +45,7 @@ const Picker = React.createClass({ getDefaultProps() { return { + prefixCls: 'rc-time-picker', defaultOpen: false, style: {}, className: '', diff --git a/src/mixin/CommonMixin.js b/src/mixin/CommonMixin.js index a6893b8..be080fd 100644 --- a/src/mixin/CommonMixin.js +++ b/src/mixin/CommonMixin.js @@ -9,7 +9,6 @@ export default { getDefaultProps() { return { - prefixCls: 'rc-time-picker', locale: enUs, }; }, diff --git a/src/module/Panel.jsx b/src/module/Panel.jsx index 4c3d071..137ec2f 100644 --- a/src/module/Panel.jsx +++ b/src/module/Panel.jsx @@ -40,6 +40,7 @@ const Panel = React.createClass({ getDefaultProps() { return { + prefixCls: 'rc-time-picker-panel', onChange: noop, onClear: noop, }; -- cgit v1.2.3 From 4984ed85e54f442998a335db70618d6184fa397e Mon Sep 17 00:00:00 2001 From: yiminghe Date: Thu, 4 Aug 2016 19:53:55 +0800 Subject: 2.x :boom: --- src/Combobox.jsx | 125 +++++++++++++++++++++++++++++ src/Header.jsx | 175 ++++++++++++++++++++++++++++++++++++++++ src/Panel.jsx | 136 +++++++++++++++++++++++++++++++ src/Select.jsx | 105 ++++++++++++++++++++++++ src/TimePicker.jsx | 64 ++++++--------- src/locale/en_US.js | 8 -- src/locale/ru_RU.js | 8 -- src/locale/zh_CN.js | 8 -- src/mixin/CommonMixin.js | 15 ---- src/module/Combobox.jsx | 141 -------------------------------- src/module/Header.jsx | 204 ----------------------------------------------- src/module/Panel.jsx | 130 ------------------------------ src/module/Select.jsx | 97 ---------------------- src/placements.js | 35 ++++++++ src/util/index.js | 8 -- src/util/placements.js | 35 -------- src/util/selection.js | 17 ---- 17 files changed, 602 insertions(+), 709 deletions(-) create mode 100644 src/Combobox.jsx create mode 100644 src/Header.jsx create mode 100644 src/Panel.jsx create mode 100644 src/Select.jsx delete mode 100644 src/locale/en_US.js delete mode 100644 src/locale/ru_RU.js delete mode 100644 src/locale/zh_CN.js delete mode 100644 src/mixin/CommonMixin.js delete mode 100644 src/module/Combobox.jsx delete mode 100644 src/module/Header.jsx delete mode 100644 src/module/Panel.jsx delete mode 100644 src/module/Select.jsx create mode 100644 src/placements.js delete mode 100644 src/util/index.js delete mode 100644 src/util/placements.js delete mode 100644 src/util/selection.js (limited to 'src') diff --git a/src/Combobox.jsx b/src/Combobox.jsx new file mode 100644 index 0000000..9d9da16 --- /dev/null +++ b/src/Combobox.jsx @@ -0,0 +1,125 @@ +import React, { PropTypes } from 'react'; +import Select from './Select'; + +const formatOption = (option, disabledOptions) => { + let value = `${option}`; + if (option < 10) { + value = `0${option}`; + } + + let disabled = false; + if (disabledOptions && disabledOptions.indexOf(option) >= 0) { + disabled = true; + } + + return { + value, + disabled, + }; +}; + +const Combobox = React.createClass({ + propTypes: { + format: PropTypes.string, + defaultOpenValue: PropTypes.object, + prefixCls: PropTypes.string, + value: PropTypes.object, + onChange: PropTypes.func, + showHour: PropTypes.bool, + showSecond: PropTypes.bool, + hourOptions: PropTypes.array, + minuteOptions: PropTypes.array, + secondOptions: PropTypes.array, + disabledHours: PropTypes.func, + disabledMinutes: PropTypes.func, + disabledSeconds: PropTypes.func, + onCurrentSelectPanelChange: PropTypes.func, + }, + + onItemChange(type, itemValue) { + const { onChange, defaultOpenValue } = this.props; + const value = (this.props.value || defaultOpenValue).clone(); + if (type === 'hour') { + value.hour(itemValue); + } else if (type === 'minute') { + value.minute(itemValue); + } else { + value.second(itemValue); + } + onChange(value); + }, + + onEnterSelectPanel(range) { + this.props.onCurrentSelectPanelChange(range); + }, + + getHourSelect(hour) { + const { prefixCls, hourOptions, disabledHours, showHour } = this.props; + if (!showHour) { + return null; + } + const disabledOptions = disabledHours(); + + return ( + formatOption(option, disabledOptions))} + selectedIndex={minuteOptions.indexOf(minute)} + type="minute" + onSelect={this.onItemChange} + onMouseEnter={this.onEnterSelectPanel.bind(this, 'minute')} + /> + ); + }, + + getSecondSelect(second) { + const { prefixCls, secondOptions, disabledSeconds, showSecond, defaultOpenValue } = this.props; + if (!showSecond) { + return null; + } + const value = this.props.value || defaultOpenValue; + const disabledOptions = disabledSeconds(value.hour(), value.minute()); + + return ( + ); + }, + + render() { + const { prefixCls } = this.props; + return ( +
+ {this.getInput()} + {this.getClearButton()} +
+ ); + }, +}); + +export default Header; diff --git a/src/Panel.jsx b/src/Panel.jsx new file mode 100644 index 0000000..f70cf38 --- /dev/null +++ b/src/Panel.jsx @@ -0,0 +1,136 @@ +import React, { PropTypes } from 'react'; +import Header from './Header'; +import Combobox from './Combobox'; +import moment from 'moment'; + +function noop() { +} + +function generateOptions(length, disabledOptions, hideDisabledOptions) { + const arr = []; + for (let value = 0; value < length; value++) { + if (!disabledOptions || disabledOptions.indexOf(value) < 0 || !hideDisabledOptions) { + arr.push(value); + } + } + return arr; +} + +const Panel = React.createClass({ + propTypes: { + clearText: PropTypes.string, + prefixCls: PropTypes.string, + defaultOpenValue: PropTypes.object, + value: PropTypes.object, + placeholder: PropTypes.string, + format: PropTypes.string, + disabledHours: PropTypes.func, + disabledMinutes: PropTypes.func, + disabledSeconds: PropTypes.func, + hideDisabledOptions: PropTypes.bool, + onChange: PropTypes.func, + onEsc: PropTypes.func, + allowEmpty: PropTypes.bool, + showHour: PropTypes.bool, + showSecond: PropTypes.bool, + onClear: PropTypes.func, + }, + + getDefaultProps() { + return { + prefixCls: 'rc-time-picker-panel', + onChange: noop, + onClear: noop, + defaultOpenValue: moment(), + }; + }, + + getInitialState() { + return { + value: this.props.value, + selectionRange: [], + }; + }, + + componentWillReceiveProps(nextProps) { + const value = nextProps.value; + if (value) { + this.setState({ + value, + }); + } + }, + + onChange(newValue) { + this.setState({ value: newValue }); + this.props.onChange(newValue); + }, + + onClear() { + this.props.onClear(); + }, + + onCurrentSelectPanelChange(currentSelectPanel) { + this.setState({ currentSelectPanel }); + }, + + render() { + const { + prefixCls, placeholder, disabledHours, disabledMinutes, + disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showSecond, + format, defaultOpenValue, clearText, onEsc, + } = this.props; + const { + value, currentSelectPanel, + } = this.state; + const disabledHourOptions = disabledHours(); + const disabledMinuteOptions = disabledMinutes(value ? value.hour() : null); + const disabledSecondOptions = disabledSeconds(value ? value.hour() : null, + value ? value.minute() : null); + const hourOptions = generateOptions(24, disabledHourOptions, hideDisabledOptions); + const minuteOptions = generateOptions(60, disabledMinuteOptions, hideDisabledOptions); + const secondOptions = generateOptions(60, disabledSecondOptions, hideDisabledOptions); + + return ( +
+
+ +
+ ); + }, +}); + +export default Panel; diff --git a/src/Select.jsx b/src/Select.jsx new file mode 100644 index 0000000..e25bb29 --- /dev/null +++ b/src/Select.jsx @@ -0,0 +1,105 @@ +import React, { PropTypes } from 'react'; +import ReactDom from 'react-dom'; +import classnames from 'classnames'; + +const scrollTo = (element, to, duration) => { + const requestAnimationFrame = window.requestAnimationFrame || + function requestAnimationFrameTimeout() { + return setTimeout(arguments[0], 10); + }; + // jump to target if duration zero + if (duration <= 0) { + element.scrollTop = to; + return; + } + const difference = to - element.scrollTop; + const perTick = difference / duration * 10; + + requestAnimationFrame(() => { + element.scrollTop = element.scrollTop + perTick; + if (element.scrollTop === to) return; + scrollTo(element, to, duration - 10); + }); +}; + +const Select = React.createClass({ + propTypes: { + prefixCls: PropTypes.string, + options: PropTypes.array, + selectedIndex: PropTypes.number, + type: PropTypes.string, + onSelect: PropTypes.func, + onMouseEnter: PropTypes.func, + }, + + componentDidMount() { + // jump to selected option + this.scrollToSelected(0); + }, + + componentDidUpdate(prevProps) { + // smooth scroll to selected option + if (prevProps.selectedIndex !== this.props.selectedIndex) { + this.scrollToSelected(120); + } + }, + + onSelect(value) { + const { onSelect, type } = this.props; + onSelect(type, value); + }, + + getOptions() { + const { options, selectedIndex, prefixCls } = this.props; + return options.map((item, index) => { + const cls = classnames({ + [`${prefixCls}-select-option-selected`]: selectedIndex === index, + [`${prefixCls}-select-option-disabled`]: item.disabled, + }); + let onclick = null; + if (!item.disabled) { + onclick = this.onSelect.bind(this, +item.value); + } + return (
  • + {item.value} +
  • ); + }); + }, + + scrollToSelected(duration) { + // move to selected item + const select = ReactDom.findDOMNode(this); + const list = ReactDom.findDOMNode(this.refs.list); + let index = this.props.selectedIndex; + if (index < 0) { + index = 0; + } + const topOption = list.children[index]; + const to = topOption.offsetTop; + scrollTo(select, to, duration); + }, + + render() { + if (this.props.options.length === 0) { + return null; + } + + const { prefixCls } = this.props; + + return ( +
    +
      {this.getOptions()}
    +
    + ); + }, +}); + +export default Select; diff --git a/src/TimePicker.jsx b/src/TimePicker.jsx index 86faa71..58f6ea1 100644 --- a/src/TimePicker.jsx +++ b/src/TimePicker.jsx @@ -1,9 +1,8 @@ import React, { PropTypes } from 'react'; import Trigger from 'rc-trigger'; -import Panel from './module/Panel'; -import placements from './util/placements'; -import CommonMixin from './mixin/CommonMixin'; -import { getFormatter } from './util/index'; +import Panel from './Panel'; +import placements from './placements'; +import moment from 'moment'; function noop() { } @@ -15,8 +14,9 @@ function refFn(field, component) { const Picker = React.createClass({ propTypes: { prefixCls: PropTypes.string, - locale: PropTypes.object, + clearText: PropTypes.string, value: PropTypes.object, + defaultOpenValue: PropTypes.object, disabled: PropTypes.bool, allowEmpty: PropTypes.bool, defaultValue: PropTypes.object, @@ -27,7 +27,7 @@ const Picker = React.createClass({ transitionName: PropTypes.string, getPopupContainer: PropTypes.func, placeholder: PropTypes.string, - formatter: PropTypes.any, + format: PropTypes.string, showHour: PropTypes.bool, style: PropTypes.object, className: PropTypes.string, @@ -41,15 +41,15 @@ const Picker = React.createClass({ onClose: PropTypes.func, }, - mixins: [CommonMixin], - getDefaultProps() { return { + clearText: 'clear', prefixCls: 'rc-time-picker', defaultOpen: false, style: {}, className: '', align: {}, + defaultOpenValue: moment(), allowEmpty: true, showHour: true, showSecond: true, @@ -118,56 +118,40 @@ const Picker = React.createClass({ this.props.onChange(value); }, - 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; + getFormat() { + const format = this.props.format; + if (format) { + return format; } if (!this.props.showSecond) { - if (!this.notShowSecondFormatter) { - this.notShowSecondFormatter = getFormatter('HH:mm', locale); - } - return this.notShowSecondFormatter; + return 'HH:mm'; } if (!this.props.showHour) { - if (!this.notShowHourFormatter) { - this.notShowHourFormatter = getFormatter('mm:ss', locale); - } - return this.notShowHourFormatter; + return 'mm:ss'; } - if (!this.normalFormatter) { - this.normalFormatter = getFormatter('HH:mm:ss', locale); - } - return this.normalFormatter; + return 'HH:mm:ss'; }, getPanelElement() { const { - prefixCls, defaultValue, locale, placeholder, disabledHours, + prefixCls, placeholder, disabledHours, disabledMinutes, disabledSeconds, hideDisabledOptions, - allowEmpty, showHour, showSecond, + allowEmpty, showHour, showSecond, defaultOpenValue, clearText, } = this.props; return ( diff --git a/src/locale/en_US.js b/src/locale/en_US.js deleted file mode 100644 index 506f4c9..0000000 --- a/src/locale/en_US.js +++ /dev/null @@ -1,8 +0,0 @@ -import enUs from 'gregorian-calendar-format/lib/locale/en_US'; -import enUsCalendar from 'gregorian-calendar/lib/locale/en_US'; - -export default { - clear: 'Clear', - format: enUs, - calendar: enUsCalendar, -}; diff --git a/src/locale/ru_RU.js b/src/locale/ru_RU.js deleted file mode 100644 index 86746ea..0000000 --- a/src/locale/ru_RU.js +++ /dev/null @@ -1,8 +0,0 @@ -import ruRu from 'gregorian-calendar-format/lib/locale/ru_RU'; -import ruRuCalendar from 'gregorian-calendar/lib/locale/ru_RU'; - -export default { - clear: 'Очистить', - format: ruRu, - calendar: ruRuCalendar, -}; diff --git a/src/locale/zh_CN.js b/src/locale/zh_CN.js deleted file mode 100644 index 1e977be..0000000 --- a/src/locale/zh_CN.js +++ /dev/null @@ -1,8 +0,0 @@ -import zhCn from 'gregorian-calendar-format/lib/locale/zh_CN'; -import zhCnCalendar from 'gregorian-calendar/lib/locale/zh_CN'; - -export default { - clear: '清除', - format: zhCn, - calendar: zhCnCalendar, -}; diff --git a/src/mixin/CommonMixin.js b/src/mixin/CommonMixin.js deleted file mode 100644 index be080fd..0000000 --- a/src/mixin/CommonMixin.js +++ /dev/null @@ -1,15 +0,0 @@ -import {PropTypes} from 'react'; -import enUs from '../locale/en_US'; - -export default { - propTypes: { - prefixCls: PropTypes.string, - locale: PropTypes.object, - }, - - getDefaultProps() { - return { - locale: enUs, - }; - }, -}; diff --git a/src/module/Combobox.jsx b/src/module/Combobox.jsx deleted file mode 100644 index f1e7c5b..0000000 --- a/src/module/Combobox.jsx +++ /dev/null @@ -1,141 +0,0 @@ -import React, {PropTypes} from 'react'; -import Select from './Select'; -import GregorianCalendar from 'gregorian-calendar'; - -const formatOption = (option, disabledOptions) => { - let value = `${option}`; - if (option < 10) { - value = `0${option}`; - } - - let disabled = false; - if (disabledOptions && disabledOptions.indexOf(option) >= 0) { - disabled = true; - } - - return { - value, - disabled, - }; -}; - -const Combobox = React.createClass({ - propTypes: { - formatter: PropTypes.object, - prefixCls: PropTypes.string, - value: PropTypes.object, - onChange: PropTypes.func, - showHour: PropTypes.bool, - gregorianCalendarLocale: PropTypes.object, - showSecond: PropTypes.bool, - hourOptions: PropTypes.array, - minuteOptions: PropTypes.array, - secondOptions: PropTypes.array, - disabledHours: PropTypes.func, - disabledMinutes: PropTypes.func, - disabledSeconds: PropTypes.func, - onCurrentSelectPanelChange: PropTypes.func, - }, - - onItemChange(type, itemValue) { - const { onChange } = this.props; - let value = this.props.value; - if (value) { - value = value.clone(); - } else { - value = this.getNow().clone(); - } - if (type === 'hour') { - value.setHourOfDay(itemValue); - } else if (type === 'minute') { - value.setMinutes(itemValue); - } else { - value.setSeconds(itemValue); - } - onChange(value); - }, - - onEnterSelectPanel(range) { - this.props.onCurrentSelectPanelChange(range); - }, - - getHourSelect(hour) { - const { prefixCls, hourOptions, disabledHours, showHour } = this.props; - if (!showHour) { - return null; - } - const disabledOptions = disabledHours(); - - return ( - formatOption(option, disabledOptions))} - selectedIndex={minuteOptions.indexOf(minute)} - type="minute" - onSelect={this.onItemChange} - onMouseEnter={this.onEnterSelectPanel.bind(this, 'minute')} - /> - ); - }, - - getSecondSelect(second) { - const { prefixCls, secondOptions, disabledSeconds, showSecond } = this.props; - if (!showSecond) { - return null; - } - const value = this.props.value || this.getNow(); - const disabledOptions = disabledSeconds(value.getHourOfDay(), value.getMinutes()); - - return ( - ); - }, - - selectRange() { - this.refs.input.select(); - if (this.props.currentSelectPanel && this.refs.input.value) { - let selectionRangeStart = 0; - let selectionRangeEnd = 0; - if (this.props.currentSelectPanel === 'hour') { - selectionRangeStart = 0; - selectionRangeEnd = this.refs.input.value.indexOf(':'); - } else if (this.props.currentSelectPanel === 'minute') { - selectionRangeStart = this.refs.input.value.indexOf(':') + 1; - selectionRangeEnd = this.refs.input.value.lastIndexOf(':'); - } else if (this.props.currentSelectPanel === 'second') { - selectionRangeStart = this.refs.input.value.lastIndexOf(':') + 1; - selectionRangeEnd = this.refs.input.value.length; - } - if (selectionRangeEnd - selectionRangeStart === 2) { - createSelection(this.refs.input, selectionRangeStart, selectionRangeEnd); - } - } - }, - - render() { - const { prefixCls } = this.props; - return ( -
    - {this.getInput()} - {this.getClearButton()} -
    - ); - }, -}); - -export default Header; diff --git a/src/module/Panel.jsx b/src/module/Panel.jsx deleted file mode 100644 index 137ec2f..0000000 --- a/src/module/Panel.jsx +++ /dev/null @@ -1,130 +0,0 @@ -import React, {PropTypes} from 'react'; -import CommonMixin from '../mixin/CommonMixin'; -import Header from './Header'; -import Combobox from './Combobox'; - -function noop() { -} - -function generateOptions(length, disabledOptions, hideDisabledOptions) { - const arr = []; - for (let value = 0; value < length; value++) { - if (!disabledOptions || disabledOptions.indexOf(value) < 0 || !hideDisabledOptions) { - arr.push(value); - } - } - return arr; -} - -const Panel = React.createClass({ - propTypes: { - prefixCls: PropTypes.string, - value: PropTypes.object, - locale: PropTypes.object, - placeholder: PropTypes.string, - gregorianCalendarLocale: PropTypes.object, - formatter: PropTypes.object, - disabledHours: PropTypes.func, - disabledMinutes: PropTypes.func, - disabledSeconds: PropTypes.func, - hideDisabledOptions: PropTypes.bool, - onChange: PropTypes.func, - onEsc: PropTypes.func, - allowEmpty: PropTypes.bool, - showHour: PropTypes.bool, - showSecond: PropTypes.bool, - onClear: PropTypes.func, - }, - - mixins: [CommonMixin], - - getDefaultProps() { - return { - prefixCls: 'rc-time-picker-panel', - onChange: noop, - onClear: noop, - }; - }, - - getInitialState() { - return { - value: this.props.value, - selectionRange: [], - }; - }, - - componentWillReceiveProps(nextProps) { - const value = nextProps.value; - if (value) { - this.setState({ - value, - }); - } - }, - - onChange(newValue) { - this.setState({ value: newValue }); - this.props.onChange(newValue); - }, - - onClear() { - this.props.onClear(); - }, - - onCurrentSelectPanelChange(currentSelectPanel) { - this.setState({ currentSelectPanel }); - }, - - render() { - const { locale, prefixCls, placeholder, disabledHours, disabledMinutes, disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showSecond, formatter, gregorianCalendarLocale } = this.props; - const value = this.state.value; - const disabledHourOptions = disabledHours(); - const disabledMinuteOptions = disabledMinutes(value ? value.getHourOfDay() : null); - const disabledSecondOptions = disabledSeconds(value ? value.getHourOfDay() : null, value ? value.getMinutes() : null); - const hourOptions = generateOptions(24, disabledHourOptions, hideDisabledOptions); - const minuteOptions = generateOptions(60, disabledMinuteOptions, hideDisabledOptions); - const secondOptions = generateOptions(60, disabledSecondOptions, hideDisabledOptions); - - return ( -
    -
    - -
    - ); - }, -}); - -export default Panel; diff --git a/src/module/Select.jsx b/src/module/Select.jsx deleted file mode 100644 index 2ab9e61..0000000 --- a/src/module/Select.jsx +++ /dev/null @@ -1,97 +0,0 @@ -import React, {PropTypes} from 'react'; -import ReactDom from 'react-dom'; -import classnames from 'classnames'; - -const scrollTo = (element, to, duration) => { - const requestAnimationFrame = window.requestAnimationFrame || - function requestAnimationFrameTimeout() { - return setTimeout(arguments[0], 10); - }; - // jump to target if duration zero - if (duration <= 0) { - element.scrollTop = to; - return; - } - const difference = to - element.scrollTop; - const perTick = difference / duration * 10; - - requestAnimationFrame(() => { - element.scrollTop = element.scrollTop + perTick; - if (element.scrollTop === to) return; - scrollTo(element, to, duration - 10); - }); -}; - -const Select = React.createClass({ - propTypes: { - prefixCls: PropTypes.string, - options: PropTypes.array, - gregorianCalendarLocale: PropTypes.object, - selectedIndex: PropTypes.number, - type: PropTypes.string, - onSelect: PropTypes.func, - onMouseEnter: PropTypes.func, - }, - - componentDidMount() { - // jump to selected option - this.scrollToSelected(0); - }, - - componentDidUpdate(prevProps) { - // smooth scroll to selected option - if (prevProps.selectedIndex !== this.props.selectedIndex) { - this.scrollToSelected(120); - } - }, - - onSelect(value) { - const { onSelect, type } = this.props; - onSelect(type, value); - }, - - getOptions() { - const { options, selectedIndex, prefixCls } = this.props; - return options.map((item, index) => { - const cls = classnames({ - [`${prefixCls}-select-option-selected`]: selectedIndex === index, - [`${prefixCls}-select-option-disabled`]: item.disabled, - }); - let onclick = null; - if (!item.disabled) { - onclick = this.onSelect.bind(this, +item.value); - } - return
  • {item.value}
  • ; - }); - }, - - scrollToSelected(duration) { - // move to selected item - const select = ReactDom.findDOMNode(this); - const list = ReactDom.findDOMNode(this.refs.list); - let index = this.props.selectedIndex; - if (index < 0) { - index = 0; - } - const topOption = list.children[index]; - const to = topOption.offsetTop; - scrollTo(select, to, duration); - }, - - render() { - if (this.props.options.length === 0) { - return null; - } - - const { prefixCls } = this.props; - - return ( -
    -
      {this.getOptions()}
    -
    - ); - }, -}); - -export default Select; diff --git a/src/placements.js b/src/placements.js new file mode 100644 index 0000000..6760286 --- /dev/null +++ b/src/placements.js @@ -0,0 +1,35 @@ +const autoAdjustOverflow = { + adjustX: 1, + adjustY: 1, +}; + +const targetOffset = [0, 0]; + +const placements = { + bottomLeft: { + points: ['tl', 'tl'], + overflow: autoAdjustOverflow, + offset: [0, -3], + targetOffset, + }, + bottomRight: { + points: ['tr', 'tr'], + overflow: autoAdjustOverflow, + offset: [0, -3], + targetOffset, + }, + topRight: { + points: ['br', 'br'], + overflow: autoAdjustOverflow, + offset: [0, 3], + targetOffset, + }, + topLeft: { + points: ['bl', 'bl'], + overflow: autoAdjustOverflow, + offset: [0, 3], + targetOffset, + }, +}; + +export default placements; diff --git a/src/util/index.js b/src/util/index.js deleted file mode 100644 index 5bc0a78..0000000 --- a/src/util/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import DateTimeFormat from 'gregorian-calendar-format'; - -export function getFormatter(format, locale) { - if (typeof format === 'string') { - return new DateTimeFormat(format, locale.format); - } - return format; -} diff --git a/src/util/placements.js b/src/util/placements.js deleted file mode 100644 index 6760286..0000000 --- a/src/util/placements.js +++ /dev/null @@ -1,35 +0,0 @@ -const autoAdjustOverflow = { - adjustX: 1, - adjustY: 1, -}; - -const targetOffset = [0, 0]; - -const placements = { - bottomLeft: { - points: ['tl', 'tl'], - overflow: autoAdjustOverflow, - offset: [0, -3], - targetOffset, - }, - bottomRight: { - points: ['tr', 'tr'], - overflow: autoAdjustOverflow, - offset: [0, -3], - targetOffset, - }, - topRight: { - points: ['br', 'br'], - overflow: autoAdjustOverflow, - offset: [0, 3], - targetOffset, - }, - topLeft: { - points: ['bl', 'bl'], - overflow: autoAdjustOverflow, - offset: [0, 3], - targetOffset, - }, -}; - -export default placements; diff --git a/src/util/selection.js b/src/util/selection.js deleted file mode 100644 index 395901e..0000000 --- a/src/util/selection.js +++ /dev/null @@ -1,17 +0,0 @@ -export default function createSelection(field, start, end) { - if (field.createTextRange) { - const selRange = field.createTextRange(); - selRange.collapse(true); - selRange.moveStart('character', start); - selRange.moveEnd('character', end); - selRange.select(); - field.focus(); - } else if (field.setSelectionRange) { - field.focus(); - field.setSelectionRange(start, end); - } else if (typeof field.selectionStart !== 'undefined') { - field.selectionStart = start; - field.selectionEnd = end; - field.focus(); - } -} -- cgit v1.2.3 From 3d4a763813161e575db61737f46879072b1983e9 Mon Sep 17 00:00:00 2001 From: yiminghe Date: Sat, 24 Sep 2016 01:15:02 +0800 Subject: add default --- src/Panel.jsx | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/Panel.jsx b/src/Panel.jsx index f70cf38..a5464c4 100644 --- a/src/Panel.jsx +++ b/src/Panel.jsx @@ -41,6 +41,9 @@ const Panel = React.createClass({ prefixCls: 'rc-time-picker-panel', onChange: noop, onClear: noop, + disabledHours: noop, + disabledMinutes: noop, + disabledSeconds: noop, defaultOpenValue: moment(), }; }, -- cgit v1.2.3 From c6a1a235f9ff6de74cae402c7359b25fa655a537 Mon Sep 17 00:00:00 2001 From: Benjy Cui Date: Mon, 26 Sep 2016 17:33:15 +0800 Subject: chore: add className for Panel --- src/Panel.jsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Panel.jsx b/src/Panel.jsx index a5464c4..f5cf7bc 100644 --- a/src/Panel.jsx +++ b/src/Panel.jsx @@ -2,6 +2,7 @@ import React, { PropTypes } from 'react'; import Header from './Header'; import Combobox from './Combobox'; import moment from 'moment'; +import classNames from 'classnames'; function noop() { } @@ -20,6 +21,7 @@ const Panel = React.createClass({ propTypes: { clearText: PropTypes.string, prefixCls: PropTypes.string, + className: PropTypes.string, defaultOpenValue: PropTypes.object, value: PropTypes.object, placeholder: PropTypes.string, @@ -79,7 +81,7 @@ const Panel = React.createClass({ render() { const { - prefixCls, placeholder, disabledHours, disabledMinutes, + prefixCls, className, placeholder, disabledHours, disabledMinutes, disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showSecond, format, defaultOpenValue, clearText, onEsc, } = this.props; @@ -95,7 +97,7 @@ const Panel = React.createClass({ const secondOptions = generateOptions(60, disabledSecondOptions, hideDisabledOptions); return ( -
    +
    Date: Mon, 26 Sep 2016 17:40:44 +0800 Subject: bump --- src/Panel.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Panel.jsx b/src/Panel.jsx index f5cf7bc..9066b03 100644 --- a/src/Panel.jsx +++ b/src/Panel.jsx @@ -97,7 +97,7 @@ const Panel = React.createClass({ const secondOptions = generateOptions(60, disabledSecondOptions, hideDisabledOptions); return ( -
    +
    Date: Thu, 20 Oct 2016 00:00:17 +0300 Subject: feat: 'addon' property support ..to be able to render something like OK button to timepicker: ``` { return ( ) }} /> ``` --- src/Panel.jsx | 9 ++++++++- src/TimePicker.jsx | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Panel.jsx b/src/Panel.jsx index 9066b03..0ed60e9 100644 --- a/src/Panel.jsx +++ b/src/Panel.jsx @@ -36,6 +36,7 @@ const Panel = React.createClass({ showHour: PropTypes.bool, showSecond: PropTypes.bool, onClear: PropTypes.func, + addon: PropTypes.func, }, getDefaultProps() { @@ -47,6 +48,7 @@ const Panel = React.createClass({ disabledMinutes: noop, disabledSeconds: noop, defaultOpenValue: moment(), + addon: noop, }; }, @@ -79,11 +81,15 @@ const Panel = React.createClass({ this.setState({ currentSelectPanel }); }, + close() { + this.props.onEsc(); + }, + render() { const { prefixCls, className, placeholder, disabledHours, disabledMinutes, disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showSecond, - format, defaultOpenValue, clearText, onEsc, + format, defaultOpenValue, clearText, onEsc, addon, } = this.props; const { value, currentSelectPanel, @@ -133,6 +139,7 @@ const Panel = React.createClass({ disabledSeconds={disabledSeconds} onCurrentSelectPanelChange={this.onCurrentSelectPanelChange} /> + {addon(this)}
    ); }, diff --git a/src/TimePicker.jsx b/src/TimePicker.jsx index 58f6ea1..358b596 100644 --- a/src/TimePicker.jsx +++ b/src/TimePicker.jsx @@ -39,6 +39,7 @@ const Picker = React.createClass({ onChange: PropTypes.func, onOpen: PropTypes.func, onClose: PropTypes.func, + addon: PropTypes.func, }, getDefaultProps() { @@ -61,6 +62,7 @@ const Picker = React.createClass({ onChange: noop, onOpen: noop, onClose: noop, + addon: noop, }; }, @@ -137,6 +139,7 @@ const Picker = React.createClass({ prefixCls, placeholder, disabledHours, disabledMinutes, disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showSecond, defaultOpenValue, clearText, + addon, } = this.props; return ( ); }, -- cgit v1.2.3 From f429b4a79df25c9eadc3901e2483716835cc7de7 Mon Sep 17 00:00:00 2001 From: yiminghe Date: Tue, 25 Oct 2016 17:41:51 +0800 Subject: add addon prop --- src/Header.jsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/Header.jsx b/src/Header.jsx index 4196ea9..2ef9827 100644 --- a/src/Header.jsx +++ b/src/Header.jsx @@ -151,14 +151,16 @@ const Header = React.createClass({ const { prefixCls, placeholder } = this.props; const { invalid, str } = this.state; const invalidClass = invalid ? `${prefixCls}-input-invalid` : ''; - return (); + return ( + + ); }, render() { -- cgit v1.2.3