Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add dynamic theme usage #305

Merged
merged 1 commit into from
Nov 25, 2024
Merged
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
7 changes: 7 additions & 0 deletions packages/arcodesign/components/context-provider/demo/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ export default function ContextProviderDemo() {
</ContextProvider>);
}
```

```less
.arco-cell-group {
.rem(border-radius, 8);
overflow: hidden;
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@
padding: 0;
background: transparent;
.rem(margin, 0, 12);
.rem(border-radius, 8);
overflow: hidden;
}
}
47 changes: 47 additions & 0 deletions packages/arcodesign/components/context-provider/demo/theme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
## 动态主题 @en{Dynamic theme}

#### 2

如果需要动态主题切换,需要配置 less 选项`@use-css-vars: 1`以启用 css 变量([详情见【快速上手 - 主题变量定制 & 动态切换】](/#/doc/readme))。@en{If there is a need for dynamic theme switching, you need to configure the less option `@use-css-vars: 1` to enable css variable([For details, see [Quick Start - Theme variable customization & dynamic switching]](/#/doc/readme)).}

请注意,由于 css variable 存在兼容性问题(<a href="https://caniuse.com/css-variables" target="_blank">查看兼容性</a>),请自行判断使用风险@en{Please note that due to the compatibility issues of css variables(<a href="https://caniuse.com/css-variables" target="_blank">Check compatibility</a>), please use it at your own risk.}

```js
import { ContextProvider, Button, Cell, Switch } from '@arco-design/mobile-react';

export default function ContextProviderDemo() {
const [checked, setChecked] = React.useState(true);
const theme = React.useMemo(() => {
if (checked) {
return {
'button-primary-background': '#34C759',
'button-primary-clicked-background': '#00B42A',
};
}
return null;
}, [checked]);
return (
<ContextProvider theme={theme}>
<Cell label="Switch Theme" bordered={false}>
<Switch
checked={checked}
platform="ios"
onChange={value => {
setChecked(value);
}}
/>
</Cell>
<Button className="context-button">button</Button>
</ContextProvider>
);
}
```

```less
.arco-cell {
.rem(border-radius, 8);
}
.context-button {
margin-top: 10px;
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ function generateComponents({

// 渲染文档站 demo 内容部分
const demoPath = path.join(compSrcPath, comp, 'demo');
const docPath = path.join(compPagePath, comp);
const { demoSource = [], lessSources = {} } =
renderComponentsDemos({
demoSrcPath: demoPath,
Expand Down Expand Up @@ -124,7 +125,6 @@ function generateComponents({
</div>
);
}`);
const docPath = path.join(compPagePath, comp);
fs.mkdirpSync(docPath);
fs.writeFile(path.join(docPath, `index${tsxFileSuffix}.tsx`), entry, () => {
resolve(`>>> Write sites file finished: ${comp}`);
Expand Down
Loading