@pega/cosmos-react-social 2.0.0-dev.9.2 → 2.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/Chat/Chat.d.ts +2 -2
- package/lib/components/Chat/Chat.d.ts.map +1 -1
- package/lib/components/Chat/Chat.js +6 -11
- package/lib/components/Chat/Chat.js.map +1 -1
- package/lib/components/Chat/ChatBody.js +2 -2
- package/lib/components/Chat/ChatBody.js.map +1 -1
- package/lib/components/Chat/ChatComposer.d.ts.map +1 -1
- package/lib/components/Chat/ChatComposer.js +20 -26
- package/lib/components/Chat/ChatComposer.js.map +1 -1
- package/lib/components/Chat/ChatHeader.d.ts +2 -2
- package/lib/components/Chat/ChatHeader.d.ts.map +1 -1
- package/lib/components/Chat/ChatHeader.js +4 -6
- package/lib/components/Chat/ChatHeader.js.map +1 -1
- package/lib/components/Chat/ChatTranscript.d.ts.map +1 -1
- package/lib/components/Chat/ChatTranscript.js +6 -7
- package/lib/components/Chat/ChatTranscript.js.map +1 -1
- package/lib/components/Chat/Message.d.ts.map +1 -1
- package/lib/components/Chat/Message.js +22 -30
- package/lib/components/Chat/Message.js.map +1 -1
- package/lib/components/Chat/Message.styles.js +2 -2
- package/lib/components/Chat/Message.styles.js.map +1 -1
- package/lib/components/Chat/MessageList.d.ts.map +1 -1
- package/lib/components/Chat/MessageList.js +11 -12
- package/lib/components/Chat/MessageList.js.map +1 -1
- package/lib/components/Chat/RepeatingView.js +6 -8
- package/lib/components/Chat/RepeatingView.js.map +1 -1
- package/lib/components/Chat/SuggestedReplyPicker.d.ts.map +1 -1
- package/lib/components/Chat/SuggestedReplyPicker.js +16 -16
- package/lib/components/Chat/SuggestedReplyPicker.js.map +1 -1
- package/lib/components/Chat/SystemMessage.js +2 -2
- package/lib/components/Chat/SystemMessage.js.map +1 -1
- package/lib/components/Chat/TranscriptMessage.js +3 -7
- package/lib/components/Chat/TranscriptMessage.js.map +1 -1
- package/lib/components/Chat/TypeIndicator.js +1 -1
- package/lib/components/Chat/TypeIndicator.js.map +1 -1
- package/lib/components/Email/Email.d.ts.map +1 -1
- package/lib/components/Email/Email.js +42 -80
- package/lib/components/Email/Email.js.map +1 -1
- package/lib/components/Email/Email.styles.d.ts +7 -2
- package/lib/components/Email/Email.styles.d.ts.map +1 -1
- package/lib/components/Email/Email.styles.js +75 -26
- package/lib/components/Email/Email.styles.js.map +1 -1
- package/lib/components/Email/Email.types.d.ts +144 -63
- package/lib/components/Email/Email.types.d.ts.map +1 -1
- package/lib/components/Email/Email.types.js.map +1 -1
- package/lib/components/Email/EmailComposer.d.ts +4 -6
- package/lib/components/Email/EmailComposer.d.ts.map +1 -1
- package/lib/components/Email/EmailComposer.js +174 -62
- package/lib/components/Email/EmailComposer.js.map +1 -1
- package/lib/components/Email/EmailConversation.d.ts +3 -1
- package/lib/components/Email/EmailConversation.d.ts.map +1 -1
- package/lib/components/Email/EmailConversation.js +88 -56
- package/lib/components/Email/EmailConversation.js.map +1 -1
- package/lib/components/Email/EmailEntity.d.ts +3 -7
- package/lib/components/Email/EmailEntity.d.ts.map +1 -1
- package/lib/components/Email/EmailEntity.js +11 -22
- package/lib/components/Email/EmailEntity.js.map +1 -1
- package/lib/components/Email/EmailSelector.d.ts +19 -0
- package/lib/components/Email/EmailSelector.d.ts.map +1 -0
- package/lib/components/Email/EmailSelector.js +103 -0
- package/lib/components/Email/EmailSelector.js.map +1 -0
- package/lib/components/Email/EmailShell.d.ts.map +1 -1
- package/lib/components/Email/EmailShell.js +18 -23
- package/lib/components/Email/EmailShell.js.map +1 -1
- package/lib/components/Email/EmailSummaryItem.d.ts +10 -0
- package/lib/components/Email/EmailSummaryItem.d.ts.map +1 -0
- package/lib/components/Email/EmailSummaryItem.js +93 -0
- package/lib/components/Email/EmailSummaryItem.js.map +1 -0
- package/lib/components/Email/EmailSummaryList.d.ts +6 -0
- package/lib/components/Email/EmailSummaryList.d.ts.map +1 -0
- package/lib/components/Email/EmailSummaryList.js +115 -0
- package/lib/components/Email/EmailSummaryList.js.map +1 -0
- package/lib/components/Email/ViewAnalysis.d.ts +6 -0
- package/lib/components/Email/ViewAnalysis.d.ts.map +1 -0
- package/lib/components/Email/ViewAnalysis.js +20 -0
- package/lib/components/Email/ViewAnalysis.js.map +1 -0
- package/lib/components/Feed/Feed.context.d.ts +12 -2
- package/lib/components/Feed/Feed.context.d.ts.map +1 -1
- package/lib/components/Feed/Feed.context.js +3 -1
- package/lib/components/Feed/Feed.context.js.map +1 -1
- package/lib/components/Feed/Feed.d.ts +12 -5
- package/lib/components/Feed/Feed.d.ts.map +1 -1
- package/lib/components/Feed/Feed.js +38 -17
- package/lib/components/Feed/Feed.js.map +1 -1
- package/lib/components/Feed/FeedAnnouncer.d.ts +7 -0
- package/lib/components/Feed/FeedAnnouncer.d.ts.map +1 -0
- package/lib/components/Feed/FeedAnnouncer.js +11 -0
- package/lib/components/Feed/FeedAnnouncer.js.map +1 -0
- package/lib/components/Feed/FeedAttachments.d.ts +3 -0
- package/lib/components/Feed/FeedAttachments.d.ts.map +1 -1
- package/lib/components/Feed/FeedAttachments.js +79 -14
- package/lib/components/Feed/FeedAttachments.js.map +1 -1
- package/lib/components/Feed/FeedButton.d.ts.map +1 -1
- package/lib/components/Feed/FeedButton.js.map +1 -1
- package/lib/components/Feed/FeedContent.d.ts.map +1 -1
- package/lib/components/Feed/FeedContent.js +10 -2
- package/lib/components/Feed/FeedContent.js.map +1 -1
- package/lib/components/Feed/FeedLikeButton.d.ts +19 -0
- package/lib/components/Feed/FeedLikeButton.d.ts.map +1 -0
- package/lib/components/Feed/FeedLikeButton.js +87 -0
- package/lib/components/Feed/FeedLikeButton.js.map +1 -0
- package/lib/components/Feed/FeedModalList.js +2 -4
- package/lib/components/Feed/FeedModalList.js.map +1 -1
- package/lib/components/Feed/FeedNewPost.d.ts.map +1 -1
- package/lib/components/Feed/FeedNewPost.js +33 -30
- package/lib/components/Feed/FeedNewPost.js.map +1 -1
- package/lib/components/Feed/FeedNewPostTypeMenu.d.ts +2 -1
- package/lib/components/Feed/FeedNewPostTypeMenu.d.ts.map +1 -1
- package/lib/components/Feed/FeedNewPostTypeMenu.js +27 -50
- package/lib/components/Feed/FeedNewPostTypeMenu.js.map +1 -1
- package/lib/components/Feed/FeedPost.d.ts +3 -100
- package/lib/components/Feed/FeedPost.d.ts.map +1 -1
- package/lib/components/Feed/FeedPost.js +56 -95
- package/lib/components/Feed/FeedPost.js.map +1 -1
- package/lib/components/Feed/FeedPost.types.d.ts +101 -0
- package/lib/components/Feed/FeedPost.types.d.ts.map +1 -0
- package/lib/components/Feed/FeedPost.types.js +2 -0
- package/lib/components/Feed/FeedPost.types.js.map +1 -0
- package/lib/components/Feed/FeedReply.d.ts +3 -67
- package/lib/components/Feed/FeedReply.d.ts.map +1 -1
- package/lib/components/Feed/FeedReply.js +24 -69
- package/lib/components/Feed/FeedReply.js.map +1 -1
- package/lib/components/Feed/FeedReply.types.d.ts +68 -0
- package/lib/components/Feed/FeedReply.types.d.ts.map +1 -0
- package/lib/components/Feed/FeedReply.types.js +2 -0
- package/lib/components/Feed/FeedReply.types.js.map +1 -0
- package/lib/components/Feed/FeedReplyInput.d.ts.map +1 -1
- package/lib/components/Feed/FeedReplyInput.js +24 -27
- package/lib/components/Feed/FeedReplyInput.js.map +1 -1
- package/lib/components/Feed/FeedRichText.d.ts.map +1 -1
- package/lib/components/Feed/FeedRichText.js +80 -19
- package/lib/components/Feed/FeedRichText.js.map +1 -1
- package/lib/components/HashtagButton/HashtagButton.d.ts +5 -3
- package/lib/components/HashtagButton/HashtagButton.d.ts.map +1 -1
- package/lib/components/HashtagButton/HashtagButton.js +22 -16
- package/lib/components/HashtagButton/HashtagButton.js.map +1 -1
- package/lib/components/MentionButton/MentionButton.d.ts +9 -3
- package/lib/components/MentionButton/MentionButton.d.ts.map +1 -1
- package/lib/components/MentionButton/MentionButton.js +33 -16
- package/lib/components/MentionButton/MentionButton.js.map +1 -1
- package/package.json +13 -14
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef } from 'react';
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useEffect, useContext } from 'react';
|
|
3
3
|
import styled, { css } from 'styled-components';
|
|
4
|
-
import { FileUploadItem, Grid, defaultThemeProp } from '@pega/cosmos-react-core';
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import { FileUploadItem, Grid, Image, defaultThemeProp, getKindFromMimeType, getMimeTypeFromFile, Flex, StyledFlex, usePrevious, useI18n } from '@pega/cosmos-react-core';
|
|
5
|
+
import BareButton from '@pega/cosmos-react-core/lib/components/Button/BareButton';
|
|
6
|
+
import { FeedContext } from './Feed.context';
|
|
7
|
+
export const StyledFeedAttachments = styled.ul(({ theme }) => {
|
|
7
8
|
return css `
|
|
8
|
-
margin: ${theme.base.spacing} 0;
|
|
9
9
|
overflow-x: auto;
|
|
10
10
|
|
|
11
11
|
> li {
|
|
@@ -15,15 +15,80 @@ export const StyledFeedAttachments = styled.ul(props => {
|
|
|
15
15
|
`;
|
|
16
16
|
});
|
|
17
17
|
StyledFeedAttachments.defaultProps = defaultThemeProp;
|
|
18
|
+
export const StyledImagePreview = styled(BareButton)(({ theme }) => {
|
|
19
|
+
return css `
|
|
20
|
+
line-height: 0;
|
|
21
|
+
|
|
22
|
+
/* stylelint-disable declaration-block-no-duplicate-properties */
|
|
23
|
+
width: -moz-fit-content;
|
|
24
|
+
width: fit-content;
|
|
25
|
+
|
|
26
|
+
/* stylelint-enable declaration-block-no-duplicate-properties */
|
|
27
|
+
border-radius: calc(0.5 * ${theme.base['border-radius']});
|
|
28
|
+
|
|
29
|
+
& + & {
|
|
30
|
+
margin: 0;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&:focus {
|
|
34
|
+
box-shadow: ${theme.components.button['focus-shadow']};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
img {
|
|
38
|
+
border-radius: calc(0.5 * ${theme.base['border-radius']});
|
|
39
|
+
object-fit: contain;
|
|
40
|
+
max-height: 32rem;
|
|
41
|
+
max-width: 100%;
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
44
|
+
});
|
|
45
|
+
StyledImagePreview.defaultProps = defaultThemeProp;
|
|
46
|
+
export const StyledAttachmentsRegion = styled.div(({ theme }) => {
|
|
47
|
+
return css `
|
|
48
|
+
margin: ${theme.base.spacing} 0;
|
|
49
|
+
|
|
50
|
+
${StyledFlex} + ${StyledFeedAttachments} {
|
|
51
|
+
margin-block-start: ${theme.base.spacing};
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
54
|
+
});
|
|
55
|
+
StyledAttachmentsRegion.defaultProps = defaultThemeProp;
|
|
18
56
|
const FeedAttachments = forwardRef((props, ref) => {
|
|
19
|
-
const { attachments } = props;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
57
|
+
const { attachments = [], readOnly } = props;
|
|
58
|
+
const t = useI18n();
|
|
59
|
+
const { announce } = useContext(FeedContext);
|
|
60
|
+
const prevAttachments = usePrevious(attachments) ?? [];
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (attachments.length !== prevAttachments?.length) {
|
|
63
|
+
const difference = attachments.length - prevAttachments.length;
|
|
64
|
+
const normalizedDifference = difference * (difference > 0 ? 1 : -1);
|
|
65
|
+
announce(t(`feed_attachments_${difference > 0 ? 'added' : 'removed'}`, [normalizedDifference], {
|
|
66
|
+
count: normalizedDifference
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
}, [attachments]);
|
|
70
|
+
if (attachments.length === 0)
|
|
71
|
+
return null;
|
|
72
|
+
const previewableFiles = [];
|
|
73
|
+
const nonPreviewableFiles = [];
|
|
74
|
+
attachments.forEach(file => {
|
|
75
|
+
const type = getKindFromMimeType(getMimeTypeFromFile(file.name) ?? '');
|
|
76
|
+
if (type === 'image')
|
|
77
|
+
previewableFiles.push(file);
|
|
78
|
+
else
|
|
79
|
+
nonPreviewableFiles.push(file);
|
|
80
|
+
});
|
|
81
|
+
return (_jsxs(StyledAttachmentsRegion, { children: [readOnly && !!previewableFiles.length && (_jsx(Flex, { container: { direction: 'column', gap: 1 }, children: previewableFiles.map(({ lastModified, name, onPreview, thumbnail }) => {
|
|
82
|
+
return (_jsx(StyledImagePreview, { onClick: () => onPreview?.(name), children: _jsx(Image, { alt: name, src: thumbnail }, void 0) }, lastModified));
|
|
83
|
+
}) }, void 0)), _jsxs(Grid, { ref: ref, as: StyledFeedAttachments, container: {
|
|
84
|
+
cols: 'repeat(auto-fill, minmax(15rem, 1fr))',
|
|
85
|
+
gap: 1
|
|
86
|
+
}, children: [!readOnly &&
|
|
87
|
+
previewableFiles.map(({ lastModified, name, size, ...restProps }) => {
|
|
88
|
+
return _jsx(FileUploadItem, { name: name, size: size, ...restProps }, lastModified);
|
|
89
|
+
}), nonPreviewableFiles.map(({ lastModified, name, size, ...restProps }) => {
|
|
90
|
+
return _jsx(FileUploadItem, { name: name, size: size, ...restProps }, lastModified);
|
|
91
|
+
})] }, void 0)] }, void 0));
|
|
27
92
|
});
|
|
28
93
|
export default FeedAttachments;
|
|
29
94
|
//# sourceMappingURL=FeedAttachments.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FeedAttachments.js","sourceRoot":"","sources":["../../../src/components/Feed/FeedAttachments.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAM,UAAU,EAAwB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"FeedAttachments.js","sourceRoot":"","sources":["../../../src/components/Feed/FeedAttachments.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAM,UAAU,EAAwB,SAAS,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACpF,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAE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CAAC,YACG,YACiB,CAC3B,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { FC, forwardRef, PropsWithoutRef, Ref, useEffect, useContext } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport {\n FileUploadItem,\n FileUploadItemProps,\n Grid,\n Image,\n defaultThemeProp,\n getKindFromMimeType,\n getMimeTypeFromFile,\n Flex,\n StyledFlex,\n usePrevious,\n useI18n\n} from '@pega/cosmos-react-core';\nimport BareButton from '@pega/cosmos-react-core/lib/components/Button/BareButton';\n\nimport { FeedContext } from './Feed.context';\n\nexport type AttachedFiles = FileUploadItemProps & File;\n\ninterface FeedAttachmentsProps {\n attachments?: AttachedFiles[];\n readOnly?: boolean;\n ref?: Ref<HTMLUListElement>;\n}\n\nexport const StyledFeedAttachments = styled.ul(({ theme }) => {\n return css`\n overflow-x: auto;\n\n > li {\n background-color: ${theme.base.palette['primary-background']};\n cursor: initial;\n }\n `;\n});\n\nStyledFeedAttachments.defaultProps = defaultThemeProp;\n\nexport const StyledImagePreview = styled(BareButton)(({ theme }) => {\n return css`\n line-height: 0;\n\n /* stylelint-disable declaration-block-no-duplicate-properties */\n width: -moz-fit-content;\n width: fit-content;\n\n /* stylelint-enable declaration-block-no-duplicate-properties */\n border-radius: calc(0.5 * ${theme.base['border-radius']});\n\n & + & {\n margin: 0;\n }\n\n &:focus {\n box-shadow: ${theme.components.button['focus-shadow']};\n }\n\n img {\n border-radius: calc(0.5 * ${theme.base['border-radius']});\n object-fit: contain;\n max-height: 32rem;\n max-width: 100%;\n }\n `;\n});\n\nStyledImagePreview.defaultProps = defaultThemeProp;\n\nexport const StyledAttachmentsRegion = styled.div(({ theme }) => {\n return css`\n margin: ${theme.base.spacing} 0;\n\n ${StyledFlex} + ${StyledFeedAttachments} {\n margin-block-start: ${theme.base.spacing};\n }\n `;\n});\n\nStyledAttachmentsRegion.defaultProps = defaultThemeProp;\n\nconst FeedAttachments: FC<FeedAttachmentsProps> = forwardRef(\n (props: PropsWithoutRef<FeedAttachmentsProps>, ref: FeedAttachmentsProps['ref']) => {\n const { attachments = [], readOnly } = props;\n const t = useI18n();\n const { announce } = useContext(FeedContext);\n const prevAttachments = usePrevious(attachments) ?? [];\n\n useEffect(() => {\n if (attachments.length !== prevAttachments?.length) {\n const difference = attachments.length - prevAttachments.length;\n const normalizedDifference = difference * (difference > 0 ? 1 : -1);\n announce(\n t(`feed_attachments_${difference > 0 ? 'added' : 'removed'}`, [normalizedDifference], {\n count: normalizedDifference\n })\n );\n }\n }, [attachments]);\n\n if (attachments.length === 0) return null;\n\n const previewableFiles: AttachedFiles[] = [];\n const nonPreviewableFiles: AttachedFiles[] = [];\n\n attachments.forEach(file => {\n const type = getKindFromMimeType(getMimeTypeFromFile(file.name) ?? '');\n\n if (type === 'image') previewableFiles.push(file);\n else nonPreviewableFiles.push(file);\n });\n\n return (\n <StyledAttachmentsRegion>\n {readOnly && !!previewableFiles.length && (\n <Flex container={{ direction: 'column', gap: 1 }}>\n {previewableFiles.map(({ lastModified, name, onPreview, thumbnail }) => {\n return (\n <StyledImagePreview key={lastModified} onClick={() => onPreview?.(name)}>\n <Image alt={name} src={thumbnail} />\n </StyledImagePreview>\n );\n })}\n </Flex>\n )}\n <Grid\n ref={ref}\n as={StyledFeedAttachments}\n container={{\n cols: 'repeat(auto-fill, minmax(15rem, 1fr))',\n gap: 1\n }}\n >\n {!readOnly &&\n previewableFiles.map(({ lastModified, name, size, ...restProps }) => {\n return <FileUploadItem key={lastModified} name={name} size={size} {...restProps} />;\n })}\n {nonPreviewableFiles.map(({ lastModified, name, size, ...restProps }) => {\n return <FileUploadItem key={lastModified} name={name} size={size} {...restProps} />;\n })}\n </Grid>\n </StyledAttachmentsRegion>\n );\n }\n);\n\nexport default FeedAttachments;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FeedButton.d.ts","sourceRoot":"","sources":["../../../src/components/Feed/FeedButton.
|
|
1
|
+
{"version":3,"file":"FeedButton.d.ts","sourceRoot":"","sources":["../../../src/components/Feed/FeedButton.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,UAAU;;;SAkBd,CAAC;AAIH,eAAe,UAAU,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FeedButton.js","sourceRoot":"","sources":["../../../src/components/Feed/FeedButton.
|
|
1
|
+
{"version":3,"file":"FeedButton.js","sourceRoot":"","sources":["../../../src/components/Feed/FeedButton.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAA2C,KAAK,CAAC,EAAE;IACjF,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IAE1C,OAAO,GAAG,CAAA;aACC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC;;;;wCAIzD,KAAK,CAAC,IAAI,CAAC,OAAO;;;MAGpD,IAAI;QACN,GAAG,CAAA;;;;KAIF;GACF,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,UAAU,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAE3C,eAAe,UAAU,CAAC","sourcesContent":["import styled, { css } from 'styled-components';\n\nimport { defaultThemeProp } from '@pega/cosmos-react-core';\n\nconst FeedButton = styled.button<{ emphasized?: boolean; icon?: boolean }>(props => {\n const { emphasized, icon, theme } = props;\n\n return css`\n color: ${emphasized ? theme.base.palette.interactive : theme.base.palette['foreground-color']};\n vertical-align: top;\n\n span {\n margin-inline-start: calc(0.5 * ${theme.base.spacing});\n }\n\n ${icon &&\n css`\n display: inline-flex;\n flex-direction: row;\n align-items: center;\n `}\n `;\n});\n\nFeedButton.defaultProps = defaultThemeProp;\n\nexport default FeedButton;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FeedContent.d.ts","sourceRoot":"","sources":["../../../src/components/Feed/FeedContent.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,EAAE,EACF,GAAG,EAOH,YAAY,EAEb,MAAM,OAAO,CAAC;AAEf,OAAO,EAAgC,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAKrF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,YAAY,GAAG,MAAM,CAAC;IAChC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC3B;AAED,QAAA,MAAM,WAAW,EAAE,EAAE,CAAC,gBAAgB,GAAG,YAAY,
|
|
1
|
+
{"version":3,"file":"FeedContent.d.ts","sourceRoot":"","sources":["../../../src/components/Feed/FeedContent.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,EAAE,EACF,GAAG,EAOH,YAAY,EAEb,MAAM,OAAO,CAAC;AAEf,OAAO,EAAgC,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAKrF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,YAAY,GAAG,MAAM,CAAC;IAChC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC3B;AAED,QAAA,MAAM,WAAW,EAAE,EAAE,CAAC,gBAAgB,GAAG,YAAY,CAsEpD,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -24,8 +24,16 @@ const FeedContent = forwardRef(({ children, maxContentHeight = Infinity, ...rest
|
|
|
24
24
|
observer.disconnect();
|
|
25
25
|
};
|
|
26
26
|
}, [rtvRef.current, maxContentHeight]);
|
|
27
|
-
return useMemo(() => typeof children === 'string' ? (_jsxs(Flex,
|
|
28
|
-
|
|
27
|
+
return useMemo(() => typeof children === 'string' ? (_jsxs(Flex, { ref: ref, container: { direction: 'column', gap: 1 }, children: [_jsx(ExpandCollapse, { collapsed: collapsed, min: exceedsMaxHeight ? `${maxContentHeight}px` : 'max-content', ...restProps, children: _jsx(RichTextViewer, { ref: rtvRef, content: children, type: 'markdown', interactionRenderers: interactionRenderers, markdownMap: markdownMap }, void 0) }, void 0), exceedsMaxHeight && (_jsx(Flex, { container: { justify: 'center' }, children: _jsx(Button, { variant: 'link', onClick: () => setCollapsed(current => !current), children: collapsed ? 'Show more' : 'Show less' }, void 0) }, void 0))] }, void 0)) : (children), [
|
|
28
|
+
children,
|
|
29
|
+
collapsed,
|
|
30
|
+
exceedsMaxHeight,
|
|
31
|
+
interactionRenderers,
|
|
32
|
+
markdownMap,
|
|
33
|
+
maxContentHeight,
|
|
34
|
+
ref,
|
|
35
|
+
restProps
|
|
36
|
+
]);
|
|
29
37
|
});
|
|
30
38
|
export default FeedContent;
|
|
31
39
|
//# sourceMappingURL=FeedContent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FeedContent.js","sourceRoot":"","sources":["../../../src/components/Feed/FeedContent.tsx"],"names":[],"mappings":";AAAA,OAAO,EAGL,UAAU,EACV,QAAQ,EACR,OAAO,EACP,MAAM,EACN,eAAe,EAGf,UAAU,EACX,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,EAAgB,MAAM,yBAAyB,CAAC;AACrF,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAY7C,MAAM,WAAW,GAAwC,UAAU,CACjE,CACE,EAAE,QAAQ,EAAE,gBAAgB,GAAG,QAAQ,EAAE,GAAG,SAAS,EAAqC,EAC1F,GAA4B,EAC5B,EAAE;IACF,MAAM,EAAE,oBAAoB,EAAE,WAA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B,CAAC,CAAC,CAAC;IAEvC,OAAO,OAAO,CACZ,GAAG,EAAE,CACH,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,CAC7B,MAAC,IAAI,IAAC,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,EAAE,aACxD,KAAC,cAAc,IACb,SAAS,EAAE,SAAS,EACpB,GAAG,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,gBAAgB,IAAI,CAAC,CAAC,CAAC,aAAa,KAC3D,SAAS,YAEb,KAAC,cAAc,IACb,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,QAAQ,EACjB,IAAI,EAAC,UAAU,EACf,oBAAoB,EAAE,oBAAoB,EAC1C,WAAW,EAAE,WAAW,WACxB,WACa,EAChB,gBAAgB,IAAI,CACnB,KAAC,IAAI,IAAC,SAAS,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,YACpC,KAAC,MAAM,IAAC,OAAO,EAAC,MAAM,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,YACpE,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,WAC/B,WACJ,CACR,YACI,CACR,CAAC,CAAC,CAAC,CACF,QAAQ,CACT,EACH;QACE,QAAQ;QACR,SAAS;QACT,gBAAgB;QAChB,oBAAoB;QACpB,WAAW;QACX,gBAAgB;QAChB,GAAG;QACH,SAAS;KACV,CACF,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,WAAW,CAAC","sourcesContent":["import {\n FC,\n Ref,\n forwardRef,\n useState,\n useMemo,\n useRef,\n useLayoutEffect,\n PropsWithoutRef,\n ReactElement,\n useContext\n} from 'react';\n\nimport { Button, ExpandCollapse, Flex, ForwardProps } from '@pega/cosmos-react-core';\nimport { RichTextViewer } from '@pega/cosmos-react-rte';\n\nimport { FeedContext } from './Feed.context';\n\nexport interface FeedContentProps {\n children: ReactElement | string;\n /**\n * A maximum height in pixels to display post content within before prompting to expand the post.\n * @default Infinity\n */\n maxContentHeight?: number;\n ref?: Ref<HTMLDivElement>;\n}\n\nconst FeedContent: FC<FeedContentProps & ForwardProps> = forwardRef(\n (\n { children, maxContentHeight = Infinity, ...restProps }: PropsWithoutRef<FeedContentProps>,\n ref: FeedContentProps['ref']\n ) => {\n const { interactionRenderers, markdownMap } = useContext(FeedContext);\n const [collapsed, setCollapsed] = useState(true);\n const [exceedsMaxHeight, setExceedsMaxHeight] = useState(true);\n const rtvRef = useRef<HTMLDivElement>(null);\n\n useLayoutEffect(() => {\n if (!rtvRef.current) return;\n\n const observer = new ResizeObserver(entries => {\n const exceedsHeight = entries.some(({ target, contentRect }) => {\n if (target !== rtvRef.current) return;\n\n return contentRect.height > maxContentHeight;\n });\n\n setExceedsMaxHeight(exceedsHeight);\n });\n\n observer.observe(rtvRef.current);\n\n return () => {\n observer.disconnect();\n };\n }, [rtvRef.current, maxContentHeight]);\n\n return useMemo(\n () =>\n typeof children === 'string' ? (\n <Flex ref={ref} container={{ direction: 'column', gap: 1 }}>\n <ExpandCollapse\n collapsed={collapsed}\n min={exceedsMaxHeight ? `${maxContentHeight}px` : 'max-content'}\n {...restProps}\n >\n <RichTextViewer\n ref={rtvRef}\n content={children}\n type='markdown'\n interactionRenderers={interactionRenderers}\n markdownMap={markdownMap}\n />\n </ExpandCollapse>\n {exceedsMaxHeight && (\n <Flex container={{ justify: 'center' }}>\n <Button variant='link' onClick={() => setCollapsed(current => !current)}>\n {collapsed ? 'Show more' : 'Show less'}\n </Button>\n </Flex>\n )}\n </Flex>\n ) : (\n children\n ),\n [\n children,\n collapsed,\n exceedsMaxHeight,\n interactionRenderers,\n markdownMap,\n maxContentHeight,\n ref,\n restProps\n ]\n );\n }\n);\n\nexport default FeedContent;\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { ForwardProps, OmitStrict } from '@pega/cosmos-react-core';
|
|
3
|
+
import { FeedPostProps } from './FeedPost.types';
|
|
4
|
+
import { FeedReplyProps } from './FeedReply.types';
|
|
5
|
+
interface BaseFeedLikeButtonProps extends OmitStrict<FeedPostProps['interactionInfo'], 'commentLabel' | 'interactionsEnabled'>, Pick<FeedPostProps, 'onLoadMoreLikes' | 'onLikeCountInteraction' | 'id'>, Pick<FeedPostProps['info'], 'liked'> {
|
|
6
|
+
showText?: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface PostFeedLikeButtonProps extends BaseFeedLikeButtonProps {
|
|
9
|
+
variant: 'post';
|
|
10
|
+
onLikeClick: FeedPostProps['onLikeClick'];
|
|
11
|
+
}
|
|
12
|
+
interface ReplyFeedLikeButtonProps extends BaseFeedLikeButtonProps {
|
|
13
|
+
variant: 'reply';
|
|
14
|
+
onLikeClick: FeedReplyProps['onLikeClick'];
|
|
15
|
+
}
|
|
16
|
+
export declare type FeedLikeButtonProps = PostFeedLikeButtonProps | ReplyFeedLikeButtonProps;
|
|
17
|
+
export declare const FeedLikeButton: FC<FeedLikeButtonProps & ForwardProps>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=FeedLikeButton.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FeedLikeButton.d.ts","sourceRoot":"","sources":["../../../src/components/Feed/FeedLikeButton.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAA0E,MAAM,OAAO,CAAC;AAGnG,OAAO,EACL,YAAY,EACZ,UAAU,EAcX,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAIjD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAMnD,UAAU,uBACR,SAAQ,UAAU,CAAC,aAAa,CAAC,iBAAiB,CAAC,EAAE,cAAc,GAAG,qBAAqB,CAAC,EAC1F,IAAI,CAAC,aAAa,EAAE,iBAAiB,GAAG,wBAAwB,GAAG,IAAI,CAAC,EACxE,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IACtC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,UAAU,uBAAwB,SAAQ,uBAAuB;IAC/D,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC;CAC3C;AAED,UAAU,wBAAyB,SAAQ,uBAAuB;IAChE,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,cAAc,CAAC,aAAa,CAAC,CAAC;CAC5C;AAED,oBAAY,mBAAmB,GAAG,uBAAuB,GAAG,wBAAwB,CAAC;AAErF,eAAO,MAAM,cAAc,EAAE,EAAE,CAAC,mBAAmB,GAAG,YAAY,CAwHjE,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useContext, useMemo, useRef, useEffect } from 'react';
|
|
3
|
+
import styled from 'styled-components';
|
|
4
|
+
import { Button, Icon, Text, Avatar, MetaList, Count, Tooltip, ModalManagerContext, useI18n, useConfiguration, useElement, formatListToLocaleString } from '@pega/cosmos-react-core';
|
|
5
|
+
import BareRoleButton from '@pega/cosmos-react-core/lib/components/Button/BareRoleButton';
|
|
6
|
+
import { FeedContext } from './Feed.context';
|
|
7
|
+
import FeedButton from './FeedButton';
|
|
8
|
+
import FeedModalList from './FeedModalList';
|
|
9
|
+
const InlineBareButton = styled(BareRoleButton) `
|
|
10
|
+
display: inline-block;
|
|
11
|
+
`;
|
|
12
|
+
export const FeedLikeButton = forwardRef((props, ref) => {
|
|
13
|
+
const { id, showText, onLikeCountInteraction, onLoadMoreLikes, liked, likeLabel, likeCount = 0, likes = [] } = props;
|
|
14
|
+
const t = useI18n();
|
|
15
|
+
const { locale } = useConfiguration();
|
|
16
|
+
const { create } = useContext(ModalManagerContext);
|
|
17
|
+
const { announce, userInfo: loggedInUser } = useContext(FeedContext);
|
|
18
|
+
const [countEl, setCountEl] = useElement(null);
|
|
19
|
+
const likesModalRef = useRef();
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
likesModalRef.current?.update({
|
|
22
|
+
count: likeCount,
|
|
23
|
+
heading: likeLabel,
|
|
24
|
+
listItems: likes,
|
|
25
|
+
onLoadMore: onLoadMoreLikes
|
|
26
|
+
});
|
|
27
|
+
}, [likeCount, likeLabel, likes, onLoadMoreLikes]);
|
|
28
|
+
const likesAttributes = useMemo(() => {
|
|
29
|
+
const likesList = likes.map(x => x.primary.toString());
|
|
30
|
+
return {
|
|
31
|
+
ariaLabel: likeCount
|
|
32
|
+
? `${t('feed_liked_by')} ${formatListToLocaleString(likesList, t, locale, {
|
|
33
|
+
count: likeCount
|
|
34
|
+
})}`
|
|
35
|
+
: t('feed_post_likes', [likeCount], { count: likeCount }),
|
|
36
|
+
label: formatListToLocaleString(likesList, t, locale, {
|
|
37
|
+
count: likeCount,
|
|
38
|
+
separator: '\n'
|
|
39
|
+
})
|
|
40
|
+
};
|
|
41
|
+
}, [likes, likeCount]);
|
|
42
|
+
const onLikeCountClick = () => {
|
|
43
|
+
if (likes.length && likeCount > 10) {
|
|
44
|
+
likesModalRef.current = create(FeedModalList, {
|
|
45
|
+
count: likeCount,
|
|
46
|
+
heading: t('feed_likes'),
|
|
47
|
+
listItems: likes,
|
|
48
|
+
onLoadMore: onLoadMoreLikes
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
onLikeCountInteraction?.();
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
announce(t(`feed_post_${liked ? 'liked' : 'deliked'}`));
|
|
57
|
+
}, [liked]);
|
|
58
|
+
return (_jsxs(Button, { variant: 'text', as: FeedButton, onClick: () => {
|
|
59
|
+
const user = {
|
|
60
|
+
id: loggedInUser.username,
|
|
61
|
+
primary: loggedInUser.fullname,
|
|
62
|
+
secondary: loggedInUser.meta ? _jsx(MetaList, { items: loggedInUser.meta }, void 0) : undefined,
|
|
63
|
+
visual: (_jsx(Avatar, { size: 'l', imageSrc: loggedInUser.avatarSrc, name: loggedInUser.fullname }, void 0))
|
|
64
|
+
};
|
|
65
|
+
let eventObj;
|
|
66
|
+
if (props.variant === 'post') {
|
|
67
|
+
eventObj = {
|
|
68
|
+
postId: id,
|
|
69
|
+
user
|
|
70
|
+
};
|
|
71
|
+
props.onLikeClick(eventObj);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
eventObj = {
|
|
75
|
+
replyId: id,
|
|
76
|
+
user
|
|
77
|
+
};
|
|
78
|
+
props.onLikeClick(eventObj);
|
|
79
|
+
}
|
|
80
|
+
}, emphasized: liked, ref: ref, children: [_jsx(Icon, { name: liked ? 'thumbs-up-solid' : 'thumbs-up' }, void 0), showText && _jsx(Text, { children: likeLabel }, void 0), likeCount > 0 && (_jsxs(_Fragment, { children: [_jsx(InlineBareButton, { ref: setCountEl, role: likes.length ? 'button' : undefined, onClick: onLikeCountClick, onFocus: onLikeCountInteraction, onMouseOver: onLikeCountInteraction, "aria-label": likesAttributes.ariaLabel, tabIndex: 0, onKeyDown: (e) => {
|
|
81
|
+
if (e.key === 'Enter') {
|
|
82
|
+
e.preventDefault();
|
|
83
|
+
onLikeCountClick();
|
|
84
|
+
}
|
|
85
|
+
}, children: _jsx(Count, { children: likeCount }, void 0) }, void 0), _jsx(Tooltip, { target: countEl, showDelay: 'none', hideDelay: 'none', children: likesAttributes.label }, void 0)] }, void 0))] }, void 0));
|
|
86
|
+
});
|
|
87
|
+
//# sourceMappingURL=FeedLikeButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FeedLikeButton.js","sourceRoot":"","sources":["../../../src/components/Feed/FeedLikeButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAM,UAAU,EAAO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CAAC,IAAI,CAChB,8BACE,KAAC,gBAAgB,IACf,GAAG,EAAE,UAAU,EACf,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,EACzC,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,sBAAsB,EAC/B,WAAW,EAAE,sBAAsB,gBACvB,eAAe,CAAC,SAAS,EACrC,QAAQ,EAAE,CAAC,EACX,SAAS,EAAE,CAAC,CAAgB,EAAE,EAAE;4BAC9B,IAAI,CAAC,CAAC,GAAG,KAAK,OAAO,EAAE;gCACrB,CAAC,CAAC,cAAc,EAAE,CAAC;gCACnB,gBAAgB,EAAE,CAAC;6BACpB;wBACH,CAAC,YAED,KAAC,KAAK,cAAE,SAAS,WAAS,WACT,EACnB,KAAC,OAAO,IAAC,MAAM,EAAE,OAAO,EAAE,SAAS,EAAC,MAAM,EAAC,SAAS,EAAC,MAAM,YACxD,eAAe,CAAC,KAAK,WACd,YACT,CACJ,YACM,CACV,CAAC;AACJ,CAAC,CACF,CAAC","sourcesContent":["import { FC, forwardRef, Ref, useContext, useMemo, useRef, useEffect, KeyboardEvent } from 'react';\nimport styled from 'styled-components';\n\nimport {\n ForwardProps,\n OmitStrict,\n Button,\n Icon,\n Text,\n Avatar,\n MetaList,\n Count,\n Tooltip,\n ModalManagerContext,\n ModalMethods,\n useI18n,\n useConfiguration,\n useElement,\n formatListToLocaleString\n} from '@pega/cosmos-react-core';\nimport BareRoleButton from '@pega/cosmos-react-core/lib/components/Button/BareRoleButton';\n\nimport { FeedPostProps } from './FeedPost.types';\nimport { FeedContext } from './Feed.context';\nimport FeedButton from './FeedButton';\nimport FeedModalList, { FeedModalListProps } from './FeedModalList';\nimport { FeedReplyProps } from './FeedReply.types';\n\nconst InlineBareButton = styled(BareRoleButton)`\n display: inline-block;\n`;\n\ninterface BaseFeedLikeButtonProps\n extends OmitStrict<FeedPostProps['interactionInfo'], 'commentLabel' | 'interactionsEnabled'>,\n Pick<FeedPostProps, 'onLoadMoreLikes' | 'onLikeCountInteraction' | 'id'>,\n Pick<FeedPostProps['info'], 'liked'> {\n showText?: boolean;\n}\n\ninterface PostFeedLikeButtonProps extends BaseFeedLikeButtonProps {\n variant: 'post';\n onLikeClick: FeedPostProps['onLikeClick'];\n}\n\ninterface ReplyFeedLikeButtonProps extends BaseFeedLikeButtonProps {\n variant: 'reply';\n onLikeClick: FeedReplyProps['onLikeClick'];\n}\n\nexport type FeedLikeButtonProps = PostFeedLikeButtonProps | ReplyFeedLikeButtonProps;\n\nexport const FeedLikeButton: FC<FeedLikeButtonProps & ForwardProps> = forwardRef(\n (props, ref: Ref<HTMLButtonElement>) => {\n const {\n id,\n showText,\n onLikeCountInteraction,\n onLoadMoreLikes,\n liked,\n likeLabel,\n likeCount = 0,\n likes = []\n } = props;\n const t = useI18n();\n const { locale } = useConfiguration();\n const { create } = useContext(ModalManagerContext);\n const { announce, userInfo: loggedInUser } = useContext(FeedContext);\n const [countEl, setCountEl] = useElement(null);\n const likesModalRef = useRef<ModalMethods<FeedModalListProps>>();\n\n useEffect(() => {\n likesModalRef.current?.update({\n count: likeCount,\n heading: likeLabel,\n listItems: likes,\n onLoadMore: onLoadMoreLikes\n });\n }, [likeCount, likeLabel, likes, onLoadMoreLikes]);\n\n const likesAttributes = useMemo(() => {\n const likesList = likes.map(x => x.primary.toString());\n return {\n ariaLabel: likeCount\n ? `${t('feed_liked_by')} ${formatListToLocaleString(likesList, t, locale, {\n count: likeCount\n })}`\n : t('feed_post_likes', [likeCount], { count: likeCount }),\n label: formatListToLocaleString(likesList, t, locale, {\n count: likeCount,\n separator: '\\n'\n })\n };\n }, [likes, likeCount]);\n\n const onLikeCountClick = () => {\n if (likes.length && likeCount > 10) {\n likesModalRef.current = create(FeedModalList, {\n count: likeCount,\n heading: t('feed_likes'),\n listItems: likes,\n onLoadMore: onLoadMoreLikes\n });\n } else {\n onLikeCountInteraction?.();\n }\n };\n\n useEffect(() => {\n announce(t(`feed_post_${liked ? 'liked' : 'deliked'}`));\n }, [liked]);\n\n return (\n <Button\n variant='text'\n as={FeedButton}\n onClick={() => {\n const user = {\n id: loggedInUser.username,\n primary: loggedInUser.fullname,\n secondary: loggedInUser.meta ? <MetaList items={loggedInUser.meta} /> : undefined,\n visual: (\n <Avatar size='l' imageSrc={loggedInUser.avatarSrc} name={loggedInUser.fullname} />\n )\n };\n let eventObj;\n if (props.variant === 'post') {\n eventObj = {\n postId: id,\n user\n } as const;\n props.onLikeClick(eventObj);\n } else {\n eventObj = {\n replyId: id,\n user\n } as const;\n props.onLikeClick(eventObj);\n }\n }}\n emphasized={liked}\n ref={ref}\n >\n <Icon name={liked ? 'thumbs-up-solid' : 'thumbs-up'} />\n {showText && <Text>{likeLabel}</Text>}\n {likeCount > 0 && (\n <>\n <InlineBareButton\n ref={setCountEl}\n role={likes.length ? 'button' : undefined}\n onClick={onLikeCountClick}\n onFocus={onLikeCountInteraction}\n onMouseOver={onLikeCountInteraction}\n aria-label={likesAttributes.ariaLabel}\n tabIndex={0}\n onKeyDown={(e: KeyboardEvent) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n onLikeCountClick();\n }\n }}\n >\n <Count>{likeCount}</Count>\n </InlineBareButton>\n <Tooltip target={countEl} showDelay='none' hideDelay='none'>\n {likesAttributes.label}\n </Tooltip>\n </>\n )}\n </Button>\n );\n }\n);\n"]}
|
|
@@ -34,7 +34,7 @@ const FeedModalList = ({ count, heading, listItems, onLoadMore }) => {
|
|
|
34
34
|
listOverflowsRef.current = true;
|
|
35
35
|
}
|
|
36
36
|
else if (entries[0].isIntersecting && listOverflowsRef.current) {
|
|
37
|
-
onLoadMore
|
|
37
|
+
onLoadMore?.();
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
intersectionObserver.observe(loadMoreEl);
|
|
@@ -43,9 +43,7 @@ const FeedModalList = ({ count, heading, listItems, onLoadMore }) => {
|
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
}, [loadMoreEl, listOverflowsRef.current]);
|
|
46
|
-
return (_jsxs(Modal,
|
|
47
|
-
_jsx(Flex, Object.assign({ item: { alignSelf: 'center' }, as: Count }, { children: count }), void 0)] }), void 0) }, { children: [_jsx(SummaryListItems, { items: listItems }, void 0),
|
|
48
|
-
onLoadMore && (_jsx(Flex, Object.assign({ ref: setLoadMoreEl, as: StyledLoadMore, visible: listOverflows, container: { justify: 'center' } }, { children: _jsx(Progress, { placement: 'inline' }, void 0) }), void 0))] }), void 0));
|
|
46
|
+
return (_jsxs(Modal, { heading: _jsxs(Flex, { container: { gap: 1 }, children: [heading, _jsx(Flex, { item: { alignSelf: 'center' }, as: Count, children: count }, void 0)] }, void 0), children: [_jsx(SummaryListItems, { items: listItems }, void 0), onLoadMore && (_jsx(Flex, { ref: setLoadMoreEl, as: StyledLoadMore, visible: listOverflows, container: { justify: 'center' }, children: _jsx(Progress, { placement: 'inline' }, void 0) }, void 0))] }, void 0));
|
|
49
47
|
};
|
|
50
48
|
export default FeedModalList;
|
|
51
49
|
//# sourceMappingURL=FeedModalList.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FeedModalList.js","sourceRoot":"","sources":["../../../src/components/Feed/FeedModalList.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAM,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACxD,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAEL,gBAAgB,EAChB,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,kBAAkB,EAClB,KAAK,EACL,KAAK,EACL,gBAAgB,EACjB,MAAM,yBAAyB,CAAC;AAajC,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAuB,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE;IAC7E,OAAO,GAAG,CAAA;MACN,OAAO;QACT,GAAG,CAAA;6BACsB,KAAK,CAAC,IAAI,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;IAE3C,OAAO,CACL,MAAC,KAAK,IACJ,OAAO,EACL,MAAC,IAAI,IAAC,SAAS,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,aACxB,OAAO,EACR,KAAC,IAAI,IAAC,IAAI,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,KAAK,YAC3C,KAAK,WACD,YACF,aAGT,KAAC,gBAAgB,IAAC,KAAK,EAAE,SAAS,WAAI,EAErC,UAAU,IAAI,CACb,KAAC,IAAI,IACH,GAAG,EAAE,aAAa,EAClB,EAAE,EAAE,cAAc,EAClB,OAAO,EAAE,aAAa,EACtB,SAAS,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,YAEhC,KAAC,QAAQ,IAAC,SAAS,EAAC,QAAQ,WAAG,WAC1B,CACR,YACK,CACT,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { FC, useEffect, useRef, useState } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport {\n SummaryListItem,\n defaultThemeProp,\n Flex,\n Progress,\n useElement,\n StyledProgressRing,\n Count,\n Modal,\n SummaryListItems\n} from '@pega/cosmos-react-core';\n\nexport interface FeedModalListProps {\n /** The count for the list of items. */\n count: number;\n /** The heading for the Modal. */\n heading: string;\n /** The list of MenuItems to render in the Modal. */\n listItems: SummaryListItem[];\n /** A callback that is triggered when the bottom of the Modal list is scrolled into view so that additional data may be displayed. */\n onLoadMore?: () => void;\n}\n\nconst StyledLoadMore = styled.div<{ visible: boolean }>(({ theme, visible }) => {\n return css`\n ${visible &&\n css`\n margin-top: calc(2 * ${theme.base.spacing});\n `}\n\n ${StyledProgressRing} {\n min-height: 0;\n min-width: 0;\n\n ${visible &&\n css`\n min-height: 2rem;\n min-width: 2rem;\n `}\n }\n `;\n});\n\nStyledLoadMore.defaultProps = defaultThemeProp;\n\nconst FeedModalList: FC<FeedModalListProps> = ({\n count,\n heading,\n listItems,\n onLoadMore\n}: FeedModalListProps) => {\n const [loadMoreEl, setLoadMoreEl] = useElement<HTMLDivElement>();\n const [listOverflows, setListOverflows] = useState(false);\n const listOverflowsRef = useRef(false);\n\n useEffect(() => {\n if (loadMoreEl) {\n const intersectionObserver = new IntersectionObserver(entries => {\n if (!entries[0].isIntersecting) {\n setListOverflows(true);\n listOverflowsRef.current = true;\n } else if (entries[0].isIntersecting && listOverflowsRef.current) {\n onLoadMore?.();\n }\n });\n\n intersectionObserver.observe(loadMoreEl);\n\n return () => {\n intersectionObserver.disconnect();\n };\n }\n }, [loadMoreEl, listOverflowsRef.current]);\n\n return (\n <Modal\n heading={\n <Flex container={{ gap: 1 }}>\n {heading}\n <Flex item={{ alignSelf: 'center' }} as={Count}>\n {count}\n </Flex>\n </Flex>\n }\n >\n <SummaryListItems items={listItems} />\n\n {onLoadMore && (\n <Flex\n ref={setLoadMoreEl}\n as={StyledLoadMore}\n visible={listOverflows}\n container={{ justify: 'center' }}\n >\n <Progress placement='inline' />\n </Flex>\n )}\n </Modal>\n );\n};\n\nexport default FeedModalList;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FeedNewPost.d.ts","sourceRoot":"","sources":["../../../src/components/Feed/FeedNewPost.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"FeedNewPost.d.ts","sourceRoot":"","sources":["../../../src/components/Feed/FeedNewPost.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,EAAE,EAAkC,MAAM,OAAO,CAAC;AAGrE,OAAO,EAcL,YAAY,EAKb,MAAM,yBAAyB,CAAC;AAKjC,OAA4B,EAE1B,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAwB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAOnE,MAAM,WAAW,gBAAgB;IAC/B,kCAAkC;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,iCAAiC;IACjC,WAAW,CAAC,EAAE,aAAa,EAAE,CAAC;IAC9B,sFAAsF;IACtF,eAAe,EAAE;QACf,mBAAmB,EAAE,MAAM,CAAC;QAC5B,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,sGAAsG;IACtG,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,IAAI,CAAC;IAChD,yEAAyE;IACzE,MAAM,EAAE,CAAC,KAAK,EAAE;QACd,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,EAAE,aAAa,EAAE,CAAC;QAC7B,UAAU,EAAE,iBAAiB,EAAE,CAAC;QAChC,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,IAAI,CAAC;KACnB,KAAK,IAAI,CAAC;IACX,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,yCAAyC;IACzC,UAAU,CAAC,EAAE,iBAAiB,CAAC,YAAY,CAAC,CAAC;IAC7C,0DAA0D;IAC1D,iBAAiB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;CACjD;AAED,eAAO,MAAM,sBAAsB,yGAajC,CAAC;AAIH,eAAO,MAAM,iBAAiB,yGAU5B,CAAC;AAQH,QAAA,MAAM,WAAW,EAAE,EAAE,CAAC,YAAY,GAAG,gBAAgB,CAiKpD,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useState, useRef, useContext
|
|
2
|
+
import { useState, useRef, useContext } from 'react';
|
|
3
3
|
import styled, { css } from 'styled-components';
|
|
4
|
-
import { Avatar, Button, CardContent, Flex, Icon, StyledIcon, StyledCard, StyledPopover, defaultThemeProp, useAutoResize, useElement, useOuterEvent, useI18n, ExpandCollapse } from '@pega/cosmos-react-core';
|
|
4
|
+
import { Avatar, Button, CardContent, Flex, Icon, registerIcon, StyledIcon, StyledCard, StyledPopover, defaultThemeProp, useAutoResize, useElement, useOuterEvent, useI18n, ExpandCollapse, useAfterInitialEffect, cap } from '@pega/cosmos-react-core';
|
|
5
5
|
import { StyledRichTextEditor } from '@pega/cosmos-react-rte';
|
|
6
|
+
import * as timesIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/times.icon';
|
|
7
|
+
import * as paperClipIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/paper-clip.icon';
|
|
6
8
|
import FeedNewPostTypeMenu from './FeedNewPostTypeMenu';
|
|
7
9
|
import FeedAttachments from './FeedAttachments';
|
|
8
10
|
import FeedButton from './FeedButton';
|
|
9
11
|
import FeedRichText from './FeedRichText';
|
|
10
12
|
import { FeedContext } from './Feed.context';
|
|
11
|
-
|
|
13
|
+
registerIcon(timesIcon, paperClipIcon);
|
|
14
|
+
export const StyledTextAreaOverflow = styled.div(() => {
|
|
12
15
|
return css `
|
|
13
16
|
overflow-y: hidden;
|
|
14
|
-
margin-top:
|
|
17
|
+
margin-top: 0.625rem;
|
|
18
|
+
min-height: 1rem;
|
|
15
19
|
width: 100%;
|
|
16
20
|
|
|
17
21
|
${StyledRichTextEditor} {
|
|
@@ -38,10 +42,11 @@ const HiddenFileInput = styled.input `
|
|
|
38
42
|
display: none;
|
|
39
43
|
`;
|
|
40
44
|
const FeedNewPost = (props) => {
|
|
41
|
-
var _a;
|
|
42
45
|
const { id, attachments = [], interactionInfo, onPost, onFilesAdded, autoFocus, recipients, onRecipientSearch, ...restProps } = props;
|
|
43
46
|
const rteRef = useRef();
|
|
44
47
|
const { textAreaPlaceholder, postLabel } = interactionInfo;
|
|
48
|
+
const { setShowSearchResults } = useContext(FeedContext);
|
|
49
|
+
const { avatarSrc, fullname, username } = useContext(FeedContext).userInfo;
|
|
45
50
|
const [emptyText, setEmptyText] = useState(true);
|
|
46
51
|
const [hasFocus, setHasFocus] = useState(autoFocus);
|
|
47
52
|
const [postType, setPostType] = useState('post');
|
|
@@ -50,59 +55,57 @@ const FeedNewPost = (props) => {
|
|
|
50
55
|
const [attachmentEl, setAttachmentEl] = useElement();
|
|
51
56
|
const [newPostEl, setNewPostEl] = useElement();
|
|
52
57
|
const [textAreaRef, resizeTextArea] = useAutoResize();
|
|
53
|
-
const { avatarSrc, fullname, username } = useContext(FeedContext).userInfo;
|
|
54
58
|
useOuterEvent('mousedown', [newPostEl], () => {
|
|
55
|
-
var _a;
|
|
56
59
|
if (emptyText)
|
|
57
|
-
|
|
60
|
+
rteRef.current?.clear();
|
|
58
61
|
});
|
|
59
62
|
const t = useI18n();
|
|
60
63
|
const handlePost = () => {
|
|
61
|
-
|
|
62
|
-
if (!emptyText || attachments.length > 0) {
|
|
64
|
+
setShowSearchResults?.(false);
|
|
65
|
+
if ((!emptyText || attachments.length > 0) && attachments.every(x => !x.error)) {
|
|
63
66
|
onPost({
|
|
64
67
|
newPostId: id,
|
|
65
|
-
value:
|
|
68
|
+
value: rteRef.current?.getPlainText() || '',
|
|
66
69
|
attachments: attachments || [],
|
|
67
70
|
recipients: selectedRecipients,
|
|
68
71
|
username,
|
|
69
72
|
clear: () => {
|
|
70
|
-
|
|
71
|
-
(_a = rteRef.current) === null || _a === void 0 ? void 0 : _a.clear();
|
|
73
|
+
rteRef.current?.clear();
|
|
72
74
|
setResetPostTypeMenu(true);
|
|
73
75
|
}
|
|
74
76
|
});
|
|
75
77
|
}
|
|
76
78
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
const handleClear = () => {
|
|
80
|
+
setShowSearchResults?.(false);
|
|
81
|
+
rteRef.current?.clear();
|
|
82
|
+
rteRef.current?.focus();
|
|
83
|
+
};
|
|
84
|
+
useAfterInitialEffect(() => {
|
|
79
85
|
if (postType === 'post') {
|
|
80
|
-
|
|
86
|
+
rteRef.current?.focus();
|
|
81
87
|
}
|
|
82
88
|
if (postType !== 'private') {
|
|
83
89
|
setSelectedRecipients([]);
|
|
84
90
|
}
|
|
85
91
|
}, [postType]);
|
|
86
|
-
return (_jsx(StyledCard,
|
|
87
|
-
|
|
88
|
-
_jsx(StyledTextAreaOverflow, Object.assign({ ref: textAreaRef }, { children: _jsx(FeedRichText, { onChange: () => {
|
|
89
|
-
var _a;
|
|
90
|
-
setEmptyText(((_a = rteRef.current) === null || _a === void 0 ? void 0 : _a.getPlainText().trim()) === '');
|
|
92
|
+
return (_jsx(StyledCard, { ref: setNewPostEl, as: StyledFeedNewPost, ...restProps, children: _jsxs(CardContent, { children: [onRecipientSearch && (_jsx(FeedNewPostTypeMenu, { recipients: recipients || [], onSetPostType: setPostType, onSelectedRecipientsUpdate: setSelectedRecipients, onRecipientSearch: onRecipientSearch, reset: resetPostTypeMenu, onReset: () => setResetPostTypeMenu(false) }, void 0)), _jsxs(Flex, { container: { alignItems: 'start', gap: 1 }, children: [_jsx(Avatar, { name: fullname, size: 'l', imageSrc: avatarSrc }, void 0), _jsx(StyledTextAreaOverflow, { ref: textAreaRef, children: _jsx(FeedRichText, { label: t('feed_new_post'), labelHidden: true, onChange: () => {
|
|
93
|
+
setEmptyText(rteRef.current?.getPlainText().trim() === '');
|
|
91
94
|
resizeTextArea();
|
|
92
|
-
}, placeholder: textAreaPlaceholder, autoFocus: autoFocus, onSubmit: handlePost, onFocus: () => setHasFocus(true), onBlur: () => setHasFocus(false), ref: rteRef }, void 0) }), void 0),
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
}, placeholder: textAreaPlaceholder, autoFocus: autoFocus, onSubmit: handlePost, onFocus: () => setHasFocus(true), onBlur: () => setHasFocus(false), ref: rteRef }, void 0) }, void 0), !emptyText && (_jsx(Button, { variant: 'simple', as: FeedButton, onClick: handleClear, icon: true, label: t('feed_cancel_conversation'), tabIndex: -1, children: _jsx(Icon, { name: 'times' }, void 0) }, void 0)), onFilesAdded && (_jsx(Button, { variant: 'simple', as: FeedButton, onClick: () => {
|
|
96
|
+
setShowSearchResults?.(false);
|
|
97
|
+
attachmentEl?.click();
|
|
98
|
+
}, icon: true, label: attachments.length
|
|
99
|
+
? cap(t('attachments_count', [], { count: 1 }))
|
|
100
|
+
: t('file_upload_text_multiple'), children: _jsx(Icon, { name: 'paper-clip' }, void 0) }, void 0))] }, void 0), _jsx(HiddenFileInput, { ref: setAttachmentEl, type: 'file', multiple: true, onChange: () => {
|
|
101
|
+
if (attachmentEl?.files) {
|
|
102
|
+
onFilesAdded?.(Array.from(attachmentEl?.files));
|
|
98
103
|
}
|
|
99
104
|
},
|
|
100
105
|
// Must trick input to believe there is no value when activated so that the same file may be added consecutively.
|
|
101
106
|
onClick: (event) => {
|
|
102
107
|
event.target.value = '';
|
|
103
|
-
} }, void 0),
|
|
104
|
-
_jsx(FeedAttachments, { attachments: attachments }, void 0),
|
|
105
|
-
_jsx(ExpandCollapse, Object.assign({ collapsed: !hasFocus && emptyText && !attachments.length }, { children: _jsx(Flex, Object.assign({ container: { justify: 'end' } }, { children: _jsx(Button, Object.assign({ variant: 'primary', disabled: emptyText && attachments.length === 0, onClick: handlePost }, { children: postLabel }), void 0) }), void 0) }), void 0)] }, void 0) }), void 0));
|
|
108
|
+
} }, void 0), _jsx(FeedAttachments, { attachments: attachments }, void 0), _jsx(ExpandCollapse, { collapsed: !hasFocus && emptyText && !attachments.length, children: _jsx(Flex, { container: { justify: 'end' }, children: _jsx(Button, { variant: 'primary', disabled: (emptyText && attachments.length === 0) || attachments.some(x => x.error), onClick: handlePost, children: postLabel }, void 0) }, void 0) }, void 0)] }, void 0) }, void 0));
|
|
106
109
|
};
|
|
107
110
|
export default FeedNewPost;
|
|
108
111
|
//# sourceMappingURL=FeedNewPost.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FeedNewPost.js","sourceRoot":"","sources":["../../../src/components/Feed/FeedNewPost.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAkB,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAChF,OAAO,MAAM,EAAE,EAAE,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G,KAAK,CAAC,IAAI,CAAC,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,KAAK,CAAC,CAAC,CAAC;yBACjD;oBACH,CAAC;oBACD,iHAAiH;oBACjH,OAAO,EAAE,CAAC,KAAiB,EAAE,EAAE;wBAC5B,KAAK,CAAC,MAA2B,CAAC,KAAK,GAAG,EAAE,CAAC;oBAChD,CAAC,WACD;gBAEF,KAAC,eAAe,IAAC,WAAW,EAAE,WAAW,WAAI;gBAE7C,KAAC,cAAc,kBAAC,SAAS,EAAE,CAAC,QAAQ,IAAI,SAAS,IAAI,CAAC,WAAW,CAAC,MAAM,gBACtE,KAAC,IAAI,kBAAC,SAAS,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,gBACjC,KAAC,MAAM,kBACL,OAAO,EAAC,SAAS,EACjB,QAAQ,EAAE,SAAS,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAC/C,OAAO,EAAE,UAAU,gBAElB,SAAS,YACH,YACJ,YACQ,YACL,YACH,CACd,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC","sourcesContent":["import { useState, FC, MouseEvent, useRef, useContext, useEffect } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport {\n Avatar,\n Button,\n CardContent,\n Flex,\n Icon,\n StyledIcon,\n StyledCard,\n StyledPopover,\n defaultThemeProp,\n useAutoResize,\n useElement,\n useOuterEvent,\n ForwardProps,\n useI18n,\n ExpandCollapse\n} from '@pega/cosmos-react-core';\nimport { RichTextEditorState, StyledRichTextEditor } from '@pega/cosmos-react-rte';\n\nimport FeedNewPostTypeMenu, {\n PostType,\n PostTypeMenuProps,\n RecipientMenuItem\n} from './FeedNewPostTypeMenu';\nimport FeedAttachments, { AttachedFiles } from './FeedAttachments';\nimport FeedButton from './FeedButton';\nimport FeedRichText from './FeedRichText';\nimport { FeedContext } from './Feed.context';\n\nexport interface FeedNewPostProps {\n /** A unique ID for the NewPost */\n id: string;\n /** A set of attachment files. */\n attachments?: AttachedFiles[];\n /** Information that is used to label buttons and inputs for accessibility purposes */\n interactionInfo: {\n textAreaPlaceholder: string;\n postLabel: string;\n };\n /** A callback containing a list of added files that will run whenever files are added to the post. */\n onFilesAdded?: (files: AttachedFiles[]) => void;\n /** A callback that will run when the new post button has been clicked */\n onPost: (event: {\n newPostId: string;\n value: string;\n attachments: AttachedFiles[];\n recipients: RecipientMenuItem[];\n username: string;\n clear: () => void;\n }) => void;\n autoFocus?: boolean;\n /** Array of private recipient options */\n recipients?: PostTypeMenuProps['recipients'];\n /** Handler for new search on private recipient options */\n onRecipientSearch?: (newSearch: string) => void;\n}\n\nexport const StyledTextAreaOverflow = styled.div(({ theme }) => {\n return css`\n overflow-y: hidden;\n margin-top: ${theme.base.spacing};\n width: 100%;\n\n ${StyledRichTextEditor} {\n &:focus-within {\n box-shadow: none;\n }\n }\n `;\n});\n\nStyledTextAreaOverflow.defaultProps = defaultThemeProp;\n\nexport const StyledFeedNewPost = styled.div(({ theme }) => {\n return css`\n ${StyledIcon}:not(${StyledPopover} ${StyledIcon}) {\n font-size: 1.25rem;\n }\n\n ${FeedButton} {\n margin-top: calc(0.5 * ${theme.base.spacing});\n }\n `;\n});\n\nStyledFeedNewPost.defaultProps = defaultThemeProp;\n\nconst HiddenFileInput = styled.input`\n display: none;\n`;\n\nconst FeedNewPost: FC<ForwardProps & FeedNewPostProps> = (props: FeedNewPostProps) => {\n const {\n id,\n attachments = [],\n interactionInfo,\n onPost,\n onFilesAdded,\n autoFocus,\n recipients,\n onRecipientSearch,\n ...restProps\n } = props;\n const rteRef = useRef<RichTextEditorState>();\n const { textAreaPlaceholder, postLabel } = interactionInfo;\n const [emptyText, setEmptyText] = useState(true);\n const [hasFocus, setHasFocus] = useState(autoFocus);\n const [postType, setPostType] = useState<PostType>('post');\n const [resetPostTypeMenu, setResetPostTypeMenu] = useState(false);\n const [selectedRecipients, setSelectedRecipients] = useState<RecipientMenuItem[]>([]);\n const [attachmentEl, setAttachmentEl] = useElement<HTMLInputElement>();\n const [newPostEl, setNewPostEl] = useElement<HTMLDivElement>();\n const [textAreaRef, resizeTextArea] = useAutoResize<HTMLDivElement>();\n const { avatarSrc, fullname, username } = useContext(FeedContext).userInfo;\n\n useOuterEvent('mousedown', [newPostEl], () => {\n if (emptyText) rteRef.current?.clear();\n });\n\n const t = useI18n();\n\n const handlePost = () => {\n if (!emptyText || attachments.length > 0) {\n onPost({\n newPostId: id,\n value: rteRef.current?.getPlainText() || '',\n attachments: attachments || [],\n recipients: selectedRecipients,\n username,\n clear: () => {\n rteRef.current?.clear();\n setResetPostTypeMenu(true);\n }\n });\n }\n };\n\n useEffect(() => {\n if (postType === 'post') {\n rteRef.current?.focus();\n }\n if (postType !== 'private') {\n setSelectedRecipients([] as RecipientMenuItem[]);\n }\n }, [postType]);\n\n return (\n <StyledCard ref={setNewPostEl} as={StyledFeedNewPost} {...restProps}>\n <CardContent>\n {onRecipientSearch && (\n <FeedNewPostTypeMenu\n recipients={recipients || ([] as PostTypeMenuProps['recipients'])}\n onSetPostType={setPostType}\n onSelectedRecipientsUpdate={setSelectedRecipients}\n onRecipientSearch={onRecipientSearch}\n reset={resetPostTypeMenu}\n onReset={() => setResetPostTypeMenu(false)}\n />\n )}\n\n <Flex container={{ alignItems: 'start', gap: 1 }}>\n <Avatar name={fullname} size='l' imageSrc={avatarSrc} />\n\n <StyledTextAreaOverflow ref={textAreaRef}>\n <FeedRichText\n onChange={() => {\n setEmptyText(rteRef.current?.getPlainText().trim() === '');\n resizeTextArea();\n }}\n placeholder={textAreaPlaceholder}\n autoFocus={autoFocus}\n onSubmit={handlePost}\n onFocus={() => setHasFocus(true)}\n onBlur={() => setHasFocus(false)}\n ref={rteRef}\n />\n </StyledTextAreaOverflow>\n\n {!emptyText && (\n <Button\n variant='simple'\n as={FeedButton}\n onClick={rteRef.current?.clear}\n icon\n label={t('feed_cancel_conversation')}\n >\n <Icon name='times' />\n </Button>\n )}\n\n {onFilesAdded && (\n <Button\n variant='simple'\n as={FeedButton}\n onClick={() => attachmentEl?.click()}\n icon\n label={t('attachment')}\n >\n <Icon name='paper-clip' />\n </Button>\n )}\n </Flex>\n\n <HiddenFileInput\n ref={setAttachmentEl}\n type='file'\n multiple\n onChange={() => {\n if (attachmentEl?.files) {\n onFilesAdded?.(Array.from(attachmentEl?.files));\n }\n }}\n // Must trick input to believe there is no value when activated so that the same file may be added consecutively.\n onClick={(event: MouseEvent) => {\n (event.target as HTMLInputElement).value = '';\n }}\n />\n\n <FeedAttachments attachments={attachments} />\n\n <ExpandCollapse collapsed={!hasFocus && emptyText && !attachments.length}>\n <Flex container={{ justify: 'end' }}>\n <Button\n variant='primary'\n disabled={emptyText && attachments.length === 0}\n onClick={handlePost}\n >\n {postLabel}\n </Button>\n </Flex>\n </ExpandCollapse>\n </CardContent>\n </StyledCard>\n );\n};\n\nexport default FeedNewPost;\n"]}
|
|
1
|
+
{"version":3,"file":"FeedNewPost.js","sourceRoot":"","sources":["../../../src/components/Feed/FeedNewPost.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAkB,MAAM,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACrE,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,MAAM,EACN,MAAM,EACN,WAAW,EACX,IAAI,EACJ,IAAI,EACJ,YAAY,EACZ,UAAU,EACV,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,UAAU,EACV,aAAa,EAEb,OAAO,EACP,cAAc,EACd,qBAAqB,EACrB,GAAG,EACJ,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAuB,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACnF,OAAO,KAAK,SAAS,MAAM,8DAA8D,CAAC;AAC1F,OAAO,KAAK,aAAa,MAAM,mEAAmE,CAAC;AAEnG,OAAO,mBAIN,MAAM,uBAAuB,CAAC;AAC/B,OAAO,eAAkC,MAAM,mBAAmB,CAA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AEP,KAAC,eAAe,IACd,GAAG,EAAE,eAAe,EACpB,IAAI,EAAC,MAAM,EACX,QAAQ,QACR,QAAQ,EAAE,GAAG,EAAE;wBACb,IAAI,YAAY,EAAE,KAAK,EAAE;4BACvB,YAAY,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,CAAC;yBACjD;oBACH,CAAC;oBACD,iHAAiH;oBACjH,OAAO,EAAE,CAAC,KAAiB,EAAE,EAAE;wBAC5B,KAAK,CAAC,MAA2B,CAAC,KAAK,GAAG,EAAE,CAAC;oBAChD,CAAC,WACD,EAEF,KAAC,eAAe,IAAC,WAAW,EAAE,WAAW,WAAI,EAE7C,KAAC,cAAc,IAAC,SAAS,EAAE,CAAC,QAAQ,IAAI,SAAS,IAAI,CAAC,WAAW,CAAC,MAAM,YACtE,KAAC,IAAI,IAAC,SAAS,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,YACjC,KAAC,MAAM,IACL,OAAO,EAAC,SAAS,EACjB,QAAQ,EAAE,CAAC,SAAS,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,EACnF,OAAO,EAAE,UAAU,YAElB,SAAS,WACH,WACJ,WACQ,YACL,WACH,CACd,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC","sourcesContent":["import { useState, FC, MouseEvent, useRef, useContext } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport {\n Avatar,\n Button,\n CardContent,\n Flex,\n Icon,\n registerIcon,\n StyledIcon,\n StyledCard,\n StyledPopover,\n defaultThemeProp,\n useAutoResize,\n useElement,\n useOuterEvent,\n ForwardProps,\n useI18n,\n ExpandCollapse,\n useAfterInitialEffect,\n cap\n} from '@pega/cosmos-react-core';\nimport { RichTextEditorState, StyledRichTextEditor } from '@pega/cosmos-react-rte';\nimport * as timesIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/times.icon';\nimport * as paperClipIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/paper-clip.icon';\n\nimport FeedNewPostTypeMenu, {\n PostType,\n PostTypeMenuProps,\n RecipientMenuItem\n} from './FeedNewPostTypeMenu';\nimport FeedAttachments, { AttachedFiles } from './FeedAttachments';\nimport FeedButton from './FeedButton';\nimport FeedRichText from './FeedRichText';\nimport { FeedContext } from './Feed.context';\n\nregisterIcon(timesIcon, paperClipIcon);\n\nexport interface FeedNewPostProps {\n /** A unique ID for the NewPost */\n id: string;\n /** A set of attachment files. */\n attachments?: AttachedFiles[];\n /** Information that is used to label buttons and inputs for accessibility purposes */\n interactionInfo: {\n textAreaPlaceholder: string;\n postLabel: string;\n };\n /** A callback containing a list of added files that will run whenever files are added to the post. */\n onFilesAdded?: (files: AttachedFiles[]) => void;\n /** A callback that will run when the new post button has been clicked */\n onPost: (event: {\n newPostId: string;\n value: string;\n attachments: AttachedFiles[];\n recipients: RecipientMenuItem[];\n username: string;\n clear: () => void;\n }) => void;\n autoFocus?: boolean;\n /** Array of private recipient options */\n recipients?: PostTypeMenuProps['recipients'];\n /** Handler for new search on private recipient options */\n onRecipientSearch?: (newSearch: string) => void;\n}\n\nexport const StyledTextAreaOverflow = styled.div(() => {\n return css`\n overflow-y: hidden;\n margin-top: 0.625rem;\n min-height: 1rem;\n width: 100%;\n\n ${StyledRichTextEditor} {\n &:focus-within {\n box-shadow: none;\n }\n }\n `;\n});\n\nStyledTextAreaOverflow.defaultProps = defaultThemeProp;\n\nexport const StyledFeedNewPost = styled.div(({ theme }) => {\n return css`\n ${StyledIcon}:not(${StyledPopover} ${StyledIcon}) {\n font-size: 1.25rem;\n }\n\n ${FeedButton} {\n margin-top: calc(0.5 * ${theme.base.spacing});\n }\n `;\n});\n\nStyledFeedNewPost.defaultProps = defaultThemeProp;\n\nconst HiddenFileInput = styled.input`\n display: none;\n`;\n\nconst FeedNewPost: FC<ForwardProps & FeedNewPostProps> = (props: FeedNewPostProps) => {\n const {\n id,\n attachments = [],\n interactionInfo,\n onPost,\n onFilesAdded,\n autoFocus,\n recipients,\n onRecipientSearch,\n ...restProps\n } = props;\n const rteRef = useRef<RichTextEditorState>();\n const { textAreaPlaceholder, postLabel } = interactionInfo;\n const { setShowSearchResults } = useContext(FeedContext);\n const { avatarSrc, fullname, username } = useContext(FeedContext).userInfo;\n const [emptyText, setEmptyText] = useState(true);\n const [hasFocus, setHasFocus] = useState(autoFocus);\n const [postType, setPostType] = useState<PostType>('post');\n const [resetPostTypeMenu, setResetPostTypeMenu] = useState(false);\n const [selectedRecipients, setSelectedRecipients] = useState<RecipientMenuItem[]>([]);\n const [attachmentEl, setAttachmentEl] = useElement<HTMLInputElement>();\n const [newPostEl, setNewPostEl] = useElement<HTMLDivElement>();\n const [textAreaRef, resizeTextArea] = useAutoResize<HTMLDivElement>();\n\n useOuterEvent('mousedown', [newPostEl], () => {\n if (emptyText) rteRef.current?.clear();\n });\n\n const t = useI18n();\n\n const handlePost = () => {\n setShowSearchResults?.(false);\n if ((!emptyText || attachments.length > 0) && attachments.every(x => !x.error)) {\n onPost({\n newPostId: id,\n value: rteRef.current?.getPlainText() || '',\n attachments: attachments || [],\n recipients: selectedRecipients,\n username,\n clear: () => {\n rteRef.current?.clear();\n setResetPostTypeMenu(true);\n }\n });\n }\n };\n\n const handleClear = () => {\n setShowSearchResults?.(false);\n rteRef.current?.clear();\n rteRef.current?.focus();\n };\n\n useAfterInitialEffect(() => {\n if (postType === 'post') {\n rteRef.current?.focus();\n }\n if (postType !== 'private') {\n setSelectedRecipients([] as RecipientMenuItem[]);\n }\n }, [postType]);\n\n return (\n <StyledCard ref={setNewPostEl} as={StyledFeedNewPost} {...restProps}>\n <CardContent>\n {onRecipientSearch && (\n <FeedNewPostTypeMenu\n recipients={recipients || ([] as PostTypeMenuProps['recipients'])}\n onSetPostType={setPostType}\n onSelectedRecipientsUpdate={setSelectedRecipients}\n onRecipientSearch={onRecipientSearch}\n reset={resetPostTypeMenu}\n onReset={() => setResetPostTypeMenu(false)}\n />\n )}\n\n <Flex container={{ alignItems: 'start', gap: 1 }}>\n <Avatar name={fullname} size='l' imageSrc={avatarSrc} />\n\n <StyledTextAreaOverflow ref={textAreaRef}>\n <FeedRichText\n label={t('feed_new_post')}\n labelHidden\n onChange={() => {\n setEmptyText(rteRef.current?.getPlainText().trim() === '');\n resizeTextArea();\n }}\n placeholder={textAreaPlaceholder}\n autoFocus={autoFocus}\n onSubmit={handlePost}\n onFocus={() => setHasFocus(true)}\n onBlur={() => setHasFocus(false)}\n ref={rteRef}\n />\n </StyledTextAreaOverflow>\n\n {!emptyText && (\n <Button\n variant='simple'\n as={FeedButton}\n onClick={handleClear}\n icon\n label={t('feed_cancel_conversation')}\n tabIndex={-1}\n >\n <Icon name='times' />\n </Button>\n )}\n\n {onFilesAdded && (\n <Button\n variant='simple'\n as={FeedButton}\n onClick={() => {\n setShowSearchResults?.(false);\n attachmentEl?.click();\n }}\n icon\n label={\n attachments.length\n ? cap(t('attachments_count', [], { count: 1 }))\n : t('file_upload_text_multiple')\n }\n >\n <Icon name='paper-clip' />\n </Button>\n )}\n </Flex>\n\n <HiddenFileInput\n ref={setAttachmentEl}\n type='file'\n multiple\n onChange={() => {\n if (attachmentEl?.files) {\n onFilesAdded?.(Array.from(attachmentEl?.files));\n }\n }}\n // Must trick input to believe there is no value when activated so that the same file may be added consecutively.\n onClick={(event: MouseEvent) => {\n (event.target as HTMLInputElement).value = '';\n }}\n />\n\n <FeedAttachments attachments={attachments} />\n\n <ExpandCollapse collapsed={!hasFocus && emptyText && !attachments.length}>\n <Flex container={{ justify: 'end' }}>\n <Button\n variant='primary'\n disabled={(emptyText && attachments.length === 0) || attachments.some(x => x.error)}\n onClick={handlePost}\n >\n {postLabel}\n </Button>\n </Flex>\n </ExpandCollapse>\n </CardContent>\n </StyledCard>\n );\n};\n\nexport default FeedNewPost;\n"]}
|