refactor(tree): change node active color & set default cancelable to true

This commit is contained in:
07akioni 2021-05-24 16:41:12 +08:00
parent 01b092dcfb
commit 06c0fafedc
7 changed files with 27 additions and 13 deletions

View File

@ -1,5 +1,7 @@
# Cascade Check # Cascade Check
Set `cascade` to use cascade check.
```html ```html
<n-tree <n-tree
block-line block-line

View File

@ -9,11 +9,11 @@ What's more, not only biology, I forget balanced tree everytime after I revise i
```demo ```demo
basic basic
cascade cascade
async
multiple multiple
filter filter
virtual
drag-drop drag-drop
virtual
async
``` ```
## Props ## Props
@ -23,7 +23,7 @@ drag-drop
| allow-drop | `(info: { dropPosition: DropPosition, node: TreeOption, phase: 'drag' \| 'drop' }) => boolean` | A function that prohibit dropping inside leaf node. | Whether to allow dropping. | | allow-drop | `(info: { dropPosition: DropPosition, node: TreeOption, phase: 'drag' \| 'drop' }) => boolean` | A function that prohibit dropping inside leaf node. | Whether to allow dropping. |
| block-line | `boolean` | `false` | | | block-line | `boolean` | `false` | |
| block-node | `boolean` | `false` | | | block-node | `boolean` | `false` | |
| cancelable | `boolean` | `false` | Whether node's select status can be cancelled. | | cancelable | `boolean` | `true` | Whether node's select status can be cancelled. |
| cascade | `boolean` | `false` | Whether to cascade checkboxes. | | cascade | `boolean` | `false` | Whether to cascade checkboxes. |
| checkable | `boolean` | `false` | | | checkable | `boolean` | `false` | |
| checked-keys | `Array<string \| number>` | `undefined` | If set, checked status will work in controlled manner. | | checked-keys | `Array<string \| number>` | `undefined` | If set, checked status will work in controlled manner. |

View File

@ -1,5 +1,7 @@
# 级联选择 # 级联选择
设定 `cascade` 进行级联选择。
```html ```html
<n-tree <n-tree
block-line block-line

View File

@ -9,11 +9,11 @@
```demo ```demo
basic basic
cascade cascade
async
multiple multiple
filter filter
virtual
drag-drop drag-drop
virtual
async
``` ```
## Props ## Props
@ -23,7 +23,7 @@ drag-drop
| allow-drop | `(info: { dropPosition: DropPosition, node: TreeOption, phase: 'drag' \| 'drop' }) => boolean` | 一个不允许 drop 在叶节点内部的函数 | 是否允许 drop | | allow-drop | `(info: { dropPosition: DropPosition, node: TreeOption, phase: 'drag' \| 'drop' }) => boolean` | 一个不允许 drop 在叶节点内部的函数 | 是否允许 drop |
| block-line | `boolean` | `false` | | | block-line | `boolean` | `false` | |
| block-node | `boolean` | `false` | | | block-node | `boolean` | `false` | |
| cancelable | `boolean` | `false` | 选中之后是否允许取消 | | cancelable | `boolean` | `true` | 选中之后是否允许取消 |
| cascade | `boolean` | `false` | 是否关联选项 | | cascade | `boolean` | `false` | 是否关联选项 |
| checkable | `boolean` | `false` | | | checkable | `boolean` | `false` | |
| checked-keys | `Array<string \| number>` | `undefined` | 如果设定则 checked 状态受控 | | checked-keys | `Array<string \| number>` | `undefined` | 如果设定则 checked 状态受控 |

View File

@ -58,7 +58,10 @@ const treeProps = {
type: Boolean, type: Boolean,
default: true default: true
}, },
cancelable: Boolean, cancelable: {
type: Boolean,
default: true
},
checkable: Boolean, checkable: Boolean,
draggable: Boolean, draggable: Boolean,
blockNode: Boolean, blockNode: Boolean,
@ -408,7 +411,7 @@ export default defineComponent({
if (onUpdateCheckedKeys) call(onUpdateCheckedKeys, value) if (onUpdateCheckedKeys) call(onUpdateCheckedKeys, value)
if (onCheckedKeysChange) call(onCheckedKeysChange, value) if (onCheckedKeysChange) call(onCheckedKeysChange, value)
} }
function doSelectedKeysChange (value: Key[]): void { function doUpdateSelectedKeys (value: Key[]): void {
const { const {
'onUpdate:selectedKeys': onUpdateSelectedKeys, 'onUpdate:selectedKeys': onUpdateSelectedKeys,
onSelectedKeysChange onSelectedKeysChange
@ -504,15 +507,15 @@ export default defineComponent({
} else if (!~index) { } else if (!~index) {
selectedKeys.push(node.key) selectedKeys.push(node.key)
} }
doSelectedKeysChange(selectedKeys) doUpdateSelectedKeys(selectedKeys)
} else { } else {
const selectedKeys = mergedSelectedKeysRef.value const selectedKeys = mergedSelectedKeysRef.value
if (selectedKeys.includes(node.key)) { if (selectedKeys.includes(node.key)) {
if (props.cancelable) { if (props.cancelable) {
doSelectedKeysChange([]) doUpdateSelectedKeys([])
} }
} else { } else {
doSelectedKeysChange([node.key]) doUpdateSelectedKeys([node.key])
} }
} }
} }

View File

@ -1,3 +1,4 @@
import { changeColor } from 'seemly'
import { checkboxDark } from '../../checkbox/styles' import { checkboxDark } from '../../checkbox/styles'
import { scrollbarDark } from '../../scrollbar/styles' import { scrollbarDark } from '../../scrollbar/styles'
import { commonDark } from '../../_styles/common' import { commonDark } from '../../_styles/common'
@ -11,7 +12,12 @@ const treeDark: TreeTheme = {
Checkbox: checkboxDark, Checkbox: checkboxDark,
Scrollbar: scrollbarDark Scrollbar: scrollbarDark
}, },
self self (vars) {
const { primaryColor } = vars
const commonSelf = self(vars)
commonSelf.nodeColorActive = changeColor(primaryColor, { alpha: 0.15 })
return commonSelf
}
} }
export default treeDark export default treeDark

View File

@ -1,3 +1,4 @@
import { changeColor } from 'seemly'
import { checkboxLight } from '../../checkbox/styles' import { checkboxLight } from '../../checkbox/styles'
import { scrollbarLight } from '../../scrollbar/styles' import { scrollbarLight } from '../../scrollbar/styles'
import { commonLight } from '../../_styles/common' import { commonLight } from '../../_styles/common'
@ -20,7 +21,7 @@ export const self = (vars: ThemeCommonVars) => {
nodeBorderRadius: borderRadiusSmall, nodeBorderRadius: borderRadiusSmall,
nodeColorHover: hoverColor, nodeColorHover: hoverColor,
nodeColorPressed: pressedColor, nodeColorPressed: pressedColor,
nodeColorActive: hoverColor, nodeColorActive: changeColor(primaryColor, { alpha: 0.1 }),
arrowColor: textColor3, arrowColor: textColor3,
nodeTextColor: textColor2, nodeTextColor: textColor2,
nodeTextColorDisabled: textColorDisabled, nodeTextColorDisabled: textColorDisabled,