Skip to content

Commit 43086e0

Browse files
committed
chore: fix theme config issues
1 parent f8ffbb4 commit 43086e0

File tree

8 files changed

+58
-8
lines changed

8 files changed

+58
-8
lines changed

packages/javascript/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export {OIDCEndpoints} from './models/oidc-endpoints';
4141
export {Store} from './models/store';
4242
export {User} from './models/user';
4343
export {Schema, SchemaAttribute, WellKnownSchemaIds} from './models/scim2-schema';
44+
export {RecursivePartial} from './models/utility-types';
4445

4546
export {default as AsgardeoJavaScriptClient} from './AsgardeoJavaScriptClient';
4647

packages/javascript/src/models/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
import {ThemeConfig, ThemeMode} from '../theme/types';
20+
import { RecursivePartial } from './utility-types';
2021

2122
export interface BaseConfig<T = unknown> {
2223
/**
@@ -79,7 +80,7 @@ export interface ThemePreferences {
7980
/**
8081
* Theme overrides to customize the default theme
8182
*/
82-
overrides?: Partial<ThemeConfig>;
83+
overrides?: RecursivePartial<ThemeConfig>;
8384
}
8485

8586
export interface Preferences {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3+
*
4+
* WSO2 LLC. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
export type RecursivePartial<T> = {
20+
[P in keyof T]?: RecursivePartial<T[P]>;
21+
};

packages/javascript/src/theme/createTheme.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* under the License.
1717
*/
1818

19+
import { RecursivePartial } from '../models/utility-types';
1920
import {Theme, ThemeConfig} from './types';
2021

2122
const lightTheme: ThemeConfig = {
@@ -24,6 +25,10 @@ const lightTheme: ThemeConfig = {
2425
main: '#1a73e8',
2526
contrastText: '#ffffff',
2627
},
28+
secondary: {
29+
main: '#424242',
30+
contrastText: '#ffffff',
31+
},
2732
background: {
2833
surface: '#f5f5f5',
2934
disabled: '#f0f0f0',
@@ -58,6 +63,10 @@ const darkTheme: ThemeConfig = {
5863
main: '#1a73e8',
5964
contrastText: '#ffffff',
6065
},
66+
secondary: {
67+
main: '#424242',
68+
contrastText: '#ffffff',
69+
},
6170
background: {
6271
surface: '#121212',
6372
disabled: '#1f1f1f',
@@ -86,12 +95,14 @@ const darkTheme: ThemeConfig = {
8695
},
8796
};
8897

89-
const toCssVariables = (theme: ThemeConfig): Record<string, string> => {
98+
const toCssVariables = (theme: RecursivePartial<ThemeConfig>): Record<string, string> => {
9099
const cssVars: Record<string, string> = {};
91100

92101
// Colors
93102
cssVars['--asgardeo-color-primary-main'] = theme.colors.primary.main;
94103
cssVars['--asgardeo-color-primary-contrastText'] = theme.colors.primary.contrastText;
104+
cssVars['--asgardeo-color-secondary-main'] = theme.colors.secondary.main;
105+
cssVars['--asgardeo-color-secondary-contrastText'] = theme.colors.secondary.contrastText;
95106
cssVars['--asgardeo-color-background-surface'] = theme.colors.background.surface;
96107
cssVars['--asgardeo-color-background-disabled'] = theme.colors.background.disabled;
97108
cssVars['--asgardeo-color-background-body-main'] = theme.colors.background.body.main;
@@ -113,14 +124,18 @@ const toCssVariables = (theme: ThemeConfig): Record<string, string> => {
113124
return cssVars;
114125
};
115126

116-
const createTheme = (config: Partial<ThemeConfig> = {}, isDark = false): Theme => {
127+
const createTheme = (config: RecursivePartial<ThemeConfig> = {}, isDark = false): Theme => {
117128
const baseTheme = isDark ? darkTheme : lightTheme;
118129
const mergedConfig = {
119130
...baseTheme,
120131
...config,
121132
colors: {
122133
...baseTheme.colors,
123134
...config.colors,
135+
secondary: {
136+
...baseTheme.colors.secondary,
137+
...(config.colors?.secondary || {}),
138+
},
124139
},
125140
spacing: {
126141
...baseTheme.spacing,
@@ -130,7 +145,7 @@ const createTheme = (config: Partial<ThemeConfig> = {}, isDark = false): Theme =
130145
...baseTheme.borderRadius,
131146
...config.borderRadius,
132147
},
133-
};
148+
} as ThemeConfig;
134149

135150
return {
136151
...mergedConfig,

packages/javascript/src/theme/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export interface ThemeColors {
2121
main: string;
2222
contrastText: string;
2323
};
24+
secondary: {
25+
main: string;
26+
contrastText: string;
27+
};
2428
background: {
2529
surface: string;
2630
disabled: string;

packages/react/src/components/presentation/UserProfile/BaseUserProfile.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export interface BaseUserProfileProps {
6767
onSubmit?: (data: any) => void;
6868
saveButtonText?: string;
6969
cancelButtonText?: string;
70-
onUpdate: (payload: any) => Promise<void>;
70+
onUpdate?: (payload: any) => Promise<void>;
7171
}
7272

7373
const BaseUserProfile: FC<BaseUserProfileProps> = ({
@@ -193,7 +193,7 @@ const BaseUserProfile: FC<BaseUserProfileProps> = ({
193193
const cancelButtonStyle = useMemo(
194194
() => ({
195195
...buttonStyle,
196-
backgroundColor: theme.colors.background.surface,
196+
backgroundColor: theme.colors.secondary.main,
197197
border: `1px solid ${theme.colors.border}`,
198198
}),
199199
[theme, buttonStyle],

packages/react/src/theme/ThemeProvider.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
*/
1818

1919
import {FC, PropsWithChildren, ReactElement, useEffect, useMemo, useState} from 'react';
20-
import {createTheme, Theme, ThemeConfig} from '@asgardeo/browser';
20+
import {createTheme, Theme, ThemeConfig, RecursivePartial} from '@asgardeo/browser';
2121
import ThemeContext from './ThemeContext';
2222

2323
export interface ThemeProviderProps {
24-
theme?: Partial<ThemeConfig>;
24+
theme?: RecursivePartial<ThemeConfig>;
2525
defaultColorScheme?: 'light' | 'dark';
2626
}
2727

recipes/vite-react-ts/src/main.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ createRoot(document.getElementById('root')!).render(
1313
preferences={{
1414
theme: {
1515
mode: 'dark',
16+
overrides: {
17+
colors: {
18+
primary: {
19+
main: '#6200ea',
20+
contrastText: '#ffffff',
21+
},
22+
},
23+
},
1624
},
1725
}}
1826
>

0 commit comments

Comments
 (0)