feat: update vc-notification vc-pagination

This commit is contained in:
tangjinzhou 2019-01-01 21:19:50 +08:00
parent 0aa764df51
commit 639547953c
14 changed files with 221 additions and 71 deletions

View File

@ -1,3 +1,3 @@
// based on rc-form 2.2.6 // based on rc-form 2.4.0
import { createForm, createFormField } from './src/' import { createForm, createFormField } from './src/'
export { createForm, createFormField } export { createForm, createFormField }

View File

@ -1,4 +1,4 @@
// based on rc-input-number 4.3.1 // based on rc-input-number 4.3.7
import PropTypes from '../../_util/vue-types' import PropTypes from '../../_util/vue-types'
import BaseMixin from '../../_util/BaseMixin' import BaseMixin from '../../_util/BaseMixin'
import { initDefaultProps, hasProp, getOptionProps } from '../../_util/props-util' import { initDefaultProps, hasProp, getOptionProps } from '../../_util/props-util'
@ -73,6 +73,8 @@ const inputNumberProps = {
required: PropTypes.bool, required: PropTypes.bool,
pattern: PropTypes.string, pattern: PropTypes.string,
decimalSeparator: PropTypes.string, decimalSeparator: PropTypes.string,
autoComplete: PropTypes.string,
title: PropTypes.string,
} }
export default { export default {
@ -90,6 +92,7 @@ export default {
step: 1, step: 1,
parser: defaultParser, parser: defaultParser,
required: false, required: false,
autoComplete: 'off',
}), }),
data () { data () {
let value let value
@ -274,7 +277,7 @@ export default {
let val = value let val = value
if (val === '') { if (val === '') {
val = '' val = ''
} else if (!this.isNotCompleteNumber(val)) { } else if (!this.isNotCompleteNumber(parseFloat(val, 10))) {
val = this.getValidValue(val) val = this.getValidValue(val)
} else { } else {
val = this.sValue val = this.sValue
@ -583,7 +586,8 @@ export default {
}, },
}, },
render () { render () {
const { prefixCls, disabled, readOnly, useTouch } = this.$props const { prefixCls, disabled, readOnly, useTouch, autoComplete,
upHandler, downHandler } = this.$props
const classes = classNames({ const classes = classNames({
[prefixCls]: true, [prefixCls]: true,
[`${prefixCls}-disabled`]: disabled, [`${prefixCls}-disabled`]: disabled,
@ -657,6 +661,7 @@ export default {
const contentProps = { const contentProps = {
on: { mouseenter, mouseleave, mouseover, mouseout }, on: { mouseenter, mouseleave, mouseover, mouseout },
class: classes, class: classes,
attrs: { title: this.$props.title },
} }
const upHandlerProps = { const upHandlerProps = {
props: { props: {
@ -697,7 +702,7 @@ export default {
<InputHandler <InputHandler
{...upHandlerProps} {...upHandlerProps}
> >
{this.upHandler || <span {upHandler || <span
unselectable='unselectable' unselectable='unselectable'
class={`${prefixCls}-handler-up-inner`} class={`${prefixCls}-handler-up-inner`}
onClick={preventDefault} onClick={preventDefault}
@ -706,7 +711,7 @@ export default {
<InputHandler <InputHandler
{...downHandlerProps} {...downHandlerProps}
> >
{this.downHandler || <span {downHandler || <span
unselectable='unselectable' unselectable='unselectable'
class={`${prefixCls}-handler-down-inner`} class={`${prefixCls}-handler-down-inner`}
onClick={preventDefault} onClick={preventDefault}
@ -727,7 +732,7 @@ export default {
onClick={this.handleInputClick} onClick={this.handleInputClick}
class={`${prefixCls}-input`} class={`${prefixCls}-input`}
tabIndex={this.tabIndex} tabIndex={this.tabIndex}
autoComplete='off' autoComplete={autoComplete}
onFocus={this.onFocus} onFocus={this.onFocus}
onBlur={this.onBlur} onBlur={this.onBlur}
onKeydown={editable ? this.onKeyDown : noop} onKeydown={editable ? this.onKeyDown : noop}

View File

@ -1,4 +1,4 @@
// based on rc-menu 7.4.19 // based on rc-menu 7.4.20
import Menu from './Menu' import Menu from './Menu'
import SubMenu from './SubMenu' import SubMenu from './SubMenu'
import MenuItem, { menuItemProps } from './MenuItem' import MenuItem, { menuItemProps } from './MenuItem'

View File

@ -3,6 +3,9 @@ import PropTypes from '../_util/vue-types'
import { getStyle, getComponentFromProp } from '../_util/props-util' import { getStyle, getComponentFromProp } from '../_util/props-util'
import BaseMixin from '../_util/BaseMixin' import BaseMixin from '../_util/BaseMixin'
function noop () {
}
export default { export default {
mixins: [BaseMixin], mixins: [BaseMixin],
props: { props: {
@ -59,7 +62,7 @@ export default {
}, },
render () { render () {
const { prefixCls, closable, clearCloseTimer, startCloseTimer, $slots, close } = this const { prefixCls, closable, clearCloseTimer, startCloseTimer, $slots, close, $listeners } = this
const componentClass = `${prefixCls}-notice` const componentClass = `${prefixCls}-notice`
const className = { const className = {
[`${componentClass}`]: 1, [`${componentClass}`]: 1,
@ -68,8 +71,12 @@ export default {
const style = getStyle(this) const style = getStyle(this)
const closeIcon = getComponentFromProp(this, 'closeIcon') const closeIcon = getComponentFromProp(this, 'closeIcon')
return ( return (
<div class={className} style={style || { right: '50%' } } onMouseenter={clearCloseTimer} <div
class={className}
style={style || { right: '50%' } }
onMouseenter={clearCloseTimer}
onMouseleave={startCloseTimer} onMouseleave={startCloseTimer}
onClick={$listeners.click || noop}
> >
<div class={`${componentClass}-content`}>{$slots.default}</div> <div class={`${componentClass}-content`}>{$slots.default}</div>
{closable {closable

View File

@ -7,6 +7,9 @@ import createChainedFunction from '../_util/createChainedFunction'
import getTransitionProps from '../_util/getTransitionProps' import getTransitionProps from '../_util/getTransitionProps'
import Notice from './Notice' import Notice from './Notice'
function noop () {
}
let seed = 0 let seed = 0
const now = Date.now() const now = Date.now()
@ -91,6 +94,7 @@ const Notification = {
}, },
on: { on: {
close, close,
click: notice.onClick || noop,
}, },
style, style,
class: className, class: className,

View File

@ -35,6 +35,9 @@ function closableFn () {
onClose () { onClose () {
console.log('closable close') console.log('closable close')
}, },
onClick () {
console.log('clicked!!!')
},
closable: true, closable: true,
}) })
} }

View File

@ -1,3 +1,3 @@
// based on rc-notification 3.2.0 // based on rc-notification 3.3.0
import Notification from './Notification' import Notification from './Notification'
export default Notification export default Notification

View File

@ -42,6 +42,10 @@ export default {
cls = `${cls} ${prefixCls}-active` cls = `${cls} ${prefixCls}-active`
} }
if (!page) {
cls = `${cls} ${prefixCls}-disabled`
}
return ( return (
<li <li
class={cls} class={cls}

View File

@ -21,6 +21,14 @@ function defaultItemRender (page, type, element) {
return element return element
} }
function calculatePage (p, state, props) {
let pageSize = p
if (typeof pageSize === 'undefined') {
pageSize = state.statePageSize
}
return Math.floor((props.total - 1) / pageSize) + 1
}
export default { export default {
name: 'Pagination', name: 'Pagination',
mixins: [BaseMixin], mixins: [BaseMixin],
@ -87,7 +95,7 @@ export default {
pageSize (val) { pageSize (val) {
const newState = {} const newState = {}
let current = this.stateCurrent let current = this.stateCurrent
const newCurrent = this.calculatePage(val) const newCurrent = calculatePage(val, this.$data, this.$props)
current = current > newCurrent ? newCurrent : current current = current > newCurrent ? newCurrent : current
if (!hasProp(this, 'current')) { if (!hasProp(this, 'current')) {
newState.stateCurrent = current newState.stateCurrent = current
@ -112,42 +120,30 @@ export default {
}, },
}, },
methods: { methods: {
isValid (page) { getJumpPrevPage () {
return isInteger(page) && page >= 1 && page !== this.stateCurrent return Math.max(1, this.stateCurrent - (this.showLessItems ? 3 : 5))
},
getJumpNextPage () {
return Math.min(
calculatePage(undefined, this.$data, this.$props),
this.stateCurrent + (this.showLessItems ? 3 : 5)
)
}, },
getItemIcon (icon) { getItemIcon (icon) {
const { prefixCls } = this.$props const { prefixCls } = this.$props
const iconNode = getComponentFromProp(this, icon, this.$props) || <a class={`${prefixCls}-item-link`} /> const iconNode = getComponentFromProp(this, icon, this.$props) || <a class={`${prefixCls}-item-link`} />
return iconNode return iconNode
}, },
calculatePage (p) { isValid (page) {
let pageSize = p return isInteger(page) && page >= 1 && page !== this.stateCurrent
if (typeof pageSize === 'undefined') {
pageSize = this.statePageSize
}
return Math.floor((this.total - 1) / pageSize) + 1
},
handleGoTO (event) {
if (event.keyCode === KEYCODE.ENTER || event.type === 'click') {
this.handleChange(this.stateCurrentInputValue)
}
},
prev () {
if (this.hasPrev()) {
this.handleChange(this.stateCurrent - 1)
}
},
next () {
if (this.hasNext()) {
this.handleChange(this.stateCurrent + 1)
}
},
hasPrev () {
return this.stateCurrent > 1
},
hasNext () {
return this.stateCurrent < this.calculatePage()
}, },
// calculatePage (p) {
// let pageSize = p
// if (typeof pageSize === 'undefined') {
// pageSize = this.statePageSize
// }
// return Math.floor((this.total - 1) / pageSize) + 1
// },
handleKeyDown (event) { handleKeyDown (event) {
if (event.keyCode === KEYCODE.ARROW_UP || event.keyCode === KEYCODE.ARROW_DOWN) { if (event.keyCode === KEYCODE.ARROW_UP || event.keyCode === KEYCODE.ARROW_DOWN) {
event.preventDefault() event.preventDefault()
@ -183,7 +179,7 @@ export default {
changePageSize (size) { changePageSize (size) {
let current = this.stateCurrent let current = this.stateCurrent
const preCurrent = current const preCurrent = current
const newCurrent = this.calculatePage(size) const newCurrent = calculatePage(size, this.$data, this.$props)
current = current > newCurrent ? newCurrent : current current = current > newCurrent ? newCurrent : current
// fix the issue: // fix the issue:
// Once 'total' is 0, 'current' in 'onShowSizeChange' is 0, which is not correct. // Once 'total' is 0, 'current' in 'onShowSizeChange' is 0, which is not correct.
@ -212,9 +208,9 @@ export default {
handleChange (p) { handleChange (p) {
let page = p let page = p
if (this.isValid(page)) { if (this.isValid(page)) {
const allTotal = this.calculatePage() const currentPage = calculatePage(undefined, this.$data, this.$props)
if (page > allTotal) { if (page > currentPage) {
page = allTotal page = currentPage
} }
if (!hasProp(this, 'current')) { if (!hasProp(this, 'current')) {
this.setState({ this.setState({
@ -229,6 +225,28 @@ export default {
} }
return this.stateCurrent return this.stateCurrent
}, },
prev () {
if (this.hasPrev()) {
this.handleChange(this.stateCurrent - 1)
}
},
next () {
if (this.hasNext()) {
this.handleChange(this.stateCurrent + 1)
}
},
jumpPrev () {
this.handleChange(this.getJumpPrevPage())
},
jumpNext () {
this.handleChange(this.getJumpNextPage())
},
hasPrev () {
return this.stateCurrent > 1
},
hasNext () {
return this.stateCurrent < calculatePage(undefined, this.$data, this.$props)
},
runIfEnter (event, callback, ...restParams) { runIfEnter (event, callback, ...restParams) {
if (event.key === 'Enter' || event.charCode === 13) { if (event.key === 'Enter' || event.charCode === 13) {
callback(...restParams) callback(...restParams)
@ -246,17 +264,10 @@ export default {
runIfEnterJumpNext (event) { runIfEnterJumpNext (event) {
this.runIfEnter(event, this.jumpNext) this.runIfEnter(event, this.jumpNext)
}, },
getJumpPrevPage () { handleGoTO (event) {
return Math.max(1, this.stateCurrent - (this.showLessItems ? 3 : 5)) if (event.keyCode === KEYCODE.ENTER || event.type === 'click') {
}, this.handleChange(this.stateCurrentInputValue)
getJumpNextPage () { }
return Math.min(this.calculatePage(), this.stateCurrent + (this.showLessItems ? 3 : 5))
},
jumpPrev () {
this.handleChange(this.getJumpPrevPage())
},
jumpNext () {
this.handleChange(this.getJumpNextPage())
}, },
}, },
render () { render () {
@ -268,7 +279,7 @@ export default {
const locale = this.locale const locale = this.locale
const prefixCls = this.prefixCls const prefixCls = this.prefixCls
const allPages = this.calculatePage() const allPages = calculatePage(undefined, this.$data, this.$props)
const pagerList = [] const pagerList = []
let jumpPrev = null let jumpPrev = null
let jumpNext = null let jumpNext = null
@ -354,19 +365,36 @@ export default {
) )
} }
if (allPages <= 5 + pageBufferSize * 2) { if (allPages <= 5 + pageBufferSize * 2) {
const pagerProps = {
props: {
locale,
rootPrefixCls: prefixCls,
showTitle: props.showTitle,
itemRender: props.itemRender,
},
on: {
click: this.handleChange,
keypress: this.runIfEnter,
},
}
if (!allPages) {
pagerList.push(
<Pager
{...pagerProps}
key='noPager'
page={allPages}
class={`${prefixCls}-disabled`}
/>
)
}
for (let i = 1; i <= allPages; i++) { for (let i = 1; i <= allPages; i++) {
const active = stateCurrent === i const active = stateCurrent === i
pagerList.push( pagerList.push(
<Pager <Pager
locale={locale} {...pagerProps}
rootPrefixCls={prefixCls}
onClick={this.handleChange}
onKeypress={this.runIfEnter}
key={i} key={i}
page={i} page={i}
active={active} active={active}
showTitle={this.showTitle}
itemRender={this.itemRender}
/> />
) )
} }
@ -530,8 +558,8 @@ export default {
</li> </li>
) )
} }
const prevDisabled = !this.hasPrev() const prevDisabled = !this.hasPrev() || !allPages
const nextDisabled = !this.hasNext() const nextDisabled = !this.hasNext() || !allPages
const buildOptionText = this.buildOptionText || this.$scopedSlots.buildOptionText const buildOptionText = this.buildOptionText || this.$scopedSlots.buildOptionText
return ( return (
<ul <ul

View File

@ -53,6 +53,16 @@
} }
} }
&-disabled {
cursor: not-allowed;
&:hover {
border-color: #d9d9d9;
a {
color: #d9d9d9;
}
}
}
&-active { &-active {
background-color: #2db7f5; background-color: #2db7f5;
border-color: #2db7f5; border-color: #2db7f5;
@ -84,6 +94,7 @@
color: #2db7f5; color: #2db7f5;
} }
} }
} }
&-jump-prev { &-jump-prev {
@ -102,6 +113,48 @@
} }
} }
&-jump-prev-custom-icon,
&-jump-next-custom-icon {
position: relative;
&:after {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: auto;
transition: all .2s;
content: "•••";
opacity: 1;
display: block;
letter-spacing: 2px;
color: #ccc;
font-size: 12px;
margin-top: 1px;
}
.custom-icon-jump-prev,
.custom-icon-jump-next {
opacity: 0;
transition: all .2s;
}
&:hover {
&:after {
opacity: 0;
color: #ccc;
}
.custom-icon-jump-prev,
.custom-icon-jump-next {
opacity: 1;
color: #2db7f5;
}
}
}
&-prev, &-jump-prev, &-jump-next { &-prev, &-jump-prev, &-jump-next {
margin-right: 8px; margin-right: 8px;
} }
@ -274,6 +327,7 @@
border-color: #2db7f5; border-color: #2db7f5;
} }
} }
} }
} }
} }

View File

@ -1,2 +1,2 @@
// based on rc-pagination 1.17.3 // based on rc-pagination 1.17.8
export { default } from './Pagination' export { default } from './Pagination'

View File

@ -0,0 +1,15 @@
export default {
// Options.jsx
items_per_page: '/ पृष्ठ',
jump_to: 'इस पर चलें',
jump_to_confirm: 'पुष्टि करें',
page: '',
// Pagination.jsx
prev_page: 'पिछला पृष्ठ',
next_page: 'अगला पृष्ठ',
prev_5: 'पिछले 5 पृष्ठ',
next_5: 'अगले 5 पृष्ठ',
prev_3: 'पिछले 3 पृष्ठ',
next_3: 'अगले 3 पेज',
}

View File

@ -0,0 +1,15 @@
export default {
// Options.jsx
items_per_page: '/ ಪುಟ',
jump_to: 'ಜಿಗಿತವನ್ನು',
jump_to_confirm: 'ಖಚಿತಪಡಿಸಲು ಜಿಗಿತವನ್ನು',
page: '',
// Pagination.jsx
prev_page: 'ಹಿಂದಿನ ಪುಟ',
next_page: 'ಮುಂದಿನ ಪುಟ',
prev_5: 'ಹಿಂದಿನ 5 ಪುಟಗಳು',
next_5: 'ಮುಂದಿನ 5 ಪುಟಗಳು',
prev_3: 'ಹಿಂದಿನ 3 ಪುಟಗಳು',
next_3: 'ಮುಂದಿನ 3 ಪುಟಗಳು',
}

View File

@ -0,0 +1,15 @@
export default {
// Options.jsx
items_per_page: '/ pagină',
jump_to: 'Mergi la',
jump_to_confirm: 'confirm',
page: '',
// Pagination.jsx
prev_page: 'Pagina Anterioară',
next_page: 'Pagina Următoare',
prev_5: '5 Pagini Anterioare',
next_5: '5 Pagini Următoare',
prev_3: '3 Pagini Anterioare',
next_3: '3 Pagini Următoare',
}