@soul-refiner/design-system 0.1.13 → 0.1.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soul-refiner/design-system",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "main": "src/index.ts",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -0,0 +1,94 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+ import { Close } from 'icons';
4
+
5
+ type BadgeColor = 'blue' | 'red' | 'green' | 'purple' | 'orange';
6
+
7
+ const colorLookup: Record<
8
+ BadgeColor,
9
+ Record<'primary' | 'secondary' | 'bg', string>
10
+ > = {
11
+ blue: {
12
+ primary: 'var(--color-hue-blue-1)',
13
+ secondary: 'var(--color-hue-blue-2)',
14
+ bg: 'var(--color-hue-blue-3)',
15
+ },
16
+ green: {
17
+ primary: 'var(--color-green-3)',
18
+ secondary: 'var(--color-green-8)',
19
+ bg: 'var(--color-green-10)',
20
+ },
21
+ orange: {
22
+ primary: 'var(--color-hue-orange-1)',
23
+ secondary: 'var(--color-hue-orange-2)',
24
+ bg: 'var(--color-hue-orange-3)',
25
+ },
26
+ purple: {
27
+ primary: 'var(--color-hue-purple-1)',
28
+ secondary: 'var(--color-hue-purple-2)',
29
+ bg: 'var(--color-hue-purple-3)',
30
+ },
31
+ red: {
32
+ primary: 'var(--color-red-4)',
33
+ secondary: 'var(--color-red-9)',
34
+ bg: 'var(--color-red-10)',
35
+ },
36
+ };
37
+
38
+ export interface BadgeProps extends React.PropsWithChildren {
39
+ color: BadgeColor;
40
+ dot?: boolean;
41
+ onDismiss?: () => void;
42
+ }
43
+
44
+ export const Badge = ({ children, color, dot, onDismiss }: BadgeProps) => {
45
+ const bgColor = colorLookup[color].bg;
46
+ const textColor = colorLookup[color].primary;
47
+ const borderColor = colorLookup[color].secondary;
48
+
49
+ return (
50
+ <Component
51
+ $bgColor={bgColor}
52
+ $borderColor={borderColor}
53
+ $textColor={textColor}
54
+ >
55
+ {dot && <Dot $secondaryColor={textColor} />}
56
+ {children}
57
+ {onDismiss && <Close size={16} />}
58
+ </Component>
59
+ );
60
+ };
61
+
62
+ const Component = styled.div<{
63
+ $bgColor: string;
64
+ $borderColor: string;
65
+ $textColor: string;
66
+ }>`
67
+ display: flex;
68
+ align-items: center;
69
+ gap: 8px;
70
+ padding: 1px 7px;
71
+ border-radius: 32px;
72
+ background-color: ${({ $bgColor }) => $bgColor};
73
+ color: ${({ $textColor }) => $textColor};
74
+ border: 1px solid ${({ $borderColor }) => $borderColor};
75
+ font-family: Inter;
76
+ font-size: 12px;
77
+ font-weight: 500;
78
+ line-height: 16px;
79
+ user-select: none;
80
+
81
+ svg {
82
+ fill: currentColor;
83
+ cursor: pointer;
84
+ }
85
+ `;
86
+
87
+ const Dot = styled.div<{
88
+ $secondaryColor: string;
89
+ }>`
90
+ width: 8px;
91
+ height: 8px;
92
+ border-radius: 50%;
93
+ background-color: ${({ $secondaryColor }) => $secondaryColor};
94
+ `;
@@ -0,0 +1,2 @@
1
+ export { Badge } from './badge';
2
+ export type { BadgeProps } from './badge';
@@ -0,0 +1,130 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+ import { Close } from 'icons';
4
+
5
+ type ChipColor =
6
+ | 'grey'
7
+ | 'blue'
8
+ | 'red'
9
+ | 'green'
10
+ | 'turquoise'
11
+ | 'purple'
12
+ | 'yellow'
13
+ | 'orange'
14
+ | 'primary-blue';
15
+ type ChipSize = 'small' | 'large';
16
+
17
+ const colorLookup: Record<
18
+ ChipColor,
19
+ Record<'primary' | 'secondary' | 'text', string>
20
+ > = {
21
+ 'primary-blue': {
22
+ primary: 'var(--color-primary-blue-2)',
23
+ secondary: 'var(--color-white)',
24
+ text: 'var(--color-white)',
25
+ },
26
+ blue: {
27
+ primary: 'var(--color-blue-9)',
28
+ secondary: 'var(--color-blue-5)',
29
+ text: 'var(--color-grey-4)',
30
+ },
31
+ green: {
32
+ primary: 'var(--color-green-9)',
33
+ secondary: 'var(--color-green-5)',
34
+ text: 'var(--color-grey-4)',
35
+ },
36
+ grey: {
37
+ primary: 'var(--color-grey-9)',
38
+ secondary: 'var(--color-grey-4)',
39
+ text: 'var(--color-grey-4)',
40
+ },
41
+ orange: {
42
+ primary: 'var(--color-orange-9)',
43
+ secondary: 'var(--color-orange-5)',
44
+ text: 'var(--color-grey-4)',
45
+ },
46
+ purple: {
47
+ primary: 'var(--color-purple-9)',
48
+ secondary: 'var(--color-purple-5)',
49
+ text: 'var(--color-grey-4)',
50
+ },
51
+ red: {
52
+ primary: 'var(--color-red-9)',
53
+ secondary: 'var(--color-red-5)',
54
+ text: 'var(--color-grey-4)',
55
+ },
56
+ turquoise: {
57
+ primary: 'var(--color-turquoise-9)',
58
+ secondary: 'var(--color-turquoise-5)',
59
+ text: 'var(--color-grey-4)',
60
+ },
61
+ yellow: {
62
+ primary: 'var(--color-yellow-9)',
63
+ secondary: 'var(--color-yellow-9)',
64
+ text: 'var(--color-grey-4)',
65
+ },
66
+ };
67
+
68
+ export interface ChipProps extends React.PropsWithChildren {
69
+ color: ChipColor;
70
+ dot?: boolean;
71
+ onDismiss?: () => void;
72
+ size: ChipSize;
73
+ }
74
+
75
+ export const Chip = ({ children, color, dot, onDismiss, size }: ChipProps) => {
76
+ const bgColor = colorLookup[color].primary;
77
+ const textColor = colorLookup[color].text;
78
+ const dotColor = colorLookup[color].secondary;
79
+
80
+ return (
81
+ <Component $bgColor={bgColor} $size={size} $textColor={textColor}>
82
+ {dot && <Dot $secondaryColor={dotColor} />}
83
+ {children}
84
+ {onDismiss && <Close size={16} />}
85
+ </Component>
86
+ );
87
+ };
88
+
89
+ const Component = styled.div<{
90
+ $bgColor: string;
91
+ $size: ChipSize;
92
+ $textColor: string;
93
+ }>`
94
+ display: flex;
95
+ align-items: center;
96
+ gap: 8px;
97
+ border-radius: 32px;
98
+ background-color: ${({ $bgColor }) => $bgColor};
99
+ color: ${({ $textColor }) => $textColor};
100
+ font-family: Inter;
101
+ user-select: none;
102
+
103
+ svg {
104
+ fill: currentColor;
105
+ cursor: pointer;
106
+ }
107
+ ${({ $size }) =>
108
+ $size === 'small'
109
+ ? // small
110
+ `
111
+ padding: 4px 16px;
112
+ font-size: 12px;
113
+ line-height: 16px;
114
+ font-weight: 500;`
115
+ : // large
116
+ `
117
+ padding: 8px 16px;
118
+ font-size: 14px;
119
+ line-height: 20px;
120
+ font-weight: 600;`}
121
+ `;
122
+
123
+ const Dot = styled.div<{
124
+ $secondaryColor: string;
125
+ }>`
126
+ width: 8px;
127
+ height: 8px;
128
+ border-radius: 50%;
129
+ background-color: ${({ $secondaryColor }) => $secondaryColor};
130
+ `;
@@ -0,0 +1,2 @@
1
+ export { Chip } from './chip';
2
+ export type { ChipProps } from './chip';
@@ -1,3 +1,5 @@
1
+ export { Badge } from './badge';
2
+ export type { BadgeProps } from './badge';
1
3
  export { Banner } from './banner';
2
4
  export type { BannerProps } from './banner';
3
5
  export { Loader } from './loader';
@@ -0,0 +1,243 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+ import Picker from '@emoji-mart/react';
4
+ import { Avatar, Box, BoxProps, P } from 'components';
5
+ import emojis from 'emoji/emojis.json';
6
+ import { ThumbsUp, Comment as CommentIcon } from 'icons';
7
+ import { abbrTimeBeforeDate } from './helpers';
8
+ import { Styles } from 'common';
9
+
10
+ export interface CommentProps {
11
+ content: string;
12
+ createdDate: Date;
13
+ onCommentClick: () => void;
14
+ onReact: (reaction: string) => void;
15
+ reactions?: Record<string, number>;
16
+ replies?: CommentProps[];
17
+ userImageUri: string;
18
+ userName: string;
19
+ userReactions?: string[];
20
+ userProfileUri: string;
21
+ }
22
+
23
+ export const Comment = ({
24
+ content,
25
+ createdDate,
26
+ onCommentClick,
27
+ onReact,
28
+ reactions,
29
+ replies,
30
+ userImageUri,
31
+ userName,
32
+ userReactions,
33
+ userProfileUri,
34
+ }: CommentProps) => {
35
+ const id = React.useId();
36
+ const [showPicker, setShowPicker] = React.useState(false);
37
+
38
+ const handleReaction = ({ native }: Record<string, string>) => {
39
+ onReact(native);
40
+ setShowPicker(false);
41
+ };
42
+
43
+ const handlePicker = (event: React.MouseEvent) => {
44
+ event.stopPropagation();
45
+ setShowPicker((prev) => !prev);
46
+ };
47
+
48
+ const handlePickerBlur = () => setShowPicker(false);
49
+
50
+ const createdTime = abbrTimeBeforeDate(createdDate, { message: true });
51
+
52
+ const reactionElements =
53
+ reactions &&
54
+ Object.entries(reactions)
55
+ .sort((a, b) => (a[1] < b[1] ? 1 : -1))
56
+ .map((reaction) => (
57
+ <Reaction
58
+ key={id + reaction[0]}
59
+ $align="center"
60
+ $dir="row"
61
+ $gap={5}
62
+ $userSelected={userReactions?.includes(reaction[0])}
63
+ >
64
+ {reaction[0]}
65
+ <P $bold $fontSize={10} $lineHeight={14}>
66
+ {reaction[1]}
67
+ </P>
68
+ </Reaction>
69
+ ));
70
+
71
+ const hasReplies = !!replies?.length && replies.length > 0;
72
+ const replyElements =
73
+ hasReplies &&
74
+ replies.map((reply, index) => (
75
+ <ReplyWrapper
76
+ $isNotLastReply={index !== replies.length - 1}
77
+ key={id + reply.createdDate.getTime().toString(36)}
78
+ >
79
+ <Comment {...reply} />
80
+ <ReplyIndicator />
81
+ </ReplyWrapper>
82
+ ));
83
+
84
+ return (
85
+ <Wrapper>
86
+ <Avatar href={userProfileUri} image={userImageUri} size={32} />
87
+ <Box $flex={1} $dir="column">
88
+ <ContentWrapper $hasReplies={hasReplies}>
89
+ <CommentBox>
90
+ <P $bold $color="grey-2" $fontSize={14} $lineHeight={20}>
91
+ {userName}
92
+ </P>
93
+ <P sx="letter-spacing: -0.176px;">{content}</P>
94
+ </CommentBox>
95
+ <Box
96
+ $align="flex-start"
97
+ $dir="row"
98
+ $display="flex"
99
+ $gap={16}
100
+ sx="margin: 8px 0px; position: relative;"
101
+ >
102
+ <ThumbsUp
103
+ color="primary-blue-2"
104
+ onClick={handlePicker}
105
+ size={24}
106
+ sx="border-radius: 50%; cursor: pointer; flex-shrink: 0;"
107
+ />
108
+ <CommentIcon
109
+ color="primary-blue-2"
110
+ onClick={onCommentClick}
111
+ size={24}
112
+ sx="border-radius: 50%; cursor: pointer; flex-shrink: 0;"
113
+ />
114
+ <P $color="grey-7">•</P>
115
+ <P
116
+ $color="grey-4"
117
+ $fontSize={12}
118
+ $lineHeight={24}
119
+ sx="flex-shrink: 0;"
120
+ >
121
+ {createdTime}
122
+ </P>
123
+ <Box
124
+ $display="flex"
125
+ $flow="row wrap"
126
+ $gap={6}
127
+ sx="max-width: calc(100% - 190px); margin-left: auto;"
128
+ >
129
+ {reactionElements}
130
+ </Box>
131
+ {showPicker && (
132
+ <PickerWrapper>
133
+ <Picker
134
+ data={emojis}
135
+ onEmojiSelect={handleReaction}
136
+ onClickOutside={handlePickerBlur}
137
+ maxFrequentRows={1}
138
+ navPosition="none"
139
+ previewPosition="none"
140
+ perLine={9}
141
+ theme="auto"
142
+ />
143
+ </PickerWrapper>
144
+ )}
145
+ </Box>
146
+ </ContentWrapper>
147
+ {hasReplies && <RepliesWrapper>{replyElements}</RepliesWrapper>}
148
+ </Box>
149
+ </Wrapper>
150
+ );
151
+ };
152
+
153
+ const Wrapper = styled.div`
154
+ max-width: 700px;
155
+ display: flex;
156
+ flex-direction: row;
157
+ align-items: flex-start;
158
+ gap: 12px;
159
+ justify-content: space-between;
160
+ position: relative;
161
+ `;
162
+
163
+ const ContentWrapper = styled.div<{
164
+ $hasReplies: boolean;
165
+ }>`
166
+ display: flex;
167
+ flex-direction: column;
168
+ ${({ $hasReplies }) =>
169
+ $hasReplies
170
+ ? `
171
+ position: relative;
172
+
173
+ &::before {
174
+ content: "";
175
+ position: absolute;
176
+ top: 32px;
177
+ left: -28px;
178
+ height: calc(100% - 12px);
179
+ border-left: 2px solid var(--color-grey-9);
180
+ }`
181
+ : ''}
182
+ `;
183
+
184
+ const CommentBox = styled.div`
185
+ padding: 16px;
186
+ display: flex;
187
+ flex-direction: column;
188
+ gap: 8px;
189
+ background-color: var(--color-grey-10);
190
+ border-radius: 16px;
191
+ `;
192
+
193
+ const PickerWrapper = styled.div`
194
+ position: absolute;
195
+ z-index: 5;
196
+ `;
197
+
198
+ const Reaction = styled.div<BoxProps & { $userSelected?: boolean }>`
199
+ ${Styles.flex}
200
+ display: flex;
201
+ padding: 2px 6px;
202
+ border-radius: 12px;
203
+ ${({ $userSelected }) =>
204
+ $userSelected
205
+ ? `
206
+ background-color: var(--color-primary-blue-4);
207
+ border: 1px solid var(--color-primary-blue-3);
208
+ `
209
+ : ''}
210
+ `;
211
+
212
+ const RepliesWrapper = styled.div`
213
+ padding-top: 12px;
214
+ `;
215
+
216
+ const ReplyWrapper = styled.div<{
217
+ $isNotLastReply?: boolean;
218
+ }>`
219
+ position: relative;
220
+ ${({ $isNotLastReply }) =>
221
+ $isNotLastReply
222
+ ? `
223
+ &::before {
224
+ content: "";
225
+ position: absolute;
226
+ left: -28px;
227
+ height: 100%;
228
+ border-left: 2px solid var(--color-grey-9);
229
+ }`
230
+ : ''}
231
+ `;
232
+
233
+ const ReplyIndicator = styled.div`
234
+ position: absolute;
235
+ top: 0;
236
+ left: -28px;
237
+ width: 28px;
238
+ height: 16px;
239
+ border-bottom-left-radius: 16px;
240
+ border: 2px solid var(--color-grey-9);
241
+ border-top: none;
242
+ border-right: none;
243
+ `;
@@ -0,0 +1,35 @@
1
+ type Options = {
2
+ message?: boolean;
3
+ };
4
+
5
+ export const abbrTimeBeforeDate = (date: Date, options?: Options) => {
6
+ const { message } = options ?? {};
7
+ const now = new Date();
8
+ const diff = now.getTime() - date.getTime();
9
+
10
+ if (diff < 60000) {
11
+ // under 1 min
12
+ if (message) return 'Now';
13
+ return 'Just now';
14
+ } else if (diff < 3600000) {
15
+ // under one hour
16
+ const minutes = Math.floor(diff / 60000);
17
+ if (message) return `${minutes}m`;
18
+ return `${minutes} ${minutes === 1 ? 'min' : 'mins'}`;
19
+ } else if (diff < 86400000) {
20
+ // under one day
21
+ const hours = Math.floor(diff / 3600000);
22
+ if (message) return `${hours}h`;
23
+ return `${hours} ${hours === 1 ? 'hour' : 'hours'}`;
24
+ } else if (diff < 604800000) {
25
+ // under one week
26
+ const days = Math.floor(diff / 86400000);
27
+ if (message) return `${days}d`;
28
+ return `${days} ${days === 1 ? 'day' : 'days'}`;
29
+ } else {
30
+ if (message) {
31
+ return `${Math.floor(diff / 604800000)}w`;
32
+ }
33
+ return date.toDateString().slice(4);
34
+ }
35
+ };
@@ -0,0 +1,2 @@
1
+ export { Comment } from './comment';
2
+ export type { CommentProps } from './comment';
@@ -1,3 +1,5 @@
1
+ export { Comment } from './comment';
2
+ export type { CommentProps } from './comment';
1
3
  export { Message } from './message';
2
4
  export type { MessageProps } from './message';
3
5
  export { Modal } from './modal';