Skip to content
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

chore: New Theme Settings Integration #29848

Merged
merged 6 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions app/client/src/ce/selectors/applicationSelectors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,9 @@ export const getCurrentPluginIdForCreateNewApp = (state: AppState) => {
};

export const getAppThemeSettings = (state: AppState) => {
return (
state.ui.applications.currentApplication?.applicationDetail?.themeSetting ||
defaultThemeSetting
);
return {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need these changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just making sure we spread out the theme setting that we get from the backend over the default settings. Previously it was like "If the backend has themeSettings, use that, otherwise use default Settings"

...defaultThemeSetting,
...state.ui.applications.currentApplication?.applicationDetail
?.themeSetting,
};
};
4 changes: 2 additions & 2 deletions app/client/src/constants/AppConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export interface NavigationSetting {

export interface ThemeSetting {
accentColor: string;
colorMode: "light" | "dark";
colorMode: "LIGHT" | "DARK";
borderRadius: string;
density: number;
sizing: number;
Expand Down Expand Up @@ -132,7 +132,7 @@ export const defaultNavigationSetting = {
export const defaultThemeSetting: ThemeSetting = {
fontFamily: "System Default",
accentColor: "#553DE9",
colorMode: "light",
colorMode: "LIGHT",
borderRadius: "6px",
density: 1,
sizing: 1,
Expand Down
22 changes: 17 additions & 5 deletions app/client/src/pages/AppViewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ import useWidgetFocus from "utils/hooks/useWidgetFocus/useWidgetFocus";
import HtmlTitle from "./AppViewerHtmlTitle";
import BottomBar from "components/BottomBar";
import type { ApplicationPayload } from "@appsmith/constants/ReduxActionConstants";
import { getCurrentApplication } from "@appsmith/selectors/applicationSelectors";
import {
getAppThemeSettings,
getCurrentApplication,
} from "@appsmith/selectors/applicationSelectors";
import { editorInitializer } from "../../utils/editor/EditorUtils";
import { widgetInitialisationSuccess } from "../../actions/widgetActions";
import {
Expand Down Expand Up @@ -111,11 +114,22 @@ function AppViewer(props: Props) {
const currentApplicationDetails: ApplicationPayload | undefined = useSelector(
getCurrentApplication,
);
const { theme } = useTheme({
const isWDSEnabled = useFeatureFlag("ab_wds_enabled");
const themeSetting = useSelector(getAppThemeSettings);
const themeProps = {
borderRadius: selectedTheme.properties.borderRadius.appBorderRadius,
seedColor: selectedTheme.properties.colors.primaryColor,
fontFamily: selectedTheme.properties.fontFamily.appFont as FontFamily,
});
};
const wdsThemeProps = {
borderRadius: themeSetting.borderRadius,
seedColor: themeSetting.accentColor,
colorMode: themeSetting.colorMode.toLowerCase(),
fontFamily: themeSetting.fontFamily as FontFamily,
userSizing: themeSetting.sizing,
userDensity: themeSetting.density,
};
const { theme } = useTheme(isWDSEnabled ? wdsThemeProps : themeProps);
const focusRef = useWidgetFocus();

const showRampSelector = showProductRamps(RAMP_NAME.MULTIPLE_ENV, true);
Expand Down Expand Up @@ -214,8 +228,6 @@ function AppViewer(props: Props) {
};
}, [selectedTheme.properties.fontFamily.appFont]);

const isWDSEnabled = useFeatureFlag("ab_wds_enabled");

const renderChildren = () => {
return (
<EditorContextProvider renderMode="PAGE">
Expand Down
2 changes: 1 addition & 1 deletion app/client/src/pages/Editor/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const Canvas = (props: CanvasProps) => {
const wdsThemeProps = {
borderRadius: themeSetting.borderRadius,
seedColor: themeSetting.accentColor,
colorMode: themeSetting.colorMode,
colorMode: themeSetting.colorMode.toLowerCase(),
fontFamily: themeSetting.fontFamily as FontFamily,
userSizing: themeSetting.sizing,
userDensity: themeSetting.density,
Expand Down
4 changes: 2 additions & 2 deletions app/client/src/pages/Editor/WDSThemePropertyPane/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ function WDSThemePropertyPane() {
/>
</section>
<Switch
defaultSelected={theme.colorMode === "dark"}
defaultSelected={theme.colorMode === "DARK"}
onChange={(isSelected: boolean) => {
updateTheme({
...theme,
colorMode: isSelected ? "dark" : "light",
colorMode: isSelected ? "DARK" : "LIGHT",
});
}}
>
Expand Down
Loading