Skip to content

Commit 6395479

Browse files
committed
feat: update vc-notification vc-pagination
1 parent 0aa764d commit 6395479

File tree

14 files changed

+221
-71
lines changed

14 files changed

+221
-71
lines changed

components/vc-form/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
// based on rc-form 2.2.6
1+
// based on rc-form 2.4.0
22
import { createForm, createFormField } from './src/'
33
export { createForm, createFormField }

components/vc-input-number/src/index.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// based on rc-input-number 4.3.1
1+
// based on rc-input-number 4.3.7
22
import PropTypes from '../../_util/vue-types'
33
import BaseMixin from '../../_util/BaseMixin'
44
import { initDefaultProps, hasProp, getOptionProps } from '../../_util/props-util'
@@ -73,6 +73,8 @@ const inputNumberProps = {
7373
required: PropTypes.bool,
7474
pattern: PropTypes.string,
7575
decimalSeparator: PropTypes.string,
76+
autoComplete: PropTypes.string,
77+
title: PropTypes.string,
7678
}
7779

7880
export default {
@@ -90,6 +92,7 @@ export default {
9092
step: 1,
9193
parser: defaultParser,
9294
required: false,
95+
autoComplete: 'off',
9396
}),
9497
data () {
9598
let value
@@ -274,7 +277,7 @@ export default {
274277
let val = value
275278
if (val === '') {
276279
val = ''
277-
} else if (!this.isNotCompleteNumber(val)) {
280+
} else if (!this.isNotCompleteNumber(parseFloat(val, 10))) {
278281
val = this.getValidValue(val)
279282
} else {
280283
val = this.sValue
@@ -583,7 +586,8 @@ export default {
583586
},
584587
},
585588
render () {
586-
const { prefixCls, disabled, readOnly, useTouch } = this.$props
589+
const { prefixCls, disabled, readOnly, useTouch, autoComplete,
590+
upHandler, downHandler } = this.$props
587591
const classes = classNames({
588592
[prefixCls]: true,
589593
[`${prefixCls}-disabled`]: disabled,
@@ -657,6 +661,7 @@ export default {
657661
const contentProps = {
658662
on: { mouseenter, mouseleave, mouseover, mouseout },
659663
class: classes,
664+
attrs: { title: this.$props.title },
660665
}
661666
const upHandlerProps = {
662667
props: {
@@ -697,7 +702,7 @@ export default {
697702
<InputHandler
698703
{...upHandlerProps}
699704
>
700-
{this.upHandler || <span
705+
{upHandler || <span
701706
unselectable='unselectable'
702707
class={`${prefixCls}-handler-up-inner`}
703708
onClick={preventDefault}
@@ -706,7 +711,7 @@ export default {
706711
<InputHandler
707712
{...downHandlerProps}
708713
>
709-
{this.downHandler || <span
714+
{downHandler || <span
710715
unselectable='unselectable'
711716
class={`${prefixCls}-handler-down-inner`}
712717
onClick={preventDefault}
@@ -727,7 +732,7 @@ export default {
727732
onClick={this.handleInputClick}
728733
class={`${prefixCls}-input`}
729734
tabIndex={this.tabIndex}
730-
autoComplete='off'
735+
autoComplete={autoComplete}
731736
onFocus={this.onFocus}
732737
onBlur={this.onBlur}
733738
onKeydown={editable ? this.onKeyDown : noop}

components/vc-menu/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// based on rc-menu 7.4.19
1+
// based on rc-menu 7.4.20
22
import Menu from './Menu'
33
import SubMenu from './SubMenu'
44
import MenuItem, { menuItemProps } from './MenuItem'

components/vc-notification/Notice.jsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import PropTypes from '../_util/vue-types'
33
import { getStyle, getComponentFromProp } from '../_util/props-util'
44
import BaseMixin from '../_util/BaseMixin'
55

6+
function noop () {
7+
}
8+
69
export default {
710
mixins: [BaseMixin],
811
props: {
@@ -59,7 +62,7 @@ export default {
5962
},
6063

6164
render () {
62-
const { prefixCls, closable, clearCloseTimer, startCloseTimer, $slots, close } = this
65+
const { prefixCls, closable, clearCloseTimer, startCloseTimer, $slots, close, $listeners } = this
6366
const componentClass = `${prefixCls}-notice`
6467
const className = {
6568
[`${componentClass}`]: 1,
@@ -68,8 +71,12 @@ export default {
6871
const style = getStyle(this)
6972
const closeIcon = getComponentFromProp(this, 'closeIcon')
7073
return (
71-
<div class={className} style={style || { right: '50%' } } onMouseenter={clearCloseTimer}
74+
<div
75+
class={className}
76+
style={style || { right: '50%' } }
77+
onMouseenter={clearCloseTimer}
7278
onMouseleave={startCloseTimer}
79+
onClick={$listeners.click || noop}
7380
>
7481
<div class={`${componentClass}-content`}>{$slots.default}</div>
7582
{closable

components/vc-notification/Notification.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import createChainedFunction from '../_util/createChainedFunction'
77
import getTransitionProps from '../_util/getTransitionProps'
88
import Notice from './Notice'
99

10+
function noop () {
11+
}
12+
1013
let seed = 0
1114
const now = Date.now()
1215

@@ -91,6 +94,7 @@ const Notification = {
9194
},
9295
on: {
9396
close,
97+
click: notice.onClick || noop,
9498
},
9599
style,
96100
class: className,

components/vc-notification/demo/simple.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ function closableFn () {
3535
onClose () {
3636
console.log('closable close')
3737
},
38+
onClick () {
39+
console.log('clicked!!!')
40+
},
3841
closable: true,
3942
})
4043
}

components/vc-notification/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
// based on rc-notification 3.2.0
1+
// based on rc-notification 3.3.0
22
import Notification from './Notification'
33
export default Notification

components/vc-pagination/Pager.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export default {
4242
cls = `${cls} ${prefixCls}-active`
4343
}
4444

45+
if (!page) {
46+
cls = `${cls} ${prefixCls}-disabled`
47+
}
48+
4549
return (
4650
<li
4751
class={cls}

components/vc-pagination/Pagination.jsx

Lines changed: 82 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ function defaultItemRender (page, type, element) {
2121
return element
2222
}
2323

24+
function calculatePage (p, state, props) {
25+
let pageSize = p
26+
if (typeof pageSize === 'undefined') {
27+
pageSize = state.statePageSize
28+
}
29+
return Math.floor((props.total - 1) / pageSize) + 1
30+
}
31+
2432
export default {
2533
name: 'Pagination',
2634
mixins: [BaseMixin],
@@ -87,7 +95,7 @@ export default {
8795
pageSize (val) {
8896
const newState = {}
8997
let current = this.stateCurrent
90-
const newCurrent = this.calculatePage(val)
98+
const newCurrent = calculatePage(val, this.$data, this.$props)
9199
current = current > newCurrent ? newCurrent : current
92100
if (!hasProp(this, 'current')) {
93101
newState.stateCurrent = current
@@ -112,42 +120,30 @@ export default {
112120
},
113121
},
114122
methods: {
115-
isValid (page) {
116-
return isInteger(page) && page >= 1 && page !== this.stateCurrent
123+
getJumpPrevPage () {
124+
return Math.max(1, this.stateCurrent - (this.showLessItems ? 3 : 5))
125+
},
126+
getJumpNextPage () {
127+
return Math.min(
128+
calculatePage(undefined, this.$data, this.$props),
129+
this.stateCurrent + (this.showLessItems ? 3 : 5)
130+
)
117131
},
118132
getItemIcon (icon) {
119133
const { prefixCls } = this.$props
120134
const iconNode = getComponentFromProp(this, icon, this.$props) || <a class={`${prefixCls}-item-link`} />
121135
return iconNode
122136
},
123-
calculatePage (p) {
124-
let pageSize = p
125-
if (typeof pageSize === 'undefined') {
126-
pageSize = this.statePageSize
127-
}
128-
return Math.floor((this.total - 1) / pageSize) + 1
129-
},
130-
handleGoTO (event) {
131-
if (event.keyCode === KEYCODE.ENTER || event.type === 'click') {
132-
this.handleChange(this.stateCurrentInputValue)
133-
}
134-
},
135-
prev () {
136-
if (this.hasPrev()) {
137-
this.handleChange(this.stateCurrent - 1)
138-
}
139-
},
140-
next () {
141-
if (this.hasNext()) {
142-
this.handleChange(this.stateCurrent + 1)
143-
}
144-
},
145-
hasPrev () {
146-
return this.stateCurrent > 1
147-
},
148-
hasNext () {
149-
return this.stateCurrent < this.calculatePage()
137+
isValid (page) {
138+
return isInteger(page) && page >= 1 && page !== this.stateCurrent
150139
},
140+
// calculatePage (p) {
141+
// let pageSize = p
142+
// if (typeof pageSize === 'undefined') {
143+
// pageSize = this.statePageSize
144+
// }
145+
// return Math.floor((this.total - 1) / pageSize) + 1
146+
// },
151147
handleKeyDown (event) {
152148
if (event.keyCode === KEYCODE.ARROW_UP || event.keyCode === KEYCODE.ARROW_DOWN) {
153149
event.preventDefault()
@@ -183,7 +179,7 @@ export default {
183179
changePageSize (size) {
184180
let current = this.stateCurrent
185181
const preCurrent = current
186-
const newCurrent = this.calculatePage(size)
182+
const newCurrent = calculatePage(size, this.$data, this.$props)
187183
current = current > newCurrent ? newCurrent : current
188184
// fix the issue:
189185
// Once 'total' is 0, 'current' in 'onShowSizeChange' is 0, which is not correct.
@@ -212,9 +208,9 @@ export default {
212208
handleChange (p) {
213209
let page = p
214210
if (this.isValid(page)) {
215-
const allTotal = this.calculatePage()
216-
if (page > allTotal) {
217-
page = allTotal
211+
const currentPage = calculatePage(undefined, this.$data, this.$props)
212+
if (page > currentPage) {
213+
page = currentPage
218214
}
219215
if (!hasProp(this, 'current')) {
220216
this.setState({
@@ -229,6 +225,28 @@ export default {
229225
}
230226
return this.stateCurrent
231227
},
228+
prev () {
229+
if (this.hasPrev()) {
230+
this.handleChange(this.stateCurrent - 1)
231+
}
232+
},
233+
next () {
234+
if (this.hasNext()) {
235+
this.handleChange(this.stateCurrent + 1)
236+
}
237+
},
238+
jumpPrev () {
239+
this.handleChange(this.getJumpPrevPage())
240+
},
241+
jumpNext () {
242+
this.handleChange(this.getJumpNextPage())
243+
},
244+
hasPrev () {
245+
return this.stateCurrent > 1
246+
},
247+
hasNext () {
248+
return this.stateCurrent < calculatePage(undefined, this.$data, this.$props)
249+
},
232250
runIfEnter (event, callback, ...restParams) {
233251
if (event.key === 'Enter' || event.charCode === 13) {
234252
callback(...restParams)
@@ -246,17 +264,10 @@ export default {
246264
runIfEnterJumpNext (event) {
247265
this.runIfEnter(event, this.jumpNext)
248266
},
249-
getJumpPrevPage () {
250-
return Math.max(1, this.stateCurrent - (this.showLessItems ? 3 : 5))
251-
},
252-
getJumpNextPage () {
253-
return Math.min(this.calculatePage(), this.stateCurrent + (this.showLessItems ? 3 : 5))
254-
},
255-
jumpPrev () {
256-
this.handleChange(this.getJumpPrevPage())
257-
},
258-
jumpNext () {
259-
this.handleChange(this.getJumpNextPage())
267+
handleGoTO (event) {
268+
if (event.keyCode === KEYCODE.ENTER || event.type === 'click') {
269+
this.handleChange(this.stateCurrentInputValue)
270+
}
260271
},
261272
},
262273
render () {
@@ -268,7 +279,7 @@ export default {
268279
const locale = this.locale
269280

270281
const prefixCls = this.prefixCls
271-
const allPages = this.calculatePage()
282+
const allPages = calculatePage(undefined, this.$data, this.$props)
272283
const pagerList = []
273284
let jumpPrev = null
274285
let jumpNext = null
@@ -354,19 +365,36 @@ export default {
354365
)
355366
}
356367
if (allPages <= 5 + pageBufferSize * 2) {
368+
const pagerProps = {
369+
props: {
370+
locale,
371+
rootPrefixCls: prefixCls,
372+
showTitle: props.showTitle,
373+
itemRender: props.itemRender,
374+
},
375+
on: {
376+
click: this.handleChange,
377+
keypress: this.runIfEnter,
378+
},
379+
}
380+
if (!allPages) {
381+
pagerList.push(
382+
<Pager
383+
{...pagerProps}
384+
key='noPager'
385+
page={allPages}
386+
class={`${prefixCls}-disabled`}
387+
/>
388+
)
389+
}
357390
for (let i = 1; i <= allPages; i++) {
358391
const active = stateCurrent === i
359392
pagerList.push(
360393
<Pager
361-
locale={locale}
362-
rootPrefixCls={prefixCls}
363-
onClick={this.handleChange}
364-
onKeypress={this.runIfEnter}
394+
{...pagerProps}
365395
key={i}
366396
page={i}
367397
active={active}
368-
showTitle={this.showTitle}
369-
itemRender={this.itemRender}
370398
/>
371399
)
372400
}
@@ -530,8 +558,8 @@ export default {
530558
</li>
531559
)
532560
}
533-
const prevDisabled = !this.hasPrev()
534-
const nextDisabled = !this.hasNext()
561+
const prevDisabled = !this.hasPrev() || !allPages
562+
const nextDisabled = !this.hasNext() || !allPages
535563
const buildOptionText = this.buildOptionText || this.$scopedSlots.buildOptionText
536564
return (
537565
<ul

0 commit comments

Comments
 (0)