@soul-refiner/design-system 0.1.15 → 0.1.17

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.15",
3
+ "version": "0.1.17",
4
4
  "main": "src/index.ts",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -6,5 +6,7 @@ export type {
6
6
  DropdownProps,
7
7
  DropdownSpacerProps,
8
8
  } from './dropdown';
9
+ export { Switch } from './switch';
10
+ export type { SwitchProps } from './switch';
9
11
  export { Upload } from './upload';
10
12
  export type { UploadProps } from './upload';
@@ -0,0 +1,2 @@
1
+ export { Switch } from './switch';
2
+ export type { SwitchProps } from './switch';
@@ -0,0 +1,116 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+
4
+ export interface SwitchProps extends React.PropsWithChildren {
5
+ disabled?: boolean;
6
+ onChange: (event: React.MouseEvent<HTMLButtonElement>) => void;
7
+ value: string;
8
+ }
9
+
10
+ export const Switch = ({
11
+ children,
12
+ disabled,
13
+ onChange,
14
+ value,
15
+ }: SwitchProps) => {
16
+ return (
17
+ <Wrapper>
18
+ {React.Children.map(children, (child) => {
19
+ if (!React.isValidElement(child)) return;
20
+ return React.cloneElement(child, {
21
+ ...child.props,
22
+ disabled: disabled,
23
+ active: value === child.props?.value,
24
+ key: child.key,
25
+ onClick: onChange,
26
+ });
27
+ })}
28
+ </Wrapper>
29
+ );
30
+ };
31
+
32
+ const Wrapper = styled.div`
33
+ display: flex;
34
+ flex-flow: row nowrap;
35
+ padding: 6px;
36
+ border-radius: 8px;
37
+ border: 1px solid var(--color-grey-8);
38
+ background-color: var(--color-grey-10);
39
+ `;
40
+
41
+ interface SwitchItemProps extends React.PropsWithChildren {
42
+ active?: boolean;
43
+ disabled?: boolean;
44
+ icon?: React.ReactElement;
45
+ onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void;
46
+ value: string;
47
+ }
48
+
49
+ const SwitchItem = ({
50
+ active,
51
+ children,
52
+ disabled,
53
+ icon,
54
+ onClick,
55
+ value,
56
+ }: SwitchItemProps) => {
57
+ return (
58
+ <Item
59
+ $active={!!active}
60
+ disabled={disabled}
61
+ onClick={onClick}
62
+ value={value}
63
+ >
64
+ {icon && React.cloneElement(icon, { size: 24, color: 'grey-6' })}
65
+ {children}
66
+ </Item>
67
+ );
68
+ };
69
+
70
+ const Item = styled.button<{
71
+ $active: boolean;
72
+ }>`
73
+ width: 154px;
74
+ height: 36px;
75
+ display: flex;
76
+ justify-content: center;
77
+ align-items: center;
78
+ gap: 8px;
79
+ font-family: Inter;
80
+ font-weight: 500;
81
+ font-size: 16px;
82
+ line-height: 24px;
83
+ border: none;
84
+ cursor: pointer;
85
+ letter-spacing: -0.176px;
86
+
87
+ svg {
88
+ pointer-events: none;
89
+ }
90
+
91
+ ${({ $active }) =>
92
+ $active
93
+ ? `
94
+ color: var(--color-primary-blue-2);
95
+ background-color: var(--color-white);
96
+ border-radius: 4px;
97
+ box-shadow: var(--elevation-1);
98
+
99
+ &:disabled {
100
+ color: var(--color-grey-7);
101
+ background-color: var(--color-grey-10);
102
+ border: 1px solid var(--color-grey-8);
103
+ box-shadow: none;
104
+ }`
105
+ : `
106
+ color: var(--color-grey-6);`}
107
+
108
+ &:disabled {
109
+ color: var(--color-grey-7);
110
+ cursor: initial;
111
+ background-color: var(--color-grey-10);
112
+ }
113
+ `;
114
+
115
+ Switch.Item = SwitchItem;
116
+ SwitchItem.displayName = 'Switch.Item';
@@ -6,5 +6,7 @@ export { Loader } from './loader';
6
6
  export type { LoaderProps } from './loader';
7
7
  export { Notification } from './notification';
8
8
  export type { NotificationProps } from './notification';
9
+ export { Progress } from './progress';
10
+ export type { ProgressProps } from './progress';
9
11
  export { Toast } from './toast';
10
12
  export type { ToastProps } from './toast';
@@ -0,0 +1,2 @@
1
+ export { Progress } from './progress';
2
+ export type { ProgressProps } from './progress';
@@ -0,0 +1,161 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+ import { colorReference } from 'common';
4
+ import { Box, P } from 'components';
5
+ import { CheckmarkCircle, Checkmarks, Close, MinusCircle, Pause } from 'icons';
6
+
7
+ type ProgressType = 'compact' | 'detailed';
8
+
9
+ export interface ProgressProps {
10
+ hasError?: boolean;
11
+ hasIcon?: boolean;
12
+ /**
13
+ * @param progress a percentage until complete
14
+ */
15
+ progress: number;
16
+ subtitle?: string;
17
+ sx?: string;
18
+ title?: string;
19
+ type?: ProgressType;
20
+ }
21
+
22
+ export const Progress = ({
23
+ hasError,
24
+ progress,
25
+ subtitle,
26
+ sx,
27
+ title,
28
+ type,
29
+ }: ProgressProps) => {
30
+ const isComplete = !hasError && progress > 99;
31
+ const isDetailed = type === 'detailed';
32
+ const percent = hasError || isComplete ? 100 : progress;
33
+ const displayPercent = hasError ? '-' : percent + '%';
34
+
35
+ const color = hasError ? 'red-4' : isComplete ? 'green-3' : 'primary-blue-2';
36
+ const gradientColors: Record<'start' | 'end' | 'empty' | 'bg', string> =
37
+ hasError
38
+ ? {
39
+ start: 'var(--color-red-6)',
40
+ end: 'var(--color-red-4)',
41
+ empty: 'var(--color-red-8)',
42
+ bg: 'var(--color-red-9)',
43
+ }
44
+ : isComplete
45
+ ? {
46
+ start: 'var(--color-green-5)',
47
+ end: 'var(--color-green-3)',
48
+ empty: 'var(--color-green-8)',
49
+ bg: 'var(--color-green-9)',
50
+ }
51
+ : {
52
+ start: '#abcfed',
53
+ end: 'var(--color-primary-blue-2)',
54
+ empty: 'var(--color-primary-blue-3)',
55
+ bg: 'var(--color-primary-blue-4)',
56
+ };
57
+
58
+ const icon = hasError ? (
59
+ <Close size={24} color={color} />
60
+ ) : isComplete ? (
61
+ <Checkmarks size={24} color={color} />
62
+ ) : (
63
+ <Pause size={24} color={color} />
64
+ );
65
+
66
+ return (
67
+ <Box $align="center" $dir="row" $gap={16} sx={sx}>
68
+ {isDetailed && (
69
+ <IconWrapper
70
+ $completedDegree={Math.round(percent * 3.6)}
71
+ $gradientColors={gradientColors}
72
+ >
73
+ <IconInnerWrapper $bg={gradientColors.bg}>{icon}</IconInnerWrapper>
74
+ </IconWrapper>
75
+ )}
76
+ <Box $dir="column" $flex={1} $gap={8}>
77
+ <Box>
78
+ {title && (
79
+ <P $color="grey-2" $fontSize={14} $lineHeight={20}>
80
+ {title}
81
+ </P>
82
+ )}
83
+ {isComplete && (
84
+ <CheckmarkCircle
85
+ color="green-3"
86
+ size={24}
87
+ sx="margin-left: auto;"
88
+ />
89
+ )}
90
+ {hasError && (
91
+ <MinusCircle color="red-4" size={24} sx="margin-left: auto;" />
92
+ )}
93
+ </Box>
94
+ <BarWrapper>
95
+ <Bar $color={colorReference[color]} $percent={percent} />
96
+ </BarWrapper>
97
+ {subtitle && (
98
+ <P $color="grey-4" $fontSize={12} $lineHeight={16}>
99
+ {subtitle}
100
+ </P>
101
+ )}
102
+ </Box>
103
+ {isDetailed && (
104
+ <P $color="grey-4" $textAlign="center" sx="width: 72px;">
105
+ {displayPercent}
106
+ </P>
107
+ )}
108
+ </Box>
109
+ );
110
+ };
111
+
112
+ const BarWrapper = styled.div`
113
+ position: relative;
114
+ width: 100%;
115
+ height: 12px;
116
+ border-radius: 32px;
117
+ background-color: var(--color-grey-8);
118
+ `;
119
+
120
+ const Bar = styled.div<{
121
+ $color: string;
122
+ $percent: number;
123
+ }>`
124
+ width: ${({ $percent }) => $percent}%;
125
+ height: 12px;
126
+ background-color: ${({ $color }) => $color};
127
+ border-radius: 32px;
128
+ `;
129
+
130
+ const IconWrapper = styled.div<{
131
+ $completedDegree: number;
132
+ $gradientColors: Record<'start' | 'end' | 'empty' | 'bg', string>;
133
+ }>`
134
+ position: relative;
135
+ display: block;
136
+ width: 45px;
137
+ height: 45px;
138
+ display: flex;
139
+ align-items: center;
140
+ justify-content: center;
141
+ border-radius: 50%;
142
+ flex-shrink: 0;
143
+ background: conic-gradient(
144
+ ${({ $gradientColors }) => $gradientColors.start},
145
+ ${({ $gradientColors }) => $gradientColors.end}
146
+ ${({ $completedDegree }) => $completedDegree}deg,
147
+ ${({ $gradientColors }) => $gradientColors.empty}
148
+ ${({ $completedDegree }) => $completedDegree}deg 360deg
149
+ );
150
+ border: 1px solid ${({ $gradientColors }) => $gradientColors.bg};
151
+ `;
152
+
153
+ const IconInnerWrapper = styled.div<{ $bg: string }>`
154
+ display: flex;
155
+ justify-content: center;
156
+ align-items: center;
157
+ height: 39px;
158
+ width: 39px;
159
+ border-radius: 50%;
160
+ background-color: ${({ $bg }) => $bg};
161
+ `;