Skip to content

Commit 80ae17f

Browse files
authored
Merge pull request #147 from brionmario/bump-dependencies
chore(react): improve components & error messages
2 parents f019b20 + dc2a632 commit 80ae17f

36 files changed

+532
-384
lines changed

packages/browser/src/__legacy__/client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@ export class AsgardeoSPAClient {
411411
}
412412

413413
return response;
414+
})
415+
.catch(error => {
416+
return Promise.reject(error)
414417
});
415418
}
416419

packages/browser/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@ export {
5858
createMediaQueryListener,
5959
BrowserThemeDetection,
6060
} from './theme/themeDetection';
61+
export {default as getActiveTheme} from './theme/getActiveTheme';
6162

6263
export {default as http} from './utils/http';
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
import {DEFAULT_THEME, ThemeMode} from '@asgardeo/javascript';
20+
import {BrowserThemeDetection, detectThemeMode} from './themeDetection';
21+
22+
/**
23+
* Gets the active theme based on the theme mode preference
24+
* @param mode - The theme mode preference ('light', 'dark', 'system', or 'class')
25+
* @param config - Additional configuration for theme detection
26+
* @returns 'light' or 'dark' based on the resolved theme
27+
*/
28+
const getActiveTheme = (mode: ThemeMode, config: BrowserThemeDetection = {}): ThemeMode => {
29+
if (mode === 'dark') {
30+
return 'dark';
31+
}
32+
33+
if (mode === 'light') {
34+
return 'light';
35+
}
36+
37+
if (mode === 'system') {
38+
if (typeof window !== 'undefined' && window.matchMedia) {
39+
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
40+
}
41+
42+
// Default to light mode if system detection is not available
43+
return DEFAULT_THEME;
44+
}
45+
46+
if (mode === 'class') {
47+
return detectThemeMode(mode, config);
48+
}
49+
50+
// Default to light mode for any unknown mode
51+
return DEFAULT_THEME;
52+
};
53+
54+
export default getActiveTheme;

packages/javascript/src/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,17 @@
1616
* under the License.
1717
*/
1818

19-
export * from './__legacy__/client';
20-
export * from './__legacy__/models';
19+
export {AsgardeoAuthClient} from './__legacy__/client';
20+
export {
21+
DefaultAuthClientConfig,
22+
WellKnownAuthClientConfig,
23+
BaseURLAuthClientConfig,
24+
ExplicitAuthClientConfig,
25+
StrictAuthClientConfig,
26+
AuthClientConfig,
27+
} from './__legacy__/models';
2128

22-
export * from './IsomorphicCrypto';
29+
export {IsomorphicCrypto} from './IsomorphicCrypto';
2330

2431
export {default as initializeEmbeddedSignInFlow} from './api/initializeEmbeddedSignInFlow';
2532
export {default as executeEmbeddedSignInFlow} from './api/executeEmbeddedSignInFlow';
@@ -119,7 +126,7 @@ export {I18nBundle, I18nTranslations, I18nMetadata} from './models/i18n';
119126

120127
export {default as AsgardeoJavaScriptClient} from './AsgardeoJavaScriptClient';
121128

122-
export {default as createTheme} from './theme/createTheme';
129+
export {default as createTheme, DEFAULT_THEME} from './theme/createTheme';
123130
export {ThemeColors, ThemeConfig, Theme, ThemeMode, ThemeDetection} from './theme/types';
124131

125132
export {default as bem} from './utils/bem';

packages/javascript/src/theme/createTheme.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* under the License.
3333
*/
3434

35-
import {Theme, ThemeConfig, ThemeVars} from './types';
35+
import {Theme, ThemeConfig, ThemeMode, ThemeVars} from './types';
3636
import {RecursivePartial} from '../models/utility-types';
3737
import VendorConstants from '../constants/VendorConstants';
3838

@@ -142,15 +142,15 @@ const lightTheme: ThemeConfig = {
142142
const darkTheme: ThemeConfig = {
143143
colors: {
144144
action: {
145-
active: 'rgba(255, 255, 255, 0.70)',
146-
hover: 'rgba(255, 255, 255, 0.04)',
145+
active: '#1c1c1c',
146+
hover: '#1c1c1c',
147147
hoverOpacity: 0.04,
148-
selected: 'rgba(255, 255, 255, 0.08)',
148+
selected: '#1c1c1c',
149149
selectedOpacity: 0.08,
150150
disabled: 'rgba(255, 255, 255, 0.26)',
151151
disabledBackground: 'rgba(255, 255, 255, 0.12)',
152152
disabledOpacity: 0.38,
153-
focus: 'rgba(255, 255, 255, 0.12)',
153+
focus: '#1c1c1c',
154154
focusOpacity: 0.12,
155155
activatedOpacity: 0.12,
156156
},
@@ -160,7 +160,7 @@ const darkTheme: ThemeConfig = {
160160
dark: '#174ea6',
161161
},
162162
secondary: {
163-
main: '#424242',
163+
main: '#8b8b8b',
164164
contrastText: '#ffffff',
165165
dark: '#212121',
166166
},
@@ -655,4 +655,6 @@ const createTheme = (config: RecursivePartial<ThemeConfig> = {}, isDark = false)
655655
};
656656
};
657657

658+
export const DEFAULT_THEME: ThemeMode = 'light';
659+
658660
export default createTheme;

packages/nextjs/src/client/contexts/Asgardeo/AsgardeoProvider.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
AsgardeoProviderProps,
4141
OrganizationProvider,
4242
BrandingProvider,
43+
getActiveTheme,
4344
} from '@asgardeo/react';
4445
import {useRouter, useSearchParams} from 'next/navigation';
4546
import {FC, PropsWithChildren, RefObject, useEffect, useMemo, useRef, useState} from 'react';
@@ -104,7 +105,6 @@ const AsgardeoClientProvider: FC<PropsWithChildren<AsgardeoClientProviderProps>>
104105
const reRenderCheckRef: RefObject<boolean> = useRef(false);
105106
const router = useRouter();
106107
const searchParams = useSearchParams();
107-
const [isDarkMode, setIsDarkMode] = useState(false);
108108
const [isLoading, setIsLoading] = useState<boolean>(true);
109109
const [user, setUser] = useState<User | null>(_user);
110110
const [userProfile, setUserProfile] = useState<UserProfile>(_userProfile);
@@ -175,12 +175,11 @@ const AsgardeoClientProvider: FC<PropsWithChildren<AsgardeoClientProviderProps>>
175175
})();
176176
}, []);
177177

178-
useEffect(() => {
178+
const isDarkMode: boolean = useMemo(() => {
179179
if (!preferences?.theme?.mode || preferences.theme.mode === 'system') {
180-
setIsDarkMode(window.matchMedia('(prefers-color-scheme: dark)').matches);
181-
} else {
182-
setIsDarkMode(preferences.theme.mode === 'dark');
180+
return window.matchMedia('(prefers-color-scheme: dark)').matches;
183181
}
182+
return preferences.theme.mode === 'dark';
184183
}, [preferences?.theme?.mode]);
185184

186185
useEffect(() => {
@@ -310,7 +309,11 @@ const AsgardeoClientProvider: FC<PropsWithChildren<AsgardeoClientProviderProps>>
310309
<AsgardeoContext.Provider value={contextValue}>
311310
<I18nProvider preferences={preferences?.i18n}>
312311
<BrandingProvider brandingPreference={brandingPreference}>
313-
<ThemeProvider theme={preferences?.theme?.overrides} mode={isDarkMode ? 'dark' : 'light'}>
312+
<ThemeProvider
313+
theme={preferences?.theme?.overrides}
314+
mode={getActiveTheme(preferences?.theme?.mode as any)}
315+
inheritFromBranding
316+
>
314317
<FlowProvider>
315318
<UserProvider profile={userProfile} onUpdateProfile={handleProfileUpdate} updateProfile={updateProfile}>
316319
<OrganizationProvider

packages/react/src/components/actions/SignInButton/SignInButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const SignInButton: ForwardRefExoticComponent<SignInButtonProps & RefAttributes<
9999
}
100100
} catch (error) {
101101
throw new AsgardeoRuntimeError(
102-
`Sign in failed: ${error instanceof Error ? error.message : String(error)}`,
102+
`Sign in failed: ${error instanceof Error ? error.message : String(JSON.stringify(error))}`,
103103
'SignInButton-handleSignIn-RuntimeError-001',
104104
'react',
105105
'Something went wrong while trying to sign in. Please try again later.',

packages/react/src/components/presentation/OrganizationSwitcher/BaseOrganizationSwitcher.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ export const BaseOrganizationSwitcher: FC<BaseOrganizationSwitcherProps> = ({
313313

314314
{isOpen && (
315315
<FloatingPortal id={portalId}>
316-
<FloatingFocusManager context={context} modal={false}>
316+
<FloatingFocusManager context={context} modal={false} initialFocus={-1}>
317317
<div ref={refs.setFloating} className={cx(styles.content)} style={floatingStyles} {...getFloatingProps()}>
318318
{/* Header - Current Organization */}
319319
{currentOrganization && (

packages/react/src/components/presentation/SignIn/options/EmailOtp.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ const EmailOtp: FC<BaseSignInOptionProps> = ({
9595
})}
9696

9797
<Button
98+
fullWidth
9899
type="submit"
100+
color="primary"
101+
variant="solid"
99102
disabled={isLoading}
100103
loading={isLoading}
101104
className={buttonClassName}
102-
color="primary"
103-
variant="solid"
104-
fullWidth
105105
style={{marginBottom: `calc(${theme.vars.spacing.unit} * 2)`}}
106106
>
107107
{t('email.otp.submit.button')}

packages/react/src/components/presentation/SignIn/options/IdentifierFirst.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ const IdentifierFirst: FC<BaseSignInOptionProps> = ({
7878
))}
7979

8080
<Button
81+
fullWidth
8182
type="submit"
83+
color="primary"
84+
variant="solid"
8285
disabled={isLoading}
8386
loading={isLoading}
8487
className={buttonClassName}
85-
color="primary"
86-
variant="solid"
87-
fullWidth
8888
style={{marginBottom: `calc(${theme.vars.spacing.unit} * 2)`}}
8989
>
9090
{t('identifier.first.submit.button')}

0 commit comments

Comments
 (0)