2022-10-24 20:33:40 -04:00
|
|
|
import { CSSProperties, FC, RefAttributes } from 'react';
|
|
|
|
|
|
|
|
|
|
import { CommonUIModule } from '../webpack';
|
2022-10-02 04:41:47 +03:00
|
|
|
import { FooterLegendProps } from './FooterLegend';
|
|
|
|
|
|
|
|
|
|
export interface DialogCommonProps extends RefAttributes<HTMLDivElement> {
|
|
|
|
|
style?: CSSProperties;
|
|
|
|
|
className?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface DialogButtonProps extends DialogCommonProps, FooterLegendProps {
|
|
|
|
|
noFocusRing?: boolean;
|
|
|
|
|
disabled?: boolean;
|
|
|
|
|
onClick?(e: MouseEvent): void;
|
|
|
|
|
onPointerDown?(e: PointerEvent): void;
|
|
|
|
|
onPointerUp?(e: PointerEvent): void;
|
|
|
|
|
onPointerCancel?(e: PointerEvent): void;
|
|
|
|
|
onMouseDown?(e: MouseEvent): void;
|
|
|
|
|
onMouseUp?(e: MouseEvent): void;
|
|
|
|
|
onTouchStart?(e: TouchEvent): void;
|
|
|
|
|
onTouchEnd?(e: TouchEvent): void;
|
|
|
|
|
onTouchCancel?(e: TouchEvent): void;
|
|
|
|
|
onSubmit?(e: SubmitEvent): void;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-24 20:33:40 -04:00
|
|
|
const CommonDialogDivs = Object.values(CommonUIModule).filter(
|
|
|
|
|
(m: any) => typeof m === 'object' && m?.render?.toString().includes('"div",Object.assign({},'),
|
|
|
|
|
);
|
|
|
|
|
const MappedDialogDivs = new Map(
|
|
|
|
|
Object.values(CommonDialogDivs).map((m: any) => {
|
|
|
|
|
const renderedDiv = m.render({});
|
|
|
|
|
// Take only the first class name segment as it identifies the element we want
|
|
|
|
|
return [renderedDiv.props.className.split(' ')[0], m];
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const DialogHeader = MappedDialogDivs.get('DialogHeader') as FC<DialogCommonProps>;
|
|
|
|
|
export const DialogSubHeader = MappedDialogDivs.get('DialogSubHeader') as FC<DialogCommonProps>;
|
|
|
|
|
export const DialogFooter = MappedDialogDivs.get('DialogFooter') as FC<DialogCommonProps>;
|
|
|
|
|
export const DialogLabel = MappedDialogDivs.get('DialogLabel') as FC<DialogCommonProps>;
|
|
|
|
|
export const DialogBodyText = MappedDialogDivs.get('DialogBodyText') as FC<DialogCommonProps>;
|
|
|
|
|
export const DialogBody = MappedDialogDivs.get('DialogBody') as FC<DialogCommonProps>;
|
|
|
|
|
export const DialogControlsSection = MappedDialogDivs.get('DialogControlsSection') as FC<DialogCommonProps>;
|
|
|
|
|
export const DialogControlsSectionHeader = MappedDialogDivs.get('DialogControlsSectionHeader') as FC<DialogCommonProps>;
|
2022-10-02 04:41:47 +03:00
|
|
|
|
|
|
|
|
export const DialogButtonPrimary = Object.values(CommonUIModule).find(
|
2022-10-24 20:33:40 -04:00
|
|
|
(mod: any) => mod?.render?.toString()?.includes('DialogButton') && mod?.render?.toString()?.includes('Primary'),
|
2022-10-02 04:41:47 +03:00
|
|
|
) as FC<DialogButtonProps>;
|
|
|
|
|
|
|
|
|
|
export const DialogButtonSecondary = Object.values(CommonUIModule).find(
|
|
|
|
|
(mod: any) =>
|
|
|
|
|
mod?.render?.toString()?.includes('Object.assign({type:"button"') &&
|
|
|
|
|
mod?.render?.toString()?.includes('DialogButton') &&
|
2022-10-24 20:33:40 -04:00
|
|
|
mod?.render?.toString()?.includes('Secondary'),
|
2022-10-02 04:41:47 +03:00
|
|
|
) as FC<DialogButtonProps>;
|
|
|
|
|
|
2022-10-24 20:33:40 -04:00
|
|
|
// This is the "main" button. The Primary can act as a submit button,
|
2022-10-02 04:41:47 +03:00
|
|
|
// therefore secondary is chosen (also for backwards comp. reasons)
|
|
|
|
|
export const DialogButton = DialogButtonSecondary;
|