@team-monolith/cds 1.114.2 → 1.115.1
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.
|
@@ -24,6 +24,8 @@ export interface CheckboxInputProps {
|
|
|
24
24
|
onClick?: (event: React.MouseEvent<HTMLInputElement>) => void;
|
|
25
25
|
/** HTML input 태그에 전달될 props */
|
|
26
26
|
inputProps?: InputHTMLAttributes<HTMLInputElement>;
|
|
27
|
+
/** 클릭 가능한 영역의 한 변의 길이(px). 기본값은 16px */
|
|
28
|
+
hitAreaSize?: number;
|
|
27
29
|
}
|
|
28
30
|
/**
|
|
29
31
|
* [피그마](https://www.figma.com/file/yhrRFizzmhPoHdw9FbYow2/Codle-PD-Kit---Components?type=design&node-id=36-907&t=G4t39O7uXZvsGQ9u-0)
|
|
@@ -15,6 +15,7 @@ import { css, useTheme } from "@emotion/react";
|
|
|
15
15
|
import * as React from "react";
|
|
16
16
|
import styled from "@emotion/styled";
|
|
17
17
|
import { ZINDEX } from "../utils/zIndex";
|
|
18
|
+
const DEFAULT_CHECKBOX_SIZE = 16;
|
|
18
19
|
export const checkboxInputClasses = {
|
|
19
20
|
root: "CheckboxInput",
|
|
20
21
|
checkbox: "CheckboxInput-checkbox",
|
|
@@ -39,6 +40,11 @@ const CHECKBOX_ICON_STYLE = (theme, type, disabled) => ({
|
|
|
39
40
|
stroke: ${theme.color.background.primary};
|
|
40
41
|
}
|
|
41
42
|
}
|
|
43
|
+
input[type="checkbox"]:focus-visible + & {
|
|
44
|
+
rect {
|
|
45
|
+
stroke: ${theme.color.background.primary};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
42
48
|
`}
|
|
43
49
|
`,
|
|
44
50
|
checked: css `
|
|
@@ -66,6 +72,12 @@ const CHECKBOX_ICON_STYLE = (theme, type, disabled) => ({
|
|
|
66
72
|
stroke: ${theme.color.background.primaryActive};
|
|
67
73
|
}
|
|
68
74
|
}
|
|
75
|
+
input[type="checkbox"]:focus-visible + & {
|
|
76
|
+
rect {
|
|
77
|
+
fill: ${theme.color.background.primaryActive};
|
|
78
|
+
stroke: ${theme.color.background.primaryActive};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
69
81
|
`}
|
|
70
82
|
`,
|
|
71
83
|
partial: css `
|
|
@@ -98,6 +110,15 @@ const CHECKBOX_ICON_STYLE = (theme, type, disabled) => ({
|
|
|
98
110
|
stroke: none;
|
|
99
111
|
}
|
|
100
112
|
}
|
|
113
|
+
input[type="checkbox"]:focus-visible + & {
|
|
114
|
+
rect {
|
|
115
|
+
stroke: ${theme.color.background.primaryActive};
|
|
116
|
+
}
|
|
117
|
+
rect + rect {
|
|
118
|
+
fill: ${theme.color.background.primaryActive};
|
|
119
|
+
stroke: none;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
101
122
|
`}
|
|
102
123
|
`,
|
|
103
124
|
})[type];
|
|
@@ -105,7 +126,7 @@ const CHECKBOX_ICON_STYLE = (theme, type, disabled) => ({
|
|
|
105
126
|
* [피그마](https://www.figma.com/file/yhrRFizzmhPoHdw9FbYow2/Codle-PD-Kit---Components?type=design&node-id=36-907&t=G4t39O7uXZvsGQ9u-0)
|
|
106
127
|
*/
|
|
107
128
|
export const CheckboxInput = React.forwardRef(function CheckboxInput(props, ref) {
|
|
108
|
-
const { className, checked, label, spacer, disabled, partial, onChange, onClick: _onClick, inputProps } = props, other = __rest(props, ["className", "checked", "label", "spacer", "disabled", "partial", "onChange", "onClick", "inputProps"]);
|
|
129
|
+
const { className, checked, label, spacer, disabled, partial, onChange, onClick: _onClick, inputProps, hitAreaSize } = props, other = __rest(props, ["className", "checked", "label", "spacer", "disabled", "partial", "onChange", "onClick", "inputProps", "hitAreaSize"]);
|
|
109
130
|
if (!label) {
|
|
110
131
|
return _jsx(Checkbox, Object.assign({}, props, { ref: ref }));
|
|
111
132
|
}
|
|
@@ -116,6 +137,7 @@ export const CheckboxInput = React.forwardRef(function CheckboxInput(props, ref)
|
|
|
116
137
|
partial,
|
|
117
138
|
onChange,
|
|
118
139
|
inputProps,
|
|
140
|
+
hitAreaSize,
|
|
119
141
|
};
|
|
120
142
|
return (_jsxs(Label, Object.assign({ className: [checkboxInputClasses.root, className]
|
|
121
143
|
.filter(Boolean)
|
|
@@ -124,35 +146,68 @@ export const CheckboxInput = React.forwardRef(function CheckboxInput(props, ref)
|
|
|
124
146
|
`, children: label })] })));
|
|
125
147
|
});
|
|
126
148
|
const Checkbox = React.forwardRef(function Checkbox(props, ref) {
|
|
127
|
-
const { className, checked, partial, disabled = false, spacer = false, onChange, onClick, inputProps } = props, other = __rest(props, ["className", "checked", "partial", "disabled", "spacer", "onChange", "onClick", "inputProps"]);
|
|
149
|
+
const { className, checked, partial, disabled = false, spacer = false, onChange, onClick, inputProps, hitAreaSize = DEFAULT_CHECKBOX_SIZE } = props, other = __rest(props, ["className", "checked", "partial", "disabled", "spacer", "onChange", "onClick", "inputProps", "hitAreaSize"]);
|
|
128
150
|
const type = checked
|
|
129
151
|
? "checked"
|
|
130
152
|
: partial
|
|
131
153
|
? "partial"
|
|
132
154
|
: "default";
|
|
133
|
-
|
|
155
|
+
const clampedSize = Math.max(hitAreaSize, DEFAULT_CHECKBOX_SIZE);
|
|
156
|
+
return (_jsxs(CheckboxContainer, Object.assign({ className: className, spacer: spacer, disabled: disabled, size: clampedSize, ref: ref }, other, { children: [_jsx(StyledInput, Object.assign({ type: "checkbox" }, inputProps, { checked: checked, disabled: disabled, onClick: onClick, onChange: onChange, size: clampedSize })), _jsx(CheckboxIcon, { type: type, disabled: disabled })] })));
|
|
134
157
|
});
|
|
135
|
-
const CheckboxContainer = styled.span(({ spacer, disabled }) => css `
|
|
136
|
-
display:
|
|
158
|
+
const CheckboxContainer = styled.span(({ theme, spacer, disabled, size }) => css `
|
|
159
|
+
display: flex;
|
|
160
|
+
align-items: center;
|
|
161
|
+
justify-content: center;
|
|
137
162
|
position: relative;
|
|
138
|
-
width:
|
|
139
|
-
height:
|
|
163
|
+
width: ${DEFAULT_CHECKBOX_SIZE}px;
|
|
164
|
+
height: ${DEFAULT_CHECKBOX_SIZE}px;
|
|
140
165
|
cursor: ${disabled ? "default" : "pointer"};
|
|
141
166
|
margin-bottom: ${spacer ? "8px" : "0"};
|
|
167
|
+
|
|
168
|
+
svg {
|
|
169
|
+
z-index: 1;
|
|
170
|
+
pointer-events: none;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
${size > DEFAULT_CHECKBOX_SIZE &&
|
|
174
|
+
css `
|
|
175
|
+
&::before {
|
|
176
|
+
content: "";
|
|
177
|
+
position: absolute;
|
|
178
|
+
top: 50%;
|
|
179
|
+
left: 50%;
|
|
180
|
+
transform: translate(-50%, -50%);
|
|
181
|
+
width: ${size}px;
|
|
182
|
+
height: ${size}px;
|
|
183
|
+
border-radius: 50%;
|
|
184
|
+
background: ${theme.color.background.neutralAltActive};
|
|
185
|
+
opacity: 0;
|
|
186
|
+
pointer-events: none;
|
|
187
|
+
}
|
|
188
|
+
`}
|
|
189
|
+
${!disabled &&
|
|
190
|
+
css `
|
|
191
|
+
&:hover::before,
|
|
192
|
+
&:focus-within::before {
|
|
193
|
+
opacity: 0.5; /* input 영역 hover 및 focus 시 표시 */
|
|
194
|
+
}
|
|
195
|
+
`}
|
|
196
|
+
`);
|
|
197
|
+
const StyledInput = styled.input(({ size }) => css `
|
|
198
|
+
cursor: inherit;
|
|
199
|
+
position: absolute;
|
|
200
|
+
top: 50%;
|
|
201
|
+
left: 50%;
|
|
202
|
+
transform: translate(-50%, -50%);
|
|
203
|
+
opacity: 0;
|
|
204
|
+
width: ${size}px;
|
|
205
|
+
height: ${size}px;
|
|
206
|
+
margin: 0;
|
|
207
|
+
padding: 0;
|
|
208
|
+
// input 컴포넌트는 보이지 않지만, 클릭이 가능하게 z-index를 설정합니다.
|
|
209
|
+
z-index: ${ZINDEX.inputBase};
|
|
142
210
|
`);
|
|
143
|
-
const StyledInput = styled.input `
|
|
144
|
-
cursor: inherit;
|
|
145
|
-
position: absolute;
|
|
146
|
-
top: 0;
|
|
147
|
-
left: 0;
|
|
148
|
-
opacity: 0;
|
|
149
|
-
width: 16px;
|
|
150
|
-
height: 16px;
|
|
151
|
-
margin: 0;
|
|
152
|
-
padding: 0;
|
|
153
|
-
// input 컴포넌트는 보이지 않지만, 클릭이 가능하게 z-index를 설정합니다.
|
|
154
|
-
z-index: ${ZINDEX.inputBase};
|
|
155
|
-
`;
|
|
156
211
|
const Label = styled.label `
|
|
157
212
|
display: flex;
|
|
158
213
|
position: relative;
|