Skip to content

Commit e020ded

Browse files
committed
some cleanup before code review
1 parent 59bb94b commit e020ded

File tree

10 files changed

+37
-55
lines changed

10 files changed

+37
-55
lines changed

packages/components/src/services/hds-theming.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export enum HdsThemeValues {
1111
Dark = 'dark',
1212
}
1313

14-
// TODO! understand if we really need this
14+
// TODO! understand if we really need this - see: https://hashicorp.atlassian.net/browse/HDS-5681
1515
export enum HdsModesBaseValues {
1616
Default = 'default',
1717
}
@@ -140,7 +140,7 @@ export default class HdsThemingService extends Service {
140140
}
141141
}
142142

143-
// IMPORTANT: for this to work, it needs to be the HTML tag (it's the `:root` in CSS)
143+
// IMPORTANT: for this to work, it needs to be the `<html>` tag (it's the `:root` in CSS)
144144
const rootElement = document.querySelector('html');
145145

146146
if (!rootElement) {
@@ -158,7 +158,7 @@ export default class HdsThemingService extends Service {
158158
rootElement.classList.add(`hds-mode-${this._currentMode}`);
159159
}
160160

161-
// store the current theme and theming options in local storage (unless undefined)
161+
// store the current theme and theming options in local storage
162162
localStorage.setItem(
163163
HDS_THEMING_LOCALSTORAGE_DATA,
164164
JSON.stringify({
@@ -198,10 +198,10 @@ export default class HdsThemingService extends Service {
198198
}
199199

200200
get currentLightTheme(): HdsModesLight {
201-
return this._currentLightTheme ?? DEFAULT_THEMING_OPTION_LIGHT_THEME;
201+
return this._currentLightTheme;
202202
}
203203

204204
get currentDarkTheme(): HdsModesDark {
205-
return this._currentDarkTheme ?? DEFAULT_THEMING_OPTION_DARK_THEME;
205+
return this._currentDarkTheme;
206206
}
207207
}

showcase/app/components/page-foundations/theming/sub-sections/components.gts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { TemplateOnlyComponent } from '@ember/component/template-only';
2-
import { on } from '@ember/modifier';
32

43
import ShwDivider from 'showcase/components/shw/divider';
54
import ShwFlex from 'showcase/components/shw/flex';

showcase/app/components/page-foundations/theming/sub-sections/contexts.gts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,8 @@ export default class SubSectionContexts extends Component {
121121

122122
{{#if (eq this.shwTheming.currentStylesheet "standard")}}
123123
<div class="shw-page-foundations-theming-banner-incorrect-stylesheet">
124-
<ShwTextBody>These examples are visible only if theming is applied via
125-
"prefers color scheme" or "CSS selectors" or "combined strategies",
126-
please select a theme below one of these two groups of options in the
127-
selector at the top of the page</ShwTextBody>
124+
<ShwTextBody>These examples are visible only if theming is applied,
125+
please select a theme in the selector at the top of the page</ShwTextBody>
128126
</div>
129127
{{else}}
130128
<ShwGrid
@@ -174,10 +172,8 @@ export default class SubSectionContexts extends Component {
174172

175173
{{#if (eq this.shwTheming.currentStylesheet "standard")}}
176174
<div class="shw-page-foundations-theming-banner-incorrect-stylesheet">
177-
<ShwTextBody>These examples are visible only if theming is applied via
178-
"CSS selectors" or "combined strategies", please select a theme below
179-
one of these two groups of options in the selector at the top of the
180-
page</ShwTextBody>
175+
<ShwTextBody>These examples are visible only if theming is applied,
176+
please select a theme in the selector at the top of the page</ShwTextBody>
181177
</div>
182178
{{else}}
183179
<ShwGrid
@@ -242,10 +238,8 @@ export default class SubSectionContexts extends Component {
242238

243239
{{#if (eq this.shwTheming.currentStylesheet "standard")}}
244240
<div class="shw-page-foundations-theming-banner-incorrect-stylesheet">
245-
<ShwTextBody>These examples are visible only if theming is applied via
246-
"prefers color scheme" or "CSS selectors" or "combined strategies",
247-
please select a theme below one of these two groups of options in the
248-
selector at the top of the page</ShwTextBody>
241+
<ShwTextBody>These examples are visible only if theming is applied,
242+
please select a theme in the selector at the top of the page</ShwTextBody>
249243
</div>
250244
{{else}}
251245
<ShwGrid
@@ -283,10 +277,8 @@ export default class SubSectionContexts extends Component {
283277

284278
{{#if (eq this.shwTheming.currentStylesheet "standard")}}
285279
<div class="shw-page-foundations-theming-banner-incorrect-stylesheet">
286-
<ShwTextBody>These examples are visible only if theming is applied via
287-
"CSS selectors" or "combined strategies", please select a theme below
288-
one of these two groups of options in the selector at the top of the
289-
page</ShwTextBody>
280+
<ShwTextBody>These examples are visible only if theming is applied,
281+
please select a theme in the selector at the top of the page</ShwTextBody>
290282
</div>
291283
{{else}}
292284
<ShwGrid

showcase/app/components/shw/theme-switcher/control/select.gts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,8 @@ export default class ShwThemeSwitcherControlSelect extends Component<ShwThemeSwi
2121
get options() {
2222
if (Array.isArray(this.args.values)) {
2323
// Convert array to an object where keys and values are the same
24-
return this.args.values.reduce(
25-
(acc, value) => {
26-
acc[value] = value;
27-
return acc;
28-
},
29-
{} as Record<string, string>,
24+
return Object.fromEntries(
25+
this.args.values.map((value) => [value, value]),
3026
);
3127
} else {
3228
// If values is already an object, return it directly

showcase/app/components/shw/theme-switcher/debugging-panel.gts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,18 @@ export default class ShwThemeSwitcherDebuggingPanel extends Component<ShwThemeSw
4141
<ShwLabel
4242
class="shw-theme-switcher__debugging-panel-value"
4343
>{{this.hdsTheming.currentMode}}</ShwLabel>
44-
{{#if @showAdvancedOptions}}
45-
<ShwLabel
46-
class="shw-theme-switcher__debugging-panel-key"
47-
>currentLightTheme:</ShwLabel>
48-
<ShwLabel
49-
class="shw-theme-switcher__debugging-panel-value"
50-
>{{this.hdsTheming.currentLightTheme}}</ShwLabel>
51-
<ShwLabel
52-
class="shw-theme-switcher__debugging-panel-key"
53-
>currentDarkTheme:</ShwLabel>
54-
<ShwLabel
55-
class="shw-theme-switcher__debugging-panel-value"
56-
>{{this.hdsTheming.currentDarkTheme}}</ShwLabel>
57-
{{/if}}
44+
<ShwLabel
45+
class="shw-theme-switcher__debugging-panel-key"
46+
>currentLightTheme:</ShwLabel>
47+
<ShwLabel
48+
class="shw-theme-switcher__debugging-panel-value"
49+
>{{this.hdsTheming.currentLightTheme}}</ShwLabel>
50+
<ShwLabel
51+
class="shw-theme-switcher__debugging-panel-key"
52+
>currentDarkTheme:</ShwLabel>
53+
<ShwLabel
54+
class="shw-theme-switcher__debugging-panel-value"
55+
>{{this.hdsTheming.currentDarkTheme}}</ShwLabel>
5856
</div>
5957
</template>
6058
}

showcase/app/routes/page-foundations/theming/frameless/demo-application-with-theme-switcher.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export type PageComponentsFormFramelessDemoFormComplexModel =
1515
export default class PageComponentsFormFramelessDemoFormComplexRoute extends Route {
1616
@service declare readonly shwTheming: ShwThemingService;
1717

18+
// this is not a perfect solution, but for the moment it will do
19+
// later we can evaluate if use a different approach
20+
// see: https://hashicorp.atlassian.net/browse/HDS-5680
1821
activate() {
1922
this.shwTheming.setStylesheet('css-selectors--migration');
2023
}

showcase/app/services/shw-theming.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const STYLESHEETS_MAPPING: Record<ShwStylesheets, string[]> = {
4040
};
4141

4242
const updatePageStylesheets = (currentStylesheet: ShwStylesheets) => {
43-
// fallback in case the `currentStylesheet` is not found in the `STYLESHEETS_MAPPING` list
43+
// we need a fallback in case the `currentStylesheet` is not found in the `STYLESHEETS_MAPPING` list
4444
// note: this may happen if the underlying code/names has changed but the `currentStylesheet` is read from local storage
4545
const styleSheetToActivate: ShwStylesheets = STYLESHEETS_MAPPING[
4646
currentStylesheet
@@ -64,6 +64,7 @@ const updatePageStylesheets = (currentStylesheet: ShwStylesheets) => {
6464
};
6565

6666
const LOCALSTORAGE_CURRENT_STYLESHEET = 'shw-theming-current-stylesheet';
67+
6768
export default class ShwThemingService extends HdsThemingService {
6869
@service declare readonly hdsTheming: HdsThemingService;
6970

showcase/app/styles/app.scss

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
* SPDX-License-Identifier: MPL-2.0
44
*/
55

6-
// @use "@hashicorp/design-system-components";
7-
// @use "@hashicorp/design-system-power-select-overrides";
8-
96
// global declarations
107

118
@use "./showcase-theming" as theming;

showcase/app/styles/showcase-pages/theming.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
// THEMING
77

8+
@use "../typography" as *;
9+
810
body.page-foundations-theming {
911
.shw-foundation-theming-light-background {
1012
padding: 8px;
@@ -36,9 +38,9 @@ body.page-foundations-theming {
3638
}
3739

3840
&.shw-foundation-theming-basic-container--not-available {
41+
@include shw-font-family("system mono");
3942
color: #7f7f7f;
4043
font-size: 24px;
41-
font-family: monaco, Consolas, "Lucida Console", monospace;
4244
background-color: transparent;
4345
opacity: 0.5;
4446
}

showcase/app/styles/showcase-theming/index.scss

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,12 @@
3232

3333
.hds-theme-light,
3434
.hds-theme-cds-g0,
35-
.hds-theme-cds-g10,
36-
[data-hds-theme='light'],
37-
[data-hds-theme='cds-g0'],
38-
[data-hds-theme='cds-g10'] {
35+
.hds-theme-cds-g10 {
3936
@include shw-theme-color-variables-light();
4037
}
4138

4239
.hds-theme-dark,
4340
.hds-theme-cds-g90,
44-
.hds-theme-cds-g100,
45-
[data-hds-theme='dark'],
46-
[data-hds-theme='cds-g90'],
47-
[data-hds-theme='cds-g100'] {
41+
.hds-theme-cds-g100 {
4842
@include shw-theme-color-variables-dark();
4943
}

0 commit comments

Comments
 (0)