Skip to content

Commit

Permalink
feat(comp: tree): add tree component (#476)
Browse files Browse the repository at this point in the history
fix #446
  • Loading branch information
danranVm authored Oct 14, 2021
1 parent 78738c2 commit 8f8ebca
Show file tree
Hide file tree
Showing 73 changed files with 4,297 additions and 49 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
- 全面拥抱 Composition Api,从源码到文档
- 完全使用 TypeScript 开发,提供完整的类型定义
- 开箱即用的 Tree Shaking
- 高覆盖率的单元测试
- 国际化语言支持
- 灵活的全局配置
- 深入细节的主题定制能力
Expand Down
8 changes: 5 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
// u can change this option to a more specific folder for test single component or util when dev
// for example, ['<rootDir>/packages/components/button']
// for example, roots: ['<rootDir>/packages/components/button'],
roots: ['<rootDir>/packages/'],

// when running jst locally, you can turn off coverage.
// for example, collectCoverage: false,
collectCoverage: true,
testEnvironment: 'jsdom',
transform: {
'^.+\\.vue$': 'vue3-jest',
Expand Down Expand Up @@ -34,7 +37,6 @@ module.exports = {
'^dayjs/esm$': 'dayjs',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
collectCoverage: true,
coverageReporters: ['json', 'lcov', 'text', 'cobertura'],
coverageThreshold: {
global: {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@
"typescript": "^4.3.5",
"unplugin-vue-components": "^0.15.0",
"vite": "^2.5.1",
"vite-plugin-eslint": "^1.3.0",
"vue3-jest": "^27.0.0-alpha.2",
"yaml-front-matter": "^4.1.1"
},
Expand Down
4 changes: 4 additions & 0 deletions packages/cdk/utils/src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,7 @@ export function callEmit<T extends (...args: any[]) => any>(
return funcs(...args)
}
}

export type VKey = string | number | symbol

export const vKeyPropDef = IxPropTypes.oneOf([String, Number, Symbol])
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import { Transition, defineComponent } from 'vue'

import { callEmit } from '@idux/cdk/utils'

import { collapseTransitionProps } from './types'

export default defineComponent({
Expand All @@ -26,6 +28,8 @@ export default defineComponent({
const mode = props.mode
el.style[mode] = ''
el.style.opacity = ''

callEmit(props.onAfterEnter)
}
const onBeforeLeave = (el: HTMLElement) => {
const mode = props.mode
Expand All @@ -40,11 +44,13 @@ export default defineComponent({
const mode = props.mode
el.style[mode] = ''
el.style.opacity = ''

callEmit(props.onAfterLeave)
}

return () => (
<Transition
appear
appear={props.appear}
name={props.name}
onBeforeEnter={onBeforeEnter}
onEnter={onEnter}
Expand Down
3 changes: 3 additions & 0 deletions packages/components/_private/collapse-transition/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ import { IxPropTypes } from '@idux/cdk/utils'
export type CollapseTransitionMode = 'height' | 'width'

export const collapseTransitionProps = {
appear: IxPropTypes.bool.def(false),
name: IxPropTypes.string.def('ix-collapse-transition'),
mode: IxPropTypes.oneOf<CollapseTransitionMode>(['height', 'width']).def('height'),
onAfterEnter: IxPropTypes.emit(),
onAfterLeave: IxPropTypes.emit(),
}

export type CollapseTransitionProps = IxInnerPropTypes<typeof collapseTransitionProps>
Expand Down
7 changes: 3 additions & 4 deletions packages/components/button/style/index.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@import '../../style/themes/default.less';
@import '../../icon/style/index.less';
@import './mixin.less';

@button-prefix: ~'@{idux-prefix}-button';
Expand Down Expand Up @@ -90,7 +89,7 @@
}

&-icon-only {
.button-icon-only(@button-prefix; @icon-prefix);
.button-icon-only(@button-prefix;);
}

&::before {
Expand All @@ -114,8 +113,8 @@
position: relative;
}

> .@{icon-prefix} + span,
> span + .@{icon-prefix} {
> .@{idux-prefix}-icon + span,
> span + .@{idux-prefix}-icon {
margin-left: @button-icon-margin-left;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/components/button/style/mixin.less
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@
}
}

.button-icon-only(@buttonPrefix; @icon-prefix) {
.button-icon-only(@buttonPrefix;) {
line-height: 1;
font-size: @button-font-size-md + 2;
&.@{buttonPrefix}-small {
Expand Down
2 changes: 1 addition & 1 deletion packages/components/collapse/src/CollapsePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default defineComponent({
return (
<div class={classes.value}>
{headerNode}
<IxCollapseTransition>
<IxCollapseTransition appear>
<div v-show={expanded} class="ix-collapse-panel-content">
<div class="ix-collapse-panel-content-box">{slots.default?.()}</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions packages/components/components.less
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
@import './switch/style/index.less';
@import './textarea/style/index.less';
// import Data Display
@import './tree/style/index.less';
@import './table/style/index.less';
@import './avatar/style/index.less';
@import './collapse/style/index.less';
Expand Down
9 changes: 9 additions & 0 deletions packages/components/config/src/defaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import type {

import { shallowReactive } from 'vue'

import { TreeConfig } from '..'
import { numFormatter } from './numFormatter'

// --------------------- Common ---------------------
Expand Down Expand Up @@ -239,6 +240,13 @@ const tooltip = shallowReactive<TooltipConfig>({
trigger: 'hover',
})

const tree = shallowReactive<TreeConfig>({
blocked: false,
expandIcon: 'right',
nodeKey: 'key',
showLine: false,
})

const popover = shallowReactive<PopoverConfig>({
autoAdjust: true,
delay: 100,
Expand Down Expand Up @@ -337,6 +345,7 @@ export const defaultConfig: GlobalConfig = {
statistic,
table,
tooltip,
tree,
popover,
// Feedback
message,
Expand Down
8 changes: 8 additions & 0 deletions packages/components/config/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ export interface TableColumnExpandableConfig {
icon: [string, string]
}

export interface TreeConfig {
blocked: boolean
expandIcon: string
nodeKey: string
showLine: boolean
}

export interface TooltipConfig {
autoAdjust: boolean
delay: number | [number | null, number | null]
Expand Down Expand Up @@ -358,6 +365,7 @@ export interface GlobalConfig {
statistic: StatisticConfig
table: TableConfig
tooltip: TooltipConfig
tree: TreeConfig
popover: PopoverConfig
stepper: StepperConfig
// Feedback
Expand Down
2 changes: 1 addition & 1 deletion packages/components/drawer/src/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const useTrigger = (props: DrawerProps, updateVisible: (value: boolean) => void)
const open = () => updateVisible(true)

const close = async (evt?: Event | unknown) => {
const result = await Promise.resolve(callEmit(props.onClose, evt))
const result = await callEmit(props.onClose, evt)
if (result === false) {
return
}
Expand Down
3 changes: 1 addition & 2 deletions packages/components/empty/style/index.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@import '../../style/themes/default.less';
@import '../../icon/style/index.less';

@empty-prefix: ~'@{idux-prefix}-empty';

Expand All @@ -17,7 +16,7 @@
height: 100%;
}

.@{icon-prefix} {
.@{idux-prefix}-icon {
font-size: @empty-icon-font-size-md;
}
}
Expand Down
6 changes: 5 additions & 1 deletion packages/components/icon/src/staticIcons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import type { IconDefinition } from './types'

import {
Calendar,
CaretDown,
CaretUp,
Check,
CheckCircle,
CheckCircleFilled,
Expand Down Expand Up @@ -47,7 +49,9 @@ export const staticIcons: IconDefinition[] = [
Up,
Down,
Left,
Right,
Right, // Tree
CaretDown, // Table
CaretUp, // Table
DoubleLeft,
DoubleRight,
Loading,
Expand Down
2 changes: 2 additions & 0 deletions packages/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { IxTextarea } from '@idux/components/textarea'
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 { IxTypography } from '@idux/components/typography'
import { version } from '@idux/components/version'

Expand Down Expand Up @@ -91,6 +92,7 @@ const components = [
IxSwitch,
IxTimePicker,
IxTable,
IxTree,
IxAvatar,
IxCollapse,
IxCollapsePanel,
Expand Down
2 changes: 1 addition & 1 deletion packages/components/menu/src/menu-sub/InlineContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default defineComponent({
})

return () => (
<IxCollapseTransition>
<IxCollapseTransition appear>
<ul v-show={isExpanded.value} class={classes.value}>
{slots.default?.()}
</ul>
Expand Down
2 changes: 1 addition & 1 deletion packages/components/message/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
width: calc(100% - @font-size-lg - @message-icon-margin-right);
}

.@{icon-prefix} {
.@{idux-prefix}-icon {
position: relative;
vertical-align: top;
top: 2px;
Expand Down
2 changes: 1 addition & 1 deletion packages/components/message/style/mixin.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.message-icon-color (@type, @color) {
&.@{message-prefix}-@{type} .@{icon-prefix} {
&.@{message-prefix}-@{type} .@{idux-prefix}-icon {
color: @color;
}
}
2 changes: 1 addition & 1 deletion packages/components/modal/src/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const useTrigger = (props: ModalProps, updateVisible: (value: boolean) => void)
const open = () => updateVisible(true)

const close = async (evt?: Event | unknown) => {
const result = await Promise.resolve(callEmit(props.onClose, evt))
const result = await callEmit(props.onClose, evt)
if (result === false) {
return
}
Expand Down
3 changes: 1 addition & 2 deletions packages/components/result/style/index.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@import '../../style/themes/default.less';
@import '../../icon/style/index.less';
@import './mixins.less';

@result-prefix: ~'@{idux-prefix}-result';
Expand All @@ -11,7 +10,7 @@
&-icon {
margin-bottom: @result-icon-margin;

& > .@{icon-prefix} {
& > .@{idux-prefix}-icon {
font-size: @result-icon-size;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/components/style/core/reset.less
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ html {
body {
// 2
color: @text-color;
background-color: @background-color-body;
background-color: @background-color-component;
font-family: @font-family;
font-size: @font-size-md;
font-weight: @font-weight-md;
Expand Down
15 changes: 14 additions & 1 deletion packages/components/style/variable/color/color.less
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,21 @@
/* color -------------------------- */
@background-color-base: hsv(0, 0, 95%); // Default grey background color
@background-color-light: hsv(0, 0, 98%); // background of header and selected item
@background-color-body: @color-white;

@background-color-component: @color-white;
@background-color-component-dark: #191c24;

@background-color-hover-dark: @color-grey-l30;
@background-color-hover: @color-grey-l40;
@background-color-hover-light: @color-grey-l50;

@background-color-selected-dark: @color-primary-l30;
@background-color-selected: @color-primary-l40;
@background-color-selected-light: @color-primary-l50;

@background-color-disabled: hsv(0, 0, 95%);

// @deprecated
@disabled-color: fade(@color-black, 25%);
@disabled-color-dark: fade(@color-white, 35%);
@disabled-bg-color: @background-color-base;
Expand All @@ -317,3 +328,5 @@
@text-color-secondary: fade(@color-black, 45%);
@text-color-dark: fade(@color-white, 85%);
@text-color-secondary-dark: fade(@color-white, 65%);
@text-color-disabled: fade(@color-black, 25%);
@text-color-disabled-dark: fade(@color-white, 35%);
2 changes: 1 addition & 1 deletion packages/components/table/demo/Basic.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<IxTable :columns="columns" :dataSource="data">
<IxTable :columns="columns" :dataSource="data" ex>
<template #name="{ value }">
<a>{{ value }}</a>
</template>
Expand Down
10 changes: 5 additions & 5 deletions packages/components/table/docs/Index.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ single: true
| `v-model:expandedRowKeys` | 展开行的 `key` 数组 | `(string \| number)[]` | - | - | - |
| `v-model:selectedRowKeys` | 选中行的 `key` 数组 | `(string \| number)[]` | - | - | - |
| `borderless` | 是否无边框 | `boolean` | `false` || - |
| `childrenKey` | 指定树形结构的列名 | `string` | `children` | - | - |
| `childrenKey` | 指定树形结构的 `key` | `string` | `children` | - | - |
| `columns` | 表格列的配置描述, 参见[TableColumn](#TableColumn) | `TableColumn[]` | - | - | - |
| `dataSource` | 表格数据数组 | `object[]` | - | - | - |
| `empty` | 空数据时的内容 | `string \| EmptyProps \| #empty` | - | - | - |
| `headless` | 是否隐藏表头 | `boolean` | `false` | - |- |
| `pagination` | 配置分页器, 参见[TablePagination](#TablePagination) | `TablePagination \| null` | - || 设置 `null` 时表示不显示分页 |
| `rowClassName` | 表格行的类名 | `(record: T, rowIndex: number) => string` | - | - | - |
| `rowKey` | 表格行 `key` 的取值 | `string \| record => string \| number` | `key` | | - |
| `rowKey` | 表格行 `key` 的取值 | `string \| record => string \| number` | `key` | - | - |
| `scroll` | 表格滚动配置项,可以指定滚动区域的宽、高, 参见[TableScroll](#TableScroll) | `TableScroll` | - | - | - |
| `size` | 表格大小 | `'large' \| 'medium' \| 'small'` | `medium` ||- |
| `spin` | 表格是否加载中 | `boolean \| SpinProps` | - | - | - |
Expand Down Expand Up @@ -93,7 +93,7 @@ export type TableColumnTitleFn = (options: { title?: string }) => VNodeTypes
| `type` | 列类型 | `'expandable'` | - | - | `type` 设置为 `expandable`,即为展开列 |
| `customExpand` | 自定义展开内容 | `string \| TableColumnExpandableExpandFn<T>` | - | - | 类型为 `string` 时,对应插槽名 |
| `customIcon` | 自定义展开图标 | `string \| TableColumnExpandableIconFn<T>` | - | - | 类型为 `string` 时,对应插槽名 |
| `enabled` | 设置是否允许行展开 | `(record:T, rowIndex: number) => boolean` | - | - | - |
| `disabled` | 设置是否允许行展开 | `(record:T, rowIndex: number) => boolean` | - | - | - |
| `icon` | 展开按钮图标 | `[string, string]` | `['plus', 'minus']` | ✅ | - |
| `indent` | 展示树形数据时,每层缩进的宽度 | `number` | `12` | - | - |
| `trigger` | 不通过图标,触发行展开的方式 | `'click' \| 'doubleClick'` | - | - | - |
Expand All @@ -116,10 +116,10 @@ export type TableColumnExpandableIconFn<T = unknown> = (options: {
| 名称 | 说明 | 类型 | 默认值 | 全局配置 | 备注 |
| --- | --- | --- | --- | --- | --- |
| `type` | 列类型 | `'selectable'` | - | - | `type` 设置为 `selectable`,即为选择列 |
| `enabled` | 设置是否允许行选择 | `(record: T, rowIndex: number) => boolean` | - | - | - |
| `disabled` | 设置是否允许行选择 | `(record: T, rowIndex: number) => boolean` | - | - | - |
| `multiple` | 是否支持多选 | `boolean` | `true` | - | - |
| `options` | 自定义列头选择项 | `boolean \| TableSelectableSelection[]` | `false` | - | 为 `false` 时,不显示,为 `true` 时,显示默认的选择项 |
| `trigger` | 不通过 `type`,触发行选择的方式 | `'click' \| 'doubleClick'` | - | - | - |
| `trigger` | 不通过点击选择框,触发行选择的方式 | `'click' \| 'doubleClick'` | - | - | - |
| `onChange` | 选中状态发生变化时触发 | `(selectedRowKeys: (string \| number)[], selectedRecords: T[]) => void` | - | - | - |
| `onSelect` | 点击选择框,或通过 `trigger` 触发 | `(selected: boolean, record: T) => void` | - | - | - |
| `onSelectAll` | 点击全选所有时触发 | `(selectedRowKeys: (string \| number)[]) => void` | - | - | - |
Expand Down
Loading

0 comments on commit 8f8ebca

Please sign in to comment.