Skip to content

Commit

Permalink
feat(comp: tree-select): add tree-select comp
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzaijiang committed Dec 12, 2021
1 parent d5c2f81 commit 3fd3196
Show file tree
Hide file tree
Showing 66 changed files with 2,960 additions and 15 deletions.
10 changes: 10 additions & 0 deletions packages/components/config/src/defaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import type {
TimeRangePickerConfig,
TooltipConfig,
TreeConfig,
TreeSelectConfig,
} from './types'

import { numFormatter } from './numFormatter'
Expand Down Expand Up @@ -191,6 +192,14 @@ const timeRangePicker: TimeRangePickerConfig = {
separator: '~',
}

const treeSelect: TreeSelectConfig = {
size: 'md',
suffix: 'down',
childrenKey: 'children',
labelKey: 'label',
nodeKey: 'key',
}

// --------------------- Data Display ---------------------
const avatar: AvatarConfig = {
gap: 4,
Expand Down Expand Up @@ -387,6 +396,7 @@ export const defaultConfig: GlobalConfig = {
textarea,
timePicker,
timeRangePicker,
treeSelect,
// Data Display
avatar,
badge,
Expand Down
10 changes: 10 additions & 0 deletions packages/components/config/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ export interface SelectConfig {
valueKey: string
}

export interface TreeSelectConfig {
size: FormSize
suffix: string
childrenKey: string
labelKey: string
nodeKey: string
target?: PortalTargetType
}

export interface TimePickerConfig {
borderless: boolean
clearable: boolean
Expand Down Expand Up @@ -411,6 +420,7 @@ export interface GlobalConfig {
radio: RadioConfig
rate: RateConfig
select: SelectConfig
treeSelect: TreeSelectConfig
timePicker: TimePickerConfig
timeRangePicker: TimeRangePickerConfig
// Data Display
Expand Down
1 change: 1 addition & 0 deletions packages/components/default.less
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@
@import './timeline/style/themes/default.less';
@import './tooltip/style/themes/default.less';
@import './tree/style/themes/default.less';
@import './tree-select/style/themes/default.less';
@import './typography/style/themes/default.less';
2 changes: 2 additions & 0 deletions packages/components/icon/demo/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ export const allIcons = [
'thunderbolt',
'tool',
'transmit',
'tree-expand',
'tree-unexpand',
'unexpand',
'unlock',
'up',
Expand Down
26 changes: 18 additions & 8 deletions packages/components/icon/src/definitions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* @license
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/IDuxFE/idux/blob/main/LICENSE
*/

/**
* @license
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/IDuxFE/idux/blob/main/LICENSE
*/

export const Alert = {
name: 'alert',
svg: '<svg viewBox="64 64 896 896"><path d="M593.536 64c7.04 0 12.8 5.76 12.8 12.8v131.072A288.128 288.128 0 0 1 799.872 480v178.752l151.424 151.424A12.8 12.8 0 0 1 942.272 832H668.8a159.808 159.808 0 0 1-313.216 0H80.32a12.8 12.8 0 0 1-8.896-22.016l152.448-147.136V480c0-124.8 79.36-231.04 190.4-271.04V76.8c0-7.04 5.76-12.8 12.8-12.8h166.4zm9.472 768H421.952a96 96 0 0 0 181.056 0zm-91.136-576a224 224 0 0 0-224 224v210.112L207.104 768h611.52l-82.752-82.752V480a224 224 0 0 0-224-224zm32.384-128h-64.128v65.728c6.016-.64 12.096-1.152 18.176-1.408l13.568-.32c10.624 0 21.12.576 31.424 1.664l.96-65.664z"/></svg>',
Expand Down Expand Up @@ -307,7 +307,7 @@ export const Ellipsis = {

export const Empty = {
name: 'empty',
svg: '<svg viewBox="64 64 896 896"><defs><style/></defs><path d="M961.991 628.895h.01V849.5c0 31.066-25.184 56.25-56.25 56.25h-787.5C87.185 905.75 62 880.566 62 849.5V628.895h.01a36.879 36.879 0 0 1 5.25-18.1l118.856-198.028c10.175-16.954 28.515-27.33 48.307-27.33h555.149c19.792 0 38.131 10.376 48.307 27.33l118.856 198.027a36.718 36.718 0 0 1 5.255 18.1zm-312.198-4.38c.362 0 .724-.005 1.084-.015h252.416a7.031 7.031 0 0 0 6.028-10.65L801.65 434.458a14.084 14.084 0 0 0-12.077-6.833h-555.15a14.083 14.083 0 0 0-12.076 6.833L114.675 613.85a7.031 7.031 0 0 0 6.029 10.65h253.505c13.108 0 24.435 9.047 27.39 21.739C411.727 697.968 457.307 737 512.002 737c37.814 0 71.271-18.657 91.668-47.268a111.935 111.935 0 0 0 18.56-42.63c2.632-13.134 14.168-22.588 27.564-22.588zM512.001 118.25c11.65 0 21.094 9.444 21.094 21.094v89.648c0 11.65-9.444 21.094-21.094 21.094s-21.094-9.444-21.094-21.094v-89.648c0-11.65 9.444-21.094 21.094-21.094zm266.341 65.892c8.237 8.238 8.237 21.593 0 29.831l-63.391 63.392c-8.238 8.237-21.594 8.237-29.831 0-8.238-8.238-8.238-21.594 0-29.831l63.391-63.392c8.237-8.238 21.593-8.238 29.831 0zm-532.682 0c8.238-8.238 21.594-8.238 29.832 0l63.39 63.392c8.238 8.237 8.238 21.593 0 29.83-8.237 8.238-21.593 8.238-29.831 0l-63.391-63.39c-8.237-8.239-8.237-21.594 0-29.832z"/></svg>',
svg: '<svg viewBox="64 64 896 896"><path d="M256 332.8V896h512V332.8c0-7.04 5.76-12.8 12.8-12.8h38.4c7.04 0 12.8 5.76 12.8 12.8v614.08a12.8 12.8 0 0 1-12.8 12.8H204.8a12.8 12.8 0 0 1-12.8-12.8V332.8c0-7.04 5.76-12.8 12.8-12.8h38.4c7.04 0 12.8 5.76 12.8 12.8zM64 192h896v64H64z"/><path d="M755.2 64c7.04 0 12.8 5.76 12.8 12.8V256h-63.552V128h-383.68v128H256V76.8c0-7.04 5.76-12.8 12.8-12.8h486.4z"/></svg>',
}

export const Environment = {
Expand Down Expand Up @@ -865,6 +865,16 @@ export const Transmit = {
svg: '<svg viewBox="64 64 896 896"><path d="M922.624 80.256a44.608 44.608 0 0 1 57.408 49.344l-1.536 6.656-262.4 830.976a33.152 33.152 0 0 1-51.456 16.512l-3.648-3.072-252.16-252.16 45.056-45.056 216.576 216.576 236.288-748.16-750.208 234.176L322.56 552.064l-45.056 45.12L75.712 395.392a33.152 33.152 0 0 1 9.856-53.568l3.712-1.536L922.624 80.256z"/><path d="M961.088 102.208a35.072 35.072 0 0 0-49.024-7.68l-644.16 468.8v259.136a38.272 38.272 0 0 0 66.88 25.408l624.128-701.824a35.072 35.072 0 0 0 2.176-43.904zM734.4 302.592 331.648 755.52V595.776L734.4 302.592z"/></svg>',
}

export const TreeExpand = {
name: 'tree-expand',
svg: '<svg viewBox="0 0 24 24"><path fill-rule="evenodd" d="M6.7 7a.3.3 0 0 1 .3.3V8h.7a.3.3 0 0 1 .3.3v.4a.3.3 0 0 1-.3.3H7v3h2.7a.3.3 0 0 1 .3.3v.4a.3.3 0 0 1-.3.3H9v3h1.7a.3.3 0 0 1 .3.3v.4a.3.3 0 0 1-.3.3H8.3a.3.3 0 0 1-.3-.3V13H6.3a.3.3 0 0 1-.3-.3V7.3a.3.3 0 0 1 .3-.3h.4Zm11 9a.3.3 0 0 1 .3.3v.4a.3.3 0 0 1-.3.3h-5.4a.3.3 0 0 1-.3-.3v-.4a.3.3 0 0 1 .3-.3h5.4Zm-1-4a.3.3 0 0 1 .3.3v.4a.3.3 0 0 1-.3.3h-5.4a.3.3 0 0 1-.3-.3v-.4a.3.3 0 0 1 .3-.3h5.4Zm-1-4a.3.3 0 0 1 .3.3v.4a.3.3 0 0 1-.3.3H9.3a.3.3 0 0 1-.3-.3v-.4a.3.3 0 0 1 .3-.3h6.4Z"/></svg>',
}

export const TreeUnexpand = {
name: 'tree-unexpand',
svg: '<svg viewBox="0 0 24 24"><path fill-rule="evenodd" d="M6.7 7a.3.3 0 0 1 .3.3V8h1.7a.3.3 0 0 1 .3.3v.4a.3.3 0 0 1-.3.3H7v3h1.7a.3.3 0 0 1 .3.3v.4a.3.3 0 0 1-.3.3H7v3h1.7a.3.3 0 0 1 .3.3v.4a.3.3 0 0 1-.3.3H6.3a.3.3 0 0 1-.3-.3V7.3a.3.3 0 0 1 .3-.3h.4Zm11 9a.3.3 0 0 1 .3.3v.4a.3.3 0 0 1-.3.3h-7.4a.3.3 0 0 1-.3-.3v-.4a.3.3 0 0 1 .3-.3h7.4Zm0-4a.3.3 0 0 1 .3.3v.4a.3.3 0 0 1-.3.3h-7.4a.3.3 0 0 1-.3-.3v-.4a.3.3 0 0 1 .3-.3h7.4Zm0-4a.3.3 0 0 1 .3.3v.4a.3.3 0 0 1-.3.3h-7.4a.3.3 0 0 1-.3-.3v-.4a.3.3 0 0 1 .3-.3h7.4Z"/></svg>',
}

export const Unexpand = {
name: 'unexpand',
svg: '<svg viewBox="64 64 896 896"><path d="M1018.645 531.298c8.635-18.61 4.601-41.42-11.442-55.864l-205.108-184.68c-19.7-17.739-50.05-16.148-67.789 3.552-17.738 19.7-16.148 50.051 3.553 67.79l166.28 149.718-167.28 150.62c-19.7 17.738-21.291 48.088-3.553 67.789 17.739 19.7 48.089 21.291 67.79 3.553l205.107-184.68a47.805 47.805 0 0 0 12.442-17.798zM119.947 511.39l166.28-149.719c19.7-17.738 21.29-48.088 3.552-67.789-17.738-19.7-48.088-21.291-67.789-3.553L16.882 475.01C.84 489.456-3.194 512.264 5.44 530.874a47.805 47.805 0 0 0 12.442 17.798l205.108 184.68c19.7 17.739 50.05 16.148 67.79-3.552 17.738-19.7 16.147-50.051-3.553-67.79l-167.28-150.62zm529.545-377.146c24.911 9.066 37.755 36.61 28.688 61.522L436.03 861.068c-9.067 24.911-36.611 37.755-61.522 28.688-24.911-9.066-37.755-36.61-28.688-61.522l242.15-665.302c9.067-24.911 36.611-37.755 61.522-28.688z"/></svg>',
Expand Down
4 changes: 4 additions & 0 deletions packages/components/icon/src/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import {
RotateRight,
Search,
StarFilled,
TreeExpand,
TreeUnexpand,
User,
VerticalAlignTop,
ZoomIn,
Expand Down Expand Up @@ -82,6 +84,8 @@ export const IDUX_ICON_DEPENDENCIES: IconDefinition[] = [
Search, // Select
StarFilled, // Rate
User, // Avatar
TreeExpand, // TreeSelect
TreeUnexpand, // TreeSelect
VerticalAlignTop, // BackTop
ZoomIn, // Image
ZoomOut, // Image
Expand Down
2 changes: 2 additions & 0 deletions packages/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import { IxTimePicker } from '@idux/components/time-picker'
import { IxTimeline, IxTimelineItem } from '@idux/components/timeline'
import { IxTooltip } from '@idux/components/tooltip'
import { IxTree } from '@idux/components/tree'
import { IxTreeSelect } from '@idux/components/tree-select'
import { IxTypography } from '@idux/components/typography'
import { version } from '@idux/components/version'

Expand Down Expand Up @@ -146,6 +147,7 @@ const components = [
IxTimelineItem,
IxTooltip,
IxTree,
IxTreeSelect,
]

const directives: Record<string, Directive> = {
Expand Down
2 changes: 2 additions & 0 deletions packages/components/style/variable/prefix.less
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
@switch-prefix: ~'@{idux-prefix}-switch';
@textarea-prefix: ~'@{idux-prefix}-textarea';
@time-picker-prefix: ~'@{idux-prefix}-time-picker';
@tree-select-prefix: ~'@{idux-prefix}-tree-select';
@tree-select-option-prefix: ~'@{idux-prefix}-tree-select-option';

// Feedback
@alert-prefix: ~'@{idux-prefix}-alert';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`TreeSelect render work 1`] = `
"<div class=\\"ix-tree-select ix-tree-select-single ix-tree-select-with-suffix ix-tree-select-md\\">
<!----><label class=\\"ix-tree-select-selector\\">
<!---->
<div class=\\"ix-tree-select-selector-input\\"><input class=\\"ix-tree-select-selector-input-inner\\" style=\\"opacity: 0;\\" autocomplete=\\"off\\">
<!---->
</div>
<div class=\\"ix-tree-select-selector-placeholder\\">
<!---->
</div>
<div class=\\"ix-tree-select-selector-suffix\\"><i class=\\"ix-icon ix-icon-down\\" role=\\"img\\" aria-label=\\"down\\"></i></div>
<!---->
</label>
</div>
<!---->"
`;
15 changes: 15 additions & 0 deletions packages/components/tree-select/__tests__/treeSelect.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { MountingOptions, mount } from '@vue/test-utils'

import { renderWork } from '@tests'

import TreeSelect from '../src/TreeSelect'
import { TreeSelectProps } from '../src/types'

describe('TreeSelect', () => {
const TreeSelectMount = (options?: MountingOptions<Partial<TreeSelectProps>>) =>
mount(TreeSelect, { ...(options as MountingOptions<TreeSelectProps>) })

renderWork<TreeSelectProps>(TreeSelect, {
props: {},
})
})
14 changes: 14 additions & 0 deletions packages/components/tree-select/demo/AsynLoad.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title:
zh: 异步加载
en: Asynchronously load
order: 7
---

## zh

点击展开节点,动态加载数据。

## en

To load data asynchronously when click to expand a treeNode.
47 changes: 47 additions & 0 deletions packages/components/tree-select/demo/AsynLoad.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<template>
<IxTreeSelect placeholder="异步加载" :dataSource="treeData" :loadChildren="loadChildren" :onLoaded="onLoaded" />
</template>

<script setup lang="ts">
import type { VKey } from '@idux/cdk/utils'
import type { TreeSelectNode } from '@idux/components/tree-select'
const treeData: TreeSelectNode[] = [
{
label: 'Parent 0',
key: '0',
},
{
label: 'Parent 1',
key: '1',
},
{
label: 'Tree Node ',
key: '2',
isLeaf: true,
},
]
const loadChildren = (node: TreeSelectNode) => {
return new Promise<TreeSelectNode[]>(resolve => {
setTimeout(() => {
const parentKey = node.key as string
const children = [
{
label: `Child ${parentKey}-0 `,
key: `${parentKey}-0`,
},
{
label: `Child ${parentKey}-1 `,
key: `${parentKey}-1`,
},
]
resolve(children)
}, 1000)
})
}
const onLoaded = (loadedKeys: VKey[], node: TreeSelectNode) => {
console.log('onLoaded', loadedKeys, node)
}
</script>
14 changes: 14 additions & 0 deletions packages/components/tree-select/demo/Basic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title:
zh: 基本使用
en: Basic usage
order: 0
---

## zh

最简单的用法。

## en

The simplest usage.
54 changes: 54 additions & 0 deletions packages/components/tree-select/demo/Basic.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<template>
<IxTreeSelect
v-model:value="value"
v-model:expandedKeys="expandedKeys"
placeholder="单选"
checkable
:dataSource="treeData"
:onExpand="onExpand"
:onSelect="onSelect"
/>
</template>

<script setup lang="ts">
import type { TreeSelectNode } from '@idux/components/tree-select'
import { ref } from 'vue'
const treeData = [
{
label: 'Node 0',
key: '0',
children: [
{
label: 'Node 0-0',
key: '0-0',
children: [
{
label: 'Node 0-0-0',
key: '0-0-0',
},
{
label: 'Node 0-0-1',
key: '0-0-1',
},
],
},
{
label: 'Node 0-1',
key: '0-1',
children: [
{ label: 'Node 0-1-0', key: '0-1-0' },
{ label: 'Node 0-1-1', key: '0-1-1' },
],
},
],
},
]
const value = ref('0-0')
const expandedKeys = ref(['0'])
const onExpand = (expanded: boolean, node: TreeSelectNode) => console.log('expanded', expanded, node)
const onSelect = (selected: boolean, node: TreeSelectNode) => console.log('select', selected, node)
</script>
13 changes: 13 additions & 0 deletions packages/components/tree-select/demo/Cascade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title:
zh: 级联
en: Cascade
order: 3
---

## zh

仅当`multiple``checkable`同时为`true`时才生效
## en


48 changes: 48 additions & 0 deletions packages/components/tree-select/demo/Cascade.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<template>
<IxTreeSelect
v-model:value="value"
placeholder="级联"
cascade
checkable
multiple
defaultExpandAll
:dataSource="treeData"
/>
</template>

<script setup lang="ts">
import { ref } from 'vue'
const treeData = [
{
label: 'Node 0',
key: '0',
children: [
{
label: 'Node 0-0',
key: '0-0',
children: [
{
label: 'Node 0-0-0',
key: '0-0-0',
},
{
label: 'Node 0-0-1',
key: '0-0-1',
},
],
},
{
label: 'Node 0-1',
key: '0-1',
children: [
{ label: 'Node 0-1-0', key: '0-1-0' },
{ label: 'Node 0-1-1', key: '0-1-1' },
],
},
],
},
]
const value = ref(['0-0'])
</script>
Loading

0 comments on commit 3fd3196

Please sign in to comment.