@soul-refiner/design-system 0.2.30 → 0.2.31

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.
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  export interface CommentProps {
3
3
  content: string;
4
4
  createdDate: Date;
5
- onCommentClick: () => void;
5
+ onComment: (comment: string) => void;
6
6
  onReact: (reaction: string) => void;
7
7
  reactions?: Record<string, number>;
8
8
  replies?: CommentProps[];
@@ -11,4 +11,4 @@ export interface CommentProps {
11
11
  userReactions?: string[];
12
12
  userProfileUri: string;
13
13
  }
14
- export declare const Comment: ({ content, createdDate, onCommentClick, onReact, reactions, replies, userImageUri, userName, userReactions, userProfileUri, }: CommentProps) => React.JSX.Element;
14
+ export declare const Comment: ({ content, createdDate, onComment, onReact, reactions, replies, userImageUri, userName, userReactions, userProfileUri, }: CommentProps) => React.JSX.Element;
@@ -2,14 +2,25 @@
2
2
  import React from 'react';
3
3
  import styled from 'styled-components';
4
4
  import Picker from '@emoji-mart/react';
5
- import { Avatar, Box, P } from '../../';
5
+ import { Avatar, Box, P, TextInput } from '../../';
6
6
  import emojis from '../../../emoji/emojis.json';
7
7
  import { ThumbsUp, Comment as CommentIcon } from '../../../icons';
8
8
  import { abbrTimeBeforeDate } from './helpers';
9
9
  import { Styles } from '../../../common';
10
- export const Comment = ({ content, createdDate, onCommentClick, onReact, reactions, replies, userImageUri, userName, userReactions, userProfileUri, }) => {
10
+ export const Comment = ({ content, createdDate, onComment, onReact, reactions, replies, userImageUri, userName, userReactions, userProfileUri, }) => {
11
11
  const id = React.useId();
12
12
  const [showPicker, setShowPicker] = React.useState(false);
13
+ const [toggleShowComment, setToggleShowComment] = React.useState(false);
14
+ const [comment, setComment] = React.useState('');
15
+ const handleCommentChange = (event) => {
16
+ setComment(event.target.value);
17
+ };
18
+ const handleCommentSubmit = (event) => {
19
+ event.stopPropagation();
20
+ event.preventDefault();
21
+ onComment(comment);
22
+ setComment('');
23
+ };
13
24
  const handleReaction = ({ native }) => {
14
25
  onReact(native);
15
26
  setShowPicker(false);
@@ -19,7 +30,8 @@ export const Comment = ({ content, createdDate, onCommentClick, onReact, reactio
19
30
  setShowPicker((prev) => !prev);
20
31
  };
21
32
  const handlePickerBlur = () => setShowPicker(false);
22
- const createdTime = abbrTimeBeforeDate(createdDate, { message: true });
33
+ const handleToggleShowComment = () => setToggleShowComment((prev) => !prev);
34
+ const createdTime = abbrTimeBeforeDate(createdDate);
23
35
  const reactionElements = reactions &&
24
36
  Object.entries(reactions)
25
37
  .sort((a, b) => (a[1] < b[1] ? 1 : -1))
@@ -40,13 +52,15 @@ export const Comment = ({ content, createdDate, onCommentClick, onReact, reactio
40
52
  React.createElement(P, { sx: "letter-spacing: -0.176px;" }, content)),
41
53
  React.createElement(Box, { "$align": "flex-start", "$dir": "row", "$display": "flex", "$gap": 16, sx: "margin: 8px 0px; position: relative;" },
42
54
  React.createElement(ThumbsUp, { color: "primary-blue-2", onClick: handlePicker, size: 24, sx: "border-radius: 50%; cursor: pointer; flex-shrink: 0;" }),
43
- React.createElement(CommentIcon, { color: "primary-blue-2", onClick: onCommentClick, size: 24, sx: "border-radius: 50%; cursor: pointer; flex-shrink: 0;" }),
55
+ React.createElement(CommentIcon, { color: "primary-blue-2", onClick: handleToggleShowComment, size: 24, sx: "border-radius: 50%; cursor: pointer; flex-shrink: 0;" }),
44
56
  React.createElement(P, { "$color": "grey-7" }, "\u2022"),
45
57
  React.createElement(P, { "$color": "grey-4", "$fontSize": 12, "$lineHeight": 24, sx: "flex-shrink: 0;" }, createdTime),
46
58
  React.createElement(Box, { "$display": "flex", "$flow": "row wrap", "$gap": 6, sx: "max-width: calc(100% - 190px); margin-left: auto;" }, reactionElements),
47
59
  showPicker && (React.createElement(PickerWrapper, null,
48
60
  React.createElement(Picker, { data: emojis, onEmojiSelect: handleReaction, onClickOutside: handlePickerBlur, maxFrequentRows: 1, navPosition: "none", previewPosition: "none", perLine: 9, theme: "auto" }))))),
49
- hasReplies && React.createElement(RepliesWrapper, null, replyElements))));
61
+ hasReplies && React.createElement(RepliesWrapper, null, replyElements),
62
+ toggleShowComment && (React.createElement(CommentWrapper, { onSubmit: handleCommentSubmit },
63
+ React.createElement(TextInput, { bg: "var(--color-grey-10)", placeholder: "Write a reply", onChange: handleCommentChange, value: comment }))))));
50
64
  };
51
65
  const Wrapper = styled.div `
52
66
  max-width: 700px;
@@ -125,3 +139,9 @@ const ReplyIndicator = styled.div `
125
139
  border-top: none;
126
140
  border-right: none;
127
141
  `;
142
+ const CommentWrapper = styled.form `
143
+ label > div {
144
+ box-shadow: var(--elevation-6);
145
+ border-radius: 16px;
146
+ }
147
+ `;
@@ -1,5 +1 @@
1
- type Options = {
2
- message?: boolean;
3
- };
4
- export declare const abbrTimeBeforeDate: (date: Date, options?: Options) => string;
5
- export {};
1
+ export declare const abbrTimeBeforeDate: (date: Date) => string;
@@ -1,38 +1,26 @@
1
- export const abbrTimeBeforeDate = (date, options) => {
2
- const { message } = options ?? {};
1
+ export const abbrTimeBeforeDate = (date) => {
3
2
  const now = new Date();
4
3
  const diff = now.getTime() - date.getTime();
5
4
  if (diff < 60000) {
6
5
  // under 1 min
7
- if (message)
8
- return 'Now';
9
- return 'Just now';
6
+ return 'Now';
10
7
  }
11
8
  else if (diff < 3600000) {
12
9
  // under one hour
13
10
  const minutes = Math.floor(diff / 60000);
14
- if (message)
15
- return `${minutes}m`;
16
- return `${minutes} ${minutes === 1 ? 'min' : 'mins'}`;
11
+ return `${minutes}m`;
17
12
  }
18
13
  else if (diff < 86400000) {
19
14
  // under one day
20
15
  const hours = Math.floor(diff / 3600000);
21
- if (message)
22
- return `${hours}h`;
23
- return `${hours} ${hours === 1 ? 'hour' : 'hours'}`;
16
+ return `${hours}h`;
24
17
  }
25
18
  else if (diff < 604800000) {
26
19
  // under one week
27
20
  const days = Math.floor(diff / 86400000);
28
- if (message)
29
- return `${days}d`;
30
- return `${days} ${days === 1 ? 'day' : 'days'}`;
21
+ return `${days}d`;
31
22
  }
32
23
  else {
33
- if (message) {
34
- return `${Math.floor(diff / 604800000)}w`;
35
- }
36
- return date.toDateString().slice(4);
24
+ return `${Math.floor(diff / 604800000)}w`;
37
25
  }
38
26
  };
@@ -8,3 +8,5 @@ export { Message } from './message';
8
8
  export type { MessageProps } from './message';
9
9
  export { Modal } from './modal';
10
10
  export type { ModalContentProps, ModalProps } from './modal';
11
+ export { Post } from './post';
12
+ export type { PostProps } from './post';
@@ -3,3 +3,4 @@ export { Comment } from './comment';
3
3
  export { Drawer } from './drawer';
4
4
  export { Message } from './message';
5
5
  export { Modal } from './modal';
6
+ export { Post } from './post';
@@ -0,0 +1 @@
1
+ export declare const abbrTimeBeforeDate: (date: Date) => string;
@@ -0,0 +1,26 @@
1
+ export const abbrTimeBeforeDate = (date) => {
2
+ const now = new Date();
3
+ const diff = now.getTime() - date.getTime();
4
+ if (diff < 60000) {
5
+ // under 1 min
6
+ return 'Just now';
7
+ }
8
+ else if (diff < 3600000) {
9
+ // under one hour
10
+ const minutes = Math.floor(diff / 60000);
11
+ return `${minutes} ${minutes === 1 ? 'min' : 'mins'}`;
12
+ }
13
+ else if (diff < 86400000) {
14
+ // under one day
15
+ const hours = Math.floor(diff / 3600000);
16
+ return `${hours} ${hours === 1 ? 'hour' : 'hours'}`;
17
+ }
18
+ else if (diff < 604800000) {
19
+ // under one week
20
+ const days = Math.floor(diff / 86400000);
21
+ return `${days} ${days === 1 ? 'day' : 'days'}`;
22
+ }
23
+ else {
24
+ return date.toDateString().slice(4);
25
+ }
26
+ };
@@ -0,0 +1,2 @@
1
+ export { Post } from './post';
2
+ export type { PostProps } from './post';
@@ -0,0 +1 @@
1
+ export { Post } from './post';
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ export interface PostProps extends React.PropsWithChildren {
3
+ author: string;
4
+ authorActive?: boolean;
5
+ authorHref: string;
6
+ authorImage: string;
7
+ content: string;
8
+ createdDate: string;
9
+ images?: string[];
10
+ }
11
+ export declare const Post: ({ author, authorActive, authorHref, authorImage, children, content, createdDate, images, }: PostProps) => React.JSX.Element;
@@ -0,0 +1,104 @@
1
+ 'use client';
2
+ import React from 'react';
3
+ import styled from 'styled-components';
4
+ import { Avatar, H, P, TextInput } from '../../';
5
+ import { abbrTimeBeforeDate } from './helpers';
6
+ export const Post = ({ author, authorActive, authorHref, authorImage, children, content, createdDate, images, }) => {
7
+ const id = React.useId();
8
+ const [comment, setComment] = React.useState('');
9
+ const _comments = React.Children.toArray(children);
10
+ const handleCommentChange = (event) => {
11
+ setComment(event.target.value);
12
+ };
13
+ const subtitle = abbrTimeBeforeDate(new Date(createdDate));
14
+ return (React.createElement(Wrapper, null,
15
+ React.createElement(Header, null,
16
+ React.createElement(Avatar, { href: authorHref, image: authorImage, size: 64, status: authorActive ? 'online' : undefined, subtitle: React.createElement(P, { as: "span", sx: "vertical-align: top;", "$fontSize": 14, "$lineHeight": 20 }, subtitle), title: React.createElement(H, { as: "span", "$bold": true, "$fontSize": 18, "$lineHeight": 26 }, author), textPosition: "right" })),
17
+ React.createElement(P, { "$sx": "padding: 24px;" }, content),
18
+ !!images?.length && (React.createElement(ImagesWrapper, { "$numImages": images.length },
19
+ images.slice(0, 4).map((url, i) => (React.createElement(ImageWrapper, { key: `${id}${url.slice(0, 15)}${i}` },
20
+ React.createElement("img", { src: url, alt: "" })))),
21
+ images.length > 4 && (React.createElement(H, { as: "p", className: "more-than", "$color": "grey-10", "$fontSize": 28, "$lineHeight": 36, "$semiBold": true },
22
+ "+",
23
+ images.length - 4)))),
24
+ !!_comments.length && React.createElement(CommentWrapper, null, children),
25
+ React.createElement(CommentInputWrapper, null,
26
+ React.createElement(Avatar, { href: authorHref, image: authorImage, size: 40 }),
27
+ React.createElement(TextInput, { bg: "var(--color-grey-10)", placeholder: "Write a comment", onChange: handleCommentChange, value: comment }))));
28
+ };
29
+ const Wrapper = styled.div `
30
+ max-width: 700px;
31
+ width: 100%;
32
+ background-color: var(--color-white);
33
+ border-radius: 24px;
34
+ box-shadow: var(--elevation-7);
35
+
36
+ label > div {
37
+ box-shadow: var(--elevation-6);
38
+ border-radius: 16px;
39
+ }
40
+ `;
41
+ const Header = styled.div `
42
+ padding: 16px 24px;
43
+ display: flex;
44
+ justify-content: space-between;
45
+ align-items: flex-start;
46
+ border-bottom: 1px solid var(--color-grey-9);
47
+ `;
48
+ const ImagesWrapper = styled.div `
49
+ position: relative;
50
+ display: flex;
51
+ gap: 8px;
52
+ flex-flow: row wrap;
53
+ justify-content: space-between;
54
+
55
+ @media screen and (max-width: 532px) {
56
+ overflow-y: auto;
57
+ }
58
+
59
+ .more-than {
60
+ position: absolute;
61
+ bottom: 94px;
62
+ right: 154px;
63
+ text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
64
+ }
65
+
66
+ ${({ $numImages }) => $numImages > 1
67
+ ? `
68
+ div {
69
+ min-width: calc(50% - 4px);
70
+ max-width: calc(50% - 4px);
71
+
72
+ flex:1;
73
+ img {
74
+ object-fit: cover;
75
+ width: 100%;
76
+ height: 100%;
77
+ }
78
+ }`
79
+ : `
80
+ div > img {
81
+ object-fit: contain;
82
+ width: 100%;
83
+ height: 100%;
84
+ }
85
+ `}
86
+ `;
87
+ const ImageWrapper = styled.div `
88
+ position: relative;
89
+ aspect-ratio: 700 / 427;
90
+ flex: 1;
91
+ min-width: min(227px, 80vw);
92
+ `;
93
+ const CommentWrapper = styled.div `
94
+ padding: 24px;
95
+ display: flex;
96
+ flex-flow: column nowrap;
97
+ gap: 24px;
98
+ `;
99
+ const CommentInputWrapper = styled.div `
100
+ padding: 24px;
101
+ display: flex;
102
+ gap: 12px;
103
+ align-items: center;
104
+ `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soul-refiner/design-system",
3
- "version": "0.2.30",
3
+ "version": "0.2.31",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "publishConfig": {