-
Notifications
You must be signed in to change notification settings - Fork 50
[04-Part2] [Project Solar / Phase 1 / Showcase] Add support for theming and theme-switching to the showcase #3390
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
94
commits into
project-solar/phase-1-main-feature-branch
Choose a base branch
from
project-solar/phase-1/HDS-5242_showcase/add-themes-support
base: project-solar/phase-1-main-feature-branch
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.
Open
Changes from all commits
Commits
Show all changes
94 commits
Select commit
Hold shift + click to select a range
ab6700c
added `Hds::ThemeSwitcher` component
didoo 6d6d7ca
added `Hds::Theming` service
didoo 57ecc17
added theming to the Showcase itself (and replaced hardcoded values wβ¦
didoo 4b2549e
added `Shw::ThemeSwitcher` component for showcase
didoo 6746107
updated `Mock::App` and added new yielded sub-components
didoo 55a9491
added `Shw:: ThemeSwitcher` to the Showcase page header
didoo 4b48670
added `foundations/theming` showcase page (and a frameless demo)
didoo af67d84
refactored `hds-theming` service to align with the new themes/modes aβ¦
didoo 0e46e57
added `hdsTheming` initialization to main showcase app
didoo cbca213
removed compilation of components Scss and replaced it with static inβ¦
didoo aac4323
added theming options via popover - part 1
didoo d77b8ac
added theming options via popover - part 2
didoo dcc0b6b
added theming options via popover - part 3
didoo aced362
added theming options via popover - part 4
didoo ae0d11c
added theming options via popover - part 5
didoo a817eb6
big code refactoring for the theme selector, to streamline user selecβ¦
didoo cf7ed9f
updated logic that sets the theming for the showcase itself (without β¦
didoo ee7d8bc
small fixes here and there for cleanup and linting
didoo e207156
fixed issue with `pnpm lint:format` (missing newline at the end of `pβ¦
didoo 66eeaa4
fixed accessibility issue in `advanced-table` page, due to changes toβ¦
didoo 763fdcf
fixed typescript error due to new mock page being added
didoo 84ffcba
added fix for tests failing
didoo 7fc5b11
started large refactoring/rewrite of the theming switcher and page inβ¦
didoo deafaf5
updated logic by creating a `shwTheming` service that extends `hdsTheβ¦
didoo 35bc27b
moved theming logic from `ShwThemeSwitcher` component/subcomponents tβ¦
didoo d8a629c
updated reference CSS files to follow new theming approach/logic
didoo 352764b
further refactoring/rewriting of theming logic
didoo ac06c81
updated approach to `light/dark` styles in showcase by using the HDS β¦
didoo 1ba1a2d
migrated back the `Contextual` demo content to the index page
didoo 0e0d261
added a `DebuggingPanel` to the `ShwThemeSwitcher` controls
didoo 3c26aea
refactored/improved `DebuggingPanel` and added new preferences to advβ¦
didoo 2974fba
small cleanups and refactorings
didoo 811cfd0
fixed small issue with `ShwThemeSwitcher` selector
didoo 8bb238d
removed some outdated comments
didoo 63af275
small refactorings
didoo df426e2
added local storage support for theming options
didoo 4ffc477
big refactoring of the `hdsTheming` service to simplify logic and redβ¦
didoo 59d5a82
cleanup of debugging comments and other stuff
didoo a6d7ebd
refactor and cleanup in preparation for PR review
didoo e5573d2
refactored code to fix logic flow for theming initialization
didoo 1162e09
fixed how the theming options were saved in local storage
didoo 08409e0
Apply suggestions from Copilot's code review
didoo 3f3138a
fixed issue with `setTheme` not being passed `options` by the `ShwTheβ¦
didoo 658922b
fix issue with the popover of the ShwThemeSwitcher component, where tβ¦
didoo f849855
Update showcase/app/services/shw-theming.ts
didoo 4a14421
small tweak to the typing of `HdsModes` per code review suggestion
didoo b3a1c0e
updated how the CSS files (tokens and components, with/without theminβ¦
didoo 8ff9558
updated logic for styleshet switching using the `disabled` attribute
didoo 413510a
removed unused import
didoo ff19bb7
removed `isInitialized` logic from the `hdeTheming` service to avoid bug
didoo 91ddbd7
TEMP - added temporary `hds-theme-light/dark` selectors
didoo 2fab643
TEMP - Added back custom token values for testing purpose
didoo deab041
fixed small issue with the `HdsThemeSwitcher` components used in the β¦
didoo 79aa445
added small comment
didoo d9fd100
updated `hdsTheming` service to support `default` theme / mode
didoo fcb145b
added support for `default` option to HDS ThemeSwitcher component
didoo 1086033
Updated βfoundations/themingβ showcase page to include variants of HDβ¦
didoo 8cdeb0b
updated Showcase ThemeSwitcher to use ``default` as theme option
didoo 6bc8726
updated logic for how CSS selectors are applied to the `html:root` elβ¦
didoo 6beef64
updated CSS selectors for local `public/assets` themed tokens CSS filβ¦
didoo 549f2bb
added fake theming for display/text typography to `public/assets` theβ¦
didoo f710b0b
updated βfoundations/themingβ showcase page to include `default` and β¦
didoo 45fef94
implemented `ThemeContex` component
didoo 77ec00b
added demos of `ThemeContext` component to showcase βfoundations/themβ¦
didoo 531ea7b
improved type definitions for ThemeContext and showcase βfoundations/β¦
didoo f9087dd
refactored how CSS selectors are applied to enable mode-specific overβ¦
didoo d51a4d7
updated CSS selectors for local `public/assets` themed tokens CSS filβ¦
didoo dd4255d
updated `ThemeContext` to use a more generic `context` argument
didoo 7b166b0
updated showcase βthemingβ page to use the new `@context` argument foβ¦
didoo a0ed075
finally defined proper typing for `ThemeContext` component
didoo 71588fb
refactored showcase code to remove handling of `[data-hds-theme]` CSSβ¦
didoo 74cf9b5
updated CSS selectors for local `public/assets` themed tokens CSS filβ¦
didoo 7cfccbf
refactored theme switching in showcase to use new CSS files
didoo c2d12f7
updated theme switcher in showcase to allow toggling of the βadvancedβ¦
didoo 1946dfd
introduced a βcarbonizationβ mixin for applying styles only for certaβ¦
didoo 65c08ef
added subtle shadow to `ThemingBasicContainer`
didoo ee26327
fixed small bug that would cause the showcase pages to crash if the vβ¦
didoo 9bed043
small fix to the control logic for the `HdsThemeSwitcher` demo in shoβ¦
didoo ed980d8
fixed TypeScript issue
didoo 9bc31cd
fix small bug in the logic when the βapplyβ with βshow advanced optioβ¦
didoo a9239d2
added `ShwBodyLinkToRoute` component
didoo 318c915
replaced custom link in AdvancedTable showcase page with newly createβ¦
didoo aad753f
reworked the demo frameless for application with theme switcher to avβ¦
didoo d80eaac
replaced custom theme switcher with proper `HdsThemeSwitcher` in `Appβ¦
didoo 34c5e91
some cleanup before code review
didoo a89edd6
changed how theming is applied to the showcase itself, to limit `prefβ¦
didoo 016918f
fixed wrong CSS selector, per code review suggestion
didoo f2193d9
prefixed `OnSetThemeCallback` with `Hds` per review suggestion
didoo e10494b
Update packages/components/src/template-registry.ts
didoo 4c76fe9
converted `updatePageStylesheets` function to a private method
didoo 2688039
small cleanup per code reviews suggestions
didoo ae0c48a
small fixes per code review
didoo 0219437
updated logic that reads the stored theming data for the `HdsThemingSβ¦
didoo a736ccf
removed comment
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> |
69 changes: 69 additions & 0 deletions
69
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,69 @@ | ||
| /** | ||
| * 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'; | ||
|
|
||
| import type { HdsThemes, HdsModes } from '../../../services/hds-theming.ts'; | ||
|
|
||
| export interface HdsThemeContextSignature { | ||
| Args: { | ||
| // can be either an `HdsTheme` or an `HdsMode` | ||
| context: HdsThemeContexts; | ||
| }; | ||
| Blocks: { | ||
| default: []; | ||
| }; | ||
| Element: HTMLElement; | ||
| } | ||
|
|
||
| export const CONTEXTUAL_THEMES: HdsThemes[] = Object.values( | ||
| HdsThemeContextThemesValues | ||
| ); | ||
| export const CONTEXTUAL_MODES: HdsModes[] = Object.values( | ||
| HdsThemeContextModesValues | ||
| ); | ||
| export const CONTEXTUAL_VALUES: HdsThemeContexts[] = [ | ||
| ...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 as HdsThemes)) { | ||
| classes.push(`hds-theme-${context}`); | ||
| } else if (CONTEXTUAL_MODES.includes(context as HdsModes)) { | ||
| classes.push(`hds-mode-${context}`); | ||
| } | ||
|
|
||
| return classes.join(' '); | ||
| } | ||
| } | ||
32 changes: 32 additions & 0 deletions
32
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,32 @@ | ||
| /** | ||
| * 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 | Exclude<HdsModes, 'default'>; |
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, | ||
| HdsOnSetThemeCallback, | ||
| } 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' }, | ||
| }; | ||
|
|
||
| export interface HdsThemeSwitcherSignature { | ||
| Args: { | ||
| toggleSize?: HdsDropdownToggleButtonSignature['Args']['size']; | ||
| toggleIsFullWidth?: HdsDropdownToggleButtonSignature['Args']['isFullWidth']; | ||
| hasDefaultOption?: boolean; | ||
| hasSystemOption?: boolean; | ||
| onSetTheme?: HdsOnSetThemeCallback; | ||
| }; | ||
| 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.
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.