Skip to content

Commit 754d897

Browse files
committed
feat: update vc-drawer vc-form
1 parent d805107 commit 754d897

File tree

12 files changed

+160
-88
lines changed

12 files changed

+160
-88
lines changed

components/drawer/index.jsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import classNames from 'classnames'
1+
import warning from 'warning'
22
import VcDrawer from '../vc-drawer/src'
33
import PropTypes from '../_util/vue-types'
44
import BaseMixin from '../_util/BaseMixin'
55
import Icon from '../icon'
6-
import { getComponentFromProp, getOptionProps } from '../_util/props-util'
6+
import { getComponentFromProp, getOptionProps, getClass } from '../_util/props-util'
77

88
const Drawer = {
99
name: 'ADrawer',
@@ -26,6 +26,10 @@ const Drawer = {
2626
},
2727
mixins: [BaseMixin],
2828
data () {
29+
warning(
30+
this.wrapClassName === undefined,
31+
'wrapClassName is deprecated, please use className instead.',
32+
)
2933
this.destoryClose = false
3034
this.preVisible = this.$props.visible
3135
return {
@@ -195,16 +199,17 @@ const Drawer = {
195199
open: visible,
196200
showMask: props.mask,
197201
placement,
198-
wrapClassName: classNames({
199-
[wrapClassName]: !!wrapClassName,
200-
[haveMask]: !!haveMask,
201-
}),
202202
},
203203
on: {
204204
maskClick: this.onMaskClick,
205205
...this.$listeners,
206206
},
207207
style: this.getRcDrawerStyle(),
208+
class: {
209+
[wrapClassName]: !!wrapClassName,
210+
...getClass(this),
211+
[haveMask]: !!haveMask,
212+
},
208213
}
209214
return (
210215
<VcDrawer

components/form/Form.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ export const ValidationRule = {
112112
// normalize?: (value: any, prevValue: any, allValues: any) => any;
113113
// /** Whether stop validate on first rule of error for this field. */
114114
// validateFirst?: boolean;
115+
// /** 是否一直保留子节点的信息 */
116+
// preserve?: boolean;
115117
// };
116118

117119
const Form = {

components/form/demo/dynamic-form-item.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Add or remove form items dynamically.
2323
`names[${k}]`,
2424
{
2525
validateTrigger: ['change', 'blur'],
26+
preserve: true,
2627
rules: [{
2728
required: true,
2829
whitespace: true,

components/vc-drawer/demo/multiple.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default {
2525
},
2626
getLevelMove (e) {
2727
const target = e.target
28-
if (target.className === 'drawer1') {
28+
if (target.className.indexOf('drawer1') >= 0) {
2929
return [200, 100]
3030
}
3131
return 100
@@ -47,7 +47,7 @@ export default {
4747
handler={false}
4848
open={this.open}
4949
onMaskClick={this.onClick}
50-
wrapperClassName='drawer1'
50+
class='drawer1'
5151
placement='right'
5252
>
5353
<div>
@@ -56,7 +56,7 @@ export default {
5656
handler={false}
5757
open={this.openChild}
5858
onMaskClick={this.onChildClick}
59-
wrapperClassName='drawer2'
59+
class='drawer2'
6060
level='.drawer1'
6161
placement='right'
6262
levelMove={100}

components/vc-drawer/demo/placement.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default {
3535
return (
3636
<div >
3737
{this.childShow && (
38-
<Drawer placement={this.placement} width={this.width} hieght={this.height}>
38+
<Drawer placement={this.placement} width={this.width} height={this.height}>
3939
<Menu
4040
defaultSelectedKeys={['1']}
4141
defaultOpenKeys={['sub1']}

components/vc-drawer/src/Drawer.js

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import classnames from 'classnames'
22
import Vue from 'vue'
33
import ref from 'vue-ref'
44
import BaseMixin from '../../_util/BaseMixin'
5-
import { initDefaultProps, getEvents } from '../../_util/props-util'
5+
import { initDefaultProps, getEvents, getClass } from '../../_util/props-util'
66
import { cloneElement } from '../../_util/vnode'
77
import ContainerRender from '../../_util/ContainerRender'
88
import getScrollBarSize from '../../_util/getScrollBarSize'
99
import drawerProps from './drawerProps'
1010
import {
1111
dataToArray,
1212
transitionEnd,
13-
trnasitionStr,
13+
transitionStr,
1414
addEventListener,
1515
removeEventListener,
1616
transformArguments,
@@ -40,7 +40,7 @@ const Drawer = {
4040
showMask: true,
4141
handler: true,
4242
maskStyle: {},
43-
wrapClassName: '',
43+
wrapperClassName: '',
4444
}),
4545
data () {
4646
this.levelDom = []
@@ -51,8 +51,9 @@ const Drawer = {
5151
this.sFirstEnter = this.firstEnter
5252
this.timeout = null
5353
this.children = null
54-
this.drawerId = Number((Date.now() + Math.random()).toString()
55-
.replace('.', Math.round(Math.random() * 9))).toString(16)
54+
this.drawerId = Number(
55+
(Date.now() + Math.random()).toString().replace('.', Math.round(Math.random() * 9)),
56+
).toString(16)
5657
const open = this.open !== undefined ? this.open : !!this.defaultOpen
5758
currentDrawer[this.drawerId] = open
5859
this.orignalOpen = this.open
@@ -170,7 +171,7 @@ const Drawer = {
170171
onWrapperTransitionEnd (e) {
171172
if (e.target === this.contentWrapper) {
172173
this.dom.style.transition = ''
173-
if (!this.sOpen && this.getCrrentDrawerSome()) {
174+
if (!this.sOpen && this.getCurrentDrawerSome()) {
174175
document.body.style.overflowX = ''
175176
if (this.maskDom) {
176177
this.maskDom.style.left = ''
@@ -185,7 +186,7 @@ const Drawer = {
185186
this.container = this.defaultGetContainer()
186187
}
187188
},
188-
getCrrentDrawerSome () {
189+
getCurrentDrawerSome () {
189190
return !Object.keys(currentDrawer).some(key => currentDrawer[key])
190191
},
191192
getSelfContainer () {
@@ -215,8 +216,11 @@ const Drawer = {
215216
if (level === 'all') {
216217
const children = Array.prototype.slice.call(this.parent.children)
217218
children.forEach(child => {
218-
if (child.nodeName !== 'SCRIPT' && child.nodeName !== 'STYLE' &&
219-
child.nodeName !== 'LINK' && child !== this.container) {
219+
if (child.nodeName !== 'SCRIPT' &&
220+
child.nodeName !== 'STYLE' &&
221+
child.nodeName !== 'LINK' &&
222+
child !== this.container
223+
) {
220224
this.levelDom.push(child)
221225
}
222226
})
@@ -251,9 +255,12 @@ const Drawer = {
251255
if (getContainer === 'body') {
252256
const eventArray = ['touchstart']
253257
const domArray = [document.body, this.maskDom, this.handlerdom, this.contentDom]
254-
const right = document.body.scrollHeight > (window.innerHeight || document.documentElement.clientHeight) &&
258+
const right =
259+
document.body.scrollHeight >
260+
(window.innerHeight || document.documentElement.clientHeight) &&
255261
window.innerWidth > document.body.offsetWidth
256-
? getScrollBarSize(1) : 0
262+
? getScrollBarSize(1)
263+
: 0
257264
let widthTransition = `width ${duration} ${ease}`
258265
const trannsformTransition = `transform ${duration} ${ease}`
259266
if (open && document.body.style.overflow !== 'hidden') {
@@ -295,12 +302,12 @@ const Drawer = {
295302
this.passive
296303
)
297304
})
298-
} else if (this.getCrrentDrawerSome()) {
305+
} else if (this.getCurrentDrawerSome()) {
299306
document.body.style.overflow = ''
300307
if ((this.isOpenChange || openTransition) && right) {
301308
document.body.style.position = ''
302309
document.body.style.width = ''
303-
if (trnasitionStr) {
310+
if (transitionStr) {
304311
document.body.style.overflowX = 'hidden'
305312
}
306313
this.dom.style.transition = 'none'
@@ -367,21 +374,19 @@ const Drawer = {
367374
maskStyle,
368375
width,
369376
height,
370-
wrapClassName,
371377
} = this.$props
372378
const children = this.$slots.default
373379
const wrapperClassname = classnames(prefixCls, {
374380
[`${prefixCls}-${placement}`]: true,
375381
[`${prefixCls}-open`]: open,
376-
[wrapClassName]: !!wrapClassName,
382+
...getClass(this),
377383
})
378384
const isOpenChange = this.isOpenChange
379385
const isHorizontal = placement === 'left' || placement === 'right'
380386
const placementName = `translate${isHorizontal ? 'X' : 'Y'}`
381387
// 百分比与像素动画不同步,第一次打用后全用像素动画。
382388
// const defaultValue = !this.contentDom || !level ? '100%' : `${value}px`;
383-
const placementPos =
384-
placement === 'left' || placement === 'top' ? '-100%' : '100%'
389+
const placementPos = placement === 'left' || placement === 'top' ? '-100%' : '100%'
385390
const transform = open ? '' : `${placementName}(${placementPos})`
386391
if (isOpenChange === undefined || isOpenChange) {
387392
const contentValue = this.contentDom ? this.contentDom.getBoundingClientRect()[
@@ -390,7 +395,7 @@ const Drawer = {
390395
const value = (isHorizontal ? width : height) || contentValue
391396
this.setLevelDomTransform(open, false, placementName, value)
392397
}
393-
let handlerCildren
398+
let handlerChildren
394399
if (handler !== false) {
395400
const handlerDefalut = (
396401
<div class='drawer-handle'>
@@ -400,7 +405,7 @@ const Drawer = {
400405
const { handler: handlerSlot } = this.$slots
401406
const handlerSlotVnode = handlerSlot || handlerDefalut
402407
const { click: handleIconClick } = getEvents(handlerSlotVnode)
403-
handlerCildren = cloneElement(handlerSlotVnode, {
408+
handlerChildren = cloneElement(handlerSlotVnode, {
404409
on: {
405410
click: (e) => {
406411
handleIconClick && handleIconClick()
@@ -475,7 +480,7 @@ const Drawer = {
475480
>
476481
{children}
477482
</div>
478-
{handlerCildren}
483+
{handlerChildren}
479484
</div>
480485
</div>
481486
)
@@ -484,7 +489,7 @@ const Drawer = {
484489
return this.open !== undefined ? this.open : this.sOpen
485490
},
486491
getTouchParentScroll (root, currentTarget, differX, differY) {
487-
if (!currentTarget) {
492+
if (!currentTarget || currentTarget === document) {
488493
return false
489494
}
490495
// root 为 drawer-content 设定了 overflow, 判断为 root 的 parent 时结束滚动;
@@ -506,20 +511,27 @@ const Drawer = {
506511
*/
507512
const t = currentTarget.scrollTop
508513
const l = currentTarget.scrollLeft
509-
currentTarget.scrollTo(currentTarget.scrollLeft + 1, currentTarget.scrollTop + 1)
514+
if (currentTarget.scrollTo) {
515+
currentTarget.scrollTo(currentTarget.scrollLeft + 1, currentTarget.scrollTop + 1)
516+
}
510517
const currentT = currentTarget.scrollTop
511518
const currentL = currentTarget.scrollLeft
512-
currentTarget.scrollTo(currentTarget.scrollLeft - 1, currentTarget.scrollTop - 1)
513-
519+
if (currentTarget.scrollTo) {
520+
currentTarget.scrollTo(currentTarget.scrollLeft - 1, currentTarget.scrollTop - 1)
521+
}
514522
if (
515-
isY && (!scrollY || !(currentT - t) ||
516-
(scrollY && (currentTarget.scrollTop >= scrollY && differY < 0 ||
517-
currentTarget.scrollTop <= 0 && differY > 0))
518-
) ||
519-
isX && (!scrollX || !(currentL - l) ||
520-
(scrollX && (currentTarget.scrollLeft >= scrollX && differX < 0 ||
521-
currentTarget.scrollLeft <= 0 && differX > 0))
522-
)
523+
(isY &&
524+
(!scrollY ||
525+
!(currentT - t) ||
526+
(scrollY &&
527+
((currentTarget.scrollTop >= scrollY && differY < 0) ||
528+
(currentTarget.scrollTop <= 0 && differY > 0))))) ||
529+
(isX &&
530+
(!scrollX ||
531+
!(currentL - l) ||
532+
(scrollX &&
533+
((currentTarget.scrollLeft >= scrollX && differX < 0) ||
534+
(currentTarget.scrollLeft <= 0 && differX > 0)))))
523535
) {
524536
return this.getTouchParentScroll(root, currentTarget.parentNode, differX, differY)
525537
}
@@ -544,8 +556,8 @@ const Drawer = {
544556
if (
545557
currentTarget === this.maskDom ||
546558
currentTarget === this.handlerdom ||
547-
currentTarget === this.contentDom &&
548-
this.getTouchParentScroll(currentTarget, e.target, differX, differY)
559+
(currentTarget === this.contentDom &&
560+
this.getTouchParentScroll(currentTarget, e.target, differX, differY))
549561
) {
550562
e.preventDefault()
551563
}
@@ -588,7 +600,7 @@ const Drawer = {
588600
</div>
589601
)
590602
}
591-
if (!this.container || !open && !this.sFirstEnter) {
603+
if (!this.container || (!open && !this.sFirstEnter)) {
592604
return null
593605
}
594606
return (

components/vc-drawer/src/drawerProps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import PropTypes from '../../_util/vue-types'
22

33
export default {
4-
wrapClassName: PropTypes.string,
4+
wrapperClassName: PropTypes.string,
55
width: PropTypes.any,
66
height: PropTypes.any,
77
defaultOpen: PropTypes.bool,

components/vc-drawer/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// base in 1.7.6
1+
// base in 1.7.7
22
// export this package's api
33
import Drawer from './Drawer'
44

components/vc-drawer/src/utils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ export function dataToArray (vars) {
44
}
55
return [vars]
66
}
7-
const trnasitionEndObject = {
7+
const transitionEndObject = {
88
transition: 'transitionend',
99
WebkitTransition: 'webkitTransitionEnd',
1010
MozTransition: 'transitionend',
1111
OTransition: 'oTransitionEnd otransitionend',
1212
}
13-
export const trnasitionStr = Object.keys(trnasitionEndObject).filter(key => {
13+
export const transitionStr = Object.keys(transitionEndObject).filter(key => {
1414
if (typeof document === 'undefined') {
1515
return false
1616
}
1717
const html = document.getElementsByTagName('html')[0]
1818
return key in (html ? html.style : {})
1919
})[0]
20-
export const transitionEnd = trnasitionEndObject[trnasitionStr]
20+
export const transitionEnd = transitionEndObject[transitionStr]
2121

2222
export function addEventListener (target, eventType, callback, options) {
2323
if (target.addEventListener) {
@@ -51,6 +51,6 @@ export function transformArguments (arg, cb) {
5151
return [result]
5252
}
5353

54-
export const isNumeric = (value) => {
54+
export const isNumeric = value => {
5555
return !isNaN(parseFloat(value)) && isFinite(value);// eslint-disable-line
5656
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { createForm } from '../index'
2+
const Form = {
3+
4+
methods: {
5+
handleSubmit (e) {
6+
e.preventDefault()
7+
const { validateFields } = this.form
8+
validateFields()
9+
.then(console.log)
10+
.catch(console.error)
11+
},
12+
},
13+
14+
render () {
15+
const { getFieldDecorator } = this.form
16+
return (
17+
<form onSubmit={this.handleSubmit}>
18+
{getFieldDecorator('name', {
19+
rules: [{
20+
required: true,
21+
}],
22+
})(<input/>)}
23+
<button type='submit'>submit</button>
24+
</form>
25+
)
26+
},
27+
}
28+
29+
export default createForm()(Form)

0 commit comments

Comments
 (0)