@soul-refiner/design-system 0.1.5 → 0.1.7

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.5",
3
+ "version": "0.1.7",
4
4
  "main": "src/index.ts",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -0,0 +1,392 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+ import { Box, Checkbox, P } from 'components';
4
+
5
+ type NativeProps = Pick<
6
+ React.HTMLAttributes<HTMLDivElement>,
7
+ | 'children'
8
+ | 'onBlur'
9
+ | 'onBlurCapture'
10
+ | 'onClick'
11
+ | 'onChange'
12
+ | 'onMouseDown'
13
+ | 'onMouseDownCapture'
14
+ | 'onMouseEnter'
15
+ | 'onMouseLeave'
16
+ | 'onMouseOut'
17
+ | 'onMouseOver'
18
+ >;
19
+
20
+ export interface DropdownProps extends NativeProps, React.PropsWithChildren {
21
+ checkbox?: boolean;
22
+ closeOnChange?: boolean;
23
+ closeOnBlur?: boolean;
24
+ defaultValue?: string | string[];
25
+ disabled?: boolean;
26
+ hasArrow?: boolean;
27
+ maintainState?: boolean;
28
+ multiple?: boolean;
29
+ offset?: [number, number];
30
+ open?: 'right' | 'left';
31
+ options?: (Omit<DropdownOptionProps, 'selected' | 'onClick'> | 'break')[];
32
+ sx?: string;
33
+ trigger: React.ReactElement;
34
+ }
35
+
36
+ const Dropdown = ({
37
+ checkbox,
38
+ children,
39
+ closeOnChange = true,
40
+ closeOnBlur = true,
41
+ defaultValue = '',
42
+ disabled = false,
43
+ hasArrow,
44
+ maintainState = true,
45
+ multiple,
46
+ offset = [0, 16],
47
+ onChange,
48
+ open: openDirection = 'right',
49
+ options,
50
+ sx,
51
+ trigger,
52
+ ...rest
53
+ }: DropdownProps) => {
54
+ const id = React.useId();
55
+ const wrapperRef = React.useRef<HTMLDivElement>(null);
56
+ const optionsRef = React.useRef<HTMLDivElement>(null);
57
+ const [open, setOpen] = React.useState(false);
58
+ const [selected, setSelected] = React.useState(() =>
59
+ defaultValue ? defaultValue : multiple ? [] : ''
60
+ );
61
+
62
+ React.useEffect(() => {
63
+ if (disabled) {
64
+ setOpen(false);
65
+ }
66
+ }, [disabled]);
67
+
68
+ const handleOpen = () => {
69
+ if (disabled) {
70
+ return;
71
+ }
72
+ setOpen((prev) => !prev);
73
+ };
74
+
75
+ const handleBlur = (event: React.FocusEvent) => {
76
+ if (
77
+ closeOnBlur &&
78
+ wrapperRef?.current &&
79
+ !wrapperRef?.current?.contains(event.relatedTarget)
80
+ ) {
81
+ setOpen(false);
82
+ }
83
+ };
84
+
85
+ const handleChangeSingle = (event: React.MouseEvent<HTMLDivElement>) => {
86
+ event.stopPropagation();
87
+ const value =
88
+ (event.target as HTMLDivElement).getAttribute('data-value') ?? '';
89
+
90
+ if (selected !== value) {
91
+ setSelected(value);
92
+ } else {
93
+ setSelected('');
94
+ }
95
+ if (closeOnChange) {
96
+ setOpen(false);
97
+ }
98
+ if (onChange) onChange(event);
99
+ };
100
+
101
+ const handleChangeMultiple = (event: React.MouseEvent<HTMLDivElement>) => {
102
+ event.stopPropagation();
103
+ const value =
104
+ (event.target as HTMLDivElement).getAttribute('data-value') ?? '';
105
+
106
+ if (Array.isArray(selected) && selected.includes(value)) {
107
+ setSelected((prev) =>
108
+ (prev as string[]).filter((item) => item !== value)
109
+ );
110
+ } else {
111
+ setSelected((prev) => [value, ...prev]);
112
+ }
113
+ if (closeOnChange) {
114
+ setOpen(false);
115
+ }
116
+ if (onChange) onChange(event);
117
+ };
118
+
119
+ const handleChange = multiple ? handleChangeMultiple : handleChangeSingle;
120
+
121
+ const isSelected = (value: string) =>
122
+ maintainState && multiple ? selected.includes(value) : value === selected;
123
+
124
+ /**
125
+ * allow for the API to accept children as options
126
+ * or options prop
127
+ */
128
+ let dropdownOptions: React.ReactElement[] | null | undefined = null;
129
+ if (children) {
130
+ dropdownOptions = React.Children.map(children, (child) => {
131
+ let props: Partial<DropdownOptionProps> & {
132
+ label: string;
133
+ value: string;
134
+ };
135
+
136
+ if (React.isValidElement(child)) {
137
+ // eslint is okay bc deconstruction removes field
138
+ // eslint-disable-next-line
139
+ const { onClick, ...possibleProps } = child.props;
140
+ props = possibleProps;
141
+
142
+ return (
143
+ <Option
144
+ key={props.value}
145
+ checkbox={!!checkbox}
146
+ onClick={handleChange}
147
+ selected={isSelected(props.value)}
148
+ {...props}
149
+ />
150
+ );
151
+ } else {
152
+ return null;
153
+ }
154
+ });
155
+ }
156
+
157
+ if (options) {
158
+ dropdownOptions = options.map((option, index) => {
159
+ if (typeof option === 'string' && option === 'break')
160
+ return <Spacer key={`${id}-spacer-${index}`} />;
161
+ return (
162
+ <Option
163
+ key={option.value}
164
+ checkbox={!!checkbox}
165
+ onClick={handleChange}
166
+ selected={isSelected(option.value)}
167
+ {...option}
168
+ />
169
+ );
170
+ });
171
+ }
172
+
173
+ return (
174
+ <Wrapper
175
+ $sx={sx}
176
+ tabIndex={0}
177
+ ref={wrapperRef}
178
+ onBlurCapture={handleBlur}
179
+ {...rest}
180
+ >
181
+ {React.cloneElement(
182
+ trigger,
183
+ typeof trigger.type === 'string'
184
+ ? { onClick: handleOpen }
185
+ : { isDropdownOpen: open, onClick: handleOpen }
186
+ )}
187
+ {open && (
188
+ <Container
189
+ $hasArrow={hasArrow}
190
+ $offset={offset}
191
+ $openDirection={openDirection}
192
+ ref={optionsRef}
193
+ >
194
+ {dropdownOptions}
195
+ </Container>
196
+ )}
197
+ </Wrapper>
198
+ );
199
+ };
200
+
201
+ const Wrapper = styled.div<{ $sx?: string }>`
202
+ position: relative;
203
+ display: block;
204
+ outline: none;
205
+ ${({ $sx }) => ($sx ? $sx : '')}
206
+ `;
207
+
208
+ const Container = styled.div<{
209
+ $hasArrow?: boolean;
210
+ $offset?: [number, number];
211
+ $openDirection: 'left' | 'right';
212
+ }>`
213
+ z-index: 1;
214
+ background-color: var(--color-white);
215
+ position: absolute;
216
+ width: max-content;
217
+ z-index: 100;
218
+ outline: none;
219
+ cursor: pointer;
220
+ box-shadow: var(--elevation-2);
221
+ border-radius: 8px;
222
+
223
+ & > div:first-of-type {
224
+ border-radius: 8px 8px 0px 0px;
225
+ }
226
+
227
+ & > div:last-of-type {
228
+ border-radius: 0px 0px 8px 8px;
229
+ }
230
+
231
+ ${({ $openDirection }) => ($openDirection === 'left' ? 'right: 100%;' : '')}
232
+
233
+ ${({ $hasArrow, $offset }) =>
234
+ $hasArrow
235
+ ? `
236
+ &:before {
237
+ content: '';
238
+ position: absolute;
239
+ width: 15px;
240
+ height: 15px;
241
+ transform: rotate(45deg) translate(${($offset?.[0] || 0) + 8}px, ${
242
+ ($offset?.[1] || 0) - 32
243
+ }px);
244
+ background-color: var(--color-white);
245
+ }
246
+ `
247
+ : ''}
248
+ ${({ $offset }) =>
249
+ $offset ? `transform: translate(${$offset[0]}px, ${$offset[1]}px);` : ''}
250
+ `;
251
+
252
+ export interface DropdownOptionProps {
253
+ checkbox?: boolean;
254
+ color?: string;
255
+ disabled?: boolean;
256
+ icon?: React.ReactElement;
257
+ label: React.ReactNode;
258
+ onClick?: (event: React.MouseEvent<HTMLDivElement>) => void | undefined;
259
+ selected: boolean;
260
+ sublabel?: string;
261
+ sx?: string;
262
+ value: string;
263
+ }
264
+
265
+ const Option = ({
266
+ checkbox,
267
+ disabled,
268
+ icon,
269
+ label,
270
+ onClick,
271
+ selected,
272
+ sublabel,
273
+ sx,
274
+ value,
275
+ }: DropdownOptionProps) => {
276
+ return (
277
+ <OptionWrapper
278
+ data-value={value}
279
+ onClick={!disabled ? onClick : undefined}
280
+ $disabled={disabled}
281
+ $hasCheckbox={!!checkbox}
282
+ $hasSublabel={!!sublabel}
283
+ $selected={selected}
284
+ $sx={sx}
285
+ >
286
+ {checkbox ? <Checkbox selected={selected} /> : icon}
287
+ <Box $dir="column" $display="flex">
288
+ <P
289
+ $color="grey-4"
290
+ $fontSize={14}
291
+ $lineHeight={20}
292
+ $mediumBold
293
+ $textClampLines={1}
294
+ >
295
+ {label}
296
+ </P>
297
+ {sublabel && (
298
+ <P
299
+ $color="grey-4"
300
+ $fontSize={12}
301
+ $lineHeight={16}
302
+ $textClampLines={1}
303
+ >
304
+ {sublabel}
305
+ </P>
306
+ )}
307
+ </Box>
308
+ </OptionWrapper>
309
+ );
310
+ };
311
+
312
+ Option.displayName = 'Dropdown.Option';
313
+ Dropdown.Option = Option;
314
+
315
+ const OptionWrapper = styled.div<{
316
+ $disabled?: boolean;
317
+ $hasCheckbox?: boolean;
318
+ $hasSublabel?: boolean;
319
+ $selected?: boolean;
320
+ $sx?: string;
321
+ }>`
322
+ position: relative;
323
+ z-index: 1;
324
+ padding: ${({ $hasSublabel }) => ($hasSublabel ? 10 : 12)}px 16px;
325
+ user-select: none;
326
+ display: flex;
327
+ align-items: center;
328
+ gap: 8px;
329
+
330
+ & > * {
331
+ pointer-events: none;
332
+ }
333
+
334
+ ${({ $disabled, $selected, $hasCheckbox }) => {
335
+ if ($disabled) {
336
+ return `cursor: initial;
337
+ color: var(--color-grey-7);
338
+ background-color: var(--color-grey-10);`;
339
+ }
340
+
341
+ if ($hasCheckbox) {
342
+ return `&:hover {
343
+ background-color: var(--color-grey-10);
344
+ }`;
345
+ }
346
+
347
+ if ($selected) {
348
+ return `
349
+ background-color: var(--color-grey-9);
350
+ &:active {
351
+ background-color: var(--color-grey-8);
352
+ }`;
353
+ }
354
+
355
+ return `
356
+ &:hover {
357
+ background-color: var(--color-grey-10);
358
+ }
359
+
360
+ &:active {
361
+ background-color: var(--color-grey-8);
362
+ }
363
+ `;
364
+ }}
365
+ ${({ $sx }) => ($sx ? $sx : '')}
366
+ `;
367
+
368
+ export interface DropdownSpacerProps {
369
+ sx?: string;
370
+ }
371
+
372
+ const Spacer = ({ sx }: DropdownSpacerProps) => {
373
+ return <SpacerWrapper $sx={sx} />;
374
+ };
375
+
376
+ Spacer.displayName = 'Dropdown.Spacer';
377
+ Dropdown.Spacer = Spacer;
378
+
379
+ const SpacerWrapper = styled.div<{
380
+ $sx?: string;
381
+ }>`
382
+ width: 100%;
383
+ height: 1px;
384
+ background-color: var(--color-grey-8);
385
+
386
+ &:hover {
387
+ appearance: none;
388
+ }
389
+ ${({ $sx }) => ($sx ? $sx : '')}
390
+ `;
391
+
392
+ export { Dropdown };
@@ -0,0 +1,6 @@
1
+ export { Dropdown } from './dropdown';
2
+ export type {
3
+ DropdownOptionProps,
4
+ DropdownProps,
5
+ DropdownSpacerProps,
6
+ } from './dropdown';
@@ -1,2 +1,8 @@
1
1
  export { Button } from './button';
2
2
  export type { ButtonProps } from './button';
3
+ export { Dropdown } from './dropdown';
4
+ export type {
5
+ DropdownOptionProps,
6
+ DropdownProps,
7
+ DropdownSpacerProps,
8
+ } from './dropdown';
@@ -2,5 +2,7 @@ export { Banner } from './banner';
2
2
  export type { BannerProps } from './banner';
3
3
  export { Loader } from './loader';
4
4
  export type { LoaderProps } from './loader';
5
+ export { Notification } from './notification';
6
+ export type { NotificationProps } from './notification';
5
7
  export { Toast } from './toast';
6
8
  export type { ToastProps } from './toast';
@@ -0,0 +1,2 @@
1
+ export { Notification } from './notification';
2
+ export type { NotificationProps } from './notification';
@@ -14,7 +14,7 @@ import {
14
14
  } from './icons';
15
15
 
16
16
  type NativeProps = Pick<
17
- React.HTMLAttributes<HTMLAnchorElement>,
17
+ React.HTMLAttributes<any>,
18
18
  | 'onBlur'
19
19
  | 'onBlurCapture'
20
20
  | 'onClick'
@@ -43,8 +43,18 @@ type Status =
43
43
  | 'declined'
44
44
  | 'approved';
45
45
 
46
- type Size = 96 | 72 | 64 | 56 | 48 | 40 | 36 | 32 | 24;
47
- type SizeStrings = '96' | '72' | '64' | '56' | '48' | '40' | '36' | '32' | '24';
46
+ type Size = 96 | 72 | 64 | 56 | 48 | 40 | 36 | 32 | 24 | 16;
47
+ type SizeStrings =
48
+ | '96'
49
+ | '72'
50
+ | '64'
51
+ | '56'
52
+ | '48'
53
+ | '40'
54
+ | '36'
55
+ | '32'
56
+ | '24'
57
+ | '16';
48
58
 
49
59
  export interface AvatarProps extends NativeProps {
50
60
  as?: React.ElementType;
@@ -62,7 +72,7 @@ export interface AvatarProps extends NativeProps {
62
72
  */
63
73
  const iconReference: Record<
64
74
  Status | 'none',
65
- React.JSXElementConstructor<SVGElement>
75
+ React.JSXElementConstructor<any>
66
76
  > = {
67
77
  approved: Approved,
68
78
  busy: Busy,
@@ -85,6 +95,7 @@ const iconSize: Record<SizeStrings, number> = {
85
95
  '36': 14,
86
96
  '32': 14,
87
97
  '24': 12,
98
+ '16': 8,
88
99
  };
89
100
 
90
101
  const iconOffsetX: Record<SizeStrings, number> = {
@@ -97,6 +108,7 @@ const iconOffsetX: Record<SizeStrings, number> = {
97
108
  '36': -12,
98
109
  '32': -12,
99
110
  '24': -10,
111
+ '16': -8,
100
112
  };
101
113
 
102
114
  const iconOffsetY: Record<SizeStrings, number> = {
@@ -109,6 +121,7 @@ const iconOffsetY: Record<SizeStrings, number> = {
109
121
  '36': -2,
110
122
  '32': -2,
111
123
  '24': -2,
124
+ '16': -1,
112
125
  };
113
126
 
114
127
  /**
@@ -2,4 +2,5 @@ export * from './actions';
2
2
  export * from './atoms';
3
3
  export * from './feedback';
4
4
  export * from './iconography';
5
+ export * from './input';
5
6
  export * from './surfaces';
@@ -0,0 +1,58 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+ import { Styles } from 'common';
4
+ import { BoxProps } from 'components';
5
+ import { Checkmark } from 'icons';
6
+
7
+ type NativeProps = Pick<
8
+ React.HTMLAttributes<HTMLDivElement>,
9
+ | 'onClick'
10
+ | 'onChange'
11
+ | 'onMouseDown'
12
+ | 'onMouseDownCapture'
13
+ | 'onMouseEnter'
14
+ | 'onMouseLeave'
15
+ | 'onMouseOut'
16
+ | 'onMouseOver'
17
+ >;
18
+
19
+ export interface CheckboxProps extends NativeProps {
20
+ disabled?: boolean;
21
+ selected: boolean;
22
+ }
23
+
24
+ export const Checkbox = ({ disabled, selected, ...rest }: CheckboxProps) => {
25
+ return (
26
+ <Box
27
+ $align="center"
28
+ $disabled={!!disabled}
29
+ $display="flex"
30
+ $justify="center"
31
+ $selected={selected}
32
+ {...rest}
33
+ >
34
+ {selected && <Checkmark color="white" />}
35
+ </Box>
36
+ );
37
+ };
38
+
39
+ const Box = styled.div<
40
+ {
41
+ $disabled: boolean;
42
+ $selected: boolean;
43
+ } & BoxProps
44
+ >`
45
+ display: flex;
46
+ width: 20px;
47
+ height: 20px;
48
+ border-radius: 4px;
49
+ cursor: pointer;
50
+ box-sizing: border-box;
51
+
52
+ ${({ $selected }) =>
53
+ $selected
54
+ ? `background-color: var(--color-primary-blue-2);
55
+ border: 1px solid var(--color-primary-blue-2);`
56
+ : 'border: 1px solid var(--color-grey-8);'}
57
+ ${Styles.flex}
58
+ `;
@@ -0,0 +1,2 @@
1
+ export { Checkbox } from './checkbox';
2
+ export type { CheckboxProps } from './checkbox';
@@ -0,0 +1,4 @@
1
+ export { Checkbox } from './checkbox';
2
+ export type { CheckboxProps } from './checkbox';
3
+ export { Radio } from './radio';
4
+ export type { RadioProps } from './radio';
@@ -0,0 +1,2 @@
1
+ export { Radio } from './radio';
2
+ export type { RadioProps } from './radio';
@@ -0,0 +1,140 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+ import { Box, BoxProps, P } from 'components';
4
+
5
+ type NativeProps = Pick<
6
+ React.HTMLAttributes<HTMLInputElement>,
7
+ | 'onClick'
8
+ | 'onChange'
9
+ | 'onMouseDown'
10
+ | 'onMouseDownCapture'
11
+ | 'onMouseEnter'
12
+ | 'onMouseLeave'
13
+ | 'onMouseOut'
14
+ | 'onMouseOver'
15
+ >;
16
+
17
+ export interface RadioProps extends NativeProps {
18
+ checked: boolean;
19
+ disabled?: boolean;
20
+ label?: string;
21
+ onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
22
+ name?: string;
23
+ reversed?: boolean;
24
+ sx?: string;
25
+ value: string;
26
+ }
27
+
28
+ const Radio = ({
29
+ checked = false,
30
+ disabled,
31
+ label,
32
+ onChange,
33
+ reversed,
34
+ sx,
35
+ value,
36
+ ...rest
37
+ }: RadioProps) => {
38
+ const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
39
+ event.stopPropagation();
40
+ onChange(event);
41
+ };
42
+
43
+ return (
44
+ <Label $disabled={disabled} $reversed={reversed} $sx={sx}>
45
+ <Input
46
+ checked={checked}
47
+ disabled={disabled}
48
+ onChange={handleChange}
49
+ type="radio"
50
+ value={value}
51
+ {...rest}
52
+ />
53
+ <P as="span">{label}</P>
54
+ </Label>
55
+ );
56
+ };
57
+
58
+ const Label = styled.label<{
59
+ $disabled?: boolean;
60
+ $reversed?: boolean;
61
+ $sx?: string;
62
+ }>`
63
+ display: flex;
64
+ align-items: center;
65
+ gap: 8px;
66
+ user-select: none;
67
+
68
+ ${({ $disabled }) =>
69
+ $disabled
70
+ ? `
71
+ & > * {
72
+ color: var(--color-grey-7);
73
+ }`
74
+ : `
75
+ cursor: pointer;
76
+ &:hover {
77
+ input {
78
+ border-color: var(--color-primary-blue-2);
79
+ }
80
+ }`}
81
+ flex-direction: ${({ $reversed }) => ($reversed ? 'row-reverse' : 'row')};
82
+ ${({ $sx }) => ($sx ? $sx : '')}
83
+ `;
84
+
85
+ const Input = styled.input`
86
+ appearance: none;
87
+ position: relative;
88
+ height: 20px;
89
+ width: 20px;
90
+ box-sizing: border-box;
91
+ display: flex;
92
+ justify-content: center;
93
+ align-items: center;
94
+ margin: 0;
95
+ background-color: var(--color-white);
96
+ border: 1px solid var(--color-grey-8);
97
+ cursor: pointer;
98
+ border-radius: 50%;
99
+
100
+ &:checked {
101
+ border-color: var(--color-primary-blue-2);
102
+ &::after {
103
+ content: '';
104
+ width: 10px;
105
+ height: 10px;
106
+ border-radius: 50%;
107
+ background-color: var(--color-primary-blue-2);
108
+ }
109
+ }
110
+
111
+ &:disabled {
112
+ &:checked {
113
+ border-color: var(--color-grey-8);
114
+ &::after {
115
+ background-color: var(--color-grey-7);
116
+ }
117
+ }
118
+ }
119
+ `;
120
+
121
+ export interface RadioGroupProps extends React.PropsWithChildren, BoxProps {
122
+ name: string;
123
+ sx?: string;
124
+ }
125
+
126
+ const RadioGroup = ({ children, name, ...rest }: RadioGroupProps) => {
127
+ return (
128
+ <Box {...rest}>
129
+ {React.Children.map(children, (child) => {
130
+ if (React.isValidElement(child))
131
+ return <Radio key={child.key} name={name} {...child.props} />;
132
+ })}
133
+ </Box>
134
+ );
135
+ };
136
+
137
+ Radio.Group = RadioGroup;
138
+ RadioGroup.displayName = 'Radio.Group';
139
+
140
+ export { Radio };
package/tsconfig.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "es2022",
4
- "lib": ["es2022", "ESNext"],
4
+ "lib": ["es2022", "ESNext", "DOM"],
5
5
  "module": "ES6",
6
6
  "jsx": "react",
7
7
  "strict": true,