Skip to content

Commit

Permalink
Merge pull request #1731 from sheinsight/release-1.10.15
Browse files Browse the repository at this point in the history
Release 1.10.15
  • Loading branch information
leehaoChen authored Aug 8, 2022
2 parents 624b5b9 + ac3c2ad commit 509b92c
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 112 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "shineout",
"version": "1.10.14",
"version": "1.10.15",
"description": "Shein 前端组件库",
"main": "./lib/index.js",
"module": "./es/index.js",
Expand Down
6 changes: 6 additions & 0 deletions site/pages/documentation/changelog/1.x.x.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# 更新日志
### 1.10.15
- 修复 DatePicker 在 range 模式下手动输入日期会校验错误的问题(1.10.14)
- 修复 DatePicker 范围选择,设置 defaultTime 后开始日期的样式没有没选中的问题(< 1.10.15)
- 修复 Select 多选创建选项时输入删除键会导致直接删除选项的问题(1.10.14 - 1.7.1)
- 优化 Table 中 td 的渲染次数来提升 Table 组件的性能

### 1.10.14
- 优化 Select Cascader TreeSelect 在 compressed 模式下至少显示一个标签
- 修复在 safari 浏览器中 Input 在禁用状态下文字模糊的问题(< 1.10.14)
Expand Down
31 changes: 20 additions & 11 deletions src/DatePicker/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,26 +262,35 @@ class Container extends PureComponent {
}
}

disabledRegister(disabled, mode) {
this.disabledMap[mode] = disabled
disabledRegister(disabled, mode, index) {
if (index === undefined) {
this.disabledMap[mode] = disabled
return
}
if (!this.disabledMap[mode]) this.disabledMap[mode] = []
this.disabledMap[mode][index] = disabled
}

handleDisabled(date) {
handleDisabled(date, index) {
const mode = this.props.type
const { disabledMap } = this
const { min, max, range, disabled, disabledTime } = this.props
const isRange = index !== undefined

switch (mode) {
case 'time':
return ParamFns.handleDisabled(date, min, max, range, disabled, disabledTime)
return isRange
? disabledMap.time[index](date, undefined, undefined, true)
: disabledMap.time(date, undefined, undefined, true)
case 'date':
return disabledMap.day(date)
return isRange ? disabledMap.day[index](date) : disabledMap.day(date)
case 'week':
return disabledMap.day(date)
return isRange ? disabledMap.day[index](date) : disabledMap.day(date)
case 'month':
return disabledMap.month(date)
return isRange ? disabledMap.month[index](date) : disabledMap.month(date)
case 'datetime':
return ParamFns.handleDisabled(date, min, max, range, disabled, disabledTime) || disabledMap.day(date)
return isRange
? disabledMap.time[index](date, undefined, undefined, true) || disabledMap.day[index](date)
: disabledMap.time(date, undefined, undefined, true) || disabledMap.day(date)
default:
return false
}
Expand All @@ -294,7 +303,7 @@ class Container extends PureComponent {
let isDisabled

if (disabled || disabledTime || max || min || range) {
isDisabled = this.handleDisabled(date)
isDisabled = this.handleDisabled(date, index)
if (isDisabled) return
}

Expand All @@ -305,7 +314,7 @@ class Container extends PureComponent {
}

const value = [
...immer(this.props.value, draft => {
...immer(this.props.value === undefined && range ? [] : this.props.value, draft => {
draft[index] = val
}),
]
Expand Down
6 changes: 3 additions & 3 deletions src/DatePicker/Day.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Day extends PureComponent {
this.handleDisabled = this.handleDisabled.bind(this)
this.formatWithDefaultTime = this.formatWithDefaultTime.bind(this)

props.disabledRegister(this.handleDisabled, 'day')
props.disabledRegister(this.handleDisabled, 'day', props.index)
}

getDays() {
Expand Down Expand Up @@ -198,7 +198,7 @@ class Day extends PureComponent {
classList.push(utils.isSameDay(date, rangeDate[index]) && 'active')

hoverClass = datepickerClass(
utils.compareAsc(rangeDate[0], date) <= 0 && utils.compareAsc(rangeDate[1], date) >= 0 && 'hover',
utils.compareDay(rangeDate[0], date) <= 0 && utils.compareDay(rangeDate[1], date) >= 0 && 'hover',
// Datetime Picker range end datetime classname #330
utils.isSameDay(rangeDate[index], date) && `hover-${index === 0 ? 'start' : 'end'} active`
)
Expand Down Expand Up @@ -315,7 +315,7 @@ Day.propTypes = {
onChangeSync: PropTypes.func,
onDayHover: PropTypes.func,
onModeChange: PropTypes.func.isRequired,
range: PropTypes.number,
range: PropTypes.oneOfType([PropTypes.number, PropTypes.bool]),
rangeDate: PropTypes.array,
rangeTemp: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
showTimePicker: PropTypes.bool,
Expand Down
2 changes: 1 addition & 1 deletion src/DatePicker/Month.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Month extends PureComponent {
this.handleYearClick = this.handleYearClick.bind(this)
this.handleDisabled = this.handleDisabled.bind(this)

props.disabledRegister(this.handleDisabled, 'month')
props.disabledRegister(this.handleDisabled, 'month', props.index)
}

handleYearChange(year) {
Expand Down
17 changes: 13 additions & 4 deletions src/DatePicker/Time.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class Time extends PureComponent {
this.handleMinuteChange = this.handleChange.bind(this, 'minute')
this.handleSecondChange = this.handleChange.bind(this, 'second')
this.handleAMPMChange = this.handleChange.bind(this, 'ampm')
this.handleDisabled = this.handleDisabled.bind(this)

props.disabledRegister(this.handleDisabled, 'time', props.index)
}

getDefaultTime() {
Expand All @@ -30,8 +33,14 @@ class Time extends PureComponent {
return this.props.value || this.defaultValue
}

handleDisabled(value, val, mode, onlyVaild) {
const { disabled, min, max, range, disabledTime } = this.props
const [isDisabled, date] = paramUtils.judgeTimeByRange(val, value, mode, min, max, range, disabled, disabledTime)
return onlyVaild ? isDisabled : [isDisabled, date]
}

handleChange(type, val) {
const { disabled, format, min, max, range, disabledTime } = this.props
const { format } = this.props
const value = this.getValue()

let mode = type
Expand All @@ -43,8 +52,7 @@ class Time extends PureComponent {
mode = 'H'
}
}

const [isDisabled, date] = paramUtils.judgeTimeByRange(val, value, mode, min, max, range, disabled, disabledTime)
const [isDisabled, date] = this.handleDisabled(value, val, mode)

if (isDisabled) return
this.props.onChange(...paramUtils.timeHandleChangeParams(date, true, false, 'time'))
Expand Down Expand Up @@ -166,14 +174,15 @@ Time.propTypes = {
min: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
max: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
onChange: PropTypes.func.isRequired,
range: PropTypes.number,
range: PropTypes.oneOfType([PropTypes.number, PropTypes.bool]),
value: PropTypes.object,
defaultTime: PropTypes.array,
index: PropTypes.number,
hourStep: PropTypes.number,
minuteStep: PropTypes.number,
secondStep: PropTypes.number,
disabledTime: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
disabledRegister: PropTypes.func,
}

export default Time
2 changes: 1 addition & 1 deletion src/DatePicker/TimeScroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ TimeScroll.propTypes = {
disabled: PropTypes.func,
min: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
max: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
range: PropTypes.number,
range: PropTypes.oneOfType([PropTypes.number, PropTypes.bool]),
current: PropTypes.object,
mode: PropTypes.string,
disabledTime: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
Expand Down
7 changes: 4 additions & 3 deletions src/DatePicker/paramUtils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import utils from './utils'
import { isNumber } from '../utils/is'

const { TIME_FORMAT, compareAsc, addSeconds, format } = utils

Expand Down Expand Up @@ -26,17 +27,18 @@ function handleTimeDisabled(date, disabledTime) {

function handleDisabled(...args) {
const [date, min, max, range, disabled, disabledTime] = args

let isDisabled
if (disabled) isDisabled = disabled(date)
if (disabledTime) isDisabled = isDisabled || handleTimeDisabled(date, disabledTime)
if (isDisabled) return true
if (!isDisabled && min) {
if (compareAsc(date, min) < 0) return true
if (range && compareAsc(date, addSeconds(min, range)) > 0) return true
if (range && isNumber(range) && compareAsc(date, addSeconds(min, range)) > 0) return true
}
if (!isDisabled && max) {
if (compareAsc(date, max) > 0) return true
if (range && compareAsc(date, addSeconds(max, -range)) < 0) return true
if (range && isNumber(range) && compareAsc(date, addSeconds(max, -range)) < 0) return true
}
return false
}
Expand Down Expand Up @@ -76,7 +78,6 @@ function judgeTimeByRange(...args) {
default:
break
}

const isDisabled = handleDisabled(date, min, max, range, disabled, disabledTime)
return [isDisabled, date]
}
Expand Down
8 changes: 8 additions & 0 deletions src/DatePicker/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ function toDateWithFormat(dirtyDate, fmt, def) {
return date
}

function compareDay(dateLeft, dateRight) {
if (!dateLeft || !dateRight) return NaN
const left = new Date(dateLeft.getFullYear(), dateLeft.getMonth(), dateLeft.getDate())
const right = new Date(dateRight.getFullYear(), dateRight.getMonth(), dateRight.getDate())
return compareAsc(left, right)
}

function compareMonth(dateLeft, dateRight, pad = 0) {
if (!dateLeft || !dateRight) return 0
const left = new Date(dateLeft.getFullYear(), dateLeft.getMonth(), 1)
Expand Down Expand Up @@ -284,6 +291,7 @@ export default {
cloneTime,
compareAsc,
compareMonth,
compareDay,
getDaysOfMonth,
format: formatted,
isInvalid,
Expand Down
108 changes: 52 additions & 56 deletions src/Select/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,11 @@ class Select extends PureComponent {
this.clearClickAway()
}

getText(key) {
return this.props.text[key] || getLocale(key)
}

getDisabledStatus() {
if (typeof this.props.disabled == 'function') {
if (typeof this.props.disabled === 'function') {
return this.props.disabled
} else {
return !!this.props.disabled
}
return !!this.props.disabled
}

getFocusSelected() {
Expand Down Expand Up @@ -388,14 +383,14 @@ class Select extends PureComponent {
}

handleDelete(e) {
const { multiple, filterText, datum, value, data } = this.props
const { multiple, inputText, datum, value, data } = this.props
if (!multiple) return
if (filterText) {
if (inputText) {
this.deleteLock = true
} else if (this.deleteLock) {
this.cancelDeleteLock()
}
if (filterText || this.deleteLock) return
if (inputText || this.deleteLock) return
if (!value || !value.length) return
e.preventDefault()
const raws = Array.isArray(value) ? value : [value]
Expand Down Expand Up @@ -428,29 +423,29 @@ class Select extends PureComponent {
const { focus, position } = this.state
const { optionWidth } = this.props
const props = {}
;[
'treeData',
'expanded',
'onExpand',
'loader',
'defaultExpanded',
'defaultExpandAll',
'datum',
'keygen',
'multiple',
'text',
'height',
'loading',
'onFilter',
'filterText',
'absolute',
'zIndex',
'childrenKey',
'expandIcons',
'emptyText',
].forEach(k => {
props[k] = this.props[k]
})
;[
'treeData',
'expanded',
'onExpand',
'loader',
'defaultExpanded',
'defaultExpandAll',
'datum',
'keygen',
'multiple',
'text',
'height',
'loading',
'onFilter',
'filterText',
'absolute',
'zIndex',
'childrenKey',
'expandIcons',
'emptyText',
].forEach(k => {
props[k] = this.props[k]
})
const style = optionWidth && { width: optionWidth }
props.renderItem = this.renderItem
return (
Expand All @@ -474,29 +469,29 @@ class Select extends PureComponent {
const { focus, control, position } = this.state
const { autoAdapt, value, optionWidth } = this.props
const props = {}
;[
'data',
'datum',
'keygen',
'multiple',
'columns',
'columnWidth',
'columnsTitle',
'text',
'itemsInView',
'absolute',
'lineHeight',
'height',
'loading',
'onFilter',
'filterText',
'zIndex',
'groupKey',
'hideCreateOption',
'emptyText',
].forEach(k => {
props[k] = this.props[k]
})
;[
'data',
'datum',
'keygen',
'multiple',
'columns',
'columnWidth',
'columnsTitle',
'text',
'itemsInView',
'absolute',
'lineHeight',
'height',
'loading',
'onFilter',
'filterText',
'zIndex',
'groupKey',
'hideCreateOption',
'emptyText',
].forEach(k => {
props[k] = this.props[k]
})

const List = props.columns >= 1 || props.columns === -1 ? WrappedBoxList : WrappedOptionList
const style = optionWidth && { width: optionWidth }
Expand Down Expand Up @@ -650,6 +645,7 @@ Select.propTypes = {
header: PropTypes.node,
maxLength: PropTypes.number,
innerTitle: PropTypes.node,
inputText: PropTypes.string,
}

Select.defaultProps = {
Expand Down
Loading

0 comments on commit 509b92c

Please sign in to comment.