@soul-refiner/design-system 0.2.39 → 0.2.41

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.
@@ -3,11 +3,11 @@ export interface CommentProps {
3
3
  content: string;
4
4
  createdDate: Date;
5
5
  hasMoreReplies?: boolean;
6
- onComment: (comment: string) => void;
6
+ onComment: (comment: string, id?: string) => void;
7
7
  onReact: (reaction: string) => void;
8
8
  onShowReplies?: () => void;
9
9
  reactions?: Record<string, number>;
10
- replies?: CommentProps[];
10
+ replies?: React.ReactElement[];
11
11
  userImageUri: string;
12
12
  userName: string;
13
13
  userReactions?: string[];
@@ -14,6 +14,7 @@ export const Comment = ({ content, createdDate, hasMoreReplies, onComment, onRea
14
14
  const [toggleShowCommentInput, setShowCommentInput] = React.useState(false);
15
15
  const [toggleShowReplies, setShowReplies] = React.useState(false);
16
16
  const [comment, setComment] = React.useState('');
17
+ const _replies = React.Children.toArray(replies);
17
18
  const handleCommentChange = (event) => {
18
19
  setComment(event.target.value);
19
20
  };
@@ -35,7 +36,7 @@ export const Comment = ({ content, createdDate, hasMoreReplies, onComment, onRea
35
36
  const handleToggleCommentInput = () => setShowCommentInput((prev) => !prev);
36
37
  const handleToggleReplies = () => {
37
38
  onShowReplies && onShowReplies();
38
- setShowReplies((prev) => !prev);
39
+ setShowReplies((prev) => true);
39
40
  };
40
41
  const createdTime = abbrTimeBeforeDate(createdDate);
41
42
  const reactionElements = reactions &&
@@ -44,11 +45,17 @@ export const Comment = ({ content, createdDate, hasMoreReplies, onComment, onRea
44
45
  .map((reaction) => (React.createElement(Reaction, { key: id + reaction[0], "$align": "center", "$dir": "row", "$gap": 5, "$userSelected": userReactions?.includes(reaction[0]) },
45
46
  reaction[0],
46
47
  React.createElement(P, { "$bold": true, "$fontSize": 10, "$lineHeight": 14 }, reaction[1]))));
47
- const hasReplies = !!replies?.length && replies.length > 0;
48
+ const hasReplies = !!_replies?.length && _replies.length > 0;
48
49
  const replyElements = hasReplies &&
49
- replies.map((reply, index) => (React.createElement(ReplyWrapper, { "$isNotLastReply": index !== replies.length - 1, key: id + reply.createdDate.getTime().toString(36) },
50
- React.createElement(Comment, { ...reply }),
51
- React.createElement(ReplyIndicator, null))));
50
+ _replies.map((reply, index) => {
51
+ if (!React.isValidElement(reply))
52
+ return null;
53
+ const key = reply.props?.id;
54
+ const hasLine = index !== _replies.length - 1 || hasMoreReplies;
55
+ return (React.createElement(ReplyWrapper, { "$hasLine": hasLine, key: key },
56
+ reply,
57
+ React.createElement(ReplyIndicator, null)));
58
+ });
52
59
  return (React.createElement(Wrapper, null,
53
60
  React.createElement(Avatar, { href: userProfileUri, image: userImageUri, size: 32 }),
54
61
  React.createElement(Box, { "$flex": 1, "$dir": "column" },
@@ -65,14 +72,14 @@ export const Comment = ({ content, createdDate, hasMoreReplies, onComment, onRea
65
72
  showPicker && (React.createElement(PickerWrapper, null,
66
73
  React.createElement(Picker, { data: emojis, onEmojiSelect: handleReaction, onClickOutside: handlePickerBlur, maxFrequentRows: 1, navPosition: "none", previewPosition: "none", perLine: 9, theme: "auto" }))))),
67
74
  hasReplies && toggleShowReplies && (React.createElement(RepliesWrapper, null, replyElements)),
68
- hasMoreReplies ||
69
- (!toggleShowReplies && hasReplies && (React.createElement(RepliesWrapper, null,
70
- React.createElement(ReplyWrapper, { "$isNotLastReply": false },
71
- React.createElement(Button, { onClick: handleToggleReplies, size: "small", sx: "color: var(--color-grey-3);", type: "text" },
72
- "show ",
73
- replies && replies.length ? 'more' : '',
74
- " replies"),
75
- React.createElement(ReplyIndicator, null))))),
75
+ !toggleShowReplies && !hasMoreReplies && hasReplies && (React.createElement(RepliesWrapper, null,
76
+ React.createElement(ReplyWrapper, { "$hasLine": false },
77
+ React.createElement(Button, { onClick: handleToggleReplies, size: "small", sx: "color: var(--color-grey-3);", type: "text" }, "show replies"),
78
+ React.createElement(ReplyIndicator, null)))),
79
+ hasMoreReplies && (React.createElement(RepliesWrapper, null,
80
+ React.createElement(ReplyWrapper, { "$hasLine": false },
81
+ React.createElement(Button, { onClick: handleToggleReplies, size: "small", sx: "color: var(--color-grey-3);", type: "text" }, "show more replies"),
82
+ React.createElement(ReplyIndicator, null)))),
76
83
  toggleShowCommentInput && (React.createElement(CommentWrapper, { onSubmit: handleCommentSubmit },
77
84
  React.createElement(TextInput, { bg: "var(--color-grey-10)", placeholder: "Write a reply", onChange: handleCommentChange, value: comment }))))));
78
85
  };
@@ -131,7 +138,7 @@ const RepliesWrapper = styled.div `
131
138
  `;
132
139
  const ReplyWrapper = styled.div `
133
140
  position: relative;
134
- ${({ $isNotLastReply }) => $isNotLastReply
141
+ ${({ $hasLine }) => $hasLine
135
142
  ? `
136
143
  &::before {
137
144
  content: "";
@@ -144,10 +151,10 @@ const ReplyWrapper = styled.div `
144
151
  `;
145
152
  const ReplyIndicator = styled.div `
146
153
  position: absolute;
147
- top: 0;
154
+ top: -12px;
148
155
  left: -28px;
149
156
  width: 28px;
150
- height: 16px;
157
+ height: 32px;
151
158
  border-bottom-left-radius: 16px;
152
159
  border: 2px solid var(--color-grey-9);
153
160
  border-top: none;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soul-refiner/design-system",
3
- "version": "0.2.39",
3
+ "version": "0.2.41",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "publishConfig": {