@dotss/ui 1.3.0 → 1.4.0
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/Button/Button.cjs +8 -7
- package/Button/Button.d.ts +3 -0
- package/Button/Button.es.js +77 -66
- package/Button/Button.stories.d.ts +1 -0
- package/DatePicker/DatePicker.cjs +1 -1
- package/DatePicker/DatePicker.es.js +2 -2
- package/TextField/TextField.stories.d.ts +1 -0
- package/hooks/index.cjs +1 -1
- package/hooks/index.d.ts +2 -0
- package/hooks/index.es.js +6 -4
- package/hooks/useForm/useForm.cjs +1 -0
- package/hooks/useForm/useForm.d.ts +48 -0
- package/hooks/useForm/useForm.es.js +98 -0
- package/hooks/useForm/useForm.utils.cjs +1 -0
- package/hooks/useForm/useForm.utils.d.ts +4 -0
- package/hooks/useForm/useForm.utils.es.js +12 -0
- package/package.json +1 -1
package/Button/Button.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("@emotion/react/jsx-runtime"),M=require("react"),j=require("../Box/Box.cjs"),N=require("../CircularProgressIndicator/CircularProgressIndicator.cjs"),E=require("../hooks/useCheckHoverPossible/useCheckHoverPossible.cjs"),T=require("../utils/getIconLabel/getIconLabel.cjs"),F=require("@emotion/styled"),s=require("../utils/getContrastingTextColor/getContrastingTextColor.cjs"),V=l=>l&&l.__esModule?l:{default:l},G=V(F),J=G.default.button`
|
|
2
2
|
display: inline-flex;
|
|
3
3
|
align-items: center;
|
|
4
4
|
justify-content: center;
|
|
@@ -7,18 +7,19 @@
|
|
|
7
7
|
color: inherit;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
${({theme:{palette:{brand:l,grey:e}},variant:t,color:
|
|
10
|
+
${({theme:{palette:{brand:l,grey:e}},variant:t,color:u})=>{let p={backgroundColor:l.primary.main,color:s.default(l.primary.main,[e.white,e[100]])};return t==="filled"&&u==="secondary"&&(p={backgroundColor:l.secondary,color:s.default(l.secondary,[e.white,e[100]])}),t==="filled"&&u==="tertiary"&&(p={backgroundColor:l.tertiary,color:s.default(l.tertiary,[e.white,e[100]])}),t==="outlined"&&(p={borderColor:e[50],backgroundColor:e.white,color:s.default(e.white,[e.white,e[100]])}),t==="text"&&u==="primary"&&(p={backgroundColor:"transparent",color:s.default("transparent",[e.white,e[100]])}),t==="text"&&u==="secondary"&&(p={backgroundColor:"transparent",color:e[70]}),p}};
|
|
11
11
|
|
|
12
|
-
${({theme:{spacing:l,typography:e},variant:t,size:
|
|
12
|
+
${({theme:{spacing:l,typography:e},variant:t,size:u,startAdornment:p,endAdornment:o,iconOnly:f})=>{let r={gap:l.content(1),padding:10,borderRadius:8,fontSize:e.b4M.size,fontWeight:e.b4M.weight,lineHeight:e.b4M.lineHeight,letterSpacing:e.b4M.letterSpacing,"& svg":{width:20,height:20}};if(u==="2xLarge"){const{h0B:i}=e;let x="26px 24px";p&&(x=t==="text"?"26px 16px 26px 12px":"26px 36px 26px 24px"),o&&(x=t==="text"?"26px 12px 26px 16px":"26px 24px 26px 36px"),p&&o&&(x=t==="text"?"26px 12px":"26px 24px"),f&&(x="26px 25px"),r={gap:l.content(3),maxHeight:100,padding:x,borderRadius:20,fontSize:i.size,fontWeight:i.weight,lineHeight:i.lineHeight,letterSpacing:i.letterSpacing,"& svg":{width:48,height:48}}}if(u==="xLarge"){const{h4B:i}=e;let x="16px 12px";p&&(x=t==="text"?"16px 8px 16px 4px":"16px 16px 16px 12px"),o&&(x=t==="text"?"16px 4px 16px 8px":"16px 12px 16px 16px"),p&&o&&(x=t==="text"?"16px 4px":"16px 12px"),f&&(x="16px 15px"),r={gap:l.content(2),maxHeight:56,padding:x,borderRadius:12,fontSize:i.size,fontWeight:i.weight,lineHeight:i.lineHeight,letterSpacing:i.letterSpacing,"& svg":{width:24,height:24}}}if(u==="large"){const{b2M:i}=e;let x="12px 8px";p&&(x=t==="text"?"12px 8px 12px 4px":"12px 12px 12px 8px"),o&&(x=t==="text"?"12px 4px 12px 8px":"12px 8px 12px 12px"),p&&o&&(x=t==="text"?"12px 4px":"12px 8px"),f&&(x="12px 11px"),r={gap:6,maxHeight:48,padding:x,borderRadius:10,fontSize:i.size,fontWeight:i.weight,lineHeight:i.lineHeight,letterSpacing:i.letterSpacing,"& svg":{width:24,height:24}}}if(u==="medium"){const{b4M:i}=e;let x="10px 8px";p&&(x=t==="text"?"10px 8px 10px 4px":"10px 10px 10px 8px"),o&&(x=t==="text"?"10px 4px 10px 8px":"10px 8px 10px 10px"),p&&o&&(x=t==="text"?"10px 4px":"10px 8px"),f&&(x="10px 9px"),r={gap:l.content(1),maxHeight:40,padding:x,borderRadius:8,fontSize:i.size,fontWeight:i.weight,lineHeight:i.lineHeight,letterSpacing:i.letterSpacing,"& svg":{width:20,height:20}}}if(u==="small"){const{c3M:i}=e;let x="8px 6px";p&&(x=t==="text"?"8px 8px 8px 4px":"8px 8px 8px 6px"),o&&(x=t==="text"?"8px 4px 8px 8px":"8px 6px 8px 8px"),p&&o&&(x=t==="text"?"8px 6px":"8px 4px"),f&&(x="8px 7px"),r={gap:l.content(1),maxHeight:32,padding:x,borderRadius:6,fontSize:i.size,fontWeight:i.weight,lineHeight:i.lineHeight,letterSpacing:i.letterSpacing,"& svg":{width:16,height:16}}}if(u==="xSmall"){const{c3M:i}=e;let x="4px 6px";p&&(x=t==="text"?"4px 8px 4px 4px":"4px 8px 4px 6px"),o&&(x=t==="text"?"4px 4px 4px 8px":"4px 6px 4px 8px"),p&&o&&(x=t==="text"?"4px":"4px 6px"),f&&(x="4px 3px"),f?r={gap:l.content(1),maxHeight:24,width:24,height:24,borderRadius:6,fontSize:i.size,fontWeight:i.weight,lineHeight:i.lineHeight,letterSpacing:i.letterSpacing,"& svg":{width:16,height:16}}:r={gap:l.content(1),maxHeight:24,padding:x,borderRadius:6,fontSize:i.size,fontWeight:i.weight,lineHeight:i.lineHeight,letterSpacing:i.letterSpacing,"& svg":{width:16,height:16}}}return t==="text"&&u==="xLarge"&&(r={...r,borderWidth:1.5}),r}};
|
|
13
13
|
|
|
14
14
|
${({rounded:l})=>l?{}:{borderRadius:"unset"}}
|
|
15
15
|
|
|
16
|
-
${({theme:{palette:{brand:l,grey:e}},variant:t,color:
|
|
16
|
+
${({theme:{palette:{brand:l,grey:e}},variant:t,color:u,isHoverPossible:p})=>{let o={'&:active:not([aria-disabled="true"])':{backgroundColor:l.primary.press},...p?{'&:hover:not([aria-disabled="true"])':{backgroundColor:l.primary.press}}:{}};return t==="filled"&&u==="secondary"&&(o={'&:active:not([aria-disabled="true"])':{backgroundColor:e[100]},...p?{'&:hover:not([aria-disabled="true"])':{backgroundColor:e[100]}}:{}}),t==="filled"&&u==="tertiary"&&(o={'&:active:not([aria-disabled="true"])':{backgroundColor:e[70]},...p?{'&:hover:not([aria-disabled="true"])':{backgroundColor:e[70]}}:{}}),(t==="outlined"||t==="text")&&(o={'&:active:not([aria-disabled="true"])':{backgroundColor:e[10]},...p?{'&:hover:not([aria-disabled="true"])':{backgroundColor:e[10]}}:{}}),o}}
|
|
17
17
|
|
|
18
|
-
&[aria-disabled="true"] {
|
|
18
|
+
&[aria-disabled="true"], &[aria-busy="true"] {
|
|
19
19
|
cursor: not-allowed;
|
|
20
|
-
|
|
20
|
+
|
|
21
|
+
${({theme:{palette:{brand:l,grey:e}},variant:t,color:u})=>{let p={backgroundColor:l.primary.disable,color:s.default(l.primary.disable,[e[30],e.white])};return t==="filled"&&u==="secondary"&&(p={backgroundColor:e[10],color:s.default(e[10],[e[30],e.white])}),t==="outlined"&&(p={borderColor:e[30],backgroundColor:e[10],color:s.default(e[30],[e[30],e.white])}),t==="text"&&(p={color:s.default(e[30],[e[30],e.white])}),p}};
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
${({fullWidth:l})=>l?{width:"100%"}:null};
|
|
24
|
-
|
|
25
|
+
`,P=M.forwardRef(function({tag:e="button",children:t,variant:u="filled",size:p="medium",color:o="primary",startAdornment:f,endAdornment:r,iconOnly:i,fullWidth:x,inlineCSS:z,rounded:W=!0,disabled:w,onClick:S,onKeyDown:H,loading:c,loadingPosition:R,loadingIndicator:h,...C},q){const{isHoverPossible:m}=E.default(),_=()=>{if(!i)return;if(C["aria-label"])return C["aria-label"];const d=f||r||t;if(M.isValidElement(d))return T.default(d.props.name)},$=d=>{w||c||S==null||S(d)},B=d=>{w||c||H==null||H(d)},L=!!c,k=h?a.jsx(a.Fragment,{children:h}):a.jsx(N.default,{loop:!0});let g=f,b=i?null:t,n=r;return L&&(R?R==="start"?(g=a.jsx(j.default,{children:k}),n=h?null:r,b=i||h?null:t):(g=h?null:f,n=a.jsx(j.default,{children:k}),b=i||h?null:t):(g=null,n=null,b=i?null:k)),a.jsxs(J,{as:e,ref:q,type:e==="button"?"button":void 0,variant:u,size:p,color:o,fullWidth:x,rounded:W,startAdornment:f,endAdornment:r,iconOnly:i,isHoverPossible:m,"aria-disabled":w||c,"aria-busy":c,"aria-label":_(),onClick:$,onKeyDown:B,...C,css:z,children:[g,b,n,c&&a.jsx(j.default,{visuallyHidden:!0,role:"status","aria-live":"polite","aria-atomic":"true",children:typeof t=="string"?`${t} 중`:"로딩 중"})]})});exports.default=P;
|
package/Button/Button.d.ts
CHANGED
|
@@ -11,6 +11,9 @@ export type ButtonProps<T extends ElementType = 'button'> = PolymorphicComponent
|
|
|
11
11
|
iconOnly?: boolean;
|
|
12
12
|
fullWidth?: boolean;
|
|
13
13
|
rounded?: boolean;
|
|
14
|
+
loading?: boolean;
|
|
15
|
+
loadingPosition?: 'start' | 'end';
|
|
16
|
+
loadingIndicator?: ReactNode;
|
|
14
17
|
};
|
|
15
18
|
type ButtonComponent<DT extends ElementType> = <T extends ElementType = DT>(props: ButtonProps<T>) => ReactNode;
|
|
16
19
|
declare const Button: ButtonComponent<'button'>;
|
package/Button/Button.es.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { forwardRef as
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
1
|
+
import { jsxs as E, jsx as g, Fragment as F } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { forwardRef as T, isValidElement as V } from "react";
|
|
3
|
+
import k from "../Box/Box.es.js";
|
|
4
|
+
import q from "../CircularProgressIndicator/CircularProgressIndicator.es.js";
|
|
5
|
+
import G from "../hooks/useCheckHoverPossible/useCheckHoverPossible.es.js";
|
|
6
|
+
import J from "../utils/getIconLabel/getIconLabel.es.js";
|
|
7
|
+
import Q from "@emotion/styled";
|
|
8
|
+
import h from "../utils/getContrastingTextColor/getContrastingTextColor.es.js";
|
|
9
|
+
const U = Q.button`
|
|
8
10
|
display: inline-flex;
|
|
9
11
|
align-items: center;
|
|
10
12
|
justify-content: center;
|
|
@@ -22,21 +24,21 @@ const $ = j.button`
|
|
|
22
24
|
}) => {
|
|
23
25
|
let p = {
|
|
24
26
|
backgroundColor: l.primary.main,
|
|
25
|
-
color:
|
|
27
|
+
color: h(l.primary.main, [e.white, e[100]])
|
|
26
28
|
};
|
|
27
29
|
return t === "filled" && o === "secondary" && (p = {
|
|
28
30
|
backgroundColor: l.secondary,
|
|
29
|
-
color:
|
|
31
|
+
color: h(l.secondary, [e.white, e[100]])
|
|
30
32
|
}), t === "filled" && o === "tertiary" && (p = {
|
|
31
33
|
backgroundColor: l.tertiary,
|
|
32
|
-
color:
|
|
34
|
+
color: h(l.tertiary, [e.white, e[100]])
|
|
33
35
|
}), t === "outlined" && (p = {
|
|
34
36
|
borderColor: e[50],
|
|
35
37
|
backgroundColor: e.white,
|
|
36
|
-
color:
|
|
38
|
+
color: h(e.white, [e.white, e[100]])
|
|
37
39
|
}), t === "text" && o === "primary" && (p = {
|
|
38
40
|
backgroundColor: "transparent",
|
|
39
|
-
color:
|
|
41
|
+
color: h("transparent", [e.white, e[100]])
|
|
40
42
|
}), t === "text" && o === "secondary" && (p = {
|
|
41
43
|
backgroundColor: "transparent",
|
|
42
44
|
color: e[70]
|
|
@@ -49,9 +51,9 @@ const $ = j.button`
|
|
|
49
51
|
size: o,
|
|
50
52
|
startAdornment: p,
|
|
51
53
|
endAdornment: r,
|
|
52
|
-
iconOnly:
|
|
54
|
+
iconOnly: u
|
|
53
55
|
}) => {
|
|
54
|
-
let
|
|
56
|
+
let f = {
|
|
55
57
|
gap: l.content(1),
|
|
56
58
|
padding: 10,
|
|
57
59
|
borderRadius: 8,
|
|
@@ -67,7 +69,7 @@ const $ = j.button`
|
|
|
67
69
|
if (o === "2xLarge") {
|
|
68
70
|
const { h0B: i } = e;
|
|
69
71
|
let x = "26px 24px";
|
|
70
|
-
p && (x = t === "text" ? "26px 16px 26px 12px" : "26px 36px 26px 24px"), r && (x = t === "text" ? "26px 12px 26px 16px" : "26px 24px 26px 36px"), p && r && (x = t === "text" ? "26px 12px" : "26px 24px"),
|
|
72
|
+
p && (x = t === "text" ? "26px 16px 26px 12px" : "26px 36px 26px 24px"), r && (x = t === "text" ? "26px 12px 26px 16px" : "26px 24px 26px 36px"), p && r && (x = t === "text" ? "26px 12px" : "26px 24px"), u && (x = "26px 25px"), f = {
|
|
71
73
|
gap: l.content(3),
|
|
72
74
|
maxHeight: 100,
|
|
73
75
|
padding: x,
|
|
@@ -85,7 +87,7 @@ const $ = j.button`
|
|
|
85
87
|
if (o === "xLarge") {
|
|
86
88
|
const { h4B: i } = e;
|
|
87
89
|
let x = "16px 12px";
|
|
88
|
-
p && (x = t === "text" ? "16px 8px 16px 4px" : "16px 16px 16px 12px"), r && (x = t === "text" ? "16px 4px 16px 8px" : "16px 12px 16px 16px"), p && r && (x = t === "text" ? "16px 4px" : "16px 12px"),
|
|
90
|
+
p && (x = t === "text" ? "16px 8px 16px 4px" : "16px 16px 16px 12px"), r && (x = t === "text" ? "16px 4px 16px 8px" : "16px 12px 16px 16px"), p && r && (x = t === "text" ? "16px 4px" : "16px 12px"), u && (x = "16px 15px"), f = {
|
|
89
91
|
gap: l.content(2),
|
|
90
92
|
maxHeight: 56,
|
|
91
93
|
padding: x,
|
|
@@ -103,7 +105,7 @@ const $ = j.button`
|
|
|
103
105
|
if (o === "large") {
|
|
104
106
|
const { b2M: i } = e;
|
|
105
107
|
let x = "12px 8px";
|
|
106
|
-
p && (x = t === "text" ? "12px 8px 12px 4px" : "12px 12px 12px 8px"), r && (x = t === "text" ? "12px 4px 12px 8px" : "12px 8px 12px 12px"), p && r && (x = t === "text" ? "12px 4px" : "12px 8px"),
|
|
108
|
+
p && (x = t === "text" ? "12px 8px 12px 4px" : "12px 12px 12px 8px"), r && (x = t === "text" ? "12px 4px 12px 8px" : "12px 8px 12px 12px"), p && r && (x = t === "text" ? "12px 4px" : "12px 8px"), u && (x = "12px 11px"), f = {
|
|
107
109
|
gap: 6,
|
|
108
110
|
maxHeight: 48,
|
|
109
111
|
padding: x,
|
|
@@ -121,7 +123,7 @@ const $ = j.button`
|
|
|
121
123
|
if (o === "medium") {
|
|
122
124
|
const { b4M: i } = e;
|
|
123
125
|
let x = "10px 8px";
|
|
124
|
-
p && (x = t === "text" ? "10px 8px 10px 4px" : "10px 10px 10px 8px"), r && (x = t === "text" ? "10px 4px 10px 8px" : "10px 8px 10px 10px"), p && r && (x = t === "text" ? "10px 4px" : "10px 8px"),
|
|
126
|
+
p && (x = t === "text" ? "10px 8px 10px 4px" : "10px 10px 10px 8px"), r && (x = t === "text" ? "10px 4px 10px 8px" : "10px 8px 10px 10px"), p && r && (x = t === "text" ? "10px 4px" : "10px 8px"), u && (x = "10px 9px"), f = {
|
|
125
127
|
gap: l.content(1),
|
|
126
128
|
maxHeight: 40,
|
|
127
129
|
padding: x,
|
|
@@ -139,7 +141,7 @@ const $ = j.button`
|
|
|
139
141
|
if (o === "small") {
|
|
140
142
|
const { c3M: i } = e;
|
|
141
143
|
let x = "8px 6px";
|
|
142
|
-
p && (x = t === "text" ? "8px 8px 8px 4px" : "8px 8px 8px 6px"), r && (x = t === "text" ? "8px 4px 8px 8px" : "8px 6px 8px 8px"), p && r && (x = t === "text" ? "8px 6px" : "8px 4px"),
|
|
144
|
+
p && (x = t === "text" ? "8px 8px 8px 4px" : "8px 8px 8px 6px"), r && (x = t === "text" ? "8px 4px 8px 8px" : "8px 6px 8px 8px"), p && r && (x = t === "text" ? "8px 6px" : "8px 4px"), u && (x = "8px 7px"), f = {
|
|
143
145
|
gap: l.content(1),
|
|
144
146
|
maxHeight: 32,
|
|
145
147
|
padding: x,
|
|
@@ -157,7 +159,7 @@ const $ = j.button`
|
|
|
157
159
|
if (o === "xSmall") {
|
|
158
160
|
const { c3M: i } = e;
|
|
159
161
|
let x = "4px 6px";
|
|
160
|
-
p && (x = t === "text" ? "4px 8px 4px 4px" : "4px 8px 4px 6px"), r && (x = t === "text" ? "4px 4px 4px 8px" : "4px 6px 4px 8px"), p && r && (x = t === "text" ? "4px" : "4px 6px"),
|
|
162
|
+
p && (x = t === "text" ? "4px 8px 4px 4px" : "4px 8px 4px 6px"), r && (x = t === "text" ? "4px 4px 4px 8px" : "4px 6px 4px 8px"), p && r && (x = t === "text" ? "4px" : "4px 6px"), u && (x = "4px 3px"), u ? f = {
|
|
161
163
|
gap: l.content(1),
|
|
162
164
|
maxHeight: 24,
|
|
163
165
|
width: 24,
|
|
@@ -171,7 +173,7 @@ const $ = j.button`
|
|
|
171
173
|
width: 16,
|
|
172
174
|
height: 16
|
|
173
175
|
}
|
|
174
|
-
} :
|
|
176
|
+
} : f = {
|
|
175
177
|
gap: l.content(1),
|
|
176
178
|
maxHeight: 24,
|
|
177
179
|
padding: x,
|
|
@@ -186,10 +188,10 @@ const $ = j.button`
|
|
|
186
188
|
}
|
|
187
189
|
};
|
|
188
190
|
}
|
|
189
|
-
return t === "text" && o === "xLarge" && (
|
|
190
|
-
...
|
|
191
|
+
return t === "text" && o === "xLarge" && (f = {
|
|
192
|
+
...f,
|
|
191
193
|
borderWidth: 1.5
|
|
192
|
-
}),
|
|
194
|
+
}), f;
|
|
193
195
|
}};
|
|
194
196
|
|
|
195
197
|
${({ rounded: l }) => l ? {} : {
|
|
@@ -220,8 +222,9 @@ const $ = j.button`
|
|
|
220
222
|
}), r;
|
|
221
223
|
}}
|
|
222
224
|
|
|
223
|
-
&[aria-disabled="true"] {
|
|
225
|
+
&[aria-disabled="true"], &[aria-busy="true"] {
|
|
224
226
|
cursor: not-allowed;
|
|
227
|
+
|
|
225
228
|
${({
|
|
226
229
|
theme: {
|
|
227
230
|
palette: { brand: l, grey: e }
|
|
@@ -231,17 +234,17 @@ const $ = j.button`
|
|
|
231
234
|
}) => {
|
|
232
235
|
let p = {
|
|
233
236
|
backgroundColor: l.primary.disable,
|
|
234
|
-
color:
|
|
237
|
+
color: h(l.primary.disable, [e[30], e.white])
|
|
235
238
|
};
|
|
236
239
|
return t === "filled" && o === "secondary" && (p = {
|
|
237
240
|
backgroundColor: e[10],
|
|
238
|
-
color:
|
|
241
|
+
color: h(e[10], [e[30], e.white])
|
|
239
242
|
}), t === "outlined" && (p = {
|
|
240
243
|
borderColor: e[30],
|
|
241
244
|
backgroundColor: e[10],
|
|
242
|
-
color:
|
|
245
|
+
color: h(e[30], [e[30], e.white])
|
|
243
246
|
}), t === "text" && (p = {
|
|
244
|
-
color:
|
|
247
|
+
color: h(e[30], [e[30], e.white])
|
|
245
248
|
}), p;
|
|
246
249
|
}};
|
|
247
250
|
}
|
|
@@ -249,62 +252,70 @@ const $ = j.button`
|
|
|
249
252
|
${({ fullWidth: l }) => l ? {
|
|
250
253
|
width: "100%"
|
|
251
254
|
} : null};
|
|
252
|
-
`,
|
|
255
|
+
`, v = T(function({
|
|
253
256
|
tag: e = "button",
|
|
254
257
|
children: t,
|
|
255
258
|
variant: o = "filled",
|
|
256
259
|
size: p = "medium",
|
|
257
260
|
color: r = "primary",
|
|
258
|
-
startAdornment:
|
|
259
|
-
endAdornment:
|
|
261
|
+
startAdornment: u,
|
|
262
|
+
endAdornment: f,
|
|
260
263
|
iconOnly: i,
|
|
261
264
|
fullWidth: x,
|
|
262
|
-
inlineCSS:
|
|
263
|
-
rounded:
|
|
264
|
-
disabled:
|
|
265
|
-
onClick:
|
|
266
|
-
onKeyDown:
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
265
|
+
inlineCSS: R,
|
|
266
|
+
rounded: W = !0,
|
|
267
|
+
disabled: w,
|
|
268
|
+
onClick: S,
|
|
269
|
+
onKeyDown: H,
|
|
270
|
+
loading: s,
|
|
271
|
+
loadingPosition: z,
|
|
272
|
+
loadingIndicator: c,
|
|
273
|
+
...m
|
|
274
|
+
}, M) {
|
|
275
|
+
const { isHoverPossible: j } = G(), $ = () => {
|
|
270
276
|
if (!i) return;
|
|
271
|
-
if (
|
|
272
|
-
const a =
|
|
273
|
-
if (
|
|
274
|
-
return
|
|
275
|
-
},
|
|
276
|
-
|
|
277
|
-
},
|
|
278
|
-
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
|
|
277
|
+
if (m["aria-label"]) return m["aria-label"];
|
|
278
|
+
const a = u || f || t;
|
|
279
|
+
if (V(a))
|
|
280
|
+
return J(a.props.name);
|
|
281
|
+
}, B = (a) => {
|
|
282
|
+
w || s || S == null || S(a);
|
|
283
|
+
}, L = (a) => {
|
|
284
|
+
w || s || H == null || H(a);
|
|
285
|
+
}, N = !!s, C = c ? /* @__PURE__ */ g(F, { children: c }) : /* @__PURE__ */ g(q, { loop: !0 });
|
|
286
|
+
let d = u, b = i ? null : t, n = f;
|
|
287
|
+
return N && (z ? z === "start" ? (d = /* @__PURE__ */ g(k, { children: C }), n = c ? null : f, b = i || c ? null : t) : (d = c ? null : u, n = /* @__PURE__ */ g(k, { children: C }), b = i || c ? null : t) : (d = null, n = null, b = i ? null : C)), /* @__PURE__ */ E(
|
|
288
|
+
U,
|
|
282
289
|
{
|
|
283
290
|
as: e,
|
|
284
|
-
ref:
|
|
291
|
+
ref: M,
|
|
292
|
+
type: e === "button" ? "button" : void 0,
|
|
285
293
|
variant: o,
|
|
286
294
|
size: p,
|
|
287
295
|
color: r,
|
|
288
296
|
fullWidth: x,
|
|
289
|
-
rounded:
|
|
290
|
-
startAdornment:
|
|
291
|
-
endAdornment:
|
|
297
|
+
rounded: W,
|
|
298
|
+
startAdornment: u,
|
|
299
|
+
endAdornment: f,
|
|
292
300
|
iconOnly: i,
|
|
293
|
-
isHoverPossible:
|
|
294
|
-
"aria-disabled":
|
|
295
|
-
"aria-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
301
|
+
isHoverPossible: j,
|
|
302
|
+
"aria-disabled": w || s,
|
|
303
|
+
"aria-busy": s,
|
|
304
|
+
"aria-label": $(),
|
|
305
|
+
onClick: B,
|
|
306
|
+
onKeyDown: L,
|
|
307
|
+
...m,
|
|
308
|
+
css: R,
|
|
300
309
|
children: [
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
310
|
+
d,
|
|
311
|
+
b,
|
|
312
|
+
n,
|
|
313
|
+
s && // TODO: loadingIndicator가 문자열이 아닌 경우 처리
|
|
314
|
+
/* @__PURE__ */ g(k, { visuallyHidden: !0, role: "status", "aria-live": "polite", "aria-atomic": "true", children: typeof t == "string" ? `${t} 중` : "로딩 중" })
|
|
304
315
|
]
|
|
305
316
|
}
|
|
306
317
|
);
|
|
307
318
|
});
|
|
308
319
|
export {
|
|
309
|
-
|
|
320
|
+
v as default
|
|
310
321
|
};
|
|
@@ -97,4 +97,4 @@
|
|
|
97
97
|
min-width: 100%;
|
|
98
98
|
height: 6px;
|
|
99
99
|
min-height: 6px;
|
|
100
|
-
`,xt=30,Je=5,bt=d.forwardRef(function({children:n,onChange:r,onChangeMonth:u,value:o,date:p,minDate:h,maxDate:y,holidayDates:je,disableDates:_,showWeekHead:Ce=!1,multiple:M=!1,period:re=!1,enableMonthSelect:J=!1,showToday:Ae=!1,edgeSpacing:he=0,renderEvent:F,inlineCSS:et,monthProps:ne,...tt},rt){const{spacing:ve}=pt.default(),[$,ie]=d.useState((typeof p=="string"||typeof p=="number"?new Date(p):p)||new Date),[x,Q]=d.useState(()=>Array.isArray(o)&&o.length>0?g(o[0]):g(o)),[Y,se]=d.useState(()=>Array.isArray(o)&&o.length>1?g(o[o.length-1]):null),[j,Te]=d.useState(0),[b,X]=d.useState(1),[Re,He]=d.useState(!1),[me,ye]=d.useState(!1),Z=d.useRef(null),D=d.useRef(null),oe=d.useRef(0),We=d.useRef(0),H=d.useRef(0),A=d.useRef(!1),C=d.useRef(b),ge=d.useRef(),ae=d.useRef(null),De=d.useRef(null),v=$.getFullYear(),ce=$.getMonth(),Fe=Me(v,ce),z=q(ce),N=g(o),B=g(je),K=g(_),we=G($,h)||pe($,h),$e=O($,y)||pe($,y),le=new Date(v,ce-1),ue=new Date(v,ce+1),L=`${v}. ${z}`,E=`${v}년 ${z}월`,P=re&&!!x&&!!Y,Ye=[{year:le.getFullYear(),month:q(le.getMonth()),weeks:Me(le.getFullYear(),le.getMonth())},{year:v,month:z,weeks:Fe},{year:ue.getFullYear(),month:q(ue.getMonth()),weeks:Me(ue.getFullYear(),ue.getMonth())}],xe=typeof F=="function",nt=Ye[1].weeks.length*(xt+(xe?10:0)+ve.content(2))+ve.content(2),ze=(t,l)=>()=>{D.current&&(D.current.style.transition="none",D.current.style.cursor="grabbing"),oe.current=t,We.current=l},I=d.useCallback(()=>{if(!A.current)return;const t=j-H.current,l=Math.abs(j-t),s=j*.1;D.current&&(D.current.style.transform=`translate3d(-${j*b}px, 0, 0)`,D.current.style.cursor="grab",D.current.style.transition="transform 0.2s"),oe.current=0,H.current=0,A.current=!1,!(l<=s)&&(j<t?X(c=>c+1):j>t&&X(c=>c-1))},[j,b]),be=(t,l)=>()=>{if(!(A.current||b!==1)&&!l){if(!re){r==null||r(t,g);return}if(R(t,x)&&Array.isArray(o)&&o.length===1){Q(null),se(null),r==null||r([],g);return}else if(R(t,x)&&!Array.isArray(o)&&R(t,o)){Q(null),se(null),r==null||r([],g);return}if(!x){Q(t),r==null||r(t,g);return}if(!Y&&x){const[s,c]=O(t,x)?[x,t]:[t,x];Q(s),se(c);const i=Ze([s,c],_);r==null||r(i,g);return}x&&Y&&(Q(t),se(null),r==null||r(t,g))}},it=t=>{M&&(A.current=!0,ze(t.clientX,t.clientY)())},st=t=>{M&&ze(t.touches[0].clientX,t.touches[0].clientY)()},Le=()=>{Re||(D.current&&(D.current.style.transition="transform 0.2s"),X(t=>t-1))},Ee=()=>{Re||(D.current&&(D.current.style.transition="transform 0.2s"),X(t=>t+1))},fe=t=>{t.stopPropagation(),ye(l=>!l)},ot=()=>ye(!1),at=t=>{if(!t)return;const[l,s]=t.toString().split(".").map(Number);ie(new Date(l,s-1)),u&&typeof u=="function"&&u(g(new Date(l,s-1)),g),ye(!1)},Ie=(t,l)=>s=>{const c=new Date(t);let i=null;if(s.stopPropagation(),s.key==="ArrowRight")i=new Date(c),i.setDate(c.getDate()+1);else if(s.key==="ArrowLeft")i=new Date(c),i.setDate(c.getDate()-1);else if(s.key==="ArrowDown")i=new Date(c),i.setDate(c.getDate()+7);else if(s.key==="ArrowUp")i=new Date(c),i.setDate(c.getDate()-7);else if(s.key==="Home")i=new Date(c),i.setDate(c.getDate()-c.getDay());else if(s.key==="End")i=new Date(c),i.setDate(c.getDate()+(6-c.getDay()));else if(s.key==="PageUp")i=new Date(c),i.setMonth(c.getMonth()-1);else if(s.key==="PageDown")i=new Date(c),i.setMonth(c.getMonth()+1);else if(s.key==="Enter"||s.key===" "){s.preventDefault(),be(t,l)();return}else if(s.key==="Escape"){s.preventDefault(),r==null||r([],g);return}if(i&&Z.current){const w=c.getMonth(),m=c.getFullYear(),k=i.getMonth(),f=i.getFullYear(),T=g(i),W=Z.current.querySelector(`[data-date="${T}"]`);if(W){if(w!==k||m!==f){i>c?(Ee(),setTimeout(()=>{W.focus()},0)):(Le(),setTimeout(()=>{W.focus()},0));return}W.focus()}}};return d.useLayoutEffect(()=>{var t;Te(((t=Z.current)==null?void 0:t.clientWidth)||0)},[M]),d.useEffect(()=>{const t=()=>{var l;Te(((l=Z.current)==null?void 0:l.clientWidth)||0)};return window.addEventListener("resize",t),window.addEventListener("scroll",t),()=>{window.removeEventListener("resize",t),window.removeEventListener("scroll",t)}},[M]),d.useEffect(()=>{const t=D.current,l=(i,w,m)=>{if(!t||!A.current&&oe.current===0)return;H.current=i-oe.current;const k=w-We.current;if(A.current=A.current||Math.abs(H.current)>Je&&Math.abs(k)<Je*2,A.current&&m.cancelable&&(m.preventDefault(),m.stopPropagation()),A.current){if(we&&H.current>0){I();return}if($e&&H.current<0){I();return}Math.abs(H.current)>=10&&(t.style.transform=`translate3d(${H.current-j*b}px, 0, 0)`,t.style.cursor="grabbing")}},s=i=>l(i.touches[0].clientX,i.touches[0].clientY,i),c=i=>{A.current&&l(i.clientX,i.clientY,i)};return t==null||t.addEventListener("mousemove",c),t==null||t.addEventListener("touchmove",s),()=>{t==null||t.removeEventListener("mousemove",c),t==null||t.removeEventListener("touchmove",s)}},[j,b,I,$e,we]),d.useEffect(()=>{He(!0),ge.current=setTimeout(()=>{if(D.current&&(D.current.style.transition="none"),b>C.current){X(1);const t=new Date($.setMonth($.getMonth()+1));ie(t),u&&typeof u=="function"&&u(g(t),g),C.current=1}else if(b<C.current){const t=new Date($.setMonth($.getMonth()-1));ie(t),u&&typeof u=="function"&&u(g(t),g),X(1),C.current=1}else C.current=b;He(!1)},200)},[b,$,u]),d.useLayoutEffect(()=>{if(!re||!Array.isArray(o))return;const t=Ze(o,_);o.length<t.length&&(r==null||r(t,g))},[re,o,r,_]),d.useEffect(()=>{let t;return me&&(t=setTimeout(()=>{if(De.current){const l=De.current.querySelector("ul"),s=l==null?void 0:l.querySelector(`[data-value="${L}"]`);s==null||s.scrollIntoView({block:"start"})}},200)),()=>{clearTimeout(t)}},[me,L]),d.useEffect(()=>()=>{ge.current&&clearTimeout(ge.current)},[]),d.useEffect(()=>{p&&ie((typeof p=="string"||typeof p=="number"?new Date(p):p)||new Date)},[p]),a.jsxs(yt,{ref:rt,"aria-label":"달력",role:"application",...tt,css:et,children:[M?a.jsxs(gt,{children:[a.jsx(Xe.default,{name:"ChevronLeftLine",size:"small",onClick:Le,disabled:we,"aria-label":`이전 달로 이동, 현재 ${E}`}),J&&a.jsxs(Ge,{ref:ae,clickable:!0,onClick:fe,"aria-label":E,...ne,children:[L,a.jsx(Ne.default,{iconOnly:!0,isMenuOpen:!1,size:"xSmall",variant:"text",menuId:"date-picker-month-menu",onClick:fe,"aria-label":`달 변경, 현재 ${E}`,startAdornment:a.jsx(_e.default,{name:"ArrowDownFill",size:"xSmall"})})]}),!J&&a.jsx(Ge,{ref:ae,id:"date-picker-title",clickable:!1,"aria-label":E,...ne,children:L}),a.jsx(Xe.default,{name:"ChevronRightLine",size:"small",onClick:Ee,disabled:$e,"aria-label":`다음 달로 이동, 현재 ${E}`})]}):a.jsxs(a.Fragment,{children:[J&&a.jsxs(Be,{ref:ae,clickable:!0,onClick:fe,"aria-label":E,...ne,children:[L,a.jsx(Ne.default,{iconOnly:!0,isMenuOpen:!1,size:"xSmall",variant:"text",menuId:"date-picker-month-menu",onClick:fe,"aria-label":`달 변경, 현재 ${E}`,startAdornment:a.jsx(_e.default,{name:"ArrowDownFill",size:"xSmall"})})]}),!J&&a.jsx(Be,{id:"date-picker-title",clickable:!1,...ne,children:L})]}),J&&a.jsx(ft.default,{id:"date-picker-month-menu",anchorRef:ae,ref:De,open:me,onClose:ot,onChange:at,value:L,placement:M?"bottom-center":"bottom-left",width:160,fitToAnchorWidth:!1,maxHeight:368,children:Array.from({length:130},(t,l)=>{const s=1970+l;return Array.from({length:12},(c,i)=>{const w=i+1,m=w<10?`0${w}`:w,k=new Date(s,i+1,0).getDate(),f=`${s}-${m}-${k}`,T=`${s}-${m}-01`;return G(f,h)||O(T,y)?null:a.jsx(dt.default,{value:`${s}. ${m}`,"aria-label":`${s}년 ${m}월 선택`,children:`${s}. ${m}`},`${s}-${m}`)})})}),a.jsxs(ut.default,{flexDirection:"column",role:"grid","aria-label":`${v}년 ${z}월 달력`,children:[Ce&&a.jsxs(Dt,{id:"date-picker-week-head",role:"row",edgeSpacing:he,children:[a.jsx("span",{role:"columnheader",children:"일"}),a.jsx("span",{role:"columnheader",children:"월"}),a.jsx("span",{role:"columnheader",children:"화"}),a.jsx("span",{role:"columnheader",children:"수"}),a.jsx("span",{role:"columnheader",children:"목"}),a.jsx("span",{role:"columnheader",children:"금"}),a.jsx("span",{role:"columnheader",children:"토"})]}),a.jsx(wt,{ref:Z,role:"presentation",children:a.jsxs($t,{role:"presentation",ref:D,onMouseDown:it,onMouseUp:I,onMouseLeave:I,onTouchStart:st,onTouchEnd:I,onTouchCancel:I,style:{transform:M?`translate3d(-${j*b}px, 0, 0)`:void 0,cursor:M?"grab":void 0,maxHeight:nt},children:[M&&Ye.map(({year:t,month:l,weeks:s},c)=>a.jsx(Ke,{role:"rowgroup",edgeSpacing:he,className:c===1?"week-body-current":"",children:s.map((i,w)=>a.jsx(Pe,{role:"row",children:i.map((m,k)=>{const f=`${t}-${l}-${V(m||0)}`,T=!m,W=R(f,new Date),ke=Array.isArray(B)?B.includes(f):B===f,ee=Array.isArray(N)?N.includes(f):N===f,U=!m||(Array.isArray(K)?K.includes(f):K===f)||O(f,y)||G(f,h),Se=P&&R(f,x),de=P&&R(f,Y),ct=P&&O(f,x)&&G(f,Y),Oe=pe(f,$),lt=Oe&&w===0&&m===1||Oe&&ee,qe=F==null?void 0:F(f);return a.jsxs(Ue,{as:"button",role:"gridcell",variant:Se?"start":de?"end":ct?"middle":void 0,onClick:be(f,U),today:Ae&&W,holiday:ke,tabIndex:lt?0:-1,"aria-rowindex":w+1,"aria-colindex":k+1,selected:ee,"aria-selected":ee,"aria-disabled":U,"aria-hidden":m===null,"data-date":f,onKeyDown:Ie(f,U),children:[a.jsx("div",{"aria-label":`${Qe(f)}`,children:a.jsx("span",{children:m})}),!T&&qe,!T&&xe&&!qe&&a.jsx(Ve,{})]},`${t}-${l}-week-row-${k}-${m?f:`${w}-${k}`}`)})},`${t}-${l}-week-row-${String(i)}`))},`week-body-${t}-${l}`)),!M&&a.jsx(Ke,{role:"rowgroup",edgeSpacing:he,children:Fe.map((t,l)=>a.jsx(Pe,{role:"row",children:t.map((s,c)=>{const i=`${v}-${z}-${V(s||0)}`,w=!s,m=R(i,new Date),k=Array.isArray(B)?B.includes(i):B===i,f=Array.isArray(N)?N.includes(i):N===i,T=!s||(Array.isArray(K)?K.includes(i):K===i)||O(i,y)||G(i,h),W=P&&R(i,x),ke=P&&R(i,Y),ee=P&&O(i,x)&&G(i,Y),U=pe(i,$),Se=U&&l===0&&s===1||U&&f,de=F==null?void 0:F(i);return a.jsxs(Ue,{as:"button",variant:W?"start":ke?"end":ee?"middle":void 0,role:"gridcell",onClick:be(i,T),today:Ae&&m,holiday:k,"aria-rowindex":l+1,"aria-colindex":c+1,selected:f,"aria-selected":f,"aria-disabled":T,"aria-hidden":s===null,tabIndex:Se?0:-1,"data-date":i,onKeyDown:Ie(i,T),children:[a.jsx("div",{"aria-label":`${Qe(i)}`,children:a.jsx("span",{children:s})}),!w&&de,!w&&xe&&!de&&a.jsx(Ve,{})]},`${v}-${z}-week-row-${t}-${s?i:`${l}-${c}`}`)})},`${v}-${z}-week-row-${String(t)}`))})]})})]}),n]})});function Me(e,n){let r=[];const u=new Date(e,n,1),o=new Date(e,n+1,0).getDate(),p=u.getDay();let h=Array.from({length:p}).fill(null);for(let y=1;y<=o;y+=1)h.push(y),(h.length===7||y===o)&&(r.push(h),h=[]);return r=r.map(y=>Array.from({length:7}).map((je,_)=>y[_]||null)),r}function q(e){return String(e+1).length===1?`0${e+1}`:e+1}function V(e){return String(e).length===1?`0${e}`:e}function g(e){if(Array.isArray(e))return e.map(n=>n instanceof Date?`${n.getFullYear()}-${q(n.getMonth())}-${V(n.getDate())}`:n);if(e instanceof Date)return`${e.getFullYear()}-${q(e.getMonth())}-${V(e.getDate())}`;if(typeof e=="number"){const n=new Date(e);return`${n.getFullYear()}-${q(n.getMonth())}-${V(n.getDate())}`}return e}function Qe(e){const[n,r,u]=e.split("-");return`${n}년 ${Number(r)}월 ${Number(u)}일`}function O(e,n){if(!e||!n)return!1;const r=e instanceof Date?e:new Date(e);r.setHours(0),r.setMinutes(0),r.setSeconds(0),r.setMilliseconds(0);const u=r.getTime(),o=n instanceof Date?n:new Date(n);o.setHours(0),o.setMinutes(0),o.setSeconds(0),o.setMilliseconds(0);const p=o.getTime();return u>p}function G(e,n){if(!e||!n)return!1;const r=e instanceof Date?e:new Date(e);r.setHours(0),r.setMinutes(0),r.setSeconds(0),r.setMilliseconds(0);const u=r.getTime(),o=n instanceof Date?n:new Date(n);o.setHours(0),o.setMinutes(0),o.setSeconds(0),o.setMilliseconds(0);const p=o.getTime();return u<p}function pe(e,n){if(!e||!n)return!1;const r=e instanceof Date?e:new Date(e),u=n instanceof Date?n:new Date(n);return`${r.getFullYear()}-${r.getMonth()}`==`${u.getFullYear()}-${u.getMonth()}`}function R(e,n){if(!e||!n)return!1;const r=e instanceof Date?e:new Date(e);r.setHours(0),r.setMinutes(0),r.setSeconds(0),r.setMilliseconds(0);const u=r.getTime(),o=n instanceof Date?n:new Date(n);o.setHours(0),o.setMinutes(0),o.setSeconds(0),o.setMilliseconds(0);const p=o.getTime();return u===p}function Ze(e,n){if(!e||!Array.isArray(e)||e.length===0)return[];const r=e.map(y=>y instanceof Date?y:y===null?new Date:new Date(y)),u=new Date(Math.min(...r.map(y=>y.getTime()))),o=new Date(Math.max(...r.map(y=>y.getTime()))),p=[],h=new Date(u);for(;h<=o;){if(Array.isArray(n)&&n.includes(h)){h.setDate(h.getDate()+1);continue}else if(n===h){h.setDate(h.getDate()+1);continue}p.push(`${h.getFullYear()}-${q(h.getMonth())}-${V(h.getDate())}`),h.setDate(h.getDate()+1)}return p}exports.default=bt;
|
|
100
|
+
`,xt=30,Je=5,bt=d.forwardRef(function({children:n,onChange:r,onChangeMonth:u,value:o,date:p,minDate:h,maxDate:y,holidayDates:je,disableDates:_,showWeekHead:Ce=!1,multiple:M=!1,period:re=!1,enableMonthSelect:J=!1,showToday:Ae=!1,edgeSpacing:he=0,renderEvent:F,inlineCSS:et,monthProps:ne,...tt},rt){const{spacing:ve}=pt.default(),[$,ie]=d.useState((typeof p=="string"||typeof p=="number"?new Date(p):p)||new Date),[x,Q]=d.useState(()=>Array.isArray(o)&&o.length>0?g(o[0]):g(o)),[Y,se]=d.useState(()=>Array.isArray(o)&&o.length>1?g(o[o.length-1]):null),[j,Te]=d.useState(0),[b,X]=d.useState(1),[Re,He]=d.useState(!1),[me,ye]=d.useState(!1),Z=d.useRef(null),D=d.useRef(null),oe=d.useRef(0),We=d.useRef(0),H=d.useRef(0),A=d.useRef(!1),C=d.useRef(b),ge=d.useRef(),ae=d.useRef(null),De=d.useRef(null),v=$.getFullYear(),ce=$.getMonth(),Fe=Me(v,ce),z=q(ce),N=g(o),B=g(je),K=g(_),we=G($,h)||pe($,h),$e=O($,y)||pe($,y),le=new Date(v,ce-1),ue=new Date(v,ce+1),L=`${v}. ${z}`,E=`${v}년 ${z}월`,P=re&&!!x&&!!Y,Ye=[{year:le.getFullYear(),month:q(le.getMonth()),weeks:Me(le.getFullYear(),le.getMonth())},{year:v,month:z,weeks:Fe},{year:ue.getFullYear(),month:q(ue.getMonth()),weeks:Me(ue.getFullYear(),ue.getMonth())}],xe=typeof F=="function",nt=Ye[1].weeks.length*(xt+(xe?10:0)+ve.content(2))+ve.content(2),ze=(t,l)=>()=>{D.current&&(D.current.style.transition="none",D.current.style.cursor="grabbing"),oe.current=t,We.current=l},I=d.useCallback(()=>{if(!A.current)return;const t=j-H.current,l=Math.abs(j-t),s=j*.1;D.current&&(D.current.style.transform=`translate3d(-${j*b}px, 0, 0)`,D.current.style.cursor="grab",D.current.style.transition="transform 0.2s"),oe.current=0,H.current=0,A.current=!1,!(l<=s)&&(j<t?X(c=>c+1):j>t&&X(c=>c-1))},[j,b]),be=(t,l)=>()=>{if(!(A.current||b!==1)&&!l){if(!re){r==null||r(t,g);return}if(R(t,x)&&Array.isArray(o)&&o.length===1){Q(null),se(null),r==null||r([],g);return}else if(R(t,x)&&!Array.isArray(o)&&R(t,o)){Q(null),se(null),r==null||r([],g);return}if(!x){Q(t),r==null||r(t,g);return}if(!Y&&x){const[s,c]=O(t,x)?[x,t]:[t,x];Q(s),se(c);const i=Ze([s,c],_);r==null||r(i,g);return}x&&Y&&(Q(t),se(null),r==null||r(t,g))}},it=t=>{M&&(A.current=!0,ze(t.clientX,t.clientY)())},st=t=>{M&&ze(t.touches[0].clientX,t.touches[0].clientY)()},Le=()=>{Re||(D.current&&(D.current.style.transition="transform 0.2s"),X(t=>t-1))},Ee=()=>{Re||(D.current&&(D.current.style.transition="transform 0.2s"),X(t=>t+1))},fe=t=>{t.stopPropagation(),ye(l=>!l)},ot=()=>ye(!1),at=t=>{if(!t)return;const[l,s]=t.toString().split(".").map(Number);ie(new Date(l,s-1)),u&&typeof u=="function"&&u(g(new Date(l,s-1)),g),ye(!1)},Ie=(t,l)=>s=>{const c=new Date(t);let i=null;if(s.stopPropagation(),s.key==="ArrowRight")i=new Date(c),i.setDate(c.getDate()+1);else if(s.key==="ArrowLeft")i=new Date(c),i.setDate(c.getDate()-1);else if(s.key==="ArrowDown")i=new Date(c),i.setDate(c.getDate()+7);else if(s.key==="ArrowUp")i=new Date(c),i.setDate(c.getDate()-7);else if(s.key==="Home")i=new Date(c),i.setDate(c.getDate()-c.getDay());else if(s.key==="End")i=new Date(c),i.setDate(c.getDate()+(6-c.getDay()));else if(s.key==="PageUp")i=new Date(c),i.setMonth(c.getMonth()-1);else if(s.key==="PageDown")i=new Date(c),i.setMonth(c.getMonth()+1);else if(s.key==="Enter"||s.key===" "){s.preventDefault(),be(t,l)();return}else if(s.key==="Escape"){s.preventDefault(),r==null||r([],g);return}if(i&&Z.current){const w=c.getMonth(),m=c.getFullYear(),k=i.getMonth(),f=i.getFullYear(),T=g(i),W=Z.current.querySelector(`[data-date="${T}"]`);if(W){if(w!==k||m!==f){i>c?(Ee(),setTimeout(()=>{W.focus()},0)):(Le(),setTimeout(()=>{W.focus()},0));return}W.focus()}}};return d.useLayoutEffect(()=>{var t;Te(((t=Z.current)==null?void 0:t.clientWidth)||0)},[M]),d.useEffect(()=>{const t=()=>{var l;Te(((l=Z.current)==null?void 0:l.clientWidth)||0)};return window.addEventListener("resize",t),window.addEventListener("scroll",t),()=>{window.removeEventListener("resize",t),window.removeEventListener("scroll",t)}},[M]),d.useEffect(()=>{const t=D.current,l=(i,w,m)=>{if(!t||!A.current&&oe.current===0)return;H.current=i-oe.current;const k=w-We.current;if(A.current=A.current||Math.abs(H.current)>Je&&Math.abs(k)<Je*2,A.current&&m.cancelable&&(m.preventDefault(),m.stopPropagation()),A.current){if(we&&H.current>0){I();return}if($e&&H.current<0){I();return}Math.abs(H.current)>=10&&(t.style.transform=`translate3d(${H.current-j*b}px, 0, 0)`,t.style.cursor="grabbing")}},s=i=>l(i.touches[0].clientX,i.touches[0].clientY,i),c=i=>{A.current&&l(i.clientX,i.clientY,i)};return t==null||t.addEventListener("mousemove",c),t==null||t.addEventListener("touchmove",s),()=>{t==null||t.removeEventListener("mousemove",c),t==null||t.removeEventListener("touchmove",s)}},[j,b,I,$e,we]),d.useEffect(()=>{He(!0),ge.current=setTimeout(()=>{if(D.current&&(D.current.style.transition="none"),b>C.current){X(1);const t=new Date($.setMonth($.getMonth()+1,1));ie(t),u&&typeof u=="function"&&u(g(t),g),C.current=1}else if(b<C.current){const t=new Date($.setMonth($.getMonth()-1,1));ie(t),u&&typeof u=="function"&&u(g(t),g),X(1),C.current=1}else C.current=b;He(!1)},200)},[b,$,u]),d.useLayoutEffect(()=>{if(!re||!Array.isArray(o))return;const t=Ze(o,_);o.length<t.length&&(r==null||r(t,g))},[re,o,r,_]),d.useEffect(()=>{let t;return me&&(t=setTimeout(()=>{if(De.current){const l=De.current.querySelector("ul"),s=l==null?void 0:l.querySelector(`[data-value="${L}"]`);s==null||s.scrollIntoView({block:"start"})}},200)),()=>{clearTimeout(t)}},[me,L]),d.useEffect(()=>()=>{ge.current&&clearTimeout(ge.current)},[]),d.useEffect(()=>{p&&ie((typeof p=="string"||typeof p=="number"?new Date(p):p)||new Date)},[p]),a.jsxs(yt,{ref:rt,"aria-label":"달력",role:"application",...tt,css:et,children:[M?a.jsxs(gt,{children:[a.jsx(Xe.default,{name:"ChevronLeftLine",size:"small",onClick:Le,disabled:we,"aria-label":`이전 달로 이동, 현재 ${E}`}),J&&a.jsxs(Ge,{ref:ae,clickable:!0,onClick:fe,"aria-label":E,...ne,children:[L,a.jsx(Ne.default,{iconOnly:!0,isMenuOpen:!1,size:"xSmall",variant:"text",menuId:"date-picker-month-menu",onClick:fe,"aria-label":`달 변경, 현재 ${E}`,startAdornment:a.jsx(_e.default,{name:"ArrowDownFill",size:"xSmall"})})]}),!J&&a.jsx(Ge,{ref:ae,id:"date-picker-title",clickable:!1,"aria-label":E,...ne,children:L}),a.jsx(Xe.default,{name:"ChevronRightLine",size:"small",onClick:Ee,disabled:$e,"aria-label":`다음 달로 이동, 현재 ${E}`})]}):a.jsxs(a.Fragment,{children:[J&&a.jsxs(Be,{ref:ae,clickable:!0,onClick:fe,"aria-label":E,...ne,children:[L,a.jsx(Ne.default,{iconOnly:!0,isMenuOpen:!1,size:"xSmall",variant:"text",menuId:"date-picker-month-menu",onClick:fe,"aria-label":`달 변경, 현재 ${E}`,startAdornment:a.jsx(_e.default,{name:"ArrowDownFill",size:"xSmall"})})]}),!J&&a.jsx(Be,{id:"date-picker-title",clickable:!1,...ne,children:L})]}),J&&a.jsx(ft.default,{id:"date-picker-month-menu",anchorRef:ae,ref:De,open:me,onClose:ot,onChange:at,value:L,placement:M?"bottom-center":"bottom-left",width:160,fitToAnchorWidth:!1,maxHeight:368,children:Array.from({length:130},(t,l)=>{const s=1970+l;return Array.from({length:12},(c,i)=>{const w=i+1,m=w<10?`0${w}`:w,k=new Date(s,i+1,0).getDate(),f=`${s}-${m}-${k}`,T=`${s}-${m}-01`;return G(f,h)||O(T,y)?null:a.jsx(dt.default,{value:`${s}. ${m}`,"aria-label":`${s}년 ${m}월 선택`,children:`${s}. ${m}`},`${s}-${m}`)})})}),a.jsxs(ut.default,{flexDirection:"column",role:"grid","aria-label":`${v}년 ${z}월 달력`,children:[Ce&&a.jsxs(Dt,{id:"date-picker-week-head",role:"row",edgeSpacing:he,children:[a.jsx("span",{role:"columnheader",children:"일"}),a.jsx("span",{role:"columnheader",children:"월"}),a.jsx("span",{role:"columnheader",children:"화"}),a.jsx("span",{role:"columnheader",children:"수"}),a.jsx("span",{role:"columnheader",children:"목"}),a.jsx("span",{role:"columnheader",children:"금"}),a.jsx("span",{role:"columnheader",children:"토"})]}),a.jsx(wt,{ref:Z,role:"presentation",children:a.jsxs($t,{role:"presentation",ref:D,onMouseDown:it,onMouseUp:I,onMouseLeave:I,onTouchStart:st,onTouchEnd:I,onTouchCancel:I,style:{transform:M?`translate3d(-${j*b}px, 0, 0)`:void 0,cursor:M?"grab":void 0,maxHeight:nt},children:[M&&Ye.map(({year:t,month:l,weeks:s},c)=>a.jsx(Ke,{role:"rowgroup",edgeSpacing:he,className:c===1?"week-body-current":"",children:s.map((i,w)=>a.jsx(Pe,{role:"row",children:i.map((m,k)=>{const f=`${t}-${l}-${V(m||0)}`,T=!m,W=R(f,new Date),ke=Array.isArray(B)?B.includes(f):B===f,ee=Array.isArray(N)?N.includes(f):N===f,U=!m||(Array.isArray(K)?K.includes(f):K===f)||O(f,y)||G(f,h),Se=P&&R(f,x),de=P&&R(f,Y),ct=P&&O(f,x)&&G(f,Y),Oe=pe(f,$),lt=Oe&&w===0&&m===1||Oe&&ee,qe=F==null?void 0:F(f);return a.jsxs(Ue,{as:"button",role:"gridcell",variant:Se?"start":de?"end":ct?"middle":void 0,onClick:be(f,U),today:Ae&&W,holiday:ke,tabIndex:lt?0:-1,"aria-rowindex":w+1,"aria-colindex":k+1,selected:ee,"aria-selected":ee,"aria-disabled":U,"aria-hidden":m===null,"data-date":f,onKeyDown:Ie(f,U),children:[a.jsx("div",{"aria-label":`${Qe(f)}`,children:a.jsx("span",{children:m})}),!T&&qe,!T&&xe&&!qe&&a.jsx(Ve,{})]},`${t}-${l}-week-row-${k}-${m?f:`${w}-${k}`}`)})},`${t}-${l}-week-row-${String(i)}`))},`week-body-${t}-${l}`)),!M&&a.jsx(Ke,{role:"rowgroup",edgeSpacing:he,children:Fe.map((t,l)=>a.jsx(Pe,{role:"row",children:t.map((s,c)=>{const i=`${v}-${z}-${V(s||0)}`,w=!s,m=R(i,new Date),k=Array.isArray(B)?B.includes(i):B===i,f=Array.isArray(N)?N.includes(i):N===i,T=!s||(Array.isArray(K)?K.includes(i):K===i)||O(i,y)||G(i,h),W=P&&R(i,x),ke=P&&R(i,Y),ee=P&&O(i,x)&&G(i,Y),U=pe(i,$),Se=U&&l===0&&s===1||U&&f,de=F==null?void 0:F(i);return a.jsxs(Ue,{as:"button",variant:W?"start":ke?"end":ee?"middle":void 0,role:"gridcell",onClick:be(i,T),today:Ae&&m,holiday:k,"aria-rowindex":l+1,"aria-colindex":c+1,selected:f,"aria-selected":f,"aria-disabled":T,"aria-hidden":s===null,tabIndex:Se?0:-1,"data-date":i,onKeyDown:Ie(i,T),children:[a.jsx("div",{"aria-label":`${Qe(i)}`,children:a.jsx("span",{children:s})}),!w&&de,!w&&xe&&!de&&a.jsx(Ve,{})]},`${v}-${z}-week-row-${t}-${s?i:`${l}-${c}`}`)})},`${v}-${z}-week-row-${String(t)}`))})]})})]}),n]})});function Me(e,n){let r=[];const u=new Date(e,n,1),o=new Date(e,n+1,0).getDate(),p=u.getDay();let h=Array.from({length:p}).fill(null);for(let y=1;y<=o;y+=1)h.push(y),(h.length===7||y===o)&&(r.push(h),h=[]);return r=r.map(y=>Array.from({length:7}).map((je,_)=>y[_]||null)),r}function q(e){return String(e+1).length===1?`0${e+1}`:e+1}function V(e){return String(e).length===1?`0${e}`:e}function g(e){if(Array.isArray(e))return e.map(n=>n instanceof Date?`${n.getFullYear()}-${q(n.getMonth())}-${V(n.getDate())}`:n);if(e instanceof Date)return`${e.getFullYear()}-${q(e.getMonth())}-${V(e.getDate())}`;if(typeof e=="number"){const n=new Date(e);return`${n.getFullYear()}-${q(n.getMonth())}-${V(n.getDate())}`}return e}function Qe(e){const[n,r,u]=e.split("-");return`${n}년 ${Number(r)}월 ${Number(u)}일`}function O(e,n){if(!e||!n)return!1;const r=e instanceof Date?e:new Date(e);r.setHours(0),r.setMinutes(0),r.setSeconds(0),r.setMilliseconds(0);const u=r.getTime(),o=n instanceof Date?n:new Date(n);o.setHours(0),o.setMinutes(0),o.setSeconds(0),o.setMilliseconds(0);const p=o.getTime();return u>p}function G(e,n){if(!e||!n)return!1;const r=e instanceof Date?e:new Date(e);r.setHours(0),r.setMinutes(0),r.setSeconds(0),r.setMilliseconds(0);const u=r.getTime(),o=n instanceof Date?n:new Date(n);o.setHours(0),o.setMinutes(0),o.setSeconds(0),o.setMilliseconds(0);const p=o.getTime();return u<p}function pe(e,n){if(!e||!n)return!1;const r=e instanceof Date?e:new Date(e),u=n instanceof Date?n:new Date(n);return`${r.getFullYear()}-${r.getMonth()}`==`${u.getFullYear()}-${u.getMonth()}`}function R(e,n){if(!e||!n)return!1;const r=e instanceof Date?e:new Date(e);r.setHours(0),r.setMinutes(0),r.setSeconds(0),r.setMilliseconds(0);const u=r.getTime(),o=n instanceof Date?n:new Date(n);o.setHours(0),o.setMinutes(0),o.setSeconds(0),o.setMilliseconds(0);const p=o.getTime();return u===p}function Ze(e,n){if(!e||!Array.isArray(e)||e.length===0)return[];const r=e.map(y=>y instanceof Date?y:y===null?new Date:new Date(y)),u=new Date(Math.min(...r.map(y=>y.getTime()))),o=new Date(Math.max(...r.map(y=>y.getTime()))),p=[],h=new Date(u);for(;h<=o;){if(Array.isArray(n)&&n.includes(h)){h.setDate(h.getDate()+1);continue}else if(n===h){h.setDate(h.getDate()+1);continue}p.push(`${h.getFullYear()}-${q(h.getMonth())}-${V(h.getDate())}`),h.setDate(h.getDate()+1)}return p}exports.default=bt;
|
|
@@ -451,10 +451,10 @@ const be = k.div`
|
|
|
451
451
|
zt(!0), $t.current = setTimeout(() => {
|
|
452
452
|
if (g.current && (g.current.style.transition = "none"), b > rt.current) {
|
|
453
453
|
K(1);
|
|
454
|
-
const e = new Date(w.setMonth(w.getMonth() + 1));
|
|
454
|
+
const e = new Date(w.setMonth(w.getMonth() + 1, 1));
|
|
455
455
|
at(e), l && typeof l == "function" && l(y(e), y), rt.current = 1;
|
|
456
456
|
} else if (b < rt.current) {
|
|
457
|
-
const e = new Date(w.setMonth(w.getMonth() - 1));
|
|
457
|
+
const e = new Date(w.setMonth(w.getMonth() - 1, 1));
|
|
458
458
|
at(e), l && typeof l == "function" && l(y(e), y), K(1), rt.current = 1;
|
|
459
459
|
} else
|
|
460
460
|
rt.current = b;
|
package/hooks/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./useCheckHoverPossible/useCheckHoverPossible.cjs"),u=require("./useCheckKeyboardMode/useCheckKeyboardMode.cjs"),s=require("./useCheckHasFocus/useCheckHasFocus.cjs"),o=require("./useFocusBoundary/useFocusBoundary.cjs"),r=require("./interactions/useCollapse/useCollapse.cjs"),t=require("./useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs"),c=require("./usePrefersReducedMotion/usePrefersReducedMotion.cjs");exports.useCheckHoverPossible=e.default;exports.useCheckKeyboardMode=u.default;exports.useCheckHasFocus=s.default;exports.useFocusBoundary=o.default;exports.useCollapse=r.default;exports.useIsomorphicLayoutEffect=t.default;exports.usePrefersReducedMotion=c.default;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./useCheckHoverPossible/useCheckHoverPossible.cjs"),u=require("./useCheckKeyboardMode/useCheckKeyboardMode.cjs"),s=require("./useCheckHasFocus/useCheckHasFocus.cjs"),o=require("./useFocusBoundary/useFocusBoundary.cjs"),r=require("./interactions/useCollapse/useCollapse.cjs"),t=require("./useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs"),c=require("./usePrefersReducedMotion/usePrefersReducedMotion.cjs"),a=require("./useForm/useForm.cjs");exports.useCheckHoverPossible=e.default;exports.useCheckKeyboardMode=u.default;exports.useCheckHasFocus=s.default;exports.useFocusBoundary=o.default;exports.useCollapse=r.default;exports.useIsomorphicLayoutEffect=t.default;exports.usePrefersReducedMotion=c.default;exports.useForm=a.default;
|
package/hooks/index.d.ts
CHANGED
|
@@ -5,5 +5,7 @@ export { default as useFocusBoundary } from './useFocusBoundary/useFocusBoundary
|
|
|
5
5
|
export { default as useCollapse } from './interactions/useCollapse/useCollapse';
|
|
6
6
|
export { default as useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';
|
|
7
7
|
export { default as usePrefersReducedMotion } from './usePrefersReducedMotion/usePrefersReducedMotion';
|
|
8
|
+
export { default as useForm } from './useForm/useForm';
|
|
8
9
|
export type { UseFocusBoundaryProps } from './useFocusBoundary/useFocusBoundary';
|
|
9
10
|
export type { UseCollapseProps } from './interactions/useCollapse/useCollapse';
|
|
11
|
+
export type { FieldErrors, FormContext, FormFieldHelper, OnSubmitFn, SubmitFn, ValidateFn, UseFormProps, UseFormReturn } from './useForm/useForm';
|
package/hooks/index.es.js
CHANGED
|
@@ -2,15 +2,17 @@ import { default as s } from "./useCheckHoverPossible/useCheckHoverPossible.es.j
|
|
|
2
2
|
import { default as a } from "./useCheckKeyboardMode/useCheckKeyboardMode.es.js";
|
|
3
3
|
import { default as f } from "./useCheckHasFocus/useCheckHasFocus.es.js";
|
|
4
4
|
import { default as d } from "./useFocusBoundary/useFocusBoundary.es.js";
|
|
5
|
-
import { default as
|
|
6
|
-
import { default as
|
|
5
|
+
import { default as m } from "./interactions/useCollapse/useCollapse.es.js";
|
|
6
|
+
import { default as c } from "./useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.es.js";
|
|
7
7
|
import { default as h } from "./usePrefersReducedMotion/usePrefersReducedMotion.es.js";
|
|
8
|
+
import { default as i } from "./useForm/useForm.es.js";
|
|
8
9
|
export {
|
|
9
10
|
f as useCheckHasFocus,
|
|
10
11
|
s as useCheckHoverPossible,
|
|
11
12
|
a as useCheckKeyboardMode,
|
|
12
|
-
|
|
13
|
+
m as useCollapse,
|
|
13
14
|
d as useFocusBoundary,
|
|
14
|
-
|
|
15
|
+
i as useForm,
|
|
16
|
+
c as useIsomorphicLayoutEffect,
|
|
15
17
|
h as usePrefersReducedMotion
|
|
16
18
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("react"),y=require("./useForm.utils.cjs");function O({fieldNames:S,values:u,validate:C,meta:n,scrollOptions:k,scrollOnError:d=!0,focusOnError:o=!1}){const a=t.useRef(new Map),E=t.useRef(new Map),[l,b]=t.useState({}),[V,F]=t.useState(!1),R=d||o,_=t.useCallback(e=>{const r=E.current.get(e);if(r)return r;const s=c=>{c?a.current.set(e,c):a.current.delete(e)};return E.current.set(e,s),s},[]),i=t.useCallback(e=>{requestAnimationFrame(()=>{for(const r of S){if(!(e==null?void 0:e[r]))continue;const c=a.current.get(r);if(d&&c&&c.scrollIntoView(k??y.DEFAULT_SCROLL_OPTIONS),o&&c){const g=c.querySelector('input:not([type="hidden"]):not([disabled]), textarea:not([disabled])');g==null||g.focus({preventScroll:!0})}break}})},[S,k,d,o]),w=t.useCallback(()=>{const e={};return C({values:u,meta:n,fieldRefs:a.current,error:e})},[C,u,n]),f=t.useCallback(({callEffectOnError:e=!0}={})=>{const r=w();b(r);const s=y.hasError(r);return s&&e&&R&&i(r),{isValid:!s,errors:r}},[w,R,i]),m=t.useCallback(({callEffectOnError:e=!0}={})=>{f({callEffectOnError:e})},[f]),q=t.useCallback(()=>{b({})},[]),M=t.useCallback((e,r)=>{b(s=>({...s,[e]:r}))},[]),h=t.useCallback(e=>{i(e)},[i]),I=t.useCallback(e=>{const r=l==null?void 0:l[e];if(r)return{severity:"error",message:r}},[l]),L=t.useCallback((e={})=>async()=>{F(!0);const{isValid:r,errors:s}=f({callEffectOnError:!0}),c={values:u,meta:n,fieldRefs:a.current,error:s};r?e!=null&&e.onSuccess&&await e.onSuccess(c):e!=null&&e.onError&&await e.onError(c),e!=null&&e.onSettled&&await e.onSettled(c)},[f,u,n,F]);return{isSubmitted:V,errors:l,registerField:_,clearErrors:q,triggerValidate:m,triggerSetFieldError:M,triggerEffectOnError:h,getFieldHelper:I,submit:L}}exports.default=O;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { DEFAULT_SCROLL_OPTIONS } from './useForm.utils';
|
|
2
|
+
|
|
3
|
+
export type FieldErrors<K extends string> = Partial<Record<K, string>>;
|
|
4
|
+
export type FormFieldHelper = {
|
|
5
|
+
severity: 'error';
|
|
6
|
+
message?: string;
|
|
7
|
+
};
|
|
8
|
+
export type FormContext<V, N extends string, M> = {
|
|
9
|
+
values: V;
|
|
10
|
+
meta?: M;
|
|
11
|
+
fieldRefs: Map<N, HTMLElement | null>;
|
|
12
|
+
error: FieldErrors<N>;
|
|
13
|
+
};
|
|
14
|
+
export type ValidateFn<V, N extends string, M> = (ctx: FormContext<V, N, M>) => FieldErrors<N>;
|
|
15
|
+
export type OnSubmitFn<V, N extends string, M> = (ctx: FormContext<V, N, M>) => void | Promise<void>;
|
|
16
|
+
export type SubmitFn<V, N extends string, M> = (options?: Partial<Record<'onError' | 'onSuccess' | 'onSettled', OnSubmitFn<V, N, M>>>) => () => Promise<void>;
|
|
17
|
+
export interface UseFormProps<V, N extends string, M> {
|
|
18
|
+
fieldNames: readonly N[];
|
|
19
|
+
values: V;
|
|
20
|
+
validate: ValidateFn<V, N, M>;
|
|
21
|
+
meta?: M;
|
|
22
|
+
scrollOptions?: typeof DEFAULT_SCROLL_OPTIONS;
|
|
23
|
+
scrollOnError?: boolean;
|
|
24
|
+
focusOnError?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface UseFormReturn<V, N extends string, M> {
|
|
27
|
+
/** 제출 여부 */
|
|
28
|
+
isSubmitted: boolean;
|
|
29
|
+
/** 에러 상태 */
|
|
30
|
+
errors: FieldErrors<N>;
|
|
31
|
+
/** 필드 등록 */
|
|
32
|
+
registerField: (name: N) => (element: HTMLElement | null) => void;
|
|
33
|
+
/** 에러 초기화 */
|
|
34
|
+
clearErrors: () => void;
|
|
35
|
+
/** 필드 에러 도움말 반환 */
|
|
36
|
+
getFieldHelper: (name: N) => FormFieldHelper | undefined;
|
|
37
|
+
/** 제출 함수 */
|
|
38
|
+
submit: SubmitFn<V, N, M>;
|
|
39
|
+
/** [imperative] 검증 후 errors 갱신 직접 호출 */
|
|
40
|
+
triggerValidate: (options?: {
|
|
41
|
+
callEffectOnError?: boolean;
|
|
42
|
+
}) => void;
|
|
43
|
+
/** [imperative] 필드 에러 설정 직접 호출 */
|
|
44
|
+
triggerSetFieldError: (name: N, message: string) => void;
|
|
45
|
+
/** [imperative] 에러 발생 시 스크롤·포커스 처리 직접 호출 */
|
|
46
|
+
triggerEffectOnError: (errors: FieldErrors<N>) => void;
|
|
47
|
+
}
|
|
48
|
+
export default function useForm<V, N extends string, M = unknown>({ fieldNames, values, validate, meta, scrollOptions, scrollOnError, focusOnError }: UseFormProps<V, N, M>): UseFormReturn<V, N, M>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { useRef as C, useState as R, useCallback as n } from "react";
|
|
2
|
+
import { DEFAULT_SCROLL_OPTIONS as T, hasError as _ } from "./useForm.utils.es.js";
|
|
3
|
+
function H({
|
|
4
|
+
fieldNames: b,
|
|
5
|
+
values: f,
|
|
6
|
+
validate: E,
|
|
7
|
+
meta: i,
|
|
8
|
+
scrollOptions: m,
|
|
9
|
+
scrollOnError: d = !0,
|
|
10
|
+
focusOnError: o = !1
|
|
11
|
+
}) {
|
|
12
|
+
const s = C(/* @__PURE__ */ new Map()), w = C(/* @__PURE__ */ new Map()), [a, g] = R({}), [k, F] = R(!1), V = d || o, h = n((e) => {
|
|
13
|
+
const r = w.current.get(e);
|
|
14
|
+
if (r)
|
|
15
|
+
return r;
|
|
16
|
+
const c = (t) => {
|
|
17
|
+
t ? s.current.set(e, t) : s.current.delete(e);
|
|
18
|
+
};
|
|
19
|
+
return w.current.set(e, c), c;
|
|
20
|
+
}, []), u = n(
|
|
21
|
+
(e) => {
|
|
22
|
+
requestAnimationFrame(() => {
|
|
23
|
+
for (const r of b) {
|
|
24
|
+
if (!(e == null ? void 0 : e[r])) continue;
|
|
25
|
+
const t = s.current.get(r);
|
|
26
|
+
if (d && t && t.scrollIntoView(m ?? T), o && t) {
|
|
27
|
+
const S = t.querySelector(
|
|
28
|
+
'input:not([type="hidden"]):not([disabled]), textarea:not([disabled])'
|
|
29
|
+
);
|
|
30
|
+
S == null || S.focus({
|
|
31
|
+
preventScroll: !0
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
[b, m, d, o]
|
|
39
|
+
), y = n(() => {
|
|
40
|
+
const e = {};
|
|
41
|
+
return E({ values: f, meta: i, fieldRefs: s.current, error: e });
|
|
42
|
+
}, [E, f, i]), l = n(
|
|
43
|
+
({ callEffectOnError: e = !0 } = {}) => {
|
|
44
|
+
const r = y();
|
|
45
|
+
g(r);
|
|
46
|
+
const c = _(r);
|
|
47
|
+
return c && e && V && u(r), { isValid: !c, errors: r };
|
|
48
|
+
},
|
|
49
|
+
[y, V, u]
|
|
50
|
+
), I = n(
|
|
51
|
+
({ callEffectOnError: e = !0 } = {}) => {
|
|
52
|
+
l({ callEffectOnError: e });
|
|
53
|
+
},
|
|
54
|
+
[l]
|
|
55
|
+
), L = n(() => {
|
|
56
|
+
g({});
|
|
57
|
+
}, []), q = n((e, r) => {
|
|
58
|
+
g((c) => ({ ...c, [e]: r }));
|
|
59
|
+
}, []), A = n(
|
|
60
|
+
(e) => {
|
|
61
|
+
u(e);
|
|
62
|
+
},
|
|
63
|
+
[u]
|
|
64
|
+
), M = n(
|
|
65
|
+
(e) => {
|
|
66
|
+
const r = a == null ? void 0 : a[e];
|
|
67
|
+
if (r)
|
|
68
|
+
return { severity: "error", message: r };
|
|
69
|
+
},
|
|
70
|
+
[a]
|
|
71
|
+
), O = n(
|
|
72
|
+
(e = {}) => async () => {
|
|
73
|
+
F(!0);
|
|
74
|
+
const { isValid: r, errors: c } = l({ callEffectOnError: !0 }), t = {
|
|
75
|
+
values: f,
|
|
76
|
+
meta: i,
|
|
77
|
+
fieldRefs: s.current,
|
|
78
|
+
error: c
|
|
79
|
+
};
|
|
80
|
+
r ? e != null && e.onSuccess && await e.onSuccess(t) : e != null && e.onError && await e.onError(t), e != null && e.onSettled && await e.onSettled(t);
|
|
81
|
+
},
|
|
82
|
+
[l, f, i, F]
|
|
83
|
+
);
|
|
84
|
+
return {
|
|
85
|
+
isSubmitted: k,
|
|
86
|
+
errors: a,
|
|
87
|
+
registerField: h,
|
|
88
|
+
clearErrors: L,
|
|
89
|
+
triggerValidate: I,
|
|
90
|
+
triggerSetFieldError: q,
|
|
91
|
+
triggerEffectOnError: A,
|
|
92
|
+
getFieldHelper: M,
|
|
93
|
+
submit: O
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
export {
|
|
97
|
+
H as default
|
|
98
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function t(e){return e?Object.values(e).some(r=>r!=null&&r!==""):!1}const n=Object.freeze({block:"center",inline:"center",behavior:"smooth"});exports.DEFAULT_SCROLL_OPTIONS=n;exports.hasError=t;
|