Skip to content

Commit

Permalink
feat(message): add some option property for meesage, it use for custo… (
Browse files Browse the repository at this point in the history
#2340)

* feat(message): add some option property for meesage, it use for custom message

* fix(rename): rename the enum value

---------

Co-authored-by: VicKun <minchengcheng@univer.ai>
  • Loading branch information
VicKun4937 and VicKun authored May 28, 2024
1 parent 5853999 commit bf2c021
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/design/src/components/message/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

/* eslint-disable react-refresh/only-export-components */

import { ErrorSingle, SuccessSingle, WarningSingle } from '@univerjs/icons';
import { ErrorSingle, Loading, SuccessSingle, WarningSingle } from '@univerjs/icons';
import { render } from 'rc-util/lib/React/render';
import type { CSSProperties, ReactElement } from 'react';
import React from 'react';
import { CSSTransition, TransitionGroup } from 'react-transition-group';
import type { IDisposable } from '../../type';
Expand All @@ -29,12 +30,15 @@ export enum MessageType {
Info = 'info',
Warning = 'warning',
Error = 'error',
Loading = 'loading',
}

export interface IMessageProps {
key: string;
type: MessageType;
content: string;
icon?: ReactElement;
style?: CSSProperties;
}

export interface IMessageOptions extends
Expand All @@ -48,15 +52,16 @@ const iconMap = {
[MessageType.Info]: <WarningSingle className={styles.messageIconInfo} />,
[MessageType.Warning]: <WarningSingle className={styles.messageIconWarning} />,
[MessageType.Error]: <ErrorSingle className={styles.messageIconError} />,
[MessageType.Loading]: <Loading className={styles.messageIconError} />,
};

const MessageItem = (props: IMessageProps) => {
const { type, content } = props;
const { type, content, icon, style } = props;

const messageElement = (
<div className={styles.messageItem}>
<div className={styles.messageItem} style={style}>
<div className={styles.messageContent}>
<span className={styles.messageIcon}>{iconMap[type]}</span>
<span className={styles.messageIcon}>{icon || iconMap[type]}</span>
<span>{content}</span>
</div>
</div>
Expand Down Expand Up @@ -141,4 +146,8 @@ export class Message {
error(options: IMessageOptions): IDisposable {
return this.append(MessageType.Error, options);
}

loading(options: IMessageOptions): IDisposable {
return this.append(MessageType.Loading, options);
}
}

0 comments on commit bf2c021

Please sign in to comment.