@asgardeo/react
Version:
React implementation of Asgardeo JavaScript SDK.
71 lines (70 loc) • 2.59 kB
TypeScript
/**
* Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you 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.
*/
import { FC, ReactElement } from 'react';
import { BaseOrganizationSwitcherProps, Organization } from './BaseOrganizationSwitcher';
/**
* Props interface for the OrganizationSwitcher component.
* Makes organizations optional since they'll be retrieved from OrganizationContext.
*/
export interface OrganizationSwitcherProps extends Omit<BaseOrganizationSwitcherProps, 'organizations' | 'currentOrganization' | 'onOrganizationSwitch'> {
/**
* Optional override for current organization (will use context if not provided)
*/
currentOrganization?: Organization;
/**
* Fallback element to render when the user is not signed in.
*/
fallback?: ReactElement;
/**
* Optional callback for organization switch (will use context if not provided)
*/
onOrganizationSwitch?: (organization: Organization) => Promise<void> | void;
/**
* Optional override for organizations list (will use context if not provided)
*/
organizations?: Organization[];
}
/**
* OrganizationSwitcher component that provides organization switching functionality.
* This component automatically retrieves organizations from the OrganizationContext.
* You can also override the organizations, currentOrganization, and onOrganizationSwitch
* by passing them as props.
*
* @example
* ```tsx
* import { OrganizationSwitcher } from '@asgardeo/react';
*
* // Basic usage - uses OrganizationContext
* <OrganizationSwitcher />
*
* // With custom organization switch handler
* <OrganizationSwitcher
* onOrganizationSwitch={(org) => {
* console.log('Switching to:', org.name);
* // Custom logic here
* }}
* />
*
* // With fallback for unauthenticated users
* <OrganizationSwitcher
* fallback={<div>Please sign in to view organizations</div>}
* />
* ```
*/
export declare const OrganizationSwitcher: FC<OrganizationSwitcherProps>;
export default OrganizationSwitcher;