Skip to content

Commit deab041

Browse files
committed
fixed small issue with the HdsThemeSwitcher components used in the Theming showcase page
context: #3240 (comment)
1 parent 2fab643 commit deab041

File tree

1 file changed

+74
-38
lines changed

1 file changed

+74
-38
lines changed
Lines changed: 74 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,83 @@
1-
import type { TemplateOnlyComponent } from '@ember/component/template-only';
1+
import Component from '@glimmer/component';
22
import style from 'ember-style-modifier';
3+
import { service } from '@ember/service';
34

45
import ShwFlex from 'showcase/components/shw/flex';
56
import ShwTextH2 from 'showcase/components/shw/text/h2';
67
import ShwTextH4 from 'showcase/components/shw/text/h4';
78
import ShwDivider from 'showcase/components/shw/divider';
89

910
import { HdsThemeSwitcher } from '@hashicorp/design-system-components/components';
11+
import ShwThemingService from 'showcase/services/shw-theming';
1012

11-
const SubSectionThemeSwitcher: TemplateOnlyComponent = <template>
12-
<ShwTextH2>Theme switcher</ShwTextH2>
13-
14-
<ShwTextH4 @tag="h3">Size</ShwTextH4>
15-
16-
<ShwFlex @gap="2rem" as |SF|>
17-
<SF.Item @label="small (default)">
18-
<HdsThemeSwitcher />
19-
</SF.Item>
20-
<SF.Item @label="medium">
21-
<HdsThemeSwitcher @toggleSize="medium" />
22-
</SF.Item>
23-
</ShwFlex>
24-
25-
<ShwFlex as |SF|>
26-
<SF.Item @label="full-width">
27-
<div {{style width="150px"}}>
28-
<HdsThemeSwitcher @toggleIsFullWidth={{true}} />
29-
</div>
30-
</SF.Item>
31-
</ShwFlex>
32-
33-
<ShwDivider @level={{2}} />
34-
35-
<ShwTextH4 @tag="h3">Options</ShwTextH4>
36-
37-
<ShwFlex @gap="2rem" as |SF|>
38-
<SF.Item @label="System/Light/Dark (default)">
39-
<HdsThemeSwitcher />
40-
</SF.Item>
41-
<SF.Item @label="Only Light/Dark">
42-
<HdsThemeSwitcher @hasSystemOption={{false}} />
43-
</SF.Item>
44-
</ShwFlex>
45-
</template>;
46-
47-
export default SubSectionThemeSwitcher;
13+
import type {
14+
OnSetThemeCallback,
15+
OnSetThemeCallbackArgs,
16+
} from '@hashicorp/design-system-components/services/hds-theming';
17+
18+
export default class SubSectionThemeSwitcher extends Component {
19+
@service declare readonly shwTheming: ShwThemingService;
20+
21+
onSetTheme: OnSetThemeCallback = ({
22+
currentTheme,
23+
}: OnSetThemeCallbackArgs) => {
24+
if (
25+
(currentTheme === 'system' &&
26+
(this.shwTheming.currentStylesheet === 'standard' ||
27+
this.shwTheming.currentStylesheet === 'css-selectors')) ||
28+
((currentTheme === 'light' || currentTheme === 'dark') &&
29+
(this.shwTheming.currentStylesheet === 'standard' ||
30+
this.shwTheming.currentStylesheet === 'prefers-color-scheme'))
31+
) {
32+
window.alert(
33+
'The theming stylesheet will be switched to "combined-strategies" to support this theme selection.',
34+
);
35+
this.shwTheming.setStylesheet('combined-strategies');
36+
}
37+
};
38+
39+
<template>
40+
<ShwTextH2>Theme switcher</ShwTextH2>
41+
42+
<ShwTextH4 @tag="h3">Size</ShwTextH4>
43+
44+
<ShwFlex @gap="2rem" as |SF|>
45+
<SF.Item @label="small (default)">
46+
<HdsThemeSwitcher @onSetTheme={{this.onSetTheme}} />
47+
</SF.Item>
48+
<SF.Item @label="medium">
49+
<HdsThemeSwitcher
50+
@toggleSize="medium"
51+
@onSetTheme={{this.onSetTheme}}
52+
/>
53+
</SF.Item>
54+
</ShwFlex>
55+
56+
<ShwFlex as |SF|>
57+
<SF.Item @label="full-width">
58+
<div {{style width="150px"}}>
59+
<HdsThemeSwitcher
60+
@toggleIsFullWidth={{true}}
61+
@onSetTheme={{this.onSetTheme}}
62+
/>
63+
</div>
64+
</SF.Item>
65+
</ShwFlex>
66+
67+
<ShwDivider @level={{2}} />
68+
69+
<ShwTextH4 @tag="h3">Options</ShwTextH4>
70+
71+
<ShwFlex @gap="2rem" as |SF|>
72+
<SF.Item @label="System/Light/Dark (default)">
73+
<HdsThemeSwitcher @onSetTheme={{this.onSetTheme}} />
74+
</SF.Item>
75+
<SF.Item @label="Only Light/Dark">
76+
<HdsThemeSwitcher
77+
@hasSystemOption={{false}}
78+
@onSetTheme={{this.onSetTheme}}
79+
/>
80+
</SF.Item>
81+
</ShwFlex>
82+
</template>
83+
}

0 commit comments

Comments
 (0)