Skip to content

Commit 89bd5af

Browse files
committed
update 3.4.0
1 parent 25d1703 commit 89bd5af

27 files changed

+331
-203
lines changed

components/_util/interopDefault.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// https://github.com/moment/moment/issues/3650
2+
export default function interopDefault (m) {
3+
return m.default || m
4+
}

components/affix/index.jsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,20 @@ export default {
128128
}
129129
this.setState({ placeholderStyle: placeholderStyle })
130130
},
131+
syncPlaceholderStyle (e) {
132+
const { affixStyle } = this
133+
if (!affixStyle) {
134+
return
135+
}
136+
this.$refs.placeholderNode.style.cssText = ''
137+
this.setAffixStyle(e, {
138+
...affixStyle,
139+
width: this.$refs.placeholderNode.offsetWidth + 'px',
140+
})
141+
this.setPlaceholderStyle({
142+
width: this.$refs.placeholderNode.offsetWidth + 'px',
143+
})
144+
},
131145

132146
updatePosition (e) {
133147
let { offsetTop } = this
@@ -200,6 +214,9 @@ export default {
200214
}
201215
this.setPlaceholderStyle(null)
202216
}
217+
if (e.type === 'resize') {
218+
this.syncPlaceholderStyle(e)
219+
}
203220
},
204221
setTargetEventListeners (getTarget) {
205222
const target = getTarget()
@@ -233,7 +250,7 @@ export default {
233250
attrs: omit($props, ['prefixCls', 'offsetTop', 'offsetBottom', 'target']),
234251
}
235252
return (
236-
<div {...props} style={placeholderStyle}>
253+
<div {...props} style={placeholderStyle} ref='placeholderNode'>
237254
<div class={className} ref='fixedNode' style={affixStyle}>
238255
{$slots.default}
239256
</div>

components/alert/index.en-US.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
| Property | Description | Type | Default |
55
| -------- | ----------- | ---- | ------- |
6+
| afterClose | Called when close animation is finished | () => void | - |
67
| banner | Whether to show as banner | boolean | false |
78
| closable | Whether Alert can be closed | boolean | - |
89
| closeText | Close text to show | string\|slot | - |
@@ -15,4 +16,5 @@
1516
### events
1617
| Events Name | Description | Arguments |
1718
| --- | --- | --- |
18-
| close | Callback when Alert is closed | Function |
19+
| close | Callback when Alert is closed | (e: MouseEvent) => void |
20+

components/alert/index.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import BaseMixin from '../_util/BaseMixin'
55
import PropTypes from '../_util/vue-types'
66
import getTransitionProps from '../_util/getTransitionProps'
77
import { getComponentFromProp } from '../_util/props-util'
8-
8+
function noop () { }
99
export const AlertProps = {
1010
/**
1111
* Type of Alert styles, options:`success`, `info`, `warning`, `error`
@@ -21,6 +21,8 @@ export const AlertProps = {
2121
description: PropTypes.any,
2222
/** Callback when close Alert */
2323
// onClose?: React.MouseEventHandler<HTMLAnchorElement>;
24+
/** Trigger when animation ending of Alert */
25+
afterClose: PropTypes.func.def(noop),
2426
/** Whether to show icon */
2527
showIcon: PropTypes.bool,
2628
iconType: PropTypes.string,
@@ -57,6 +59,7 @@ export default {
5759
closed: true,
5860
closing: true,
5961
})
62+
this.afterClose()
6063
},
6164
},
6265

components/alert/index.zh-CN.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
| 参数 | 说明 | 类型 | 默认值 |
55
| --- | --- | --- | --- |
6+
| afterClose | 关闭动画结束后的回掉 | () => void | - |
67
| banner | 是否用作顶部公告 | boolean | false |
78
| closable | 默认不显示关闭按钮 | boolean ||
89
| closeText | 自定义关闭按钮 | string\|slot ||
@@ -15,4 +16,4 @@
1516
### 事件
1617
| 事件名称 | 说明 | 回调参数 |
1718
| --- | --- | --- |
18-
| close | 关闭时触发的回调函数 | Function |
19+
| close | 关闭时触发的回调函数 | (e: MouseEvent) => void |

components/button/button.jsx

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@ export default {
1818
},
1919
clicked: false,
2020
sLoading: !!this.loading,
21+
hasTwoCNChar: false,
2122
}
2223
},
24+
mounted () {
25+
this.fixTwoCNChar()
26+
},
27+
updated () {
28+
this.fixTwoCNChar()
29+
},
2330
watch: {
2431
loading (val) {
2532
clearTimeout(this.delayTimeout)
@@ -32,7 +39,8 @@ export default {
3239
},
3340
computed: {
3441
classes () {
35-
const { prefixCls, type, shape, size, sLoading, ghost, clicked, sizeMap } = this
42+
const { prefixCls, type, shape, size, hasTwoCNChar,
43+
sLoading, ghost, clicked, sizeMap } = this
3644
const sizeCls = sizeMap[size] || ''
3745
return {
3846
[`${prefixCls}`]: true,
@@ -42,6 +50,7 @@ export default {
4250
[`${prefixCls}-loading`]: sLoading,
4351
[`${prefixCls}-clicked`]: clicked,
4452
[`${prefixCls}-background-ghost`]: ghost || type === 'ghost',
53+
[`${prefixCls}-two-chinese-chars`]: hasTwoCNChar,
4554
}
4655
},
4756
iconType () {
@@ -50,6 +59,18 @@ export default {
5059
},
5160
},
5261
methods: {
62+
fixTwoCNChar () {
63+
// Fix for HOC usage like <FormatMessage />
64+
const node = this.$el
65+
const buttonText = node.textContent || node.innerText
66+
if (this.isNeedInserted() && isTwoCNChar(buttonText)) {
67+
if (!this.hasTwoCNChar) {
68+
this.hasTwoCNChar = true
69+
}
70+
} else if (this.hasTwoCNChar) {
71+
this.hasTwoCNChar = false
72+
}
73+
},
5374
handleClick (event) {
5475
this.clicked = true
5576
clearTimeout(this.timeout)
@@ -67,9 +88,16 @@ export default {
6788
}
6889
return child
6990
},
91+
isNeedInserted () {
92+
const { loading, icon, $slots } = this
93+
const iconType = loading ? 'loading' : icon
94+
return $slots.default && $slots.default.length === 1 && (!iconType || iconType === 'loading')
95+
},
7096
},
7197
render () {
72-
const { htmlType, classes, disabled, handleClick, iconType, $slots, $attrs, $listeners } = this
98+
const { htmlType, classes,
99+
disabled, handleClick, iconType,
100+
$slots, $attrs, $listeners } = this
73101
const buttonProps = {
74102
props: {
75103
},
@@ -84,8 +112,7 @@ export default {
84112
click: handleClick,
85113
},
86114
}
87-
const needInserted = $slots.default && $slots.default.length === 1 && (!iconType || iconType === 'loading')
88-
const kids = $slots.default && $slots.default.length === 1 ? this.insertSpace($slots.default[0], needInserted) : $slots.default
115+
const kids = $slots.default && $slots.default.length === 1 ? this.insertSpace($slots.default[0], this.isNeedInserted()) : $slots.default
89116
return (
90117
<button {...buttonProps}>
91118
{iconType ? <Icon type={iconType}></Icon> : null}

components/button/style/mixin.less

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,14 @@
5454
.button-variant-danger(@color; @background; @border) {
5555
.button-color(@color; @background; @border);
5656

57-
&:hover,
58-
&:focus {
57+
&:hover {
5958
.button-color(@btn-primary-color; ~`colorPalette("@{color}", 5)`; ~`colorPalette("@{color}", 5)`);
6059
}
6160

61+
&:focus {
62+
.button-color(~`colorPalette("@{color}", 5)`; #fff; ~`colorPalette("@{color}", 5)`);
63+
}
64+
6265
&:active,
6366
&.active {
6467
.button-color(@btn-primary-color; ~`colorPalette("@{color}", 7)`; ~`colorPalette("@{color}", 7)`);
@@ -108,6 +111,7 @@
108111
display: inline-block;
109112
> .@{btnClassName} {
110113
position: relative;
114+
line-height: @btn-height-base - 2px;
111115

112116
&:hover,
113117
&:focus,
@@ -124,10 +128,12 @@
124128
// size
125129
&-lg > .@{btnClassName} {
126130
.button-size(@btn-height-lg; @btn-padding-lg; @btn-font-size-lg; @btn-border-radius-base);
131+
line-height: @btn-height-lg - 2px;
127132
}
128133

129134
&-sm > .@{btnClassName} {
130135
.button-size(@btn-height-sm; @btn-padding-sm; @font-size-base; @btn-border-radius-sm);
136+
line-height: @btn-height-sm - 2px;
131137
> .@{iconfont-css-prefix} {
132138
font-size: @font-size-base;
133139
}
@@ -198,7 +204,8 @@
198204
&:focus,
199205
&:active,
200206
&.active {
201-
background: #fff;
207+
background: @btn-default-bg;
208+
text-decoration: none;
202209
}
203210
}
204211

components/calendar/Header.jsx

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const HeaderProps = {
1616
// onValueChange: PropTypes.(value: moment.Moment) => void,
1717
// onTypeChange: PropTypes.(type: string) => void,
1818
value: PropTypes.any,
19+
validRange: PropTypes.array,
1920
}
2021

2122
export default {
@@ -28,9 +29,20 @@ export default {
2829
// private calenderHeaderNode: HTMLDivElement;
2930
methods: {
3031
getYearSelectElement (year) {
31-
const { yearSelectOffset, yearSelectTotal, locale, prefixCls, fullscreen } = this
32-
const start = year - yearSelectOffset
33-
const end = start + yearSelectTotal
32+
const {
33+
yearSelectOffset,
34+
yearSelectTotal,
35+
locale,
36+
prefixCls,
37+
fullscreen,
38+
validRange,
39+
} = this
40+
let start = year - yearSelectOffset
41+
let end = start + yearSelectTotal
42+
if (validRange) {
43+
start = validRange[0].get('year')
44+
end = validRange[1].get('year') + 1
45+
}
3446
const suffix = locale.year === '年' ? '年' : ''
3547

3648
const options = []
@@ -63,10 +75,20 @@ export default {
6375
},
6476

6577
getMonthSelectElement (month, months) {
66-
const { prefixCls, fullscreen } = this
78+
const { prefixCls, fullscreen, validRange, value } = this
6779
const options = []
68-
69-
for (let index = 0; index < 12; index++) {
80+
let start = 0
81+
let end = 12
82+
if (validRange) {
83+
const [rangeStart, rangeEnd] = validRange
84+
const currentYear = value.get('year')
85+
if (rangeEnd.get('year') === currentYear) {
86+
end = rangeEnd.get('month') + 1
87+
} else {
88+
start = rangeStart.get('month')
89+
}
90+
}
91+
for (let index = start; index < end; index++) {
7092
options.push(<Option key={`${index}`}>{months[index]}</Option>)
7193
}
7294

@@ -85,8 +107,21 @@ export default {
85107
},
86108

87109
onYearChange (year) {
88-
const newValue = this.value.clone()
110+
const { value, validRange } = this
111+
const newValue = value.clone()
89112
newValue.year(parseInt(year, 10))
113+
// switch the month so that it remains within range when year changes
114+
if (validRange) {
115+
const [start, end] = validRange
116+
const newYear = newValue.get('year')
117+
const newMonth = newValue.get('month')
118+
if (newYear === end.get('year') && newMonth > end.get('month')) {
119+
newValue.month(end.get('month'))
120+
}
121+
if (newYear === start.get('year') && newMonth < start.get('month')) {
122+
newValue.month(start.get('month'))
123+
}
124+
}
90125
this.$emit('valueChange', newValue)
91126
},
92127

components/calendar/index.en-US.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ customize the progress dot by setting a scoped slot
3131
| mode | The display mode of the calendar | `month` \| `year` | `month` |
3232
| monthCellRender | Customize the display of the month cell by setting a scoped slot, the returned content will be appended to the cell | function(date: moment) | - |
3333
| monthFullCellRender | Customize the display of the month cell by setting a scoped slot, the returned content will override the cell | function(date: moment) | - |
34+
| validRange | to set valid range | \[[moment](http://momentjs.com/), [moment](http://momentjs.com/)] | - |
3435
| value(v-model) | The current selected date | [moment](http://momentjs.com/) | current date |
3536

3637
### events

0 commit comments

Comments
 (0)