-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added new message content types
Message.HtmlContent Message.TextContent Message.ImageContent Message.CustomContent
- Loading branch information
1 parent
c70e3f4
commit 32439f7
Showing
6 changed files
with
264 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import classNames from "classnames"; | ||
import { prefix } from "../settings"; | ||
|
||
export const MessageCustomContent = ({ children, className }) => { | ||
const cName = `${prefix}-message__custom-content`; | ||
|
||
return <div className={classNames(cName, className)}>{children}</div>; | ||
}; | ||
|
||
MessageCustomContent.displayName = "Message.CustomContent"; | ||
|
||
MessageCustomContent.propTypes = { | ||
/** Primary content. */ | ||
children: PropTypes.node, | ||
|
||
/** Additional classes. */ | ||
className: PropTypes.string, | ||
}; | ||
|
||
MessageCustomContent.defaultProps = {}; | ||
|
||
export default MessageCustomContent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import classNames from "classnames"; | ||
import { prefix } from "../settings"; | ||
|
||
export const MessageHtmlContent = ({ html, className }) => { | ||
const cName = `${prefix}-message__html-content`; | ||
|
||
const createMarkup = () => ({ __html: html }); | ||
|
||
return ( | ||
<div | ||
className={classNames(cName, className)} | ||
dangerouslySetInnerHTML={createMarkup()} | ||
/> | ||
); | ||
}; | ||
|
||
MessageHtmlContent.displayName = "Message.HtmlContent"; | ||
|
||
MessageHtmlContent.propTypes = { | ||
/** | ||
* Html string will be rendered in component using dangerouslySetInnerHTML | ||
*/ | ||
html: PropTypes.string, | ||
|
||
/** Additional classes. */ | ||
className: PropTypes.string, | ||
}; | ||
|
||
MessageHtmlContent.defaultProps = {}; | ||
|
||
export default MessageHtmlContent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import classNames from "classnames"; | ||
import { prefix } from "../settings"; | ||
|
||
export const MessageImageContent = ({ src, width, height, alt, className }) => { | ||
const cName = `${prefix}-message__image-content`; | ||
|
||
const style = { | ||
width: | ||
typeof width === "number" | ||
? `${width}px` | ||
: typeof width === "string" | ||
? width | ||
: undefined, | ||
height: | ||
typeof height === "number" | ||
? `${height}px` | ||
: typeof height === "string" | ||
? height | ||
: undefined, | ||
}; | ||
|
||
return ( | ||
<div className={classNames(cName, className)}> | ||
<img src={src} style={style} alt={alt} /> | ||
</div> | ||
); | ||
}; | ||
|
||
MessageImageContent.displayName = "Message.ImageContent"; | ||
|
||
MessageImageContent.propTypes = { | ||
/** Image source*/ | ||
src: PropTypes.string, | ||
|
||
/** Image width */ | ||
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
|
||
/** Image height */ | ||
height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
|
||
/** Alternate text for image */ | ||
alt: PropTypes.string, | ||
|
||
/** Additional classes. */ | ||
className: PropTypes.string, | ||
}; | ||
|
||
MessageImageContent.defaultProps = {}; | ||
|
||
export default MessageImageContent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import classNames from "classnames"; | ||
import { prefix } from "../settings"; | ||
|
||
export const MessageTextContent = ({ text, className, children }) => { | ||
const cName = `${prefix}-message__text-content`; | ||
|
||
const content = children ?? text; | ||
|
||
return <div className={classNames(cName, className)}>{content}</div>; | ||
}; | ||
|
||
MessageTextContent.displayName = "Message.TextContent"; | ||
|
||
MessageTextContent.propTypes = { | ||
/** Primary content - message text */ | ||
children: PropTypes.string, | ||
|
||
/** Message text. Property has precedence over children */ | ||
text: PropTypes.string, | ||
|
||
/** Additional classes. */ | ||
className: PropTypes.string, | ||
}; | ||
|
||
MessageTextContent.defaultProps = {}; | ||
|
||
export default MessageTextContent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters