2020-12-01 10:28:42 +08:00
|
|
|
export const LEFT_CHECK_CHANGE_EVENT = 'left-check-change'
|
|
|
|
export const RIGHT_CHECK_CHANGE_EVENT = 'right-check-change'
|
2020-08-30 20:33:21 +08:00
|
|
|
|
2020-12-01 10:28:42 +08:00
|
|
|
import type { TransferCheckedState, Key } from './transfer'
|
2020-09-05 15:38:55 +08:00
|
|
|
export const useCheckedChange = (checkedState: TransferCheckedState, emit) => {
|
2020-08-30 20:33:21 +08:00
|
|
|
const onSourceCheckedChange = (val: Key[], movedKeys: Key[]) => {
|
2020-09-05 15:38:55 +08:00
|
|
|
checkedState.leftChecked = val
|
2020-08-30 20:33:21 +08:00
|
|
|
if (movedKeys === undefined) return
|
|
|
|
emit(LEFT_CHECK_CHANGE_EVENT, val, movedKeys)
|
|
|
|
}
|
|
|
|
|
|
|
|
const onTargetCheckedChange = (val: Key[], movedKeys: Key[]) => {
|
2020-09-05 15:38:55 +08:00
|
|
|
checkedState.rightChecked = val
|
2020-08-30 20:33:21 +08:00
|
|
|
if (movedKeys === undefined) return
|
|
|
|
emit(RIGHT_CHECK_CHANGE_EVENT, val, movedKeys)
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
onSourceCheckedChange,
|
|
|
|
onTargetCheckedChange,
|
|
|
|
}
|
|
|
|
}
|