@soul-refiner/design-system 0.1.10 → 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.10",
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
  `;
@@ -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 };