Skip to content

Commit 15e4be2

Browse files
authored
Merge pull request #18 from SHUAXINDIARY/main
feat:add theme switch
2 parents 545ba32 + 4e52b1b commit 15e4be2

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

demo/Single.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,33 @@ export default class Single extends Component {
397397
Square
398398
</p>
399399
</div>
400+
{/* Theme */}
401+
<div className="field">
402+
Theme
403+
</div>
404+
<div className="opts">
405+
<p
406+
className={
407+
classnames("opt", { active: config.theme === "light" })}
408+
onClick={this.updateConfig.bind(this, "theme", "light")}
409+
>
410+
Light
411+
</p>
412+
<p
413+
className={
414+
classnames("opt", { active: config.theme === "dark" })}
415+
onClick={this.updateConfig.bind(this, "theme", "dark")}
416+
>
417+
Dark
418+
</p>
419+
<p
420+
className={
421+
classnames("opt", { active: config.theme === "system" })}
422+
onClick={this.updateConfig.bind(this, "theme", "system")}
423+
>
424+
Follow System
425+
</p>
426+
</div>
400427
</div>
401428
</div>
402429
);

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

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)