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