fix: 消息组件的若干问题
This commit is contained in:
@@ -1,65 +1,81 @@
|
|||||||
export default function Message({ direction = 'left', children }) {
|
import Avatar from "../Avatar.js"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 一条消息
|
||||||
|
* @param { Object } param
|
||||||
|
* @param { "left" | "right" } [param.direction="left"] 消息方向
|
||||||
|
* @param { String } [param.avatar] 头像链接
|
||||||
|
* @param { String } [param.nickname] 昵称
|
||||||
|
* @returns { React.JSX.Element }
|
||||||
|
*/
|
||||||
|
export default function Message({ direction = 'left', avatar, nickname, children, ...props } = {}) {
|
||||||
|
let isAtRight = direction == 'right'
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
slot="trigger"
|
slot="trigger"
|
||||||
style={{
|
style={{
|
||||||
width: "100%",
|
width: "100%",
|
||||||
display: "flex",
|
display: "flex",
|
||||||
justifyContent: "flex-start",
|
justifyContent: isAtRight ? "flex-end" : "flex-start",
|
||||||
flexDirection: "column"
|
flexDirection: "column"
|
||||||
}}>
|
}}
|
||||||
|
{...props}>
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
justifyContent: "flex-start"
|
justifyContent: isAtRight ? "flex-end" : "flex-start",
|
||||||
}}>
|
}}>
|
||||||
{
|
{
|
||||||
// 发送者昵称(左)
|
// 发送者昵称(左)
|
||||||
direction == 'left' && <span
|
isAtRight && <span
|
||||||
style={{
|
|
||||||
alignSelf: "center",
|
|
||||||
fontSize: "90%"
|
|
||||||
}}></span>
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// 发送者头像
|
|
||||||
}
|
|
||||||
<mdui-avatar
|
|
||||||
style={{
|
|
||||||
width: "43px",
|
|
||||||
height: "43px",
|
|
||||||
margin: "11px"
|
|
||||||
}}>
|
|
||||||
</mdui-avatar>
|
|
||||||
{
|
|
||||||
// 发送者昵称(右)
|
|
||||||
direction == 'right' && <span
|
|
||||||
style={{
|
style={{
|
||||||
alignSelf: "center",
|
alignSelf: "center",
|
||||||
fontSize: "90%"
|
fontSize: "90%"
|
||||||
}}>
|
}}>
|
||||||
|
{nickname}
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// 发送者头像
|
||||||
|
}
|
||||||
|
<Avatar
|
||||||
|
src={avatar}
|
||||||
|
text={nickname}
|
||||||
|
style={{
|
||||||
|
width: "43px",
|
||||||
|
height: "43px",
|
||||||
|
margin: "11px"
|
||||||
|
}} />
|
||||||
|
{
|
||||||
|
// 发送者昵称(右)
|
||||||
|
!isAtRight && <span
|
||||||
|
style={{
|
||||||
|
alignSelf: "center",
|
||||||
|
fontSize: "90%"
|
||||||
|
}}>
|
||||||
|
{nickname}
|
||||||
</span>
|
</span>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
<mdui-card
|
<mdui-card
|
||||||
variant="elevated"
|
variant="elevated"
|
||||||
style={{
|
style={{
|
||||||
maxWidth: (window.matchMedia('(pointer: fine)') && "50%") || (window.matchMedia('(pointer: coarse)') && "77%"),
|
maxWidth: 'var(--whitesilk-widget-message-maxwidth)', // (window.matchMedia('(pointer: fine)') && "50%") || (window.matchMedia('(pointer: coarse)') && "77%"),
|
||||||
minWidth: "0%",
|
minWidth: "0%",
|
||||||
marginLeft: "55px",
|
[isAtRight ? "marginRight" : "marginLeft"]: "55px",
|
||||||
marginTop: "-5px",
|
marginTop: "-5px",
|
||||||
padding: "15px",
|
padding: "15px",
|
||||||
alignSelf: "flex-start"
|
alignSelf: isAtRight ? "flex-end" : "flex-start",
|
||||||
}}>
|
}}>
|
||||||
{
|
|
||||||
// 消息内容
|
|
||||||
children
|
|
||||||
}
|
|
||||||
<span
|
<span
|
||||||
id="msg"
|
id="msg"
|
||||||
style={{
|
style={{
|
||||||
fontSize: "94%"
|
fontSize: "94%"
|
||||||
}}>
|
}}>
|
||||||
|
{
|
||||||
|
// 消息内容
|
||||||
|
children
|
||||||
|
}
|
||||||
</span>
|
</span>
|
||||||
</mdui-card>
|
</mdui-card>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user