Skip to content

Commit

Permalink
Merge pull request #61 from duenyang/feature/tooltip
Browse files Browse the repository at this point in the history
feat(tooltip): add tooltip 🎉
  • Loading branch information
dntzhang authored Jun 25, 2024
2 parents d56844a + 079fcea commit 7d6d58d
Show file tree
Hide file tree
Showing 18 changed files with 623 additions and 65 deletions.
60 changes: 0 additions & 60 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
},
"dependencies": {
"@babel/runtime": "^7.24.7",
"@omiu/transition": "^0.0.17",
"@popperjs/core": "^2.11.8",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
Expand Down
26 changes: 25 additions & 1 deletion script/plugin-tdoc/md-to-wc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import esbuild from 'esbuild';
import fs from 'fs';
import matter from 'gray-matter';
import { spawn } from 'node:child_process';
import path from 'path';
// import camelCase from 'camelcase';
// import { compileUsage } from '../../src/_common/docs/compile';

Expand Down Expand Up @@ -80,6 +81,8 @@ export default async function mdToReact(options) {
const tab = signal(query.get('tab') || 'demo');
const tabRef = signal({});
const lastUpdated = tab === 'design' ? ${mdSegment.designDocLastUpdated} : ${mdSegment.lastUpdated};
effect(() => {
tabRef.value?.addEventListener?.('change', (event) => {
tab.value = event.detail;
Expand Down Expand Up @@ -108,11 +111,14 @@ export default async function mdToReact(options) {
<div style={isShow('api')} name="API">
${mdSegment.apiMd}
</div>
<div style={isShow('design')} name="DESIGN">
${mdSegment.designMd}
</div>
</>
) : <div name="DOC" className="${mdSegment.docClass}">${mdSegment.docMd}</div>
}
<div style={{ marginTop: 48 }}>
<td-doc-history time={${mdSegment.lastUpdated}} key={${mdSegment.lastUpdated}}></td-doc-history>
<td-doc-history time={lastUpdated} key={lastUpdated}></td-doc-history>
</div>
</>
)
Expand Down Expand Up @@ -152,6 +158,7 @@ async function customRender({ source, file, md }) {
apiFlag: /#+\s*API/,
docClass: '',
lastUpdated,
designDocLastUpdated: lastUpdated,
...data,
};

Expand Down Expand Up @@ -210,5 +217,22 @@ async function customRender({ source, file, md }) {
`${pageData.toc ? '[toc]\n' : ''}${content.replace(/<!--[\s\S]+?-->/g, '')}`,
).html;
}

// 设计指南内容 不展示 design Tab 则不解析
if (pageData.isComponent && pageData.tdDocTabs.some((item) => item.tab === 'design')) {
const designDocPath = path.resolve(__dirname, `../../src/_common/docs/web/design/${componentName}.md`);

if (fs.existsSync(designDocPath)) {
const designDocLastUpdated =
(await getGitTimestamp(designDocPath)) || Math.round(fs.statSync(designDocPath).mtimeMs);
mdSegment.designDocLastUpdated = designDocLastUpdated;

const designMd = fs.readFileSync(designDocPath, 'utf-8');
mdSegment.designMd = md.render.call(md, `${pageData.toc ? '[toc]\n' : ''}${designMd}`).html;
} else {
console.log(`[vite-plugin-tdoc]: 未找到 ${designDocPath} 文件`);
}
}

return mdSegment;
}
6 changes: 6 additions & 0 deletions site/sidebar.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ export default [
path: '/components/image',
component: () => import('tdesign-web-components/image/README.md'),
},
{
title: 'Tooltip 文字提示',
name: 'tooltip',
path: '/components/tooltip',
component: () => import('tdesign-web-components/tooltip/README.md'),
},
],
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default class Button extends Component<ButtonProps> {
}

let iconNode = icon;
if (loading) iconNode = <t-icon className="mb-[2px]" name={'loading'} />;
if (loading) iconNode = <t-icon className="mr-[2px]" name={'loading'} />;

const Tag = this.tag as string;
return (
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './icon';
export * from './image';
export * from './input';
export * from './popup';
export * from './textarea';
export * from './space';
export * from './switch';
export * from './textarea';
export * from './tooltip';
1 change: 0 additions & 1 deletion src/popup/popup.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'omi-transition';

// import '@omiu/transition';
import { createPopper } from '@popperjs/core';
import debounce from 'lodash/debounce';
import { Component, createRef, OmiProps, tag } from 'omi';
Expand Down
53 changes: 53 additions & 0 deletions src/tooltip/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
title: Tooltip 文字提示
description: 用于文字提示的气泡框。
isComponent: true
usage: { title: '', description: '' }
spline: data
---

### 基础用法

{{ base }}

### 带箭头的文字提示

带箭头的文字提示有较明确的指向性。常用于有多个需要提示的信息并列放置时,对某个具体信息进行提示。

{{ arrow }}

### 不带箭头的文字提示

不带箭头的文字提示没有明确指向性。常用于不需要针对性提示的场景中。

{{ no-arrow }}

### 带主题色的文字提示

提供浅灰色、蓝色、绿色、红色、黄色主题的文字提示。

{{ theme }}

### 不同触发方式的文字提示

支持常见元素事件触发文字提示。

{{ trigger }}

### 定时消失

{{ duration }}


## API
### Tooltip Props

名称 | 类型 | 默认值 | 说明 | 必传
-- | -- | -- | -- | --
delay | Number | - | 【议案讨论中】延迟出现提示,用于异步加载提示信息需要延迟显示的业务场景下 | N
destroyOnClose | Boolean | true | 是否在关闭浮层时销毁浮层 | N
duration | Number | - | 用于设置提示默认显示多长时间之后消失,初始第一次有效,单位:毫秒 | N
placement | String | top | 浮层出现位置。TS 类型:`PopupPlacement`[Popup API Documents](./popup?tab=api)[详细类型定义](https://github.com/Tencent/tdesign-react/blob/develop/src/tooltip/type.ts) | N
showArrow | Boolean | true | 是否显示浮层箭头 | N
theme | String | default | 文字提示风格。可选项:default/primary/success/danger/warning/light | N
`PopupProps` | \- | - | 继承 `PopupProps` 中的全部 API | N
10 changes: 10 additions & 0 deletions src/tooltip/_example/arrow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'tdesign-web-components/button';
import 'tdesign-web-components/tooltip';

export default function BasicUsage() {
return (
<t-tooltip content="文字提示仅展示文本内容">
<t-button variant="outline">默认文字提示</t-button>
</t-tooltip>
);
}
Loading

0 comments on commit 7d6d58d

Please sign in to comment.