Skip to content

Commit cc02040

Browse files
authored
Merge pull request #8559 from Turbo87/dark-mode
Implement dark mode via `light-dark()` fn
2 parents 21150de + edcf04e commit cc02040

37 files changed

+273
-118
lines changed

app/components/color-scheme-menu.hbs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Dropdown local-class="dropdown" data-test-dark-mode-menu ...attributes as |dd|>
2+
<dd.Trigger @hideArrow={{true}} local-class="trigger" data-test-dark-mode-toggle>
3+
{{svg-jar this.icon local-class="icon"}}
4+
<span local-class="trigger-label">Change color scheme</span>
5+
</dd.Trigger>
6+
7+
<dd.Menu local-class="menu" as |menu|>
8+
{{#each this.colorSchemes as |colorScheme|}}
9+
<menu.Item>
10+
<button
11+
local-class="menu-button {{if (eq colorScheme.mode this.colorScheme.scheme) 'selected'}}"
12+
type="button"
13+
{{on 'click' (fn this.colorScheme.set colorScheme.mode)}}
14+
>
15+
{{svg-jar colorScheme.svg local-class="icon"}} {{colorScheme.mode}}
16+
</button>
17+
</menu.Item>
18+
{{/each}}
19+
</dd.Menu>
20+
</Dropdown>

app/components/color-scheme-menu.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { inject as service } from '@ember/service';
2+
import Component from '@glimmer/component';
3+
4+
export default class Header extends Component {
5+
/** @type {import("../services/dark-mode").default} */
6+
@service colorScheme;
7+
8+
colorSchemes = [
9+
{ mode: 'light', svg: 'sun' },
10+
{ mode: 'dark', svg: 'moon' },
11+
{ mode: 'system', svg: 'color-mode' },
12+
];
13+
14+
get icon() {
15+
return this.colorSchemes.find(({ mode }) => mode === this.colorScheme.scheme)?.svg;
16+
}
17+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.dropdown {
2+
line-height: 1rem;
3+
}
4+
5+
.icon {
6+
width: 1.4em;
7+
height: auto;
8+
}
9+
10+
.trigger {
11+
background: none;
12+
border: 0;
13+
padding: 0;
14+
}
15+
16+
.trigger-label {
17+
composes: sr-only from '../styles/shared/a11y.module.css'
18+
}
19+
20+
.menu {
21+
right: 0;
22+
min-width: max-content;
23+
}
24+
25+
.menu-button {
26+
composes: button-reset from '../styles/shared/buttons.module.css';
27+
align-items: center;
28+
gap: var(--space-2xs);
29+
cursor: pointer;
30+
text-transform: capitalize;
31+
}
32+
33+
.selected {
34+
background: light-dark(#e6e6e6, #404040);
35+
}

app/components/crate-downloads-list.module.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
}
1010

1111
.link {
12-
color: #525252;
13-
background-color: #edebdd;
12+
color: light-dark(#525252, #999999);
13+
background-color: light-dark(#edebdd, #141413);
1414
font-size: 90%;
1515
padding: var(--space-s) var(--space-xs);
1616
display: flex;

app/components/crate-row.module.css

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
.crate-row {
2-
--shadow: 0 1px 3px hsla(51, 90%, 42%, .35);
2+
--shadow: 0 1px 3px light-dark(hsla(51, 90%, 42%, .35), #232321);
33

44
display: flex;
55
flex-wrap: wrap;
66
padding: var(--space-s-m) var(--space-m-l);
7-
background-color: white;
7+
background-color: light-dark(white, #141413);
88
border-radius: var(--space-3xs);
99
box-shadow: var(--shadow);
1010
}
@@ -77,6 +77,10 @@
7777
width: calc(1em + 20px);
7878
margin: -10px;
7979
margin-right: calc(var(--space-xs) - 10px);
80+
81+
circle {
82+
fill: none;
83+
}
8084
}
8185
}
8286
}

app/components/crate-sidebar.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
cursor: pointer;
8282

8383
&:hover {
84-
background-color: white;
84+
background-color: light-dark(white, #141413);
8585
}
8686
}
8787

app/components/dependency-list/row.module.css

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
.row {
22
--bg-color: var(--grey200);
3-
--hover-bg-color: hsl(217, 37%, 98%);
4-
--range-color: var(--grey900);
5-
--crate-color: var(--grey700);
3+
--hover-bg-color: light-dark(hsl(217, 37%, 98%), hsl(204, 3%, 11%));
4+
--range-color: light-dark(var(--grey900), #d1cfc7);
5+
--crate-color: light-dark(var(--grey700), #d1cfc7);
66
--placeholder-opacity: 0.35;
7-
--shadow: 0 1px 3px hsla(51, 90%, 42%, .35);
7+
--shadow: 0 1px 3px light-dark(hsla(51, 90%, 42%, .35), #232321);
88

99
display: flex;
1010
align-items: center;
1111
position: relative;
1212
font-size: 18px;
1313
padding: var(--space-s) var(--space-m);
14-
background-color: white;
14+
background-color: light-dark(white, #141413);
1515
border-radius: var(--space-3xs);
1616
box-shadow: var(--shadow);
1717
transition: all var(--transition-slow);
@@ -26,8 +26,8 @@
2626
}
2727

2828
&.optional {
29-
--range-color: var(--grey600);
30-
--crate-color: var(--grey600);
29+
--range-color: light-dark(var(--grey600), var(--grey600));
30+
--crate-color: light-dark(var(--grey600), var(--grey600));
3131
--placeholder-opacity: 0.15;
3232
}
3333

app/components/dropdown/menu.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
margin: 0;
33
text-align: left;
44
padding: 0;
5-
background: white;
5+
background: light-dark(white, #141413);
66
border: 1px solid var(--gray-border);
77
list-style: none;
88
overflow: hidden;

app/components/dropdown/trigger.hbs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<button type="button" local-class="button" {{on "click" @toggle}} ...attributes>
22
{{yield}}
3-
<span local-class="arrow"></span>
3+
{{#unless @hideArrow}}
4+
<span local-class="arrow"></span>
5+
{{/unless}}
46
</button>

app/components/front-page-list/item.module.css

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
.link {
2-
--shadow: 0 2px 3px hsla(51, 50%, 44%, .35);
2+
--shadow: 0 2px 3px light-dark(hsla(51, 50%, 44%, .35), #232321);
33

44
display: flex;
55
align-items: center;
66
width: 100%;
77
height: var(--space-2xl);
88
padding: 0 var(--space-s);
9-
background-color: white;
10-
color: #525252;
9+
background-color: light-dark(white, #141413);
10+
color: light-dark(#525252, #f9f7ec);
1111
text-decoration: none;
1212
border-radius: var(--space-3xs);
1313
box-shadow: var(--shadow);
@@ -19,8 +19,8 @@
1919
}
2020

2121
&:hover, &:focus-visible {
22-
color: #525252;
23-
background-color: hsl(58deg 72% 97%);
22+
color: light-dark(#525252, #f9f7ec);
23+
background-color: light-dark(hsl(58deg 72% 97%), hsl(204, 3%, 11%));
2424
transition: background-color var(--transition-instant);
2525
}
2626

@@ -48,13 +48,13 @@
4848
.subtitle {
4949
margin-top: var(--space-3xs);
5050
font-size: 13px;
51-
color: rgb(118, 131, 138);
51+
color: light-dark(rgb(118, 131, 138), #cccac2);
5252
}
5353

5454
.right {
5555
flex-shrink: 0;
5656
height: var(--space-s);
5757
width: auto;
5858
margin-left: var(--space-xs);
59-
color: rgb(118, 131, 138);
59+
color: light-dark(rgb(118, 131, 138), #cccac2);
6060
}

0 commit comments

Comments
 (0)