@soul-refiner/design-system 0.1.9 → 0.1.11

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.9",
3
+ "version": "0.1.11",
4
4
  "main": "src/index.ts",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -0,0 +1 @@
1
+ export {} from '';
@@ -0,0 +1,75 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+ import { Box, P } from 'components';
4
+
5
+ export interface ToggleProps {
6
+ checked?: boolean;
7
+ label?: string;
8
+ onChange?: () => void;
9
+ }
10
+
11
+ export const Toggle = ({ checked, label, onChange }: ToggleProps) => {
12
+ const status =
13
+ checked === undefined ? 'indeterminate' : checked ? 'checked' : 'unchecked';
14
+
15
+ return (
16
+ <Box $align="center" $gap={8}>
17
+ <Wrapper as="label" onClick={onChange}>
18
+ <Input checked={!!checked} onChange={onChange} type="checkbox" />
19
+ <Slider $status={status} />
20
+ </Wrapper>
21
+ {label && <P $fontSize={14}>{label}</P>}
22
+ </Box>
23
+ );
24
+ };
25
+
26
+ const Wrapper = styled.label`
27
+ width: 28px;
28
+ height: 16px;
29
+ position: relative;
30
+ display: inline-block;
31
+ `;
32
+
33
+ const Input = styled.input`
34
+ opacity: 0;
35
+ width: 0;
36
+ height: 0;
37
+ `;
38
+
39
+ const Slider = styled.span<{
40
+ $status: 'indeterminate' | 'checked' | 'unchecked';
41
+ }>`
42
+ position: absolute;
43
+ cursor: pointer;
44
+ top: 0px;
45
+ bottom: 0px;
46
+ right: 0px;
47
+ left: 0px;
48
+ border-radius: 18px;
49
+ ${({ $status }) =>
50
+ $status === 'checked'
51
+ ? `
52
+ background-color: var(--color-primary-blue-2);
53
+ &:before {
54
+ transform: translateX(12px);
55
+ }`
56
+ : $status === 'unchecked'
57
+ ? 'background-color: var(--color-grey-8);'
58
+ : `
59
+ background-color: var(--color-yellow-5);
60
+ &:before {
61
+ transform: translateX(6px);
62
+ }
63
+ `}
64
+
65
+ &:before {
66
+ position: absolute;
67
+ content: '';
68
+ height: 12px;
69
+ width: 12px;
70
+ left: 2px;
71
+ bottom: 2px;
72
+ background-color: var(--color-white);
73
+ border-radius: 50%;
74
+ }
75
+ `;
@@ -256,8 +256,6 @@ const Wrapper = styled.div<{
256
256
  border-radius: ${({ $size }) => ($size === 'large' ? '16px' : '8px')};
257
257
  `;
258
258
 
259
- const TextWrapper = styled.div``;
260
-
261
259
  const Input = styled.input`
262
260
  display: none;
263
261
  `;
@@ -63,6 +63,7 @@ export interface AvatarProps extends NativeProps {
63
63
  size: Size;
64
64
  status?: Status;
65
65
  subtitle?: React.ReactNode;
66
+ sx?: string;
66
67
  textPosition?: 'left' | 'right';
67
68
  title?: React.ReactNode;
68
69
  }
@@ -135,6 +136,7 @@ const Avatar = ({
135
136
  size = 64,
136
137
  status,
137
138
  subtitle,
139
+ sx,
138
140
  textPosition = 'left',
139
141
  title,
140
142
  ...rest
@@ -144,7 +146,7 @@ const Avatar = ({
144
146
  const Icon = iconReference?.[status ?? 'none'];
145
147
 
146
148
  return (
147
- <Box $align="center" $gap={18} {...rest}>
149
+ <Box $align="center" $gap={18} {...rest} sx={sx}>
148
150
  <Container as={as} $size={size} href={href}>
149
151
  {!displayDefault && (
150
152
  <img src={image ?? ''} onError={() => setDisplayDefault(true)} />
@@ -3,4 +3,5 @@ export * from './atoms';
3
3
  export * from './feedback';
4
4
  export * from './iconography';
5
5
  export * from './input';
6
+ export * from './navigation';
6
7
  export * from './surfaces';
@@ -0,0 +1,2 @@
1
+ export { Tabs } from './tabs';
2
+ export type { TabProps } from './tabs';
@@ -0,0 +1,2 @@
1
+ export { Tabs } from './tabs';
2
+ export type { TabProps } from './tabs';
@@ -0,0 +1,246 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+ import { P } from 'components';
4
+
5
+ type TabColors =
6
+ | 'blue'
7
+ | 'grey'
8
+ | 'green'
9
+ | 'mint'
10
+ | 'orange'
11
+ | 'ocean'
12
+ | 'pink'
13
+ | 'purple'
14
+ | 'red'
15
+ | 'yellow';
16
+ type TabSizes = 'small' | 'medium' | 'large';
17
+
18
+ const colorLookup: Record<TabColors, Record<'icon' | 'bg', string>> = {
19
+ blue: {
20
+ bg: 'var(--color-hue-blue-2)',
21
+ icon: 'var(--color-hue-blue-1)',
22
+ },
23
+ green: {
24
+ bg: 'var(--color-green-8)',
25
+ icon: 'var(--color-green-2)',
26
+ },
27
+ grey: {
28
+ bg: 'var(--color-grey-9)',
29
+ icon: 'var(--color-grey-7)',
30
+ },
31
+ mint: {
32
+ bg: 'var(--color-hue-mint-2)',
33
+ icon: 'var(--color-hue-mint-1)',
34
+ },
35
+ ocean: {
36
+ bg: 'var(--color-hue-ocean-2)',
37
+ icon: 'var(--color-hue-ocean-1)',
38
+ },
39
+ orange: {
40
+ bg: 'var(--color-hue-orange-2)',
41
+ icon: 'var(--color-hue-orange-1)',
42
+ },
43
+ pink: {
44
+ bg: 'var(--color-hue-pink-2)',
45
+ icon: 'var(--color-hue-pink-1)',
46
+ },
47
+ purple: {
48
+ bg: 'var(--color-hue-purple-2)',
49
+ icon: 'var(--color-hue-purple-1)',
50
+ },
51
+ red: {
52
+ bg: 'var(--color-red-9)',
53
+ icon: 'var(--color-red-3)',
54
+ },
55
+ yellow: {
56
+ bg: 'var(--color-yellow-8)',
57
+ icon: 'var(--color-yellow-3)',
58
+ },
59
+ };
60
+
61
+ export interface TabProps {
62
+ activeIndex: number;
63
+ items: {
64
+ color?: TabColors;
65
+ disabled?: boolean;
66
+ icon?: React.ReactElement;
67
+ label: string;
68
+ }[];
69
+ onChange: (index: number) => void;
70
+ size?: TabSizes;
71
+ sx?: string;
72
+ }
73
+
74
+ const Tabs = ({
75
+ activeIndex,
76
+ items,
77
+ onChange,
78
+ size = 'large',
79
+ sx,
80
+ }: TabProps) => {
81
+ const id = React.useId();
82
+
83
+ return (
84
+ <Wrapper $sx={sx}>
85
+ {items.map((item, index) => (
86
+ <Item
87
+ active={activeIndex === index}
88
+ color={item?.color}
89
+ disabled={item?.disabled}
90
+ key={id + index.toString(36)}
91
+ icon={item?.icon}
92
+ label={item.label}
93
+ onClick={() => onChange(index)}
94
+ size={size}
95
+ />
96
+ ))}
97
+ </Wrapper>
98
+ );
99
+ };
100
+
101
+ const Wrapper = styled.ul<{
102
+ $sx?: string;
103
+ }>`
104
+ display: flex;
105
+ flex-flow: row nowrap;
106
+ align-items: flex-end;
107
+ justify-content: center;
108
+ gap: 16px;
109
+ margin: 0px;
110
+ padding: 0px;
111
+
112
+ ${({ $sx }) => ($sx ? $sx : '')}
113
+ `;
114
+
115
+ export interface TabsItemProps {
116
+ active: boolean;
117
+ color?: TabColors;
118
+ disabled?: boolean;
119
+ icon?: React.ReactElement;
120
+ label: string;
121
+ onClick: () => void;
122
+ size: TabSizes;
123
+ }
124
+
125
+ const Item = ({
126
+ active,
127
+ color,
128
+ disabled,
129
+ icon,
130
+ label,
131
+ onClick,
132
+ size = 'large',
133
+ }: TabsItemProps) => {
134
+ const inputColor = disabled ? 'grey' : color ? color : 'blue';
135
+ const iconColor = colorLookup[inputColor].icon;
136
+ const bgColor = colorLookup[inputColor].bg;
137
+ const fontSize = size === 'large' ? 16 : size === 'medium' ? 14 : 12;
138
+ const lineHeight = size === 'large' ? 24 : size === 'medium' ? 20 : 16;
139
+
140
+ return (
141
+ <Li
142
+ $active={active}
143
+ $color={iconColor}
144
+ $disabled={disabled}
145
+ $hasIcon={!!icon}
146
+ $size={size}
147
+ onClick={!disabled ? onClick : undefined}
148
+ >
149
+ {icon && <IconWrapper $bg={bgColor}>{icon}</IconWrapper>}
150
+ <P $fontSize={fontSize} $lineHeight={lineHeight} $semiBold>
151
+ {label}
152
+ </P>
153
+ </Li>
154
+ );
155
+ };
156
+
157
+ const Li = styled.li<{
158
+ $active: boolean;
159
+ $color: string;
160
+ $disabled?: boolean;
161
+ $hasIcon: boolean;
162
+ $size: TabSizes;
163
+ }>`
164
+ position: relative;
165
+ display: flex;
166
+ align-items: center;
167
+ gap: 8px;
168
+ cursor: pointer;
169
+ user-select: none;
170
+
171
+ ${({ $size, $hasIcon }) =>
172
+ $hasIcon
173
+ ? 'padding: 16px 12px;'
174
+ : $size === 'small'
175
+ ? 'padding: 10px 8px;'
176
+ : $size === 'medium'
177
+ ? 'padding: 14px 10px;'
178
+ : 'padding: 22px 12px;'}
179
+
180
+ ${({ $hasIcon, $color, $disabled }) =>
181
+ $disabled
182
+ ? `
183
+ cursor: initial;
184
+ `
185
+ : $hasIcon
186
+ ? `
187
+ &:hover {
188
+ p {
189
+ color: ${$color};
190
+ }
191
+ }
192
+
193
+ div > svg {
194
+ fill: ${$color};
195
+ }`
196
+ : `
197
+ &:hover {
198
+ background-color: var(--color-grey-10);
199
+ &:after {
200
+ position: absolute;
201
+ content: '';
202
+ width: 100%;
203
+ height: 3px;
204
+ bottom: 0px;
205
+ left: 0px;
206
+ background-color: var(--color-primary-blue-3);
207
+ border-top-right-radius: 3px;
208
+ border-top-left-radius: 3px;
209
+ }
210
+ }
211
+ &:active {
212
+ background-color: var(--color-grey-9);
213
+ }`}
214
+
215
+ ${({ $active, $color, $hasIcon }) =>
216
+ $active
217
+ ? `
218
+ &:after {
219
+ position: absolute;
220
+ content: '';
221
+ width: 100%;
222
+ height: 3px;
223
+ bottom: 0px;
224
+ left: 0px;
225
+ background-color: ${
226
+ $hasIcon ? $color : 'var(--color-primary-blue-2)'
227
+ } !important;
228
+ border-top-right-radius: 3px;
229
+ border-top-left-radius: 3px;
230
+ }
231
+ `
232
+ : ''}
233
+ `;
234
+
235
+ const IconWrapper = styled.div<{
236
+ $bg: string;
237
+ }>`
238
+ padding: 8px;
239
+ border-radius: 8px;
240
+ background-color: ${({ $bg }) => $bg};
241
+ `;
242
+
243
+ Tabs.Item = Item;
244
+ Item.displayName = 'Tabs.Item';
245
+
246
+ export { Tabs };
@@ -1,2 +1,4 @@
1
+ export { Message } from './message';
2
+ export type { MessageProps } from './message';
1
3
  export { Modal } from './modal';
2
4
  export type { ModalContentProps, ModalProps } from './modal';
@@ -0,0 +1,2 @@
1
+ export { Message } from './message';
2
+ export type { MessageProps } from './message';
@@ -0,0 +1,122 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+ import { Avatar, Box, P, H } from 'components';
4
+
5
+ export interface MessageProps {
6
+ messages: {
7
+ content: string;
8
+ senderHref: string;
9
+ senderId: string;
10
+ senderName: string;
11
+ senderAvatarURI: string;
12
+ createdDate: Date;
13
+ }[];
14
+ userId: string;
15
+ }
16
+
17
+ export const Message = ({ messages, userId }: MessageProps) => {
18
+ const id = React.useId();
19
+ return (
20
+ <Box $display="flex" $dir="column" $gap={16}>
21
+ {messages.map(
22
+ (
23
+ {
24
+ content,
25
+ createdDate,
26
+ senderAvatarURI,
27
+ senderHref,
28
+ senderId,
29
+ senderName,
30
+ },
31
+ index
32
+ ) => {
33
+ const isSelf = senderId === userId;
34
+ const isFirstMessageBySender =
35
+ messages?.[index - 1]?.senderId !== senderId;
36
+
37
+ if (isSelf) {
38
+ return (
39
+ <React.Fragment key={id + index}>
40
+ {isFirstMessageBySender && (
41
+ <P
42
+ $color="grey-4"
43
+ $fontSize={12}
44
+ $lineHeight={16}
45
+ sx="margin-top: 40px; margin-left: auto;"
46
+ >
47
+ {createdDate.toLocaleDateString()}{' '}
48
+ {createdDate.toLocaleTimeString()}
49
+ </P>
50
+ )}
51
+ <Wrapper $isSelf={isSelf}>{content}</Wrapper>
52
+ </React.Fragment>
53
+ );
54
+ }
55
+
56
+ return (
57
+ <React.Fragment key={id + index}>
58
+ {isFirstMessageBySender && (
59
+ <Avatar
60
+ image={senderAvatarURI}
61
+ href={senderHref}
62
+ subtitle={
63
+ <P
64
+ as="span"
65
+ $color="blue-2"
66
+ $fontSize={12}
67
+ $lineHeight={16}
68
+ sx="vertical-align: top;"
69
+ >
70
+ {createdDate.toLocaleTimeString()}
71
+ </P>
72
+ }
73
+ size={56}
74
+ sx="margin-top: 40px;"
75
+ textPosition="right"
76
+ title={
77
+ <H
78
+ as="span"
79
+ $color="blue-2"
80
+ $fontSize={18}
81
+ $lineHeight={26}
82
+ $mediumBold
83
+ >
84
+ {senderName}
85
+ </H>
86
+ }
87
+ />
88
+ )}
89
+ <Wrapper $isSelf={isSelf}>{content}</Wrapper>
90
+ </React.Fragment>
91
+ );
92
+ }
93
+ )}
94
+ </Box>
95
+ );
96
+ };
97
+
98
+ const Wrapper = styled.div<{
99
+ $isSelf: boolean;
100
+ }>`
101
+ max-width: 552px;
102
+ padding: 16px;
103
+ border-radius: 16px;
104
+ font-family: Inter;
105
+ font-size: 14px;
106
+ line-height: 20px;
107
+ letter-spacing: -0.006em;
108
+
109
+ ${({ $isSelf }) =>
110
+ $isSelf
111
+ ? `
112
+ margin-left: auto;
113
+ color: var(--color-white);
114
+ background-color: var(--color-primary-blue-2);
115
+ border-top-right-radius: 0px;`
116
+ : `
117
+ margin-left: 68px;
118
+ margin-right: auto;
119
+ color: var(--color-grey-3);
120
+ background-color: var(--color-grey-9);
121
+ border-top-left-radius: 0px;`}
122
+ `;