-
Notifications
You must be signed in to change notification settings - Fork 190
feat: add ColorScheme API for light/dark theme support #22718
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
Merged
+846
−13
Merged
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
a228ebb
feat: add API for switching between light and dark theme variants
Artur- 56cd091
Use short name
Artur- 6e6531b
fix: handle null theme variant in Page.getThemeVariant()
Artur- 9c85778
fix: use native color-scheme property instead of --aura-color-scheme
Artur- baa12b2
Merge remote-tracking branch 'origin/main' into flow-change-dark
Artur- 2b62645
fix: treat "normal" color-scheme as no variant set
Artur- fbbb751
test: add integration tests for theme variant API
Artur- e2a7214
fix: revert waitUntil changes in ThemeVariantIT
Artur- 20e7116
fix: update initialThemeVariant test to handle browser default
Artur- fa332c8
Merge remote-tracking branch 'origin/main' into flow-change-dark
Artur- a5b6788
use setThemeVariant
Artur- 9d18083
Move conversion
Artur- 4c20b8d
format
Artur- be2ea9a
Really use "" for themeVariant
Artur- 2c1e328
Merge remote-tracking branch 'origin/main' into flow-change-dark
Artur- 49d4ef8
feat: add ColorScheme API with enum-based type-safe implementation
Artur- 3af289d
refactor: rename ThemeVariant test files to ColorScheme
Artur- 99669c2
fix: update CSS to use light-dark() function for color scheme
Artur- 60bca58
fix: use theme attribute for color scheme with CSS color-scheme property
Artur- 210eb83
Update comment
Artur- 3c0f595
Merge remote-tracking branch 'origin/main' into flow-change-dark
Artur- 6f18a10
format
Artur- fb20f9a
fix: set theme attribute in IndexHtmlRequestHandler and update tests
Artur- 8b5bf5a
Merge branch 'main' into flow-change-dark
Artur- 6d3277b
docs: clarify NORMAL color scheme behavior
Artur- 13f6589
fix: set color-scheme property in addition to theme attribute
Artur- b8a2162
fix: use hyphenated theme attribute for multi-value color schemes
Artur- 7ce5642
Merge branch 'main' into flow-change-dark
Artur- 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
134 changes: 134 additions & 0 deletions
134
flow-server/src/main/java/com/vaadin/flow/component/page/ColorScheme.java
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,134 @@ | ||
| /* | ||
| * Copyright 2000-2025 Vaadin Ltd. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
| * use this file except in compliance with the License. You may obtain a copy of | ||
| * the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations under | ||
| * the License. | ||
| */ | ||
| package com.vaadin.flow.component.page; | ||
|
|
||
| import java.lang.annotation.Documented; | ||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Inherited; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| /** | ||
| * Defines the color scheme for the application using the CSS color-scheme | ||
| * property. | ||
| * <p> | ||
| * This annotation should be placed on a class that implements | ||
| * {@link com.vaadin.flow.component.page.AppShellConfigurator} to set the | ||
| * initial color scheme for the entire application. | ||
| * <p> | ||
| * Example usage: | ||
| * | ||
| * <pre> | ||
| * @ColorScheme(ColorScheme.Value.DARK) | ||
| * public class AppShell implements AppShellConfigurator { | ||
| * } | ||
| * </pre> | ||
| * <p> | ||
| * The color scheme can also be changed programmatically at runtime using | ||
| * {@link Page#setColorScheme(ColorScheme.Value)}. | ||
| * | ||
| * @see Page#setColorScheme(ColorScheme.Value) | ||
| * @see Page#getColorScheme() | ||
| */ | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Target(ElementType.TYPE) | ||
| @Inherited | ||
| @Documented | ||
| public @interface ColorScheme { | ||
|
|
||
| /** | ||
| * The initial color scheme for the application. | ||
| * | ||
| * @return the color scheme value | ||
| */ | ||
| Value value() default Value.NORMAL; | ||
|
|
||
| /** | ||
| * Enumeration of supported color scheme values. | ||
| * <p> | ||
| * These values correspond to the CSS color-scheme property values and | ||
| * control how the browser renders UI elements and how the application | ||
| * responds to system color scheme preferences. | ||
| */ | ||
| enum Value { | ||
| /** | ||
| * Light color scheme only. The application will use a light theme | ||
| * regardless of system preferences. | ||
| */ | ||
| LIGHT("light"), | ||
|
|
||
| /** | ||
| * Dark color scheme only. The application will use a dark theme | ||
| * regardless of system preferences. | ||
| */ | ||
| DARK("dark"), | ||
|
|
||
| /** | ||
| * Supports both light and dark color schemes, with a preference for | ||
| * light. The application can adapt to system preferences but defaults | ||
| * to light mode. | ||
| */ | ||
| LIGHT_DARK("light dark"), | ||
|
|
||
| /** | ||
| * Supports both light and dark color schemes, with a preference for | ||
| * dark. The application can adapt to system preferences but defaults to | ||
| * dark mode. | ||
| */ | ||
| DARK_LIGHT("dark light"), | ||
|
|
||
| /** | ||
| * Normal/default color scheme. Uses the browser's default behavior | ||
| * without any specific color scheme preference. | ||
| */ | ||
| NORMAL("normal"); | ||
|
|
||
| private final String value; | ||
|
|
||
| Value(String value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the CSS color-scheme property value. | ||
| * | ||
| * @return the CSS value string | ||
| */ | ||
| public String getValue() { | ||
| return value; | ||
| } | ||
|
|
||
| /** | ||
| * Converts a string to a ColorScheme.Value enum. | ||
| * | ||
| * @param value | ||
| * the CSS color-scheme value string | ||
| * @return the corresponding enum value, or NORMAL if not recognized | ||
| */ | ||
| public static Value fromString(String value) { | ||
| if (value == null || value.isEmpty()) { | ||
| return NORMAL; | ||
| } | ||
| for (Value v : values()) { | ||
| if (v.value.equals(value)) { | ||
| return v; | ||
| } | ||
| } | ||
| return NORMAL; | ||
| } | ||
| } | ||
| } | ||
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
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
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
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.