Skip to content
Open
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
26 changes: 26 additions & 0 deletions packages/tdesign-uniapp-chat/site/docs/dark-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,29 @@ import './uni_modules/tdesign-uniapp/components/theme.css';
```

> 💡Tips:什么是虚拟节点请参考 [微信文档](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html#%E8%99%9A%E6%8B%9F%E5%8C%96%E7%BB%84%E4%BB%B6%E8%8A%82%E7%82%B9)。

## 禁用深色模式

如果你不需要深色模式,希望应用始终保持浅色主题(即使用户系统切换到深色模式也不会变色),可以使用纯浅色版本的主题文件替代默认的主题文件:

#### CLI 模式

```js
// Less(推荐)
import '@tdesign/uniapp/theme-light.less';

// 或者引入编译后的 CSS 文件
import '@tdesign/uniapp/theme-light.css';
```

#### HBuilderX 模式

```js
// Less(推荐)
import './uni_modules/tdesign-uniapp/components/theme-light.less';

// 或者引入编译后的 CSS 文件
import './uni_modules/tdesign-uniapp/components/theme-light.css';
```

> 💡Tips:`theme-light` 与 `theme` 的区别在于:`theme` 包含浅色和深色两套变量,通过 `@media (prefers-color-scheme)` 媒体查询自动切换;而 `theme-light` 仅包含浅色变量,不含任何媒体查询包裹,因此不会响应系统深色模式的切换。
11 changes: 5 additions & 6 deletions packages/tdesign-uniapp/example/script/release/less.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { PACKAGES_ROOT, PROJECT_ROOT } = require('./config');
const CONFIG = {
whiteList: [
path.resolve(PACKAGES_ROOT, 'uniapp-components/common/style/theme/index.less'),
path.resolve(PACKAGES_ROOT, 'uniapp-components/common/style/theme/index-light.less'),
path.resolve(PACKAGES_ROOT, 'uniapp-components/common/style/base.less'),
path.resolve(PACKAGES_ROOT, 'uniapp-components/common/style/_variables.less'),
path.resolve(PACKAGES_ROOT, 'uniapp-components/common/style/mixins/'),
Expand All @@ -26,16 +27,16 @@ const options = {
// 处理流程
async function processLess(inputFile, rawOutputFile) {
if (!inputFile.endsWith('.less')) return;
if (CONFIG.whiteList.find((item) => inputFile.startsWith(item))) {
if (CONFIG.whiteList.find(item => inputFile.startsWith(item))) {
return;
}

try {
let lessCode = fs.readFileSync(inputFile, 'utf8');

lessCode = lessCode.replace(
"@import '@tdesign/uniapp/common/style/base.less'",
"@import '../common/style/base.less'",
'@import \'@tdesign/uniapp/common/style/base.less\'',
'@import \'../common/style/base.less\'',
);

const cssResult = await less.render(lessCode, {
Expand All @@ -48,9 +49,7 @@ async function processLess(inputFile, rawOutputFile) {
],
});

const postcssResult = await postcss(
[CONFIG.useRpxTransform ? rpxTransform(options) : null].filter(Boolean),
).process(cssResult.css, { from: undefined });
const postcssResult = await postcss([CONFIG.useRpxTransform ? rpxTransform(options) : null].filter(Boolean)).process(cssResult.css, { from: undefined });

const getOutputFile = (rawOutputFile) => {
const filename = `${path.basename(rawOutputFile, path.extname(rawOutputFile)).replace(/^_/, '')}.css`;
Expand Down
12 changes: 12 additions & 0 deletions packages/tdesign-uniapp/example/script/release/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ const STYLE_SHORTCUTS = [
type: 'import',
importPath: './common/style/theme/index.less',
},
{
// 纯浅色模式 css(不含深色模式,不随系统主题切换)
source: 'common/style/theme/index-light.css',
target: 'theme-light.css',
type: 'copy',
},
{
// 纯浅色模式 less
target: 'theme-light.less',
type: 'import',
importPath: './common/style/theme/index-light.less',
},
];

function generateStyleShortcuts(targetDir) {
Expand Down
8 changes: 8 additions & 0 deletions packages/tdesign-uniapp/example/script/types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ const BASE_EXTRA_EXPORTS = {
types: './theme.less.d.ts',
default: './theme.less',
},
'./theme-light.css': {
types: './dist/theme-light.css.d.ts',
default: './dist/theme-light.css',
},
'./theme-light.less': {
types: './dist/theme-light.less.d.ts',
default: './dist/theme-light.less',
},
};

function getOtherExports(isChat) {
Expand Down
8 changes: 8 additions & 0 deletions packages/tdesign-uniapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@
"types": "./dist/theme.less.d.ts",
"default": "./dist/theme.less"
},
"./theme-light.css": {
"types": "./dist/theme-light.css.d.ts",
"default": "./dist/theme-light.css"
},
"./theme-light.less": {
"types": "./dist/theme-light.less.d.ts",
"default": "./dist/theme-light.less"
},
"./global": {
"types": "./global.d.ts"
},
Expand Down
26 changes: 26 additions & 0 deletions packages/tdesign-uniapp/site/docs/dark-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,29 @@ import './uni_modules/tdesign-uniapp/components/theme.css';
```

> 💡Tips:什么是虚拟节点请参考 [微信文档](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html#%E8%99%9A%E6%8B%9F%E5%8C%96%E7%BB%84%E4%BB%B6%E8%8A%82%E7%82%B9)。

## 禁用深色模式

如果你不需要深色模式,希望应用始终保持浅色主题(即使用户系统切换到深色模式也不会变色),可以使用纯浅色版本的主题文件替代默认的主题文件:

#### CLI 模式

```js
// Less(推荐)
import '@tdesign/uniapp/theme-light.less';

// 或者引入编译后的 CSS 文件
import '@tdesign/uniapp/theme-light.css';
```

#### HBuilderX 模式

```js
// Less(推荐)
import './uni_modules/tdesign-uniapp/components/theme-light.less';

// 或者引入编译后的 CSS 文件
import './uni_modules/tdesign-uniapp/components/theme-light.css';
```

> 💡Tips:`theme-light` 与 `theme` 的区别在于:`theme` 包含浅色和深色两套变量,通过 `@media (prefers-color-scheme)` 媒体查询自动切换;而 `theme-light` 仅包含浅色变量,不含任何媒体查询包裹,因此不会响应系统深色模式的切换。
Loading
Loading