Skip to content

Commit c257cbb

Browse files
committed
TS 类型使用相对路径引入 (merge request !439)
Squash merge branch '0518_chore_path' into 'develop' * refactor(global.d.ts): remove global.d.ts; and use common.ts instead * feat(menu): add ts type export * docs: update snapshots * fix(date-picker): rename destroyOnHide to destroyOnClose * docs(api): update * feat(render-tnode): support vue3 * feat(menu): icon * feat(menue): code as api.md * feat: merge from origin/develop * refactor: @Tdtype to be ../../types * feat: merge from origin/develop * Merge remote-tracking branch 'origin/develop' into 0518_chore_path * feat: update common * refactor: remove global.d.ts, import required types
1 parent c9d5d25 commit c257cbb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+342
-128
lines changed

common

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit 5dcc8ce63df3399ac9ecc1f6539d5fd5f026160c
1+
Subproject commit c0b1a99c19f1180e658cfdf4c4363b6a27532bb1

examples/tabs/tabs.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99
:::
1010

1111
:: BASE_PROPS ::
12+
13+
`list` 待实现

globals.d.ts

-46
Original file line numberDiff line numberDiff line change
@@ -1,47 +1 @@
1-
2-
/** Vue2 特有全局变量 */
3-
41
declare const __VERSION__: string;
5-
6-
declare type TNodeReturnValue = import('vue/types/vnode').ScopedSlotReturnValue;
7-
declare type TNode<T = any> = (h: Vue.CreateElement, props?: T) => TNodeReturnValue;
8-
declare type JsxNode = TNodeReturnValue;
9-
10-
declare type AttachNodeReturnValue = HTMLElement | Element | Document;
11-
declare type AttachNode = CSSSelector | (() => AttachNodeReturnValue);
12-
13-
// 与滚动相关的容器类型,因为 document 上没有 scroll 相关属性, 因此排除document
14-
declare type ScrollContainerElement = Window | HTMLElement
15-
declare type ScrollContainer = (() => ScrollContainerElement) | CSSSelector;
16-
17-
declare type FormResetEvent = Event;
18-
declare type FormSubmitEvent = SubmitEvent;
19-
20-
declare interface Styles {
21-
[css: string]: string | number;
22-
}
23-
24-
declare module '@tencent/tdesign-vue' {
25-
export * from 'src';
26-
}
27-
28-
/** 通用全局变量 */
29-
30-
declare type OptionData = {
31-
label?: string;
32-
value?: string | number;
33-
} & { [key: string]: any };
34-
35-
declare type TreeOptionData = {
36-
children?: Array<TreeOptionData>;
37-
} & OptionData;
38-
39-
declare type SizeEnum = 'small' | 'medium' | 'large';
40-
41-
declare type HorizontalAlignEnum = 'left' | 'center' | 'right';
42-
43-
declare type VerticalAlignEnum = 'top' | 'middle' | 'bottom';
44-
45-
declare type ClassName = { [className: string]: any } | ClassName[] | string;
46-
47-
declare type CSSSelector = string;

src/affix/affix.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { prefix } from '../config';
33
import { on, off, getScrollContainer } from '../utils/dom';
44
import affixProps from '../../types/affix/props';
55
import isFunction from 'lodash/isFunction';
6+
import { ScrollContainerElement } from '../../types/common';
67

78
const name = `${prefix}-affix`;
89
export interface Affix extends Vue {

src/breadcrumb/breadcrumb.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { prefix } from '../config';
33
import props from '../../types/breadcrumb/props';
44
import BreadcrumbItem from '../breadcrumbItem/index';
55
import { TdBreadcrumbItemProps } from '../../types/breadcrumb/TdBreadcrumbProps';
6+
import { TNodeReturnValue } from '../../types/common';
7+
68
const name = `${prefix}-breadcrumb`;
79

810
export default Vue.extend({

src/button/button.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default Vue.extend({
1818
removeClickAnimation(this.$refs.button as HTMLElement);
1919
},
2020
render(): VNode {
21-
let buttonContent: JsxNode = renderContent(this, 'default', 'content');
21+
let buttonContent = renderContent(this, 'default', 'content');
2222
const icon = this.loading ? <TIconLoading/> : renderTNodeJSX(this, 'icon');
2323
const iconOnly = icon && !Boolean(buttonContent);
2424
let { theme } = this;

src/checkbox/checkbox.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { prefix } from '../config';
33
import CLASSNAMES from '../utils/classnames';
44
import checkboxProps from '../../types/checkbox/props';
55
import Group from './group';
6+
import { ClassName } from '../../types/common';
7+
68

79
const name = `${prefix}-checkbox`;
810

src/date-picker/date-picker.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ export default mixins(getLocalRecevierMixins<TdDatePickerProps & DatePickerInsta
690690
trigger="click"
691691
placement="bottom-left"
692692
disabled={disabled}
693-
destroyOnHide
693+
destroyOnClose
694694
showArrow={false}
695695
visible={isOpen}
696696
popupProps={popupProps}

src/dialog/dialog.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import mixins from '../utils/mixins';
1111
import getLocalRecevierMixins from '../locale/local-receiver';
1212
import TransferDom from '../utils/transfer-dom';
1313
import { emitEvent } from '../utils/event';
14+
import { ClassName, Styles, TNode } from '../../types/common';
1415

1516
type FooterButton = string | ButtonProps | TNode;
1617
type FooterButtonType = 'confirm' | 'cancel';

src/drawer/drawer.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import mixins from '../utils/mixins';
88
import getLocalRecevierMixins from '../locale/local-receiver';
99
import TransferDom from '../utils/transfer-dom';
1010
import { emitEvent } from '../utils/event';
11+
import { ClassName, Styles } from '../../types/common';
1112

1213
type FooterButtonType = 'confirm' | 'cancel';
1314

src/dropdown/dropdown-item.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Icon from '../icon';
33
import { prefix } from '../config';
44
import CLASSNAMES from '../utils/classnames';
55
import bus from './bus';
6+
import { TNodeReturnValue } from '../../types/common';
67

78
const name = `${prefix}-dropdown__item`;
89

@@ -54,10 +55,10 @@ export default Vue.extend({
5455
};
5556
},
5657
methods: {
57-
renderIcon(): JsxNode {
58+
renderIcon(): TNodeReturnValue {
5859
return this.iconName ? <Icon name={this.iconName} /> : '';
5960
},
60-
renderSuffix(): JsxNode {
61+
renderSuffix(): TNodeReturnValue {
6162
return this.hasChildren ? <Icon class="children-suffix" name="chevron-right" /> : '';
6263
},
6364
handleItemClick(): void {

src/dropdown/dropdown-menu.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Vue from 'vue';
22
import DropdownItem from './dropdown-item';
33
import bus from './bus';
44
import { prefix } from '../config';
5+
import { TNodeReturnValue } from '../../types/common';
56

67
const name = `${prefix}-dropdown__menu`;
78

@@ -42,7 +43,7 @@ export default Vue.extend({
4243
}
4344
return this.path.indexOf(itemPath) === 0;
4445
},
45-
renderMenuColumn(children: Array<OptionItem>, showSubmenu: boolean, pathPrefix: string): JsxNode {
46+
renderMenuColumn(children: Array<OptionItem>, showSubmenu: boolean, pathPrefix: string): TNodeReturnValue {
4647
return (
4748
<div class={`${name}__column ${showSubmenu ? 'submenu__visible' : ''}`} style={{
4849
maxHeight: `${this.maxColumnHeight}px`,
@@ -78,7 +79,7 @@ export default Vue.extend({
7879
});
7980
},
8081
render() {
81-
const columns: JsxNode[] = [];
82+
const columns: TNodeReturnValue[] = [];
8283
let menuItems = this.options as OptionItem[];
8384
let pathPrefix = '';
8485
// 根据path渲染

src/form/form-item.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { NormalizedScopedSlot } from 'vue/types/vnode';
99
import cloneDeep from 'lodash/cloneDeep';
1010
import lodashGet from 'lodash/get';
1111
import lodashSet from 'lodash/set';
12+
import { ClassName, TNodeReturnValue } from '../../types/common';
1213

1314
type Result = ValidateResult<TdFormProps['data']>;
1415

src/form/form.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { FORM_ITEM_CLASS_PREFIX, CLASS_NAMES } from './const';
66
import isEmpty from 'lodash/isEmpty';
77
import { emitEvent } from '../utils/event';
88
import FormItem from './form-item';
9+
import { FormResetEvent, FormSubmitEvent, ClassName } from '../../types/common';
910

1011
type FormItemInstance = InstanceType<typeof FormItem>;
1112

src/grid/row.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Vue from 'vue';
22
import { prefix } from '../config';
33
import responsiveObserver from '../utils/responsive-observer';
44
import props from '../../types/row/props';
5+
import { ClassName } from '../../types/common';
56

67
const name = `${prefix}-row`;
78

src/input-number/input-number.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import CLASSNAMES from '../utils/classnames';
88
import props from '../../types/input-number/props';
99
import { ChangeSource } from '../../types/input-number/TdInputNumberProps';
1010
import { addClickAnimation, removeClickAnimation } from '../utils/animation';
11+
import { ClassName, TNodeReturnValue } from '../../types/common';
1112

1213
const name = `${prefix}-input-number`;
1314

src/input/input.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export default (Vue as VueConstructor<InputInstance>).extend({
106106
h: CreateElement,
107107
icon: string | Function | undefined,
108108
iconType: 'prefix-icon' | 'suffix-icon',
109-
): JsxNode {
109+
) {
110110
if (typeof icon === 'function') {
111111
return icon(h);
112112
}

src/list/list.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import CLASSNAMES from '../utils/classnames';
77
import { LOAD_MORE, LOADING } from './const';
88
import { TdListProps } from '../../types/list/TdListProps';
99
import { ScopedSlotReturnValue } from 'vue/types/vnode';
10+
import { ClassName } from '../../types/common';
1011

1112
const name = `${prefix}-list`;
1213

src/menu/const.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MenuValue } from '@TdTypes/menu/TdMenuProps';
1+
import { MenuValue } from '../../types/menu/TdMenuProps';
22
import { Ref } from '@vue/composition-api';
33
import { VNodeChildren } from 'vue';
44

src/menu/head-menu.tsx

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { defineComponent, computed, provide, ref, reactive, watch } from '@vue/composition-api';
22
import { prefix } from '../config';
3-
import props from '@TdTypes/head-menu/props';
4-
import { MenuValue } from '@TdTypes/menu/TdMenuProps';
3+
import props from '../../types/head-menu/props';
4+
import { MenuValue } from '../../types/menu/TdMenuProps';
55
import { TdMenuInterface, TdMenuItem } from './const';
66
import { Tabs, TabPanel } from '../tabs';
7+
import { renderContent, renderTNodeJSX } from '../utils/render-tnode';
8+
79
const name = `${prefix}-head-menu`;
810

911
export default defineComponent({
@@ -109,18 +111,19 @@ export default defineComponent({
109111
},
110112
},
111113
render() {
114+
if (this.$slots.options) {
115+
console.warn('TDesign Warn: `options` slot is going to be deprecated, please use `operations` for slot instead.');
116+
}
117+
const operations = renderContent(this, 'operations', 'options');
118+
const logo = renderTNodeJSX(this, 'logo');
112119
return (
113120
<div class={this.menuClass}>
114121
<div class={`${prefix}-head-menu__inner`}>
115-
<div class={`${prefix}-menu__logo`}>
116-
{this.$slots.logo}
117-
</div>
122+
{logo && <div class={`${prefix}-menu__logo`}>{logo}</div>}
118123
<ul class={`${prefix}-menu`}>
119-
{this.$slots.default}
124+
{renderContent(this, 'default', 'content')}
120125
</ul>
121-
<div class={`${prefix}-menu__options`}>
122-
{this.$slots.options}
123-
</div>
126+
{operations && <div class={`${prefix}-menu__options`}>{operations}</div>}
124127
</div>
125128
{this.mode === 'normal' && this.renderNormalSubmenu()}
126129
</div>

src/menu/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import _MenuGroup from './menu-group';
88
import withInstall from '../utils/withInstall';
99

1010

11-
// export * from '../../types/menu/TdMenuProps';
11+
export * from '../../types/menu/TdMenuProps';
1212

1313
export const Menu = withInstall('Menu', _Menu, VueCompositionAPI);
1414
export const HeadMenu = withInstall('HeadMenu', _HeadMenu, VueCompositionAPI);

src/menu/menu-item.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { defineComponent, computed, inject, onMounted } from '@vue/composition-api';
22
import { prefix } from '../config';
3-
import props from '@TdTypes/menu-item/props';
3+
import props from '../../types/menu-item/props';
44
import { TdMenuInterface, TdSubMenuInterface } from './const';
55
import Ripple from '../utils/ripple';
6+
import { renderContent, renderTNodeJSX } from '../utils/render-tnode';
7+
68
const name = `${prefix}-menu-item`;
79

810
export default defineComponent({
@@ -66,8 +68,8 @@ export default defineComponent({
6668
render() {
6769
return (
6870
<li v-ripple={this.menu.theme.value === 'light' ? '#E7E7E7' : '#383838'} class={this.classes} onClick={this.handleClick} ref="button">
69-
{this.$slots.icon}
70-
<span class={[`${prefix}-menu__content`]}>{this.$slots.default}</span>
71+
{renderTNodeJSX(this, 'icon')}
72+
<span class={[`${prefix}-menu__content`]}>{renderContent(this, 'default', 'content')}</span>
7173
</li>
7274
);
7375
},

src/menu/menu.tsx

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { defineComponent, ref, computed, provide, watchEffect, watch } from '@vue/composition-api';
22
import { prefix } from '../config';
3-
import props from '@TdTypes/menu/props';
4-
import { MenuValue } from '@TdTypes/menu/TdMenuProps';
3+
import props from '../../types/menu/props';
4+
import { MenuValue } from '../../types/menu/TdMenuProps';
55
import { TdMenuInterface } from './const';
6+
import { renderContent, renderTNodeJSX } from '../utils/render-tnode';
7+
68
const name = `${prefix}-menu`;
79

810
export default defineComponent({
@@ -108,18 +110,19 @@ export default defineComponent({
108110
};
109111
},
110112
render() {
113+
if (this.$slots.options) {
114+
console.warn('TDesign Warn: `options` slot is going to be deprecated, please use `operations` for slot instead.');
115+
}
116+
const operations = renderContent(this, 'operations', 'options');
117+
const logo = renderTNodeJSX(this, 'logo');
111118
return (
112119
<div class={this.menuClass} style={this.styles}>
113120
<div class={`${prefix}-default-menu__inner`}>
114-
{
115-
this.$slots.logo && (<div class={`${prefix}-menu__logo`}>{this.$slots.logo}</div>)
116-
}
121+
{logo && (<div class={`${prefix}-menu__logo`}>{logo}</div>)}
117122
<ul class={this.innerClasses}>
118-
{this.$slots.default}
123+
{renderContent(this, 'default', 'content')}
119124
</ul>
120-
{
121-
this.$slots.options && (<div class={`${prefix}-menu__options`}>{this.$slots.options}</div>)
122-
}
125+
{operations && (<div class={`${prefix}-menu__options`}>{operations}</div>)}
123126
</div>
124127
</div>
125128
);

src/menu/submenu.tsx

+7-6
Original file line numberDiff line numberDiff line change
@@ -153,29 +153,30 @@ export default defineComponent({
153153
},
154154
renderSubmenu() {
155155
const hasContent = this.$slots.content || this.$slots.default;
156+
const icon = renderTNodeJSX(this, 'icon');
156157
const svgArrow = (
157158
<svg class={this.arrowClass} width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
158159
<path d="M3.75 5.7998L7.99274 10.0425L12.2361 5.79921" stroke="black" stroke-opacity="0.9" stroke-width="1.3"/>
159160
</svg>);
160161
const normalSubmenu = [
161162
<div v-ripple={this.rippleColor} class={this.submenuClass} onClick={this.handleSubmenuItemClick}>
162-
{this.$slots.icon}
163-
<span class={[`${prefix}-menu__content`]}>{renderTNodeJSX(this as Vue, 'title')}</span>
163+
{icon}
164+
<span class={[`${prefix}-menu__content`]}>{renderTNodeJSX(this, 'title')}</span>
164165
{hasContent && svgArrow}
165166
</div>,
166167
<ul class={this.subClass} >
167-
{renderContent(this as Vue, 'default', 'content')}
168+
{renderContent(this, 'default', 'content')}
168169
</ul>,
169170
];
170171
const popupSubmenu = [
171172
<div class={this.submenuClass}>
172-
{this.$slots.icon}
173-
<span class={[`${prefix}-menu__content`]}>{renderTNodeJSX(this as Vue, 'title')}</span>
173+
{icon}
174+
<span class={[`${prefix}-menu__content`]}>{renderTNodeJSX(this, 'title')}</span>
174175
{svgArrow}
175176
</div>,
176177
<div ref="popup" class={this.popupClass}>
177178
<ul ref="popupInner" class={`${prefix}-menu__popup-wrapper`}>
178-
{renderContent(this as Vue, 'default', 'content')}
179+
{renderContent(this, 'default', 'content')}
179180
</ul>
180181
</div>,
181182
];

src/message/message.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import TIconClose from '../icon/close';
99
import { THEME_LIST } from './const';
1010
import { renderTNodeJSX, renderContent } from '../utils/render-tnode';
1111
import props from '../../types/message/props';
12+
import { ClassName } from '../../types/common';
1213

1314
const name = `${prefix}-message`;
1415

src/message/messageList.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { PLACEMENT_OFFSET } from './const';
33
import TMessage from './message';
44
import { prefix } from '../config';
55
import { MessageOptions } from '../../types/message/TdMessageProps';
6+
import { Styles } from '../../types/common';
67

78
export const DEFAULT_Z_INDEX = 6000;
89

src/message/plugin.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
MessageCloseMethod,
4141
MessageCloseAllMethod,
4242
} from '../../types/message/TdMessageProps';
43+
import { AttachNodeReturnValue } from '../../types/common';
4344

4445
// 存储不同 attach 和 不同 placement 消息列表实例
4546
const instanceMap: Map<AttachNodeReturnValue, object> = new Map();

0 commit comments

Comments
 (0)