-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented basic HDS switcher for testing
- Loading branch information
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/components/src/components/hds/theme-switcher/index.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{{! | ||
Copyright (c) HashiCorp, Inc. | ||
SPDX-License-Identifier: MPL-2.0 | ||
}} | ||
<Hds::Form::Select::Base | ||
{{on "change" this._onChangePageTheme}} | ||
class="hds-theme-switcher-control" | ||
as |C| | ||
> | ||
<C.Options> | ||
<option value="none" selected={{eq this._selectedTheme "none"}}>None</option> | ||
<option value="auto" selected={{eq this._selectedTheme "auto"}}>System</option> | ||
<option value="light" selected={{eq this._selectedTheme "light"}}>Light</option> | ||
<option value="dark" selected={{eq this._selectedTheme "dark"}}>Dark</option> | ||
</C.Options> | ||
</Hds::Form::Select::Base> |
48 changes: 48 additions & 0 deletions
48
packages/components/src/components/hds/theme-switcher/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Copyright (c) HashiCorp, Inc. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
import Component from '@glimmer/component'; | ||
import { inject as service } from '@ember/service'; | ||
import { action } from '@ember/object'; | ||
|
||
import type { HdsFormSelectBaseSignature } from '../form/select/base.ts'; | ||
import type HdsThemingService from '../../../services/hds-theming.ts'; | ||
import { type HdsThemes } from '../../../services/hds-theming.ts'; | ||
|
||
export interface HdsThemeSwitcherSignature { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-object-type | ||
Args: {}; | ||
Element: HdsFormSelectBaseSignature['Element']; | ||
} | ||
|
||
export default class HdsThemeSwitcher extends Component<HdsThemeSwitcherSignature> { | ||
@service declare readonly hdsTheming: HdsThemingService; | ||
|
||
_selectedTheme: HdsThemes; | ||
|
||
constructor(owner: unknown, args: HdsThemeSwitcherSignature['Args']) { | ||
super(owner, args); | ||
this._selectedTheme = this.hdsTheming.getTheme() || undefined; | ||
} | ||
|
||
@action | ||
_onChangePageTheme(event: Event): void { | ||
const select = event.target as HTMLSelectElement; | ||
|
||
// this._selectedTheme = select.value === 'none' ? undefined : select.value; | ||
if (select.value === 'none') { | ||
this._selectedTheme = undefined; | ||
} else if ( | ||
select.value === 'auto' || | ||
select.value === 'light' || | ||
select.value === 'dark' | ||
) { | ||
this._selectedTheme = select.value; | ||
} | ||
|
||
// we set the theme in the global service | ||
this.hdsTheming.setTheme(this._selectedTheme); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters