-
Notifications
You must be signed in to change notification settings - Fork 51
[WIP-04] [Project Solar / Phase 1 / Showcase] Add support for theming and theme-switching to the showcase #3240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
didoo
wants to merge
70
commits into
project-solar/phase-1/HDS-5505_components/modes-css-compilation
Choose a base branch
from
project-solar/phase-1/HDS-5242_showcase/add-themes-support
base: project-solar/phase-1/HDS-5505_components/modes-css-compilation
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+25,257
β69
Open
Changes from all commits
Commits
Show all changes
70 commits
Select commit
Hold shift + click to select a range
88b2940
added `Hds::ThemeSwitcher` component
didoo 3d408da
added `Hds::Theming` service
didoo fbb16f8
added theming to the Showcase itself (and replaced hardcoded values wβ¦
didoo d7e3e92
added `Shw::ThemeSwitcher` component for showcase
didoo de0984e
updated `Mock::App` and added new yielded sub-components
didoo 6a31cff
added `Shw:: ThemeSwitcher` to the Showcase page header
didoo 57799ef
added `foundations/theming` showcase page (and a frameless demo)
didoo bed93e9
refactored `hds-theming` service to align with the new themes/modes aβ¦
didoo cc65171
added `hdsTheming` initialization to main showcase app
didoo 359e934
removed compilation of components Scss and replaced it with static inβ¦
didoo 2788299
added theming options via popover - part 1
didoo 5d04eba
added theming options via popover - part 2
didoo 719411a
added theming options via popover - part 3
didoo b0a2218
added theming options via popover - part 4
didoo fb62738
added theming options via popover - part 5
didoo 98ac8d4
big code refactoring for the theme selector, to streamline user selecβ¦
didoo 55c4841
updated logic that sets the theming for the showcase itself (without β¦
didoo 90ec51f
small fixes here and there for cleanup and linting
didoo f5e040a
fixed issue with `pnpm lint:format` (missing newline at the end of `pβ¦
didoo 86b998b
fixed accessibility issue in `advanced-table` page, due to changes toβ¦
didoo 8b9d6ff
fixed typescript error due to new mock page being added
didoo c9dfdf9
added fix for tests failing
didoo fd21465
started large refactoring/rewrite of the theming switcher and page inβ¦
didoo 40563cf
updated logic by creating a `shwTheming` service that extends `hdsTheβ¦
didoo 78e96b0
moved theming logic from `ShwThemeSwitcher` component/subcomponents tβ¦
didoo d12eb32
updated reference CSS files to follow new theming approach/logic
didoo 2766694
further refactoring/rewriting of theming logic
didoo 040810b
updated approach to `light/dark` styles in showcase by using the HDS β¦
didoo deaa58d
migrated back the `Contextual` demo content to the index page
didoo b6e5be6
added a `DebuggingPanel` to the `ShwThemeSwitcher` controls
didoo dc64ab6
refactored/improved `DebuggingPanel` and added new preferences to advβ¦
didoo 254d913
small cleanups and refactorings
didoo 7575e9a
fixed small issue with `ShwThemeSwitcher` selector
didoo 65cb852
removed some outdated comments
didoo 7affe21
small refactorings
didoo e26eb15
added local storage support for theming options
didoo 8f39d2b
big refactoring of the `hdsTheming` service to simplify logic and redβ¦
didoo 14e8fa5
cleanup of debugging comments and other stuff
didoo b4f25ae
refactor and cleanup in preparation for PR review
didoo 11475f2
refactored code to fix logic flow for theming initialization
didoo 8ae3979
fixed how the theming options were saved in local storage
didoo fe848d5
Apply suggestions from Copilot's code review
didoo 633627a
fixed issue with `setTheme` not being passed `options` by the `ShwTheβ¦
didoo b94de3a
fix issue with the popover of the ShwThemeSwitcher component, where tβ¦
didoo d1d4c5d
Update showcase/app/services/shw-theming.ts
didoo b89cab8
small tweak to the typing of `HdsModes` per code review suggestion
didoo 6078feb
updated how the CSS files (tokens and components, with/without theminβ¦
didoo e271652
updated logic for styleshet switching using the `disabled` attribute
didoo 852bf16
removed unused import
didoo 0526e49
removed `isInitialized` logic from the `hdeTheming` service to avoid bug
didoo f6d2ca9
TEMP - added temporary `hds-theme-light/dark` selectors
didoo ebe0f95
TEMP - Added back custom token values for testing purpose
didoo f680549
fixed small issue with the `HdsThemeSwitcher` components used in the β¦
didoo a012d1d
added small comment
didoo a0fc423
updated `hdsTheming` service to support `default` theme / mode
didoo edd9898
added support for `default` option to HDS ThemeSwitcher component
didoo e614486
Updated βfoundations/themingβ showcase page to include variants of HDβ¦
didoo 451b508
updated Showcase ThemeSwitcher to use ``default` as theme option
didoo 54cd4f4
updated logic for how CSS selectors are applied to the `html:root` elβ¦
didoo 623fcde
updated CSS selectors for local `public/assets` themed tokens CSS filβ¦
didoo 91b0e34
added fake theming for display/text typography to `public/assets` theβ¦
didoo a470cd8
updated βfoundations/themingβ showcase page to include `default` and β¦
didoo 46391f1
implemented `ThemeContex` component
didoo 8bee0d9
added demos of `ThemeContext` component to showcase βfoundations/themβ¦
didoo 166ac3d
improved type definitions for ThemeContext and showcase βfoundations/β¦
didoo a3e69bc
refactored how CSS selectors are applied to enable mode-specific overβ¦
didoo 47859c6
updated CSS selectors for local `public/assets` themed tokens CSS filβ¦
didoo c9fd7ec
updated `ThemeContext` to use a more generic `context` argument
didoo fea2372
updated showcase βthemingβ page to use the new `@context` argument foβ¦
didoo 5450cb7
finally defined proper typing for `ThemeContext` component
didoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
5 changes: 5 additions & 0 deletions
5
packages/components/src/components/hds/theme-context/index.hbs
This file contains hidden or 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,5 @@ | ||
| {{! | ||
| Copyright (c) HashiCorp, Inc. | ||
| SPDX-License-Identifier: MPL-2.0 | ||
| }} | ||
| <div class={{this.classNames}} ...attributes>{{yield}}</div> |
67 changes: 67 additions & 0 deletions
67
packages/components/src/components/hds/theme-context/index.ts
This file contains hidden or 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,67 @@ | ||
| /** | ||
| * Copyright (c) HashiCorp, Inc. | ||
| * SPDX-License-Identifier: MPL-2.0 | ||
| */ | ||
|
|
||
| import Component from '@glimmer/component'; | ||
| import { assert } from '@ember/debug'; | ||
| import type Owner from '@ember/owner'; | ||
|
|
||
| import { | ||
| HdsThemeContextThemesValues, | ||
| HdsThemeContextModesValues, | ||
| } from './types.ts'; | ||
| import type { HdsThemeContexts } from './types.ts'; | ||
|
|
||
| export interface HdsThemeContextSignature { | ||
| Args: { | ||
| // it can be an `HdsTheme` or an `HdsMode` | ||
| context: HdsThemeContexts; | ||
| }; | ||
| Blocks: { | ||
| default: []; | ||
| }; | ||
| Element: HTMLElement; | ||
| } | ||
|
|
||
| export const CONTEXTUAL_THEMES: string[] = Object.values( | ||
| HdsThemeContextThemesValues | ||
| ); | ||
| export const CONTEXTUAL_MODES: string[] = Object.values( | ||
| HdsThemeContextModesValues | ||
| ); | ||
| export const CONTEXTUAL_VALUES: string[] = [ | ||
| ...CONTEXTUAL_THEMES, | ||
| ...CONTEXTUAL_MODES, | ||
| ]; | ||
|
|
||
| export default class HdsThemeContext extends Component<HdsThemeContextSignature> { | ||
| constructor(owner: Owner, args: HdsThemeContextSignature['Args']) { | ||
| super(owner, args); | ||
|
|
||
| const { context } = args; | ||
|
|
||
| assert( | ||
| `@context for "Hds::ThemeContext" must be one of the following: ${CONTEXTUAL_VALUES.join( | ||
| ', ' | ||
| )}; received: ${context}`, | ||
| CONTEXTUAL_VALUES.includes(context) | ||
| ); | ||
| } | ||
|
|
||
| // Get the class names to apply to the component. | ||
| get classNames(): string { | ||
| const classes = ['hds-theme-context']; | ||
|
|
||
| const { context } = this.args; | ||
|
|
||
| // add "theme" or "mode" classes based on the @context arguments | ||
| if (CONTEXTUAL_THEMES.includes(context)) { | ||
| classes.push(`hds-theme-${context}`); | ||
| } else if (CONTEXTUAL_MODES.includes(context)) { | ||
| classes.push(`hds-mode-${context}`); | ||
| } | ||
|
|
||
| return classes.join(' '); | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
packages/components/src/components/hds/theme-context/types.ts
This file contains hidden or 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,35 @@ | ||
| /** | ||
| * Copyright (c) HashiCorp, Inc. | ||
| * SPDX-License-Identifier: MPL-2.0 | ||
| */ | ||
|
|
||
| import { | ||
| HdsThemeValues, | ||
| HdsModesLightValues, | ||
| HdsModesDarkValues, | ||
| } from '../../../services/hds-theming.ts'; | ||
|
|
||
| import type { | ||
| HdsThemes, | ||
| HdsModes, | ||
| } from '../../../services/hds-theming.ts'; | ||
|
|
||
| // re-export the enum values for the `HdsThemes` to use in the component | ||
| // note: using `as const` ensures Object.values() returns only the values (not keys _and_ values) | ||
| export const HdsThemeContextThemesValues = { | ||
| Default: HdsThemeValues.Default, | ||
| System: HdsThemeValues.System, | ||
| Light: HdsThemeValues.Light, | ||
| Dark: HdsThemeValues.Dark, | ||
| } as const; | ||
|
|
||
| // re-export the enum values for the `HdsModes` to use in the component | ||
| // note: using `as const` ensures Object.values() returns only the values (not keys _and_ values) | ||
| export const HdsThemeContextModesValues = { | ||
| CdsG0: HdsModesLightValues.CdsG0, | ||
| CdsG10: HdsModesLightValues.CdsG10, | ||
| CdsG90: HdsModesDarkValues.CdsG90, | ||
| CdsG100: HdsModesDarkValues.CdsG100, | ||
| } as const; | ||
|
|
||
| export type HdsThemeContexts = HdsThemes | HdsModes; |
29 changes: 29 additions & 0 deletions
29
packages/components/src/components/hds/theme-switcher/index.hbs
This file contains hidden or 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,29 @@ | ||
| {{! | ||
| Copyright (c) HashiCorp, Inc. | ||
| SPDX-License-Identifier: MPL-2.0 | ||
| }} | ||
|
|
||
| {{! | ||
| ------------------------------------------------------------------------------------------ | ||
| IMPORTANT: this is a temporary implementation, while we wait for the design specifications | ||
| ------------------------------------------------------------------------------------------ | ||
| }} | ||
|
|
||
| <Hds::Dropdown | ||
| @enableCollisionDetection={{true}} | ||
| @matchToggleWidth={{@toggleIsFullWidth}} | ||
| class="hds-theme-switcher-control" | ||
| ...attributes | ||
| as |D| | ||
| > | ||
| <D.ToggleButton | ||
| @color="secondary" | ||
| @size={{this.toggleSize}} | ||
| @isFullWidth={{this.toggleIsFullWidth}} | ||
| @text={{this.toggleContent.label}} | ||
| @icon={{this.toggleContent.icon}} | ||
| /> | ||
| {{#each-in this._options as |key data|}} | ||
| <D.Interactive @icon={{data.icon}} {{on "click" (fn this.onSelectTheme data.theme)}}>{{data.label}}</D.Interactive> | ||
| {{/each-in}} | ||
| </Hds::Dropdown> |
108 changes: 108 additions & 0 deletions
108
packages/components/src/components/hds/theme-switcher/index.ts
This file contains hidden or 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,108 @@ | ||
| /** | ||
| * Copyright (c) HashiCorp, Inc. | ||
| * SPDX-License-Identifier: MPL-2.0 | ||
| */ | ||
|
|
||
| // ------------------------------------------------------------------------------------------ | ||
| // IMPORTANT: this is a temporary implementation, while we wait for the design specifications | ||
| // ------------------------------------------------------------------------------------------ | ||
|
|
||
| import Component from '@glimmer/component'; | ||
| import { inject as service } from '@ember/service'; | ||
| import { action } from '@ember/object'; | ||
|
|
||
| import type { HdsDropdownSignature } from '../dropdown/index.ts'; | ||
| import type { HdsDropdownToggleButtonSignature } from '../dropdown/toggle/button.ts'; | ||
| import type { HdsIconSignature } from '../icon/index.ts'; | ||
| import type HdsThemingService from '../../../services/hds-theming.ts'; | ||
| import type { | ||
| HdsThemes, | ||
| OnSetThemeCallback, | ||
| } from '../../../services/hds-theming.ts'; | ||
|
|
||
| interface ThemeOption { | ||
| theme: HdsThemes | undefined; | ||
| icon: HdsIconSignature['Args']['name']; | ||
| label: string; | ||
| } | ||
|
|
||
| const OPTIONS: Record<HdsThemes, ThemeOption> = { | ||
| default: { theme: 'default', icon: 'hashicorp', label: 'Default' }, | ||
| system: { theme: 'system', icon: 'monitor', label: 'System' }, | ||
| light: { theme: 'light', icon: 'sun', label: 'Light' }, | ||
| dark: { theme: 'dark', icon: 'moon', label: 'Dark' }, | ||
| }; | ||
|
|
||
| interface HdsThemeSwitcherSignature { | ||
| Args: { | ||
| toggleSize?: HdsDropdownToggleButtonSignature['Args']['size']; | ||
| toggleIsFullWidth?: HdsDropdownToggleButtonSignature['Args']['isFullWidth']; | ||
| hasDefaultOption?: boolean; | ||
| hasSystemOption?: boolean; | ||
| onSetTheme?: OnSetThemeCallback; | ||
| }; | ||
| Element: HdsDropdownSignature['Element']; | ||
| } | ||
|
|
||
| export default class HdsThemeSwitcher extends Component<HdsThemeSwitcherSignature> { | ||
| @service declare readonly hdsTheming: HdsThemingService; | ||
|
|
||
| get toggleSize() { | ||
| return this.args.toggleSize ?? 'small'; | ||
| } | ||
|
|
||
| get toggleIsFullWidth() { | ||
| return this.args.toggleIsFullWidth ?? false; | ||
| } | ||
|
|
||
| get toggleContent() { | ||
| if ( | ||
| (this.currentTheme === 'default' && this.hasDefaultOption) || | ||
| (this.currentTheme === 'system' && this.hasSystemOption) || | ||
| this.currentTheme === 'light' || | ||
| this.currentTheme === 'dark' | ||
| ) { | ||
| return { | ||
| label: OPTIONS[this.currentTheme].label, | ||
| icon: OPTIONS[this.currentTheme].icon, | ||
| }; | ||
| } else { | ||
| return { label: 'Theme', icon: undefined }; | ||
| } | ||
| } | ||
|
|
||
| // note: we will use the `default` option in development, while migrating to the `cds` theming | ||
| // during this process, consumers will enable/disable this option via code logic or feature flag | ||
| get hasDefaultOption() { | ||
| return this.args.hasDefaultOption ?? false; | ||
| } | ||
|
|
||
| get hasSystemOption() { | ||
| return this.args.hasSystemOption ?? true; | ||
| } | ||
|
|
||
| get _options() { | ||
| const options: Partial<typeof OPTIONS> = { ...OPTIONS }; | ||
|
|
||
| if (!this.hasDefaultOption) { | ||
| delete options.default; | ||
| } | ||
|
|
||
| if (!this.hasSystemOption) { | ||
| delete options.system; | ||
| } | ||
|
|
||
| return options; | ||
| } | ||
|
|
||
| get currentTheme() { | ||
| // we get the theme from the global service | ||
| return this.hdsTheming.currentTheme; | ||
| } | ||
|
|
||
| @action | ||
| onSelectTheme(theme: HdsThemes | undefined): void { | ||
| // we set the theme in the global service (and provide an optional user-defined callback) | ||
| this.hdsTheming.setTheme({ theme, onSetTheme: this.args.onSetTheme }); | ||
| } | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -4,3 +4,5 @@ | |
| */ | ||
|
|
||
| // This file is used to expose public services | ||
|
|
||
| export * from './services/hds-theming.ts'; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.