@soul-refiner/design-system 0.1.16 → 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
|
@@ -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';
|