Skip to content

Commit

Permalink
chore: optimized code
Browse files Browse the repository at this point in the history
  • Loading branch information
bk1012 committed Oct 31, 2024
1 parent 61cefb0 commit 6a437a7
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions packages/components/src/dialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ export interface IDialogProps extends IOverlayProps {
keyboard?: boolean;
}

export interface IDialogContentProps extends IOverlayProps {
primaryText: string | React.ReactNode;
secondaryText?: string | React.ReactNode;
closable?: boolean;
messageType?: MessageType;
buttons?: JSX.Element[] | JSX.Element;
type?: ModalType;
icon?: IconDesc;
onOk?: () => void;
onCancel?: () => void;
okText?: string;
cancelText?: string;
}

const DefaultButtons = ({ onCancel, onOk, cancelText, okText }) => (
<>
<Button onClick={onCancel} type='secondary'>
Expand All @@ -44,15 +58,15 @@ const DefaultButtons = ({ onCancel, onOk, cancelText, okText }) => (
</>
);

export const DialogContent: React.FC<IDialogProps> = ({
export const DialogContent: React.FC<IDialogContentProps> = ({
primaryText,
secondaryText,
onClose,
closable,
messageType = MessageType.Info,
icon,
message,
buttons,
type = 'confirm',
title,
onOk,
onCancel,
okText,
Expand All @@ -70,8 +84,8 @@ export const DialogContent: React.FC<IDialogProps> = ({
/>
)}
<div className={'kt-dialog-content_area'}>
<p className={'kt-dialog-content_title'}>{title}</p>
{message && <span className={'kt-dialog-message'}>{message}</span>}
<p className={'kt-dialog-content_title'}>{primaryText}</p>
{secondaryText && <span className={'kt-dialog-message'}>{secondaryText}</span>}
</div>
{closable && type !== 'basic' && (
<button className={cls('kt-dialog-closex', getIcon('close'))} onClick={onClose}></button>
Expand Down Expand Up @@ -125,6 +139,13 @@ export const Dialog: React.FC<IDialogProps> = ({
afterClose={afterClose}
{...restProps}
>
<DialogContent title={message} message={detail} buttons={buttons} visible={visible} icon={icon} {...restProps} />
<DialogContent
primaryText={message}
secondaryText={detail}
buttons={buttons}
visible={visible}
icon={icon}
{...restProps}
/>
</Overlay>
);

0 comments on commit 6a437a7

Please sign in to comment.