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

fix(react): type issue in Dialog with OverridableComponent #294

Merged
merged 5 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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: 6 additions & 3 deletions examples/multi-brand-identity/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@

import {AppBar, ColorModeToggle, Toolbar, ThemeProvider, IconButton, Theme, Tooltip} from '@oxygen-ui/react';
import {ReactElement, useReducer, useState} from 'react';
import {BrandingActions, brandingReducer, DefaultTheme} from './branding';
import {BrandSwitcher, BuildingIcon, OrganizationSelectionDialog} from './components';
import {LoginPage} from './pages';
import brandingReducer, {BrandingActions} from './branding/store/branding-reducer';
import DefaultTheme from './branding/themes/DefaultTheme';
import BrandSwitcher from './components/BrandSwitcher';
import BuildingIcon from './components/icons/BuildingIcon';
import OrganizationSelectionDialog from './components/OrganizationSelectionDialog';
import LoginPage from './pages/LoginPage';

const App = (): ReactElement => {
const [theme, dispatch] = useReducer(brandingReducer, DefaultTheme as never);
Expand Down
20 changes: 0 additions & 20 deletions examples/multi-brand-identity/src/branding/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
*/

import {Theme} from '@oxygen-ui/react';
import {AsgardeoTheme, BallerinaTheme, ChoreoTheme, DefaultTheme} from '../themes';
import AsgardeoTheme from '../themes/AsgardeoTheme';
import BallerinaTheme from '../themes/BallerinaTheme';
import ChoreoTheme from '../themes/ChoreoTheme';
import DefaultTheme from '../themes/DefaultTheme';

export enum BrandingActions {
ChangeTheme = 'ChangeTheme',
}

export const brandingReducer = (theme: Theme, action: any): Theme => {
const brandingReducer = (theme: Theme, action: any): Theme => {
switch (action.type) {
case BrandingActions.ChangeTheme: {
if (action.brand === 'WSO2') {
Expand All @@ -50,3 +53,5 @@ export const brandingReducer = (theme: Theme, action: any): Theme => {
}
}
};

export default brandingReducer;
19 changes: 0 additions & 19 deletions examples/multi-brand-identity/src/branding/store/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import tokens from '@oxygen-ui/primitives/dist/design-tokens/web/asgardeo/es/tokens';
import {extendTheme, Theme} from '@oxygen-ui/react';

export const AsgardeoTheme: Theme = extendTheme({
const AsgardeoTheme: Theme = extendTheme({
colorSchemes: {
dark: {
brand: {
Expand Down Expand Up @@ -256,3 +256,5 @@ export const AsgardeoTheme: Theme = extendTheme({
},
},
});

export default AsgardeoTheme;
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import {extendTheme, Theme} from '@oxygen-ui/react';

export const BallerinaTheme: Theme = extendTheme({
const BallerinaTheme: Theme = extendTheme({
colorSchemes: {
dark: {
brand: {
Expand Down Expand Up @@ -144,3 +144,5 @@ export const BallerinaTheme: Theme = extendTheme({
},
},
});

export default BallerinaTheme;
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import tokens from '@oxygen-ui/primitives/dist/design-tokens/web/choreo/es/tokens';
import {extendTheme, Theme} from '@oxygen-ui/react';

export const ChoreoTheme: Theme = extendTheme({
const ChoreoTheme: Theme = extendTheme({
components: {
MuiTooltip: {
styleOverrides: {
Expand Down Expand Up @@ -414,3 +414,5 @@ export const ChoreoTheme: Theme = extendTheme({
},
},
});

export default ChoreoTheme;
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import darkTokens from '@oxygen-ui/primitives/dist/design-tokens/web/oxygen/es/d
import lightTokens from '@oxygen-ui/primitives/dist/design-tokens/web/oxygen/es/tokens';
import {extendTheme, Theme} from '@oxygen-ui/react';

export const DefaultTheme: Theme = extendTheme({
const DefaultTheme: Theme = extendTheme({
colorSchemes: {
dark: {
brand: {
Expand Down Expand Up @@ -136,3 +136,5 @@ export const DefaultTheme: Theme = extendTheme({
].join(','),
},
});

export default DefaultTheme;
22 changes: 0 additions & 22 deletions examples/multi-brand-identity/src/branding/themes/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
* under the License.
*/

import {ToggleButtonGroup, ToggleButton, Paper, Tooltip} from '@oxygen-ui/react';
import {ToggleButtonGroup, ToggleButton} from '@oxygen-ui/react';
import Paper from '@oxygen-ui/react/Paper';
import Tooltip from '@oxygen-ui/react/Tooltip';
import {useState, MouseEvent, ReactElement} from 'react';

interface Brand {
Expand Down Expand Up @@ -62,7 +64,7 @@ export interface BrandSwitcherProps {
onBrandChange?: (brand: string) => void;
}

export const BrandSwitcher = (props: BrandSwitcherProps): ReactElement => {
const BrandSwitcher = (props: BrandSwitcherProps): ReactElement => {
const {onBrandChange} = props;

const [activeBrand, setActiveBrand] = useState<string>(BRANDS[0].name);
Expand Down Expand Up @@ -103,3 +105,5 @@ export const BrandSwitcher = (props: BrandSwitcherProps): ReactElement => {
</Paper>
);
};

export default BrandSwitcher;
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,25 @@
* under the License.
*/

import {
Button,
Dialog,
DialogTitle,
DialogContent,
DialogContentText,
DialogActions,
TextField,
extendTheme,
Theme,
Alert,
} from '@oxygen-ui/react';
import {extendTheme, Theme} from '@oxygen-ui/react';
import Alert from '@oxygen-ui/react/Alert';
import Button from '@oxygen-ui/react/Button';
import Dialog from '@oxygen-ui/react/Dialog';
import DialogActions from '@oxygen-ui/react/DialogActions';
import DialogContent from '@oxygen-ui/react/DialogContent';
import DialogContentText from '@oxygen-ui/react/DialogContentText';
import DialogTitle from '@oxygen-ui/react/DialogTitle';
import TextField from '@oxygen-ui/react/TextField';
import {ChangeEvent, FC, ReactElement, useState} from 'react';
import {BrandingActions} from '../branding';
import {BrandingActions} from '../branding/store/branding-reducer';

interface OrganizationSelectionDialogProps {
export interface OrganizationSelectionDialogProps {
onClose: () => void;
onOrganizationConnect: (action: {brand: string | undefined; theme: Theme; type: BrandingActions}) => void;
open: boolean;
}

export const OrganizationSelectionDialog: FC<OrganizationSelectionDialogProps> = (
const OrganizationSelectionDialog: FC<OrganizationSelectionDialogProps> = (
props: OrganizationSelectionDialogProps,
): ReactElement => {
const {open, onClose, onOrganizationConnect} = props;
Expand Down Expand Up @@ -167,3 +164,5 @@ export const OrganizationSelectionDialog: FC<OrganizationSelectionDialogProps> =
</Dialog>
);
};

export default OrganizationSelectionDialog;
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import {Theme, useColorScheme} from '@oxygen-ui/react';
import {ReactElement} from 'react';

export const BuildingIcon = ({theme}: {theme: Theme}): ReactElement => {
const BuildingIcon = ({theme}: {theme: Theme}): ReactElement => {
const {mode} = useColorScheme();

return (
Expand All @@ -37,3 +37,5 @@ export const BuildingIcon = ({theme}: {theme: Theme}): ReactElement => {
</svg>
);
};

export default BuildingIcon;
19 changes: 0 additions & 19 deletions examples/multi-brand-identity/src/components/icons/index.ts

This file was deleted.

21 changes: 0 additions & 21 deletions examples/multi-brand-identity/src/components/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
* under the License.
*/

import {Grid, SignIn, useTheme, useColorScheme, Theme} from '@oxygen-ui/react';
import {useTheme, useColorScheme, Theme} from '@oxygen-ui/react';
import Grid from '@oxygen-ui/react/Grid';
import SignIn from '@oxygen-ui/react/SignIn';
import {ReactElement} from 'react';

export const LoginPage = (): ReactElement => {
const LoginPage = (): ReactElement => {
const theme: Theme = useTheme();
const {mode} = useColorScheme();

Expand All @@ -43,3 +45,5 @@ export const LoginPage = (): ReactElement => {
</Grid>
);
};

export default LoginPage;
19 changes: 0 additions & 19 deletions examples/multi-brand-identity/src/pages/index.ts

This file was deleted.

10 changes: 4 additions & 6 deletions packages/react/src/components/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@

import MuiDialog from '@mui/material/Dialog';
import type {DialogProps as MuiDialogProps} from '@mui/material/Dialog';
import type {ModalTypeMap} from '@mui/material/Modal';
import {OverridableComponent} from '@mui/material/OverridableComponent';
import clsx from 'clsx';
import {forwardRef} from 'react';
import {forwardRef, ForwardRefExoticComponent} from 'react';
import type {ElementType, ReactElement, Ref} from 'react';

export type DialogProps<C extends ElementType = ElementType> = {
Expand All @@ -46,19 +44,19 @@ export type DialogProps<C extends ElementType = ElementType> = {
*
* @remarks
* - ✔️ Props of the [Modal](https://mui.com/material-ui/api/modal/) component are also available.
* - `component` prop is supported.
* - FIXME: ⚠️ `component` prop is temporarily not supported due to https://github.com/wso2/oxygen-ui/issues/283
* - ✅ The `ref` is forwarded to the root element.
*
* @template C - The type of the component.
* @param props - The props for the Dialog component.
* @param ref - The ref to be forwarded to the MuiDialog component.
* @returns The rendered Dialog component.
*/
const Dialog: OverridableComponent<ModalTypeMap<ModalTypeMap['defaultComponent'], DialogProps>> = forwardRef(
const Dialog: ForwardRefExoticComponent<DialogProps> = forwardRef(
<C extends ElementType = ElementType>(
{className, ...rest}: DialogProps<C>,
ref: Ref<HTMLDivElement>,
): ReactElement => <MuiDialog ref={ref} className={clsx('OxygenDialog-root')} {...rest} />,
) as OverridableComponent<ModalTypeMap<ModalTypeMap['defaultComponent'], DialogProps>>;
) as ForwardRefExoticComponent<DialogProps>;

export default Dialog;
Loading
Loading