feat: update time-picker

pull/309/head
tangjinzhou 2018-12-09 12:50:26 +08:00
parent e2cc5eb252
commit ca249252b7
8 changed files with 83 additions and 12 deletions

View File

@ -7,7 +7,7 @@ import HideColumn from './hide-column'
import IntervalOptions from './interval-options' import IntervalOptions from './interval-options'
import Size from './size' import Size from './size'
import Value from './value' import Value from './value'
import Suffix from './suffix'
import CN from '../index.zh-CN.md' import CN from '../index.zh-CN.md'
import US from '../index.en-US.md' import US from '../index.en-US.md'
const md = { const md = {
@ -39,6 +39,7 @@ export default {
<IntervalOptions/> <IntervalOptions/>
<Size/> <Size/>
<Value/> <Value/>
<Suffix/>
<api> <api>
<CN slot='cn' /> <CN slot='cn' />
<US/> <US/>

View File

@ -0,0 +1,28 @@
<cn>
#### 后缀图标
点击 TimePicker然后可以在浮层中选择或者输入某一时间。
</cn>
<us>
#### Suffix
Click `TimePicker`, and then we could select or input a time in panel.
</us>
```html
<template>
<a-time-picker @change="onChange" :defaultOpenValue="moment('00:00:00', 'HH:mm:ss')">
<a-icon type="smile" slot="suffixIcon"/>
</a-time-picker>
</template>
<script>
import moment from 'moment';
export default {
methods: {
moment,
onChange(time, timeString){
console.log(time, timeString);
}
},
}
</script>
```

View File

@ -22,6 +22,7 @@
| placeholder | display when there's no value | string | "Select a time" | | placeholder | display when there's no value | string | "Select a time" |
| popupClassName | className of panel | string | '' | | popupClassName | className of panel | string | '' |
| secondStep | interval between seconds in picker | number | 1 | | secondStep | interval between seconds in picker | number | 1 |
| suffixIcon | The custom suffix icon | string \| VNode \| slot | - |
| use12Hours | display as 12 hours format, with default format `h:mm:ss a` | boolean | false | | use12Hours | display as 12 hours format, with default format `h:mm:ss a` | boolean | false |
| value(v-model) | to set time | [moment](http://momentjs.com/) | - | | value(v-model) | to set time | [moment](http://momentjs.com/) | - |

View File

@ -5,8 +5,10 @@ import LocaleReceiver from '../locale-provider/LocaleReceiver'
import defaultLocale from './locale/en_US' import defaultLocale from './locale/en_US'
import BaseMixin from '../_util/BaseMixin' import BaseMixin from '../_util/BaseMixin'
import PropTypes from '../_util/vue-types' import PropTypes from '../_util/vue-types'
import Icon from '../icon'
import interopDefault from '../_util/interopDefault' import interopDefault from '../_util/interopDefault'
import { initDefaultProps, hasProp, getOptionProps, getComponentFromProp } from '../_util/props-util' import { initDefaultProps, hasProp, getOptionProps, getComponentFromProp, isValidElement } from '../_util/props-util'
import { cloneElement } from '../_util/vnode'
export function generateShowHourMinuteSecond (format) { export function generateShowHourMinuteSecond (format) {
// Ref: http://momentjs.com/docs/#/parsing/string-format/ // Ref: http://momentjs.com/docs/#/parsing/string-format/
@ -52,6 +54,7 @@ export const TimePickerProps = () => ({
clearText: PropTypes.string, clearText: PropTypes.string,
defaultOpenValue: PropTypes.object, defaultOpenValue: PropTypes.object,
popupClassName: PropTypes.string, popupClassName: PropTypes.string,
suffixIcon: PropTypes.any,
align: PropTypes.object, align: PropTypes.object,
placement: PropTypes.any, placement: PropTypes.any,
transitionName: PropTypes.string, transitionName: PropTypes.string,
@ -136,7 +139,41 @@ const TimePicker = {
const className = { const className = {
[`${props.prefixCls}-${props.size}`]: !!props.size, [`${props.prefixCls}-${props.size}`]: !!props.size,
} }
const tempAddon = getComponentFromProp(this, 'addon') let addon = getComponentFromProp(this, 'addon')
addon = addon ? <div class={`${props.prefixCls}-panel-addon`}>
{addon}
</div> : null
const { prefixCls } = props
let suffixIcon = getComponentFromProp(this, 'suffixIcon')
suffixIcon = Array.isArray(suffixIcon) ? suffixIcon[0] : suffixIcon
const clockIcon = suffixIcon && (
isValidElement(suffixIcon)
? cloneElement(
suffixIcon,
{
class: `${prefixCls}-clock-icon`,
},
) : <span class={`${prefixCls}-clock-icon`}>{suffixIcon}</span>) || (
<Icon
type='clock-circle'
class={`${prefixCls}-clock-icon`}
theme='outlined'
/>
)
const inputIcon = (
<span class={`${prefixCls}-icon`}>
{clockIcon}
</span>
)
const clearIcon = (
<Icon
type='close-circle'
class={`${prefixCls}-panel-clear-btn-icon`}
theme='filled'
/>
)
const timeProps = { const timeProps = {
props: { props: {
...generateShowHourMinuteSecond(format), ...generateShowHourMinuteSecond(format),
@ -144,6 +181,9 @@ const TimePicker = {
format, format,
value: this.sValue, value: this.sValue,
placeholder: props.placeholder === undefined ? locale.placeholder : props.placeholder, placeholder: props.placeholder === undefined ? locale.placeholder : props.placeholder,
addon,
inputIcon,
clearIcon,
}, },
class: className, class: className,
ref: 'timePicker', ref: 'timePicker',
@ -155,13 +195,7 @@ const TimePicker = {
}, },
} }
return ( return (
<VcTimePicker {...timeProps}> <VcTimePicker {...timeProps}/>
{tempAddon ? <template slot='addon'>
<div class={`${props.prefixCls}-panel-addon`}>
{tempAddon}
</div>
</template> : null}
</VcTimePicker>
) )
}, },
}, },

View File

@ -23,6 +23,7 @@
| placeholder | 没有值的时候显示的内容 | string | "请选择时间" | | placeholder | 没有值的时候显示的内容 | string | "请选择时间" |
| popupClassName | 弹出层类名 | string | '' | | popupClassName | 弹出层类名 | string | '' |
| secondStep | 秒选项间隔 | number | 1 | | secondStep | 秒选项间隔 | number | 1 |
| suffixIcon | 自定义的选择框后缀图标 | string \| VNode \| slot | - |
| use12Hours | 使用 12 小时制,为 true 时 `format` 默认为 `h:mm:ss a` | boolean | false | | use12Hours | 使用 12 小时制,为 true 时 `format` 默认为 `h:mm:ss a` | boolean | false |
| value(v-model) | 当前时间 | [moment](http://momentjs.com/) | 无 | | value(v-model) | 当前时间 | [moment](http://momentjs.com/) | 无 |

View File

@ -1,5 +1,5 @@
const locale = { const locale = {
placeholder: 'Selezionare il tempo', placeholder: 'Selezionare l\'orario',
} }
export default locale export default locale

View File

@ -0,0 +1,5 @@
const locale = {
placeholder: 'Цаг сонгох',
}
export default locale

View File

@ -60,6 +60,7 @@ export default {
id: PropTypes.string, id: PropTypes.string,
inputIcon: PropTypes.any, inputIcon: PropTypes.any,
clearIcon: PropTypes.any, clearIcon: PropTypes.any,
addon: PropTypes.any,
}, { }, {
clearText: 'clear', clearText: 'clear',
prefixCls: 'rc-time-picker', prefixCls: 'rc-time-picker',
@ -207,7 +208,7 @@ export default {
onKeydown={onKeyDown2} onKeydown={onKeyDown2}
clearIcon={clearIcon} clearIcon={clearIcon}
> >
{this.$slots.addon} {getComponentFromProp(this, 'addon')}
</Panel> </Panel>
) )
}, },