Skip to content

Commit 8cb1edb

Browse files
authored
Merge branch 'TDesignOteam:main' into main
2 parents 261647e + f3a8594 commit 8cb1edb

34 files changed

+481
-328
lines changed

DEVELOP_GUIDE.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,15 @@ npm run start
123123
},
124124
```
125125

126+
### Demo 格式
127+
128+
目前支持 omi class 组件和 function 组件demo,前者适用于有状态的demo,后者适用于静态的demo展示,具体可参考`switch`组件
129+
126130
### 组件 Demo 演示配置
127131

128132
为了保证与 vue 等其他仓库演示文档内容统一,目前将公共基础演示 demo 与说明归档在 `src/_common/docs/web/api/[组件].md` 中,其中需要各个技术栈的组件提供文档里面所要求的基础 demo 文件否则会编译警告。
129133

130-
例如 `tooltip` 组件则需要 `_expample` 文件夹中包含有 `arrow.jsx``noArrow.jsx` 文件
134+
例如 `tooltip` 组件则需要 `_expample` 文件夹中包含有 `arrow.tsx``noArrow.tsx` 文件
131135

132136
```md
133137
# Tooltip 文字提示

script/generate-entry.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const __dirname = path.dirname(__filename);
88
const componentsPath = path.resolve(__dirname, '../src');
99

1010
const components = fs.readdirSync(componentsPath).filter((name) => {
11-
if (name === '_common' || name === 'style') return false;
11+
if (name === 'style' || name.startsWith('_')) return false;
1212
const componentPath = path.resolve(componentsPath, name);
1313
if (fs.statSync(componentPath).isDirectory()) {
1414
return true;
@@ -21,5 +21,3 @@ const code = components.reduce((pre, next) => `${pre}export * from './${next}';\
2121
fs.writeFileSync(path.resolve(componentsPath, 'index.ts'), code, {
2222
encoding: 'utf-8',
2323
});
24-
25-
console.log(code);

script/plugin-tdoc/md-to-wc.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export default async function mdToReact(options) {
126126
sourcemap: true,
127127
});
128128

129-
return { code: result.code, map: result.map };
129+
return { code: result.code.replace(/{/g, '{').replace(/}/g, '}'), map: result.map };
130130
}
131131

132132
const DEFAULT_TABS = [
@@ -199,14 +199,16 @@ async function customRender({ source, file, md }) {
199199
).html;
200200
mdSegment.apiMd = md.render.call(
201201
md,
202-
`${pageData.toc ? '[toc]\n' : ''}${apiMd.replace(/<!--[\s\S]+?-->/g, '')}`,
202+
`${pageData.toc ? '[toc]\n' : ''}${apiMd
203+
.replace(/<!--[\s\S]+?-->/g, '')
204+
.replace(/\{/g, '&#123;')
205+
.replace(/\}/g, '&#125;')}`, // 防止esbuild编译报错
203206
).html;
204207
} else {
205208
mdSegment.docMd = md.render.call(
206209
md,
207210
`${pageData.toc ? '[toc]\n' : ''}${content.replace(/<!--[\s\S]+?-->/g, '')}`,
208211
).html;
209212
}
210-
211213
return mdSegment;
212214
}

script/plugin-tdoc/transforms.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default {
4848
.map(
4949
(key) => `
5050
let ${key}Component = null;
51-
if('${key}'.endsWith('omi')){
51+
if(${key}.toString().startsWith('class')){
5252
define('t-${key.toLocaleLowerCase()}', ${key});
5353
${key}Component = <t-${key.toLocaleLowerCase()} />;
5454
} else {

site/pages/components/breadcrumb.tsx

Lines changed: 0 additions & 29 deletions
This file was deleted.

site/pages/components/dark-switch.tsx

Lines changed: 0 additions & 90 deletions
This file was deleted.

site/pages/components/docs-sidebar.tsx

Lines changed: 0 additions & 96 deletions
This file was deleted.

site/sidebar.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default [
8989
title: 'Switch 开关',
9090
name: 'switch',
9191
path: '/components/switch',
92-
// component: () => import('tdesign-web-components/switch/README.md'),
92+
component: () => import('tdesign-web-components/switch/README.md'),
9393
},
9494
],
9595
},

src/_util/classname.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { type ClassValue, clsx } from 'clsx';
2+
import { twMerge } from 'tailwind-merge';
3+
4+
export default function classname(...inputs: ClassValue[]) {
5+
return twMerge(clsx(inputs));
6+
}
7+
8+
export function getClassPrefix() {
9+
return (window as any).__TDESIGN_THEME_PREFIX__ || 't';
10+
}
11+
12+
export const classPrefix = getClassPrefix();
13+
14+
export function getCommonClassName() {
15+
const names = {
16+
SIZE: {
17+
default: '',
18+
xs: `${classPrefix}-size-xs`,
19+
small: `${classPrefix}-size-s`,
20+
medium: `${classPrefix}-size-m`,
21+
large: `${classPrefix}-size-l`,
22+
xl: `${classPrefix}-size-xl`,
23+
block: `${classPrefix}-size-full-width`,
24+
},
25+
STATUS: {
26+
loading: `${classPrefix}-is-loading`,
27+
disabled: `${classPrefix}-is-disabled`,
28+
focused: `${classPrefix}-is-focused`,
29+
success: `${classPrefix}-is-success`,
30+
error: `${classPrefix}-is-error`,
31+
warning: `${classPrefix}-is-warning`,
32+
selected: `${classPrefix}-is-selected`,
33+
active: `${classPrefix}-is-active`,
34+
checked: `${classPrefix}-is-checked`,
35+
current: `${classPrefix}-is-current`,
36+
hidden: `${classPrefix}-is-hidden`,
37+
visible: `${classPrefix}-is-visible`,
38+
expanded: `${classPrefix}-is-expanded`,
39+
indeterminate: `${classPrefix}-is-indeterminate`,
40+
},
41+
};
42+
return {
43+
SIZE: names.SIZE,
44+
STATUS: names.STATUS,
45+
sizeClassNames: names.SIZE,
46+
statusClassNames: names.STATUS,
47+
classPrefix,
48+
};
49+
}

src/_util/parseTNode.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import isFunction from 'lodash/isFunction';
2+
import { cloneElement } from 'omi';
3+
4+
import log from '../_common/js/log';
5+
import { TNode } from '../common';
6+
7+
// 解析 TNode 数据结构
8+
export default function parseTNode(
9+
renderNode: TNode | TNode<any> | undefined,
10+
renderParams?: any,
11+
defaultNode?: TNode,
12+
): TNode {
13+
let node: TNode = null;
14+
15+
if (typeof renderNode === 'function') {
16+
node = renderNode(renderParams);
17+
} else if (renderNode !== null) {
18+
node = renderNode ?? defaultNode;
19+
}
20+
return node as TNode;
21+
}
22+
23+
/**
24+
* 解析各种数据类型的 TNode
25+
* 函数类型:content={(props) => <Icon></Icon>}
26+
* 组件类型:content={<Button>click me</Button>} 这种方式可以避免函数重复渲染,对应的 props 已经注入
27+
* 字符类型
28+
*/
29+
export function parseContentTNode<T>(tnode: TNode<T>, props: T) {
30+
if (isFunction(tnode)) return tnode(props) as TNode;
31+
if (!tnode || ['string', 'number', 'boolean'].includes(typeof tnode)) return tnode as TNode;
32+
try {
33+
return cloneElement(tnode, { ...props });
34+
} catch (e) {
35+
log.warn('parseContentTNode', `${tnode} is not a valid ReactNode`);
36+
return null;
37+
}
38+
}

0 commit comments

Comments
 (0)