UNPKG

@nexusui/components

Version:

These are custom components specially-developed for NexusUI applications. They will make your life easier by giving you out-of-the-box implementations for various high-level UI elements that you can drop directly into your application.

2 lines (1 loc) 2.68 kB
import{jsx as e,jsxs as t,Fragment as o}from"react/jsx-runtime";import{useMemo as n,useRef as i,useState as a,useCallback as r,useEffect as s}from"react";import d from"@mui/material/Stack";import m from"@mui/material/Card";import l from"@mui/material/CardContent";import c from"clsx";import{styles as g,classes as p}from"./CommentCard.styles.js";import{useTranslate as h}from"../../locales/index.js";import C from"../locale.json.js";import{CommentCardHeader as u}from"./CommentCardHeader.js";import{CommentCardContent as f}from"./CommentCardContent.js";import{CommentFieldContainer as v}from"../CommentField/CommentField.container.js";const x=(e,t)=>{if(e.length<1)return[];const o=[];return e.forEach((e=>{o.find((t=>t.id===e.id))||e.id===t.id||o.push(e)})),o},j=j=>{const{id:S,author:k,participants:M=[],statusMapping:w,dateModified:y,stackDate:E=!0,message:R,attachments:T=[],tags:b=[],metadata:H,tagging:L=!1,onTagCancel:I,highlight:P,maxLines:A=3,replies:D=0,actions:F=[],disableHover:N,selected:U,unread:q,resolved:z,canResolve:B,onResolved:G=()=>{},onUnresolved:J=()=>{},onLayoutChange:K,onSelected:O,editing:Q,onEditCancel:V,onEditSave:W,mode:X="plaintext",richTextConfig:Y,sx:Z={},...$}=j,_=F.length>0,ee=E||N,te=n((()=>x(M,k)),[M,k]),oe=h(C),ne=i(null),[ie,ae]=a(!1),[re,se]=a(!1),[de,me]=a(!1),le=r((()=>{if(!ne.current)return;const e=ne.current?.scrollHeight||parseInt(window.getComputedStyle(ne.current).height,10),t=parseInt(window.getComputedStyle(ne.current).lineHeight,10);ae(e>t*A),se(!!U)}),[A,R,U]);s((()=>{le()}),[le]);const ce=Q?e(d,{direction:"row",sx:{alignItems:"center",mb:4},onClick:e=>{e.stopPropagation()},children:e(v,{author:k,richTextConfig:Y,initialComment:R,initialAttachments:T,initialTags:b,initialMetadata:H,onSave:W,onCancel:V,onCommentChange:()=>{K?.()},mode:X,state:"edit"})}):t(o,{children:[e(u,{id:S,author:k,unread:q,editing:Q,uniqueParticipants:te,statusMapping:w,shouldStackDate:ee,hovering:de,hasActions:_,canResolve:B,resolved:z,dateModified:y,disableHover:N,actions:F,onUnresolved:J,onResolved:G,t:oe}),e(f,{multiRowRef:ne,expanded:re,expandable:ie,onExpandClick:e=>{e.stopPropagation(),se((e=>!e)),K?.()},maxLines:A,message:R,attachments:T,tags:b,metadata:H,tagging:L,onTagCancel:I,highlight:P,selected:U,replies:D,mode:X,onEditSave:W,richTextConfig:Y,onLayoutChange:K,t:oe})]});return e(m,{"data-testid":"CommentCard",...$,sx:[g.card,Z],className:c({[p.active]:U,[p.clickable]:(O||_||B)&&!Q&&!N},"NexusCommentCard-root"),elevation:0,onClick:O&&!Q?e=>O(S,e):void 0,onMouseEnter:N?void 0:()=>me(!0),onMouseLeave:()=>me(!1),children:e(l,{sx:{px:6,py:4},children:ce})})};export{j as CommentCardComponent,x as getNonAuthorParticipants};