Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/pro-components/chat/chat-actionbar/README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ placement | String | start | options: start/end/space-around/space-between | N
name | params | description
-- | -- | --
actions | `(detail: {name: string, active: boolean})` | \-

### CSS Variables

The component provides the following CSS variables, which can be used to customize styles.
Name | Default Value | Description
-- | -- | --
--chat-actionbar-item-padding | 16rpx 28rpx | -
--chat-actionbar-padding | 0 | -
8 changes: 8 additions & 0 deletions packages/pro-components/chat/chat-actionbar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,11 @@ placement | String | start | 【实验】操作栏位置。可选项:start/end
名称 | 参数 | 描述
-- | -- | --
actions | `(detail: {name: string, active: boolean})` | 点击点赞,点踩,复制,分享,重新生成按钮时触发发

### CSS Variables
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chat 系列暂时不对外暴露 css vars,后面会统一支持


组件提供了下列 CSS 变量,可用于自定义样式。
名称 | 默认值 | 描述
-- | -- | --
--chat-actionbar-item-padding | 16rpx 28rpx | -
--chat-actionbar-padding | 0 | -
9 changes: 9 additions & 0 deletions packages/pro-components/chat/chat-content/README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ content | Object | - | required。Typescript: `TdChatContentType ` `interface Td
markdown-props | Object | - | Typescript: `ChatMarkdownProps`,[ChatMarkdown API Documents](./chat-markdown?tab=api)。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/pro-components/chat/chat-content/type.ts) | N
role | String | - | required。options: user/assistant/system | Y
status | String | - | options: error / '' | N

### CSS Variables

The component provides the following CSS variables, which can be used to customize styles.
Name | Default Value | Description
-- | -- | --
--td-chat-content-assistant-text-color | @text-color-primary | -
--td-chat-content-error-text-color | @error-color | -
--td-chat-content-user-text-color | @text-color-primary | -
9 changes: 9 additions & 0 deletions packages/pro-components/chat/chat-content/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,12 @@ content | Object | - | 必需。聊天内容对象。TS 类型:`TdChatContentT
markdown-props | Object | - | marked 解析器的配置选项。TS 类型:`ChatMarkdownProps`,[ChatMarkdown API Documents](./chat-markdown?tab=api)。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/packages/pro-components/chat/chat-content/type.ts) | N
role | String | - | 必需。消息角色,用于区分用户和助手的消息样式 。可选项:user/assistant/system | Y
status | String | - | 正文状态。可选项:error / '' | N

### CSS Variables

组件提供了下列 CSS 变量,可用于自定义样式。
名称 | 默认值 | 描述
-- | -- | --
--td-chat-content-assistant-text-color | @text-color-primary | -
--td-chat-content-error-text-color | @error-color | -
--td-chat-content-user-text-color | @text-color-primary | -
7 changes: 7 additions & 0 deletions packages/pro-components/chat/chat-sender/README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,10 @@ keyboardheightchange | `(detail: {height: number, duration: number})` | \-
send | `(value:string, context: {\| KeyboardEvent })` | \-
stop | `(value:string)` | \-
upload-click | \- | \-

### CSS Variables

The component provides the following CSS variables, which can be used to customize styles.
Name | Default Value | Description
-- | -- | --
--td-chat-sender-bg-color | @bg-color-specialcomponent | -
7 changes: 7 additions & 0 deletions packages/pro-components/chat/chat-sender/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,10 @@ keyboardheightchange | `(detail: {height: number, duration: number})` | 选择
send | `(value:string, context: {\| KeyboardEvent })` | 点击消息发送的回调方法
stop | `(value:string)` | 点击消息终止的回调方法
upload-click | \- | 【实验】点击上传按钮时触发

### CSS Variables

组件提供了下列 CSS 变量,可用于自定义样式。
名称 | 默认值 | 描述
-- | -- | --
--td-chat-sender-bg-color | @bg-color-specialcomponent | -
5 changes: 3 additions & 2 deletions packages/tdesign-miniprogram-chat/site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"site": "vite build --configLoader runner",
"site:dev": "vite --configLoader runner",
"site:preview": "cross-env NODE_ENV=development vite build --configLoader runner --mode preview && cp dist/index.html dist/404.html",
"site:prerender": "node scripts/prerender.mjs"
"site:prerender": "node scripts/prerender.mjs",
"update:css": "node scripts/generate-css-vars.mjs"
},
"license": "MIT",
"dependencies": {
Expand All @@ -28,4 +29,4 @@
"vite": "^6.2.3",
"vite-plugin-tdoc": "^2.0.1"
}
}
}
118 changes: 118 additions & 0 deletions packages/tdesign-miniprogram-chat/site/scripts/generate-css-vars.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import fs from 'fs';
import resolveCwd from './utils.mjs';

const COMPONENT_NAME = process.argv[process.argv.indexOf('--NAME') + 1]; // 在 --NAME 后面
const ROOT_DIR = resolveCwd('../../../packages/pro-components/chat');

const combine = {
'chat-markdown': [
'chat-markdown',
'chat-markdown/components/chat-markdown-code',
'chat-markdown/components/chat-markdown-node',
'chat-markdown/components/chat-markdown-table',
],
};

const findFilePath = (componentPath, componentName) => `${ROOT_DIR}/${componentPath}/${componentName}.less`;

const getAllComponentName = async (dirPath) => {
const items = await fs.promises.readdir(dirPath, { withFileTypes: true });
return items.filter((item) => item.isDirectory()).map((item) => item.name);
};

const generateCssVariables = async (componentName) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

解析脚本后面挪到common 仓库跟 mobile-vue 和 mobile-react公用

const lessPath = [];

const parsedKeys = [];
let cssVariableBodyContent = '';

if (combine[componentName]) {
combine[componentName].forEach((item) => {
lessPath.push(findFilePath(item, item.includes('/') ? item.split('/').pop() : item));
});
} else {
lessPath.push(findFilePath(componentName, componentName));
}

const validPaths = lessPath.filter((item) => fs.existsSync(item));

// 使用 fs.promises.readFile 并行读取文件
const fileContents = await Promise.all(validPaths.map((item) => fs.promises.readFile(item, 'utf8')));

fileContents.forEach((file) => {
const matchReg = /(?<=var)\([\s\S]*?(?=;)/g;

const list = file.match(matchReg)?.sort();

list?.forEach((item) => {
const key = item.slice(1, item.indexOf(',')).trim();
const value = item.slice(item.indexOf(',') + 2, item.length - 1).trim();
if (!key || !value) {
throw new Error('⚠️ 解析失败,请检查 less 文件');
}
if (!parsedKeys.includes(key)) {
parsedKeys.push(key);
cssVariableBodyContent += `${key} | ${value} | -${'\n'}`;
}
});
});

return cssVariableBodyContent.trimEnd();
};

/**
* 替换文档中的 CSS 变量部分
* @param {string} filePath - 文档路径
* @param {string} headContent - 变量表头部内容
* @param {string} variables - 生成的变量内容
*/
const updateDocVariables = (filePath, headContent, variables) => {
if (!fs.existsSync(filePath)) return;

const content = fs.readFileSync(filePath, 'utf8');
const cssVariablesSection = `\n${headContent}${variables}\n`;

// 检查是否存在 ### CSS Variables 部分
if (content.includes('### CSS Variables')) {
// 替换现有部分
const newContent = content.replace(/(^|\n+)### CSS Variables[\s\S]*?(?=###|$)/, cssVariablesSection);
fs.writeFileSync(filePath, newContent, 'utf8');
} else {
// 追加到文件末尾
const trimmedContent = content.trimEnd();
const newContent = `${trimmedContent}${cssVariablesSection}\n`;
fs.writeFileSync(filePath, newContent, 'utf8');
}
};

// 批量处理所有组件
const processAllComponents = async () => {
const cssVariableHeadContent = `\n### CSS Variables\n\n组件提供了下列 CSS 变量,可用于自定义样式。\n名称 | 默认值 | 描述 \n-- | -- | --\n`;
const cssVariableHeadContentEn = `\n### CSS Variables\n\nThe component provides the following CSS variables, which can be used to customize styles.\nName | Default Value | Description \n-- | -- | --\n`;

let COMPONENT_NAMES = [];
if (COMPONENT_NAME === 'all') {
COMPONENT_NAMES = await getAllComponentName(ROOT_DIR);
} else {
COMPONENT_NAMES = [COMPONENT_NAME];
}

// 并行处理所有组件
await Promise.all(
COMPONENT_NAMES.map(async (name) => {
const variables = await generateCssVariables(name);
if (variables) {
updateDocVariables(`${ROOT_DIR}/${name}/README.md`, cssVariableHeadContent, variables);
updateDocVariables(`${ROOT_DIR}/${name}/README.en-US.md`, cssVariableHeadContentEn, variables);
console.log(`✅ 组件 "${name}" 文档更新完成`);
} else {
console.log(`${name}: 没有找到 CSS 变量`);
}
}),
);
};

// 执行入口
processAllComponents().catch((err) =>
console.error(`${COMPONENT_NAME === 'all' ? '❌ 批量处理失败:' : `${COMPONENT_NAME}处理失败`}`, err),
);
8 changes: 8 additions & 0 deletions packages/tdesign-miniprogram-chat/site/scripts/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import path from 'path';

function resolveCwd(...args) {
args.unshift(process.cwd());
return path.join(...args);
}

export default resolveCwd;
Loading