Skip to content

Commit 50f8cbd

Browse files
committed
add PinIndicator components to team and livestream messages
1 parent 8a43857 commit 50f8cbd

File tree

6 files changed

+83
-4
lines changed

6 files changed

+83
-4
lines changed

src/components/Message/MessageLivestream.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ import {
3636
} from './hooks';
3737
import { areMessagePropsEqual } from './utils';
3838
import { MessageActions } from '../MessageActions';
39-
import { ReactionIcon, ThreadIcon, ErrorIcon } from './icons';
39+
import {
40+
ErrorIcon,
41+
PinIndicator as DefaultPinIndicator,
42+
ReactionIcon,
43+
ThreadIcon,
44+
} from './icons';
4045
import MessageTimestamp from './MessageTimestamp';
4146

4247
/**
@@ -76,6 +81,7 @@ const MessageLivestreamComponent = (props) => {
7681
t: propT,
7782
tDateTimeParser: propTDateTimeParser,
7883
MessageDeleted,
84+
PinIndicator = DefaultPinIndicator,
7985
} = props;
8086
const { t: contextT } = useContext(TranslationContext);
8187
const t = propT || contextT;
@@ -163,6 +169,11 @@ const MessageLivestreamComponent = (props) => {
163169

164170
return (
165171
<React.Fragment>
172+
{message?.pinned && (
173+
<div className="str-chat__message-livestream-pin-indicator">
174+
<PinIndicator message={message} t={t} />
175+
</div>
176+
)}
166177
<div
167178
data-testid="message-livestream"
168179
className={`str-chat__message-livestream str-chat__message-livestream--${firstGroupStyle} str-chat__message-livestream--${
@@ -421,6 +432,12 @@ MessageLivestreamComponent.propTypes = {
421432
* Defaults to and accepts same props as: [EditMessageForm](https://github.com/GetStream/stream-chat-react/blob/master/src/components/MessageInput/EditMessageForm.js)
422433
* */
423434
EditMessageInput: /** @type {PropTypes.Validator<React.FC<import("types").MessageInputProps>>} */ (PropTypes.elementType),
435+
/**
436+
* Custom UI component to override default pinned message indicator
437+
*
438+
* Defaults to and accepts same props as: [PinIndicator](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Message/icon.js)
439+
* */
440+
PinIndicator: /** @type {PropTypes.Validator<React.FC<import("types").PinIndicatorProps>>} */ (PropTypes.elementType),
424441
/**
425442
*
426443
* @deprecated Its not recommended to use this anymore. All the methods in this HOC are provided explicitly.

src/components/Message/MessageTeam.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ import {
3232
} from './hooks';
3333
import { areMessagePropsEqual, getReadByTooltipText } from './utils';
3434
import {
35+
DeliveredCheckIcon,
36+
ErrorIcon,
37+
PinIndicator as DefaultPinIndicator,
3538
ReactionIcon,
3639
ThreadIcon,
37-
ErrorIcon,
38-
DeliveredCheckIcon,
3940
} from './icons';
4041
import MessageTimestamp from './MessageTimestamp';
4142

@@ -60,6 +61,7 @@ const MessageTeam = (props) => {
6061
Avatar = DefaultAvatar,
6162
EditMessageInput = DefaultEditMessageForm,
6263
MessageDeleted,
64+
PinIndicator = DefaultPinIndicator,
6365
ReactionsList = DefaultReactionsList,
6466
ReactionSelector = DefaultReactionSelector,
6567
editing: propEditing,
@@ -162,6 +164,11 @@ const MessageTeam = (props) => {
162164

163165
return (
164166
<React.Fragment>
167+
{message?.pinned && (
168+
<div className="str-chat__message-team-pin-indicator">
169+
<PinIndicator message={message} t={t} />
170+
</div>
171+
)}
165172
<div
166173
data-testid="message-team"
167174
className={`str-chat__message-team str-chat__message-team--${firstGroupStyle} str-chat__message-team--${
@@ -509,6 +516,12 @@ MessageTeam.propTypes = {
509516
* Defaults to and accepts same props as: [EditMessageForm](https://github.com/GetStream/stream-chat-react/blob/master/src/components/MessageInput/EditMessageForm.js)
510517
* */
511518
EditMessageInput: /** @type {PropTypes.Validator<React.FC<import("types").MessageInputProps>>} */ (PropTypes.elementType),
519+
/**
520+
* Custom UI component to override default pinned message indicator
521+
*
522+
* Defaults to and accepts same props as: [PinIndicator](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Message/icon.js)
523+
* */
524+
PinIndicator: /** @type {PropTypes.Validator<React.FC<import("types").PinIndicatorProps>>} */ (PropTypes.elementType),
512525
/**
513526
*
514527
* @deprecated Its not recommended to use this anymore. All the methods in this HOC are provided explicitly.

src/components/Message/icons.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,36 @@ export const ErrorIcon = () => (
5252
/>
5353
</svg>
5454
);
55+
56+
export const PinIcon = () => (
57+
<svg
58+
width="14"
59+
height="13"
60+
viewBox="0 0 14 13"
61+
xmlns="http://www.w3.org/2000/svg"
62+
>
63+
<path
64+
d="M13.3518 6.686L6.75251 0.0866699L5.80984 1.02867L6.75318 1.972V1.97334L3.45318 5.272L3.45251 5.27334L2.50984 4.32934L1.56718 5.27267L4.39584 8.10067L0.624512 11.8713L1.56718 12.814L5.33851 9.04334L8.16718 11.8713L9.10984 10.9293L8.16718 9.986L11.4672 6.686L12.4098 7.62867L13.3518 6.686ZM7.22451 9.04267L7.22385 9.04334L4.39584 6.21467L7.69518 2.91467L10.5232 5.74267L7.22451 9.04267Z"
65+
fillRule="evenodd"
66+
/>
67+
</svg>
68+
);
69+
70+
/** @type {React.FC<import("types").PinIndicatorProps>} */
71+
export const PinIndicator = ({ message, t }) => {
72+
if (!message || !t) return null;
73+
74+
return (
75+
<div style={{ display: 'flex', alignItems: 'center' }}>
76+
<PinIcon />
77+
<div
78+
style={{
79+
marginBottom: '0',
80+
marginTop: '0',
81+
marginLeft: '8px',
82+
fontSize: '14px',
83+
}}
84+
>{`${t('Pinned by')} ${message.name || message.id}`}</div>
85+
</div>
86+
);
87+
};

src/styles/MessageLivestream.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
border: 1px solid rgba(0, 0, 0, 0);
88
position: relative;
99

10+
&-pin-indicator {
11+
padding-left: 10px;
12+
}
13+
1014
&-left {
1115
width: 30px;
1216
.str-chat__avatar {

src/styles/MessageTeam.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
margin-right: 0;
1515
}
1616

17+
&-pin-indicator {
18+
padding-left: 40px;
19+
}
20+
1721
&-actions {
1822
$actionsBorderColor: #e0e0e0;
1923
$actionsHeight: 24px;

types/index.d.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,14 @@ export interface MessageUIComponentProps
956956
additionalMessageInputProps?: object;
957957
initialMessage?: boolean;
958958
EditMessageInput?: React.FC<MessageInputProps>;
959+
PinIndicator?: React.FC<PinIndicatorProps>;
959960
}
961+
962+
export type PinIndicatorProps = {
963+
message?: StreamChatReactMessageResponse;
964+
t?: i18next.TFunction;
965+
};
966+
960967
export interface MessageDeletedProps extends TranslationContextValue {
961968
/** The message object */
962969
message: Client.MessageResponse;
@@ -1418,7 +1425,8 @@ export class MessageTeam extends React.PureComponent<
14181425
MessageTeamState
14191426
> {}
14201427

1421-
export interface MessageSimpleProps extends MessageUIComponentProps {}
1428+
export interface MessageSimpleProps
1429+
extends Omit<MessageUIComponentProps, 'PinIndicator'> {}
14221430
export interface MessageTimestampProps {
14231431
customClass?: string;
14241432
message?: Client.MessageResponse;

0 commit comments

Comments
 (0)