@primer/react
Version:
An implementation of GitHub's Primer Design System using React
162 lines • 6.32 kB
TypeScript
import React from 'react';
import type { ButtonProps } from '../Button';
import type { ResponsiveValue } from '../hooks/useResponsiveValue';
import type { ForwardRefComponent as PolymorphicForwardRefComponent } from '../utils/polymorphic';
/**
* Props that characterize a button to be rendered into the footer of
* a Dialog.
*/
export type DialogButtonProps = Omit<ButtonProps, 'content'> & {
/**
* The variant of Button to use
*/
buttonType?: 'default' | 'primary' | 'danger' | 'normal';
/**
* The Button's inner text
*/
content: React.ReactNode;
/**
* If true, and if this is the only button with autoFocus set to true,
* focus this button automatically when the dialog appears.
*/
autoFocus?: boolean;
/**
* A reference to the rendered Button’s DOM node, used together with
* `autoFocus` for `focusTrap`’s `initialFocus`.
*/
ref?: React.RefObject<HTMLButtonElement | null>;
};
/**
* Props to customize the rendering of the Dialog.
*/
export interface DialogProps {
/**
* Title of the Dialog. Also serves as the aria-label for this Dialog.
*/
title?: React.ReactNode;
/**
* The Dialog's subtitle. Optional. Rendered below the title in smaller
* type with less contrast. Also serves as the aria-describedby for this
* Dialog.
*/
subtitle?: React.ReactNode;
/**
* Provide a custom renderer for the dialog header. This content is
* rendered directly into the dialog body area, full bleed from edge
* to edge, top to the start of the body element.
*
* Warning: using a custom renderer may violate Primer UX principles.
*/
renderHeader?: React.FunctionComponent<React.PropsWithChildren<DialogHeaderProps>>;
/**
* Provide a custom render function for the dialog body. This content is
* rendered directly into the dialog body area, full bleed from edge to
* edge, header to footer.
*
* Warning: using a custom renderer may violate Primer UX principles.
*/
renderBody?: React.FunctionComponent<React.PropsWithChildren<DialogProps>>;
/**
* Provide a custom render function for the dialog footer. This content is
* rendered directly into the dialog footer area, full bleed from edge to
* edge, end of the body element to bottom.
*
* Warning: using a custom renderer may violate Primer UX principles.
*/
renderFooter?: React.FunctionComponent<React.PropsWithChildren<DialogProps>>;
/**
* Specifies the buttons to be rendered in the Dialog footer.
*/
footerButtons?: DialogButtonProps[];
/**
* This method is invoked when a gesture to close the dialog is used (either
* an Escape key press, clicking the backdrop, or clicking the "X" in the top-right corner). The
* gesture argument indicates the gesture that was used to close the dialog
* ('close-button' or 'escape').
*/
onClose: (gesture: 'close-button' | 'escape') => void;
/**
* Default: "dialog". The ARIA role to assign to this dialog.
* @see https://www.w3.org/TR/wai-aria-practices-1.1/#dialog_modal
* @see https://www.w3.org/TR/wai-aria-practices-1.1/#alertdialog
*/
role?: 'dialog' | 'alertdialog';
/**
* The width of the dialog.
* small: 296px
* medium: 320px
* large: 480px
* xlarge: 640px
*/
width?: DialogWidth;
/**
* The height of the dialog.
* small: 296x480
* large: 480x640
* auto: variable based on contents
*/
height?: DialogHeight;
/**
* The position of the dialog
*/
position?: 'center' | 'left' | 'right' | ResponsiveValue<'left' | 'right' | 'bottom' | 'fullscreen' | 'center'>;
/**
* Return focus to this element when the Dialog closes,
* instead of the element that had focus immediately before the Dialog opened
*/
returnFocusRef?: React.RefObject<HTMLElement | null>;
/**
* The element to focus when the Dialog opens
*/
initialFocusRef?: React.RefObject<HTMLElement | null>;
/**
* Additional class names to apply to the dialog
*/
className?: string;
}
/**
* Props that are passed to a component that serves as a dialog header
*/
export interface DialogHeaderProps extends DialogProps {
/**
* ID of the element that will be used as the `aria-labelledby` attribute on the
* dialog. This ID should be set to the element that renders the dialog's title.
*/
dialogLabelId: string;
/**
* ID of the element that will be used as the `aria-describedby` attribute on the
* dialog. This ID should be set to the element that renders the dialog's subtitle.
*/
dialogDescriptionId: string;
}
declare const heightMap: {
readonly small: "480px";
readonly large: "640px";
readonly auto: "auto";
};
declare const widthMap: {
readonly small: "296px";
readonly medium: "320px";
readonly large: "480px";
readonly xlarge: "640px";
};
export type DialogWidth = keyof typeof widthMap;
export type DialogHeight = keyof typeof heightMap;
export declare const Dialog: React.ForwardRefExoticComponent<DialogProps & {
children?: React.ReactNode | undefined;
} & React.RefAttributes<HTMLDivElement>> & {
__SLOT__: symbol;
Header: PolymorphicForwardRefComponent<"div", React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>>;
Title: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>, "ref"> & React.RefAttributes<HTMLHeadingElement>>;
Subtitle: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>, "ref"> & React.RefAttributes<HTMLHeadingElement>>;
Body: PolymorphicForwardRefComponent<"div", React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>>;
Footer: PolymorphicForwardRefComponent<"div", React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>>;
Buttons: React.FC<React.PropsWithChildren<{
buttons: DialogButtonProps[];
}>>;
CloseButton: React.FC<React.PropsWithChildren<{
onClose: () => void;
}>>;
};
export {};
//# sourceMappingURL=Dialog.d.ts.map