Skip to content

Commit 28686df

Browse files
author
biantao.shuaxin
committed
feat:add theme switch
1 parent 66df50b commit 28686df

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

demo/Single.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,33 @@ export default class Single extends Component {
387387
Square
388388
</p>
389389
</div>
390+
{/* Theme */}
391+
<div className="field">
392+
Theme
393+
</div>
394+
<div className="opts">
395+
<p
396+
className={
397+
classnames("opt", { active: config.theme === "light" })}
398+
onClick={this.updateConfig.bind(this, "theme", "light")}
399+
>
400+
Light
401+
</p>
402+
<p
403+
className={
404+
classnames("opt", { active: config.theme === "dark" })}
405+
onClick={this.updateConfig.bind(this, "theme", "dark")}
406+
>
407+
Dark
408+
</p>
409+
<p
410+
className={
411+
classnames("opt", { active: config.theme === "system" })}
412+
onClick={this.updateConfig.bind(this, "theme", "system")}
413+
>
414+
Follow System
415+
</p>
416+
</div>
390417
</div>
391418
</div>
392419
);

demo/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default class App extends Component {
3131
const { currentTab, config } = this.state;
3232

3333
return (
34-
<div className="app">
34+
<div className={classnames("app", { appDark: config.theme === "dark", appSystemDark: config.theme === "system" })}>
3535
<a className="iconfont icon-github" href="https://github.com/chilllab/react-nice-avatar" />
3636

3737
<header className="header">

demo/app.scss

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,37 @@ $headerHeight: 6rem;
365365
margin-top: 1rem;
366366
}
367367
}
368+
369+
// Dark Mode
370+
.appDark{
371+
.header,
372+
.appContent {
373+
background: #000;
374+
color: #ffffffc2;
375+
376+
}
377+
.singleSection {
378+
.info {
379+
.opts {
380+
.opt {
381+
border: 1px solid #b9bcc06b;
382+
color: #ffffffc2;
383+
}
384+
.active{
385+
color: $blue-purple;
386+
border-color: $blue-purple;
387+
}
388+
}
389+
}
390+
}
391+
.application {
392+
background-color: #fff;
393+
}
394+
}
395+
396+
// follow system
397+
@media (prefers-color-scheme: dark) {
398+
.appSystemDark{
399+
@extend .appDark;
400+
}
401+
}

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,5 +200,8 @@ export const genConfig = (userConfig = {}) => {
200200
// Background color
201201
response.bgColor = userConfig.bgColor || _pickRandomFromList(bgColor, { avoidList: [response.hairColor, response.shirtColor] });
202202

203+
// Theme
204+
response.theme = userConfig.theme || "light";
205+
203206
return response;
204207
};

0 commit comments

Comments
 (0)