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

[AlertDialog] Move types to namespaces #591

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function UnstyledDialogIntroduction() {
);
}

function TriggerButton(props: AlertDialog.TriggerProps) {
function TriggerButton(props: AlertDialog.Trigger.Props) {
const className = `
bg-slate-900 dark:bg-slate-50 text-slate-50 dark:text-slate-900
py-2 px-4 rounded min-w-[80px] border-none font-sans
Expand All @@ -29,7 +29,7 @@ function TriggerButton(props: AlertDialog.TriggerProps) {
return <AlertDialog.Trigger {...props} className={className} />;
}

function Popup(props: AlertDialog.PopupProps) {
function Popup(props: AlertDialog.Popup.Props) {
const className = `
bg-slate-50 dark:bg-slate-900 border-[1px] border-solid border-slate-100 dark:border-slate-700
min-w-[400px] rounded shadow-xl fixed top-2/4 left-2/4 z-[2100]
Expand All @@ -47,7 +47,7 @@ function Controls(props: React.ComponentPropsWithoutRef<'div'>) {
);
}

function CloseButton(props: AlertDialog.CloseProps) {
function CloseButton(props: AlertDialog.Close.Props) {
const className = `
bg-transparent border-[1px] border-solid border-slate-500 dark:border-slate-300
text-slate-900 dark:text-slate-50 py-2 px-4 rounded font-sans min-w-[80px]
Expand All @@ -56,15 +56,15 @@ function CloseButton(props: AlertDialog.CloseProps) {
return <AlertDialog.Close {...props} className={className} />;
}

function Title(props: AlertDialog.TitleProps) {
function Title(props: AlertDialog.Title.Props) {
return <AlertDialog.Title {...props} className="text-lg" />;
}

function Description(props: AlertDialog.DescriptionProps) {
function Description(props: AlertDialog.Description.Props) {
return <AlertDialog.Description {...props} />;
}

function Backdrop(props: AlertDialog.BackdropProps) {
function Backdrop(props: AlertDialog.Backdrop.Props) {
return (
<AlertDialog.Backdrop
{...props}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { FloatingPortal } from '@floating-ui/react';
import type {
AlertDialogBackdropOwnerState,
AlertDialogBackdropProps,
} from './AlertDialogBackdrop.types';
import { useAlertDialogRootContext } from '../Root/AlertDialogRootContext';
import { useDialogBackdrop } from '../../Dialog/Backdrop/useDialogBackdrop';
import { useComponentRenderer } from '../../utils/useComponentRenderer';
import type { TransitionStatus } from '../../utils/useTransitionStatus';
import type { BaseUIComponentProps } from '../../utils/types';

/**
*
Expand All @@ -20,7 +18,7 @@ import { useComponentRenderer } from '../../utils/useComponentRenderer';
* - [AlertDialogBackdrop API](https://base-ui.netlify.app/components/react-alert-dialog/#api-reference-AlertDialogBackdrop)
*/
const AlertDialogBackdrop = React.forwardRef(function AlertDialogBackdrop(
props: AlertDialogBackdropProps,
props: AlertDialogBackdrop.Props,
forwardedRef: React.ForwardedRef<HTMLDivElement>,
) {
const { render, className, keepMounted = false, ...other } = props;
Expand All @@ -37,7 +35,7 @@ const AlertDialogBackdrop = React.forwardRef(function AlertDialogBackdrop(
onUnmount: handleUnmount,
});

const ownerState: AlertDialogBackdropOwnerState = { open, transitionStatus };
const ownerState: AlertDialogBackdrop.OwnerState = { open, transitionStatus };

const { renderElement } = useComponentRenderer({
render: render ?? 'div',
Expand Down Expand Up @@ -71,6 +69,22 @@ const AlertDialogBackdrop = React.forwardRef(function AlertDialogBackdrop(
return <FloatingPortal>{renderElement()}</FloatingPortal>;
});

namespace AlertDialogBackdrop {
export interface Props extends BaseUIComponentProps<'div', OwnerState> {
/**
* If `true`, the backdrop element is kept in the DOM when closed.
*
* @default false
*/
keepMounted?: boolean;
}

export interface OwnerState {
open: boolean;
transitionStatus: TransitionStatus;
}
}

AlertDialogBackdrop.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
Expand Down

This file was deleted.

14 changes: 11 additions & 3 deletions packages/mui-base/src/AlertDialog/Close/AlertDialogClose.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { AlertDialogCloseOwnerState, AlertDialogCloseProps } from './AlertDialogClose.types';
import { useAlertDialogRootContext } from '../Root/AlertDialogRootContext';
import { useDialogClose } from '../../Dialog/Close/useDialogClose';
import { useComponentRenderer } from '../../utils/useComponentRenderer';
import type { BaseUIComponentProps } from '../../utils/types';

/**
*
Expand All @@ -16,14 +16,14 @@ import { useComponentRenderer } from '../../utils/useComponentRenderer';
* - [AlertDialogClose API](https://base-ui.netlify.app/components/react-alert-dialog/#api-reference-AlertDialogClose)
*/
const AlertDialogClose = React.forwardRef(function AlertDialogClose(
props: AlertDialogCloseProps,
props: AlertDialogClose.Props,
forwardedRef: React.ForwardedRef<HTMLButtonElement>,
) {
const { render, className, ...other } = props;
const { open, onOpenChange } = useAlertDialogRootContext();
const { getRootProps } = useDialogClose({ open, onOpenChange });

const ownerState: AlertDialogCloseOwnerState = {
const ownerState: AlertDialogClose.OwnerState = {
open,
};

Expand All @@ -39,6 +39,14 @@ const AlertDialogClose = React.forwardRef(function AlertDialogClose(
return renderElement();
});

namespace AlertDialogClose {
export interface Props extends BaseUIComponentProps<'button', OwnerState> {}

export interface OwnerState {
open: boolean;
}
}

AlertDialogClose.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import type {
AlertDialogDescriptionOwnerState,
AlertDialogDescriptionProps,
} from './AlertDialogDescription.types';
import { useAlertDialogRootContext } from '../Root/AlertDialogRootContext';
import { useComponentRenderer } from '../../utils/useComponentRenderer';
import { useEnhancedEffect } from '../../utils/useEnhancedEffect';
import { useId } from '../../utils/useId';
import type { BaseUIComponentProps } from '../../utils/types';

/**
*
Expand All @@ -20,13 +17,13 @@ import { useId } from '../../utils/useId';
* - [AlertDialogDescription API](https://base-ui.netlify.app/components/react-alert-dialog/#api-reference-AlertDialogDescription)
*/
const AlertDialogDescription = React.forwardRef(function AlertDialogDescription(
props: AlertDialogDescriptionProps,
props: AlertDialogDescription.Props,
forwardedRef: React.ForwardedRef<HTMLParagraphElement>,
) {
const { render, className, id: idProp, ...other } = props;
const { setDescriptionElementId, open } = useAlertDialogRootContext();

const ownerState: AlertDialogDescriptionOwnerState = {
const ownerState: AlertDialogDescription.OwnerState = {
open,
};

Expand All @@ -50,6 +47,14 @@ const AlertDialogDescription = React.forwardRef(function AlertDialogDescription(
return renderElement();
});

namespace AlertDialogDescription {
export interface Props extends BaseUIComponentProps<'p', OwnerState> {}

export interface OwnerState {
open: boolean;
}
}

AlertDialogDescription.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
Expand Down

This file was deleted.

28 changes: 25 additions & 3 deletions packages/mui-base/src/AlertDialog/Popup/AlertDialogPopup.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { FloatingFocusManager, FloatingPortal } from '@floating-ui/react';
import { AlertDialogPopupOwnerState, AlertDialogPopupProps } from './AlertDialogPopup.types';
import { useDialogPopup } from '../../Dialog/Popup/useDialogPopup';
import { useAlertDialogRootContext } from '../Root/AlertDialogRootContext';
import { useComponentRenderer } from '../../utils/useComponentRenderer';
import { refType, HTMLElementType } from '../../utils/proptypes';
import type { BaseUIComponentProps } from '../../utils/types';
import type { TransitionStatus } from '../../utils/useTransitionStatus';

/**
*
Expand All @@ -18,7 +19,7 @@ import { refType, HTMLElementType } from '../../utils/proptypes';
* - [AlertDialogPopup API](https://base-ui.netlify.app/components/react-alert-dialog/#api-reference-AlertDialogPopup)
*/
const AlertDialogPopup = React.forwardRef(function AlertDialogPopup(
props: AlertDialogPopupProps,
props: AlertDialogPopup.Props,
forwardedRef: React.ForwardedRef<HTMLDivElement>,
) {
const { className, container, id, keepMounted = false, render, ...other } = props;
Expand All @@ -34,7 +35,7 @@ const AlertDialogPopup = React.forwardRef(function AlertDialogPopup(
...rootContext,
});

const ownerState: AlertDialogPopupOwnerState = {
const ownerState: AlertDialogPopup.OwnerState = {
open,
nestedOpenDialogCount,
transitionStatus,
Expand Down Expand Up @@ -78,6 +79,27 @@ const AlertDialogPopup = React.forwardRef(function AlertDialogPopup(
);
});

namespace AlertDialogPopup {
export interface Props extends BaseUIComponentProps<'div', OwnerState> {
/**
* The container element to which the popup is appended to.
*/
container?: HTMLElement | null | React.MutableRefObject<HTMLElement | null>;
/**
* If `true`, the dialog element is kept in the DOM when closed.
*
* @default false
*/
keepMounted?: boolean;
}

export interface OwnerState {
open: boolean;
nestedOpenDialogCount: number;
transitionStatus: TransitionStatus;
}
}

AlertDialogPopup.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
Expand Down

This file was deleted.

8 changes: 6 additions & 2 deletions packages/mui-base/src/AlertDialog/Root/AlertDialogRoot.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { AlertDialogRootProps } from './AlertDialogRoot.types';
import type { DialogRootProps } from '../../Dialog/Root/DialogRoot.types';
import { AlertDialogRootContext } from './AlertDialogRootContext';
import { useDialogRoot } from '../../Dialog/Root/useDialogRoot';

Expand All @@ -14,7 +14,7 @@ import { useDialogRoot } from '../../Dialog/Root/useDialogRoot';
*
* - [AlertDialogRoot API](https://base-ui.netlify.app/components/react-alert-dialog/#api-reference-AlertDialogRoot)
*/
function AlertDialogRoot(props: AlertDialogRootProps) {
function AlertDialogRoot(props: AlertDialogRoot.Props) {
const { children, defaultOpen, onOpenChange, open: openProp, animated = true } = props;

const dialogRootContext = React.useContext(AlertDialogRootContext);
Expand Down Expand Up @@ -42,6 +42,10 @@ function AlertDialogRoot(props: AlertDialogRootProps) {
);
}

namespace AlertDialogRoot {
export type Props = Omit<DialogRootProps, 'modal' | 'dismissible'>;
}

AlertDialogRoot.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
Expand Down
15 changes: 0 additions & 15 deletions packages/mui-base/src/AlertDialog/Root/AlertDialogRoot.types.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import { UseDialogRootReturnValue } from '@base_ui/react/Dialog';
import * as React from 'react';
import type { AlertDialogRootContextValue } from './AlertDialogRoot.types';

export const AlertDialogRootContext = React.createContext<AlertDialogRootContextValue | undefined>(
export interface AlertDialogRootContext extends UseDialogRootReturnValue {
/**
* If `true`, the dialog supports CSS-based animations and transitions.
* It is kept in the DOM until the animation completes.
*/
animated: boolean;
/**
* Determines if the dialog is nested within a parent dialog.
*/
hasParentDialog: boolean;
}

export const AlertDialogRootContext = React.createContext<AlertDialogRootContext | undefined>(
undefined,
);

Expand Down
Loading
Loading