jy-headless 0.3.7 → 0.3.12

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.
Files changed (67) hide show
  1. package/README.md +62 -0
  2. package/dist/Autocomplete/Autocomplete.d.ts +8 -0
  3. package/dist/Autocomplete/Autocomplete.js +297 -0
  4. package/dist/Autocomplete/Autocomplete.type.d.ts +37 -0
  5. package/dist/Autocomplete/index.d.ts +1 -0
  6. package/dist/Input/TextInput.d.ts +4 -0
  7. package/dist/Input/TextInput.js +77 -0
  8. package/{cjs → dist}/Input/TextInput.type.d.ts +2 -2
  9. package/dist/cjs/Autocomplete/Autocomplete.d.ts +8 -0
  10. package/dist/cjs/Autocomplete/Autocomplete.js +299 -0
  11. package/dist/cjs/Autocomplete/Autocomplete.type.d.ts +37 -0
  12. package/dist/cjs/Autocomplete/index.d.ts +1 -0
  13. package/dist/cjs/Input/TextInput.d.ts +4 -0
  14. package/dist/cjs/Input/TextInput.js +79 -0
  15. package/{Input → dist/cjs/Input}/TextInput.type.d.ts +2 -2
  16. package/{cjs → dist/cjs}/index.d.ts +1 -0
  17. package/{cjs → dist/cjs}/index.js +2 -0
  18. package/{index.d.ts → dist/index.d.ts} +1 -0
  19. package/{index.js → dist/index.js} +2 -0
  20. package/package.json +66 -50
  21. package/Input/TextInput.d.ts +0 -3
  22. package/Popover/Popover.d.ts +0 -2
  23. package/Popover/Popover.js +0 -28
  24. package/Popover/Popover.type.d.ts +0 -12
  25. package/Popover/index.d.ts +0 -2
  26. package/cjs/Input/TextInput.d.ts +0 -3
  27. package/cjs/Popover/Popover.d.ts +0 -2
  28. package/cjs/Popover/Popover.js +0 -30
  29. package/cjs/Popover/Popover.type.d.ts +0 -12
  30. package/cjs/Popover/index.d.ts +0 -2
  31. package/version.txt +0 -1
  32. /package/{Input → dist/Input}/NumberInput.d.ts +0 -0
  33. /package/{Input → dist/Input}/NumberInput.type.d.ts +0 -0
  34. /package/{Input → dist/Input}/index.d.ts +0 -0
  35. /package/{Select → dist/Select}/Select.d.ts +0 -0
  36. /package/{Select → dist/Select}/Select.js +0 -0
  37. /package/{Select → dist/Select}/Select.type.d.ts +0 -0
  38. /package/{Select → dist/Select}/index.d.ts +0 -0
  39. /package/{Tooltip → dist/Tooltip}/Tooltip.d.ts +0 -0
  40. /package/{Tooltip → dist/Tooltip}/Tooltip.js +0 -0
  41. /package/{Tooltip → dist/Tooltip}/Tooltip.type.d.ts +0 -0
  42. /package/{Tooltip → dist/Tooltip}/index.d.ts +0 -0
  43. /package/{cjs → dist/cjs}/Input/NumberInput.d.ts +0 -0
  44. /package/{cjs → dist/cjs}/Input/NumberInput.type.d.ts +0 -0
  45. /package/{cjs → dist/cjs}/Input/index.d.ts +0 -0
  46. /package/{cjs → dist/cjs}/Select/Select.d.ts +0 -0
  47. /package/{cjs → dist/cjs}/Select/Select.js +0 -0
  48. /package/{cjs → dist/cjs}/Select/Select.type.d.ts +0 -0
  49. /package/{cjs → dist/cjs}/Select/index.d.ts +0 -0
  50. /package/{cjs → dist/cjs}/Tooltip/Tooltip.d.ts +0 -0
  51. /package/{cjs → dist/cjs}/Tooltip/Tooltip.js +0 -0
  52. /package/{cjs → dist/cjs}/Tooltip/Tooltip.type.d.ts +0 -0
  53. /package/{cjs → dist/cjs}/Tooltip/index.d.ts +0 -0
  54. /package/{cjs → dist/cjs}/hooks/index.d.ts +0 -0
  55. /package/{cjs → dist/cjs}/hooks/useDebounce.d.ts +0 -0
  56. /package/{cjs → dist/cjs}/hooks/useDebounce.js +0 -0
  57. /package/{cjs → dist/cjs}/hooks/usePortal.d.ts +0 -0
  58. /package/{cjs → dist/cjs}/hooks/usePortal.js +0 -0
  59. /package/{cjs → dist/cjs}/hooks/useThrottle.d.ts +0 -0
  60. /package/{cjs → dist/cjs}/hooks/useThrottle.js +0 -0
  61. /package/{hooks → dist/hooks}/index.d.ts +0 -0
  62. /package/{hooks → dist/hooks}/useDebounce.d.ts +0 -0
  63. /package/{hooks → dist/hooks}/useDebounce.js +0 -0
  64. /package/{hooks → dist/hooks}/usePortal.d.ts +0 -0
  65. /package/{hooks → dist/hooks}/usePortal.js +0 -0
  66. /package/{hooks → dist/hooks}/useThrottle.d.ts +0 -0
  67. /package/{hooks → dist/hooks}/useThrottle.js +0 -0
package/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # jy-headless
2
+
3
+ React용 Headless UI 라이브러리
4
+
5
+ ---
6
+
7
+ ## 특징
8
+
9
+ * React 기반 Headless UI
10
+ * 스타일 비강제 (디자인 시스템 자유 적용)
11
+ * Portal 기반 레이어 UI 지원
12
+ * 고급 입력 처리 지원
13
+ * debounce / throttle
14
+ * validate / format / parse
15
+ * IME 대응
16
+ * 접근성 고려한 인터랙션 로직
17
+ * 재사용 가능한 훅 제공
18
+
19
+ ---
20
+
21
+ ## 제공 요소
22
+
23
+ ### Components
24
+
25
+ * Select (Compound Component, Portal 기반)
26
+ * Autocomplete (Compound Component, Portal 기반)
27
+ * TextInput
28
+ * NumberInput
29
+ * Tooltip (Portal 기반)
30
+
31
+ ---
32
+
33
+ ### Hooks
34
+
35
+ * usePortal
36
+ * useDebounce
37
+ * useThrottle
38
+ * (추가 예정) useOutsideClick 등
39
+
40
+ ---
41
+
42
+ ## 사용 목적
43
+
44
+ * 디자인 시스템 구축
45
+ * 커스텀 UI 라이브러리 제작
46
+ * 접근성 + 인터랙션 로직 재사용
47
+ * 입력 처리 로직 표준화
48
+
49
+ ---
50
+
51
+ ## 스타일링
52
+
53
+ * Tailwind
54
+ * CSS-in-JS
55
+ * CSS Modules
56
+ * 어떤 방식이든 자유
57
+
58
+ ---
59
+
60
+ ## 라이선스
61
+
62
+ MIT
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import type { AutocompleteInputProps, AutocompleteOptionProps, AutocompleteOptionsProps, AutocompleteProps } from './Autocomplete.type';
3
+ declare const Autocomplete: (({ value, onChange, inputValue, onInputChange, disabled, filterFn, children, }: AutocompleteProps) => import("react/jsx-runtime").JSX.Element) & {
4
+ Input: ({ onKeyDown, onFocus, onChange, onCompositionStart, onCompositionEnd, ...props }: AutocompleteInputProps) => import("react/jsx-runtime").JSX.Element;
5
+ Options: ({ items, renderItem, itemHeight, maxVisibleItems, overscan, children, ...props }: AutocompleteOptionsProps) => React.ReactPortal | null;
6
+ Option: ({ value, label, disabled, children, ...props }: AutocompleteOptionProps) => import("react/jsx-runtime").JSX.Element | null;
7
+ };
8
+ export default Autocomplete;
@@ -0,0 +1,297 @@
1
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
2
+ import { createContext, useState, useRef, useId, useMemo, useEffect, useContext } from 'react';
3
+ import usePortal from '../hooks/usePortal.js';
4
+ import TextInput from '../Input/TextInput.js';
5
+
6
+ const AutocompleteContext = createContext(null);
7
+ const useAutocomplete = () => {
8
+ const ctx = useContext(AutocompleteContext);
9
+ if (!ctx)
10
+ throw new Error('Autocomplete components must be used within <Autocomplete>');
11
+ return ctx;
12
+ };
13
+ const defaultFilter = (item, query) => item.label.toLowerCase().includes(query.trim().toLowerCase());
14
+ /**
15
+ * Root
16
+ */
17
+ const AutocompleteContainer = ({ value, onChange, inputValue, onInputChange, disabled, filterFn = defaultFilter, children, }) => {
18
+ const [open, setOpen] = useState(false);
19
+ const [activeIndex, setActiveIndex] = useState(-1);
20
+ const inputRef = useRef(null);
21
+ // controlled/uncontrolled query
22
+ const [internalQuery, setInternalQuery] = useState('');
23
+ const query = inputValue ?? internalQuery;
24
+ const setQuery = (v) => {
25
+ onInputChange?.(v);
26
+ if (inputValue === undefined)
27
+ setInternalQuery(v);
28
+ };
29
+ const listboxId = useId();
30
+ // NOTE:
31
+ // - virtualization을 제대로 하려면 options data(items)가 Root에 필요하지만,
32
+ // compound API 유지를 위해 Options에서 items를 주입받아 Root에서 filtered를 만들기 어렵다.
33
+ // 그래서 Root에서는 "filtered"를 Options에서 제공할 수 있게 설계하면 복잡해짐.
34
+ // ✅ 해결: Options에 items를 주면 Root가 접근할 수 있도록 "itemsRef"를 둔다.
35
+ const itemsRef = useRef([]);
36
+ const setItems = (items) => {
37
+ itemsRef.current = items;
38
+ };
39
+ const filtered = useMemo(() => {
40
+ const src = itemsRef.current ?? [];
41
+ if (!query.trim())
42
+ return src;
43
+ return src.filter((it) => filterFn(it, query));
44
+ }, [query, filterFn]);
45
+ const close = () => {
46
+ setOpen(false);
47
+ setActiveIndex(-1);
48
+ };
49
+ const commitByIndex = (index) => {
50
+ const item = filtered[index];
51
+ if (!item || item.disabled)
52
+ return;
53
+ onChange(item.value);
54
+ setQuery(item.label);
55
+ close();
56
+ };
57
+ // 외부 value 변경 시 input label 동기화
58
+ useEffect(() => {
59
+ if (!value)
60
+ return;
61
+ const found = itemsRef.current.find((i) => i.value === value);
62
+ if (found)
63
+ setQuery(found.label);
64
+ // eslint-disable-next-line react-hooks/exhaustive-deps
65
+ }, [value]);
66
+ const statusText = useMemo(() => {
67
+ if (!open)
68
+ return '';
69
+ const n = filtered.length;
70
+ if (n === 0)
71
+ return 'No results.';
72
+ if (n === 1)
73
+ return '1 result available.';
74
+ return `${n} results available.`;
75
+ }, [open, filtered.length]);
76
+ return (jsxs(AutocompleteContext.Provider, { value: {
77
+ open,
78
+ setOpen,
79
+ selectedValue: value,
80
+ setSelectedValue: onChange,
81
+ query,
82
+ setQuery,
83
+ disabled,
84
+ inputRef,
85
+ listboxId,
86
+ activeIndex,
87
+ setActiveIndex,
88
+ filtered,
89
+ statusText,
90
+ commitByIndex,
91
+ close,
92
+ }, children: [jsx(ItemsBridge, { onItems: setItems }), children] }));
93
+ };
94
+ /**
95
+ * Options에서 items를 주입해주기 위한 브릿지(보이지 않는 컴포넌트)
96
+ * - Options가 items prop을 받으면, 내부에서 window.__ 같은 걸 쓰지 않고 Root ref에 주입
97
+ */
98
+ const ItemsBridgeContext = createContext(null);
99
+ const ItemsBridge = ({ onItems }) => {
100
+ return jsx(ItemsBridgeContext.Provider, { value: onItems });
101
+ };
102
+ const useItemsBridge = () => useContext(ItemsBridgeContext);
103
+ /**
104
+ * Input (Combobox Trigger)
105
+ * - 포커스는 input 유지
106
+ * - aria-activedescendant로 active option을 알려줌
107
+ */
108
+ // ...생략
109
+ const Input = ({ onKeyDown, onFocus, onChange, onCompositionStart, onCompositionEnd, ...props }) => {
110
+ const { open, setOpen, query, setQuery, disabled, listboxId, activeIndex, setActiveIndex, filtered, commitByIndex, close, inputRef, } = useAutocomplete();
111
+ // ✅ IME 조합 중에는 방향키/엔터로 옵션 선택하지 않게 막기
112
+ const composingRef = useRef(false);
113
+ const activeId = activeIndex >= 0 ? `${listboxId}-opt-${activeIndex}` : undefined;
114
+ const move = (delta) => {
115
+ if (!filtered.length)
116
+ return;
117
+ setOpen(true);
118
+ setActiveIndex(activeIndex < 0 ? 0 : (activeIndex + delta + filtered.length) % filtered.length);
119
+ };
120
+ return (jsxs(Fragment, { children: [jsx(TextInput, { ref: inputRef, role: 'combobox', "aria-autocomplete": 'list', "aria-expanded": open, "aria-controls": listboxId, "aria-activedescendant": activeId, disabled: disabled, value: query, onFocus: (e) => {
121
+ if (!disabled) {
122
+ setOpen(true);
123
+ setActiveIndex(filtered.length ? 0 : -1);
124
+ }
125
+ onFocus?.(e);
126
+ }, onChange: (e) => {
127
+ if (disabled)
128
+ return;
129
+ setQuery(e.target.value);
130
+ setOpen(true);
131
+ setActiveIndex(0);
132
+ onChange?.(e);
133
+ }, onCompositionStart: (e) => {
134
+ composingRef.current = true;
135
+ onCompositionStart?.(e);
136
+ }, onCompositionEnd: (e) => {
137
+ composingRef.current = false;
138
+ onCompositionEnd?.(e);
139
+ }, onKeyDown: (e) => {
140
+ if (disabled)
141
+ return;
142
+ // ✅ 조합중이면 Autocomplete 키처리 하지 않음
143
+ if (composingRef.current) {
144
+ onKeyDown?.(e);
145
+ return;
146
+ }
147
+ switch (e.key) {
148
+ case 'ArrowDown':
149
+ e.preventDefault();
150
+ move(1);
151
+ break;
152
+ case 'ArrowUp':
153
+ e.preventDefault();
154
+ move(-1);
155
+ break;
156
+ case 'Enter':
157
+ if (open && activeIndex >= 0) {
158
+ e.preventDefault();
159
+ commitByIndex(activeIndex);
160
+ }
161
+ break;
162
+ case 'Escape':
163
+ e.preventDefault();
164
+ close();
165
+ break;
166
+ case 'Tab':
167
+ close();
168
+ break;
169
+ }
170
+ onKeyDown?.(e);
171
+ }, ...props }), jsx("span", { "aria-live": 'polite', style: {
172
+ position: 'absolute',
173
+ width: 1,
174
+ height: 1,
175
+ overflow: 'hidden',
176
+ clip: 'rect(0 0 0 0)',
177
+ whiteSpace: 'nowrap',
178
+ }, children: open ? `${filtered.length} results.` : '' })] }));
179
+ };
180
+ /**
181
+ * Options
182
+ * - portal
183
+ * - outside click close
184
+ * - virtualization (items + renderItem provided)
185
+ */
186
+ const Options = ({ items, renderItem, itemHeight = 36, maxVisibleItems = 8, overscan = 3, children, ...props }) => {
187
+ const bridge = useItemsBridge();
188
+ const { open, setOpen, close, inputRef, listboxId, filtered, activeIndex, setActiveIndex, commitByIndex, } = useAutocomplete();
189
+ // items 주입(가상화 모드)
190
+ useEffect(() => {
191
+ if (items && bridge)
192
+ bridge(items);
193
+ }, [items, bridge]);
194
+ const popoverRef = useRef(null);
195
+ const triggerWidth = inputRef.current?.getBoundingClientRect().width;
196
+ // outside click
197
+ useEffect(() => {
198
+ if (!open)
199
+ return;
200
+ const onDown = (e) => {
201
+ const t = e.target;
202
+ if (inputRef.current?.contains(t) || popoverRef.current?.contains(t))
203
+ return;
204
+ close();
205
+ };
206
+ document.addEventListener('mousedown', onDown);
207
+ return () => document.removeEventListener('mousedown', onDown);
208
+ }, [open, close, inputRef]);
209
+ // scroll container ref for virtualization
210
+ const scrollRef = useRef(null);
211
+ // active option이 항상 보이게 스크롤 보정
212
+ useEffect(() => {
213
+ if (!open)
214
+ return;
215
+ if (!scrollRef.current)
216
+ return;
217
+ if (activeIndex < 0)
218
+ return;
219
+ const top = activeIndex * itemHeight;
220
+ const bottom = top + itemHeight;
221
+ const viewTop = scrollRef.current.scrollTop;
222
+ const viewBottom = viewTop + scrollRef.current.clientHeight;
223
+ if (top < viewTop)
224
+ scrollRef.current.scrollTop = top;
225
+ else if (bottom > viewBottom)
226
+ scrollRef.current.scrollTop = bottom - scrollRef.current.clientHeight;
227
+ }, [open, activeIndex, itemHeight]);
228
+ // virtualization range
229
+ const total = filtered.length;
230
+ const viewportCount = Math.min(maxVisibleItems, Math.max(1, total));
231
+ const viewportHeight = viewportCount * itemHeight;
232
+ const [scrollTop, setScrollTop] = useState(0);
233
+ const startIndex = Math.max(0, Math.floor(scrollTop / itemHeight) - overscan);
234
+ const endIndex = Math.min(total, Math.ceil((scrollTop + viewportHeight) / itemHeight) + overscan);
235
+ const visible = filtered.slice(startIndex, endIndex);
236
+ const { portal } = usePortal({
237
+ visible: open,
238
+ targetRef: inputRef,
239
+ popoverRef,
240
+ direction: 'bottom',
241
+ gap: 4,
242
+ content: (jsx("div", { ref: popoverRef, style: { width: triggerWidth }, ...props, children: items && renderItem ? (jsx("div", { id: listboxId, role: 'listbox', ref: scrollRef, style: { maxHeight: viewportHeight, overflow: 'auto', position: 'relative' }, onScroll: (e) => setScrollTop(e.target.scrollTop), children: jsx("div", { style: { height: total * itemHeight, position: 'relative' }, children: visible.map((item, i) => {
243
+ const index = startIndex + i; // filtered index
244
+ const isActive = index === activeIndex;
245
+ const isSelected = item.value === undefined; // selection 표시를 더 강하게 원하면 ctx.selectedValue 비교해서 쓰면 됨
246
+ return (jsx("div", { id: `${listboxId}-opt-${index}`, role: 'option', "aria-selected": isSelected, "aria-disabled": item.disabled, "data-active": isActive, tabIndex: -1, onMouseEnter: () => setActiveIndex(index), onMouseDown: (e) => {
247
+ // 클릭 시 input blur 방지(중요)
248
+ e.preventDefault();
249
+ }, onClick: () => commitByIndex(index), style: {
250
+ position: 'absolute',
251
+ top: index * itemHeight,
252
+ left: 0,
253
+ right: 0,
254
+ height: itemHeight,
255
+ display: 'flex',
256
+ alignItems: 'center',
257
+ }, children: renderItem(item) }, item.value));
258
+ }) }) })) : (
259
+ /* ✅ children 모드(비가상화) */
260
+ jsx("div", { id: listboxId, role: 'listbox', children: children })) })),
261
+ });
262
+ return open ? portal : null;
263
+ };
264
+ /**
265
+ * Option (children 모드 전용 / small list)
266
+ * - a11y option role/ids만 최소 보장
267
+ * - 가상화는 여기엔 적용하지 않음
268
+ */
269
+ const Option = ({ value, label, disabled, children, ...props }) => {
270
+ const { listboxId, filtered, query, open, setOpen, setQuery, setSelectedValue, activeIndex, setActiveIndex, } = useAutocomplete();
271
+ // children 모드에서 필터링은 “간단 버전”
272
+ const visible = useMemo(() => {
273
+ if (!query.trim())
274
+ return true;
275
+ return label.toLowerCase().includes(query.trim().toLowerCase());
276
+ }, [label, query]);
277
+ useMemo(() => {
278
+ // filtered는 items 모드에서만 의미있음.
279
+ // children 모드는 간단히 -1 처리(aria-activedescendant는 items 모드가 권장)
280
+ return -1;
281
+ }, []);
282
+ if (!visible)
283
+ return null;
284
+ return (jsx("div", { role: "option", "aria-disabled": disabled, "aria-selected": false, tabIndex: -1, onMouseDown: (e) => e.preventDefault(), onClick: () => {
285
+ if (disabled)
286
+ return;
287
+ setSelectedValue(value);
288
+ setQuery(label);
289
+ setOpen(false);
290
+ setActiveIndex(-1);
291
+ }, ...props, children: children ?? label }));
292
+ };
293
+ Object.assign(AutocompleteContainer, {
294
+ Input,
295
+ Options,
296
+ Option,
297
+ });
@@ -0,0 +1,37 @@
1
+ import { HTMLAttributes, ReactNode } from 'react';
2
+ import { TextInputProps } from '../Input/TextInput.type';
3
+ export type AutocompleteItem = {
4
+ value: string;
5
+ label: string;
6
+ disabled?: boolean;
7
+ };
8
+ export interface AutocompleteProps {
9
+ value: string | null;
10
+ onChange: (v: string | null) => void;
11
+ inputValue?: string;
12
+ onInputChange?: (v: string) => void;
13
+ disabled?: boolean;
14
+ /** 옵션 필터 커스터마이즈 */
15
+ filterFn?: (item: AutocompleteItem, query: string) => boolean;
16
+ children: ReactNode;
17
+ }
18
+ export interface AutocompleteInputProps extends TextInputProps {
19
+ /** label 연결용 (없으면 aria-label 필수) */
20
+ 'aria-label'?: string;
21
+ }
22
+ export interface AutocompleteOptionsProps extends HTMLAttributes<HTMLDivElement> {
23
+ /** ✅ 가상화 모드: 데이터 기반 */
24
+ items?: AutocompleteItem[];
25
+ /** 가상화 모드에서 항목 렌더 */
26
+ renderItem?: (item: AutocompleteItem) => ReactNode;
27
+ /** virtualization 옵션 */
28
+ itemHeight?: number;
29
+ maxVisibleItems?: number;
30
+ overscan?: number;
31
+ }
32
+ export interface AutocompleteOptionProps extends HTMLAttributes<HTMLDivElement> {
33
+ /** children 모드(비가상화) */
34
+ value: string;
35
+ label: string;
36
+ disabled?: boolean;
37
+ }
@@ -0,0 +1 @@
1
+ export * from './Autocomplete';
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { TextInputProps } from './TextInput.type';
3
+ declare const TextInput: React.ForwardRefExoticComponent<TextInputProps & React.RefAttributes<HTMLInputElement>>;
4
+ export default TextInput;
@@ -0,0 +1,77 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { forwardRef, useState, useRef, useMemo } from 'react';
3
+ import 'react-dom';
4
+ import { useDebounce } from '../hooks/useDebounce.js';
5
+ import { useThrottle } from '../hooks/useThrottle.js';
6
+
7
+ function mergeRefs(...refs) {
8
+ return (value) => {
9
+ refs.forEach((ref) => {
10
+ if (!ref)
11
+ return;
12
+ if (typeof ref === 'function')
13
+ ref(value);
14
+ else
15
+ ref.current = value;
16
+ });
17
+ };
18
+ }
19
+ const TextInput = forwardRef(({ maxLength, onChange, pattern, onValidate, validator, onCompositionStart, onCompositionEnd, disallowPattern, trimWhitespace, debounceMs, throttleMs, onDebouncedChange, onThrottledChange, onBlur, ...props }, ref) => {
20
+ const [isComposing, setIsComposing] = useState(false);
21
+ const innerRef = useRef(null);
22
+ const combinedRef = useMemo(() => mergeRefs(innerRef, ref), [ref]);
23
+ const debouncedChange = useDebounce((value) => onDebouncedChange?.(value), debounceMs || 0);
24
+ const throttledChange = useThrottle((value) => onThrottledChange?.(value), throttleMs || 0);
25
+ const handleCompositionStart = (e) => {
26
+ setIsComposing(true);
27
+ onCompositionStart?.(e);
28
+ };
29
+ const handleCompositionEnd = (e) => {
30
+ setIsComposing(false);
31
+ onCompositionEnd?.(e);
32
+ };
33
+ const handleChange = (e) => {
34
+ if (maxLength && !isComposing && e.target.value.length > maxLength)
35
+ return;
36
+ if (pattern) {
37
+ const regex = new RegExp(pattern);
38
+ if (!regex.test(e.target.value))
39
+ return;
40
+ }
41
+ if (disallowPattern && !disallowPattern.test(e.target.value))
42
+ return;
43
+ if (debounceMs && onDebouncedChange)
44
+ debouncedChange(e.target.value);
45
+ if (throttleMs && onThrottledChange)
46
+ throttledChange(e.target.value);
47
+ if (validator) {
48
+ const result = validator(e.target.value);
49
+ const isValid = typeof result === 'boolean' ? result : true;
50
+ const error = typeof result === 'string' ? result : undefined;
51
+ onValidate?.(isValid, error);
52
+ if (!isValid)
53
+ return;
54
+ }
55
+ onChange?.(e);
56
+ };
57
+ const handleBlur = (e) => {
58
+ if (trimWhitespace && innerRef.current) {
59
+ const trimmedValue = e.target.value.trim();
60
+ if (trimmedValue !== e.target.value) {
61
+ innerRef.current.value = trimmedValue;
62
+ const syntheticEvent = {
63
+ ...e,
64
+ target: innerRef.current,
65
+ currentTarget: innerRef.current,
66
+ type: 'change',
67
+ };
68
+ onChange?.(syntheticEvent);
69
+ }
70
+ }
71
+ onBlur?.(e);
72
+ };
73
+ return (jsx("input", { ref: combinedRef, ...props, onBlur: handleBlur, onChange: handleChange, onCompositionStart: handleCompositionStart, onCompositionEnd: handleCompositionEnd }));
74
+ });
75
+ TextInput.displayName = 'TextInput';
76
+
77
+ export { TextInput as default };
@@ -1,4 +1,4 @@
1
- import { ChangeEvent, CompositionEvent, HTMLProps } from 'react';
1
+ import { ChangeEvent, CompositionEvent, InputHTMLAttributes } from 'react';
2
2
  /**
3
3
  * 고급 기능을 제공하는 TextInput 컴포넌트 props
4
4
  *
@@ -9,7 +9,7 @@ import { ChangeEvent, CompositionEvent, HTMLProps } from 'react';
9
9
  * - IME(한글 입력) 대응
10
10
  * - 공백 제어
11
11
  */
12
- export interface TextInputProps extends HTMLProps<HTMLInputElement> {
12
+ export interface TextInputProps extends InputHTMLAttributes<HTMLInputElement> {
13
13
  /**
14
14
  * 입력값 검증 함수
15
15
  *
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import type { AutocompleteInputProps, AutocompleteOptionProps, AutocompleteOptionsProps, AutocompleteProps } from './Autocomplete.type';
3
+ declare const Autocomplete: (({ value, onChange, inputValue, onInputChange, disabled, filterFn, children, }: AutocompleteProps) => import("react/jsx-runtime").JSX.Element) & {
4
+ Input: ({ onKeyDown, onFocus, onChange, onCompositionStart, onCompositionEnd, ...props }: AutocompleteInputProps) => import("react/jsx-runtime").JSX.Element;
5
+ Options: ({ items, renderItem, itemHeight, maxVisibleItems, overscan, children, ...props }: AutocompleteOptionsProps) => React.ReactPortal | null;
6
+ Option: ({ value, label, disabled, children, ...props }: AutocompleteOptionProps) => import("react/jsx-runtime").JSX.Element | null;
7
+ };
8
+ export default Autocomplete;