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.
- package/README.md +62 -0
- package/dist/Autocomplete/Autocomplete.d.ts +8 -0
- package/dist/Autocomplete/Autocomplete.js +297 -0
- package/dist/Autocomplete/Autocomplete.type.d.ts +37 -0
- package/dist/Autocomplete/index.d.ts +1 -0
- package/dist/Input/TextInput.d.ts +4 -0
- package/dist/Input/TextInput.js +77 -0
- package/{cjs → dist}/Input/TextInput.type.d.ts +2 -2
- package/dist/cjs/Autocomplete/Autocomplete.d.ts +8 -0
- package/dist/cjs/Autocomplete/Autocomplete.js +299 -0
- package/dist/cjs/Autocomplete/Autocomplete.type.d.ts +37 -0
- package/dist/cjs/Autocomplete/index.d.ts +1 -0
- package/dist/cjs/Input/TextInput.d.ts +4 -0
- package/dist/cjs/Input/TextInput.js +79 -0
- package/{Input → dist/cjs/Input}/TextInput.type.d.ts +2 -2
- package/{cjs → dist/cjs}/index.d.ts +1 -0
- package/{cjs → dist/cjs}/index.js +2 -0
- package/{index.d.ts → dist/index.d.ts} +1 -0
- package/{index.js → dist/index.js} +2 -0
- package/package.json +66 -50
- package/Input/TextInput.d.ts +0 -3
- package/Popover/Popover.d.ts +0 -2
- package/Popover/Popover.js +0 -28
- package/Popover/Popover.type.d.ts +0 -12
- package/Popover/index.d.ts +0 -2
- package/cjs/Input/TextInput.d.ts +0 -3
- package/cjs/Popover/Popover.d.ts +0 -2
- package/cjs/Popover/Popover.js +0 -30
- package/cjs/Popover/Popover.type.d.ts +0 -12
- package/cjs/Popover/index.d.ts +0 -2
- package/version.txt +0 -1
- /package/{Input → dist/Input}/NumberInput.d.ts +0 -0
- /package/{Input → dist/Input}/NumberInput.type.d.ts +0 -0
- /package/{Input → dist/Input}/index.d.ts +0 -0
- /package/{Select → dist/Select}/Select.d.ts +0 -0
- /package/{Select → dist/Select}/Select.js +0 -0
- /package/{Select → dist/Select}/Select.type.d.ts +0 -0
- /package/{Select → dist/Select}/index.d.ts +0 -0
- /package/{Tooltip → dist/Tooltip}/Tooltip.d.ts +0 -0
- /package/{Tooltip → dist/Tooltip}/Tooltip.js +0 -0
- /package/{Tooltip → dist/Tooltip}/Tooltip.type.d.ts +0 -0
- /package/{Tooltip → dist/Tooltip}/index.d.ts +0 -0
- /package/{cjs → dist/cjs}/Input/NumberInput.d.ts +0 -0
- /package/{cjs → dist/cjs}/Input/NumberInput.type.d.ts +0 -0
- /package/{cjs → dist/cjs}/Input/index.d.ts +0 -0
- /package/{cjs → dist/cjs}/Select/Select.d.ts +0 -0
- /package/{cjs → dist/cjs}/Select/Select.js +0 -0
- /package/{cjs → dist/cjs}/Select/Select.type.d.ts +0 -0
- /package/{cjs → dist/cjs}/Select/index.d.ts +0 -0
- /package/{cjs → dist/cjs}/Tooltip/Tooltip.d.ts +0 -0
- /package/{cjs → dist/cjs}/Tooltip/Tooltip.js +0 -0
- /package/{cjs → dist/cjs}/Tooltip/Tooltip.type.d.ts +0 -0
- /package/{cjs → dist/cjs}/Tooltip/index.d.ts +0 -0
- /package/{cjs → dist/cjs}/hooks/index.d.ts +0 -0
- /package/{cjs → dist/cjs}/hooks/useDebounce.d.ts +0 -0
- /package/{cjs → dist/cjs}/hooks/useDebounce.js +0 -0
- /package/{cjs → dist/cjs}/hooks/usePortal.d.ts +0 -0
- /package/{cjs → dist/cjs}/hooks/usePortal.js +0 -0
- /package/{cjs → dist/cjs}/hooks/useThrottle.d.ts +0 -0
- /package/{cjs → dist/cjs}/hooks/useThrottle.js +0 -0
- /package/{hooks → dist/hooks}/index.d.ts +0 -0
- /package/{hooks → dist/hooks}/useDebounce.d.ts +0 -0
- /package/{hooks → dist/hooks}/useDebounce.js +0 -0
- /package/{hooks → dist/hooks}/usePortal.d.ts +0 -0
- /package/{hooks → dist/hooks}/usePortal.js +0 -0
- /package/{hooks → dist/hooks}/useThrottle.d.ts +0 -0
- /package/{hooks → dist/hooks}/useThrottle.js +0 -0
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var usePortal = require('../hooks/usePortal.js');
|
|
6
|
+
var TextInput = require('../Input/TextInput.js');
|
|
7
|
+
|
|
8
|
+
const AutocompleteContext = react.createContext(null);
|
|
9
|
+
const useAutocomplete = () => {
|
|
10
|
+
const ctx = react.useContext(AutocompleteContext);
|
|
11
|
+
if (!ctx)
|
|
12
|
+
throw new Error('Autocomplete components must be used within <Autocomplete>');
|
|
13
|
+
return ctx;
|
|
14
|
+
};
|
|
15
|
+
const defaultFilter = (item, query) => item.label.toLowerCase().includes(query.trim().toLowerCase());
|
|
16
|
+
/**
|
|
17
|
+
* Root
|
|
18
|
+
*/
|
|
19
|
+
const AutocompleteContainer = ({ value, onChange, inputValue, onInputChange, disabled, filterFn = defaultFilter, children, }) => {
|
|
20
|
+
const [open, setOpen] = react.useState(false);
|
|
21
|
+
const [activeIndex, setActiveIndex] = react.useState(-1);
|
|
22
|
+
const inputRef = react.useRef(null);
|
|
23
|
+
// controlled/uncontrolled query
|
|
24
|
+
const [internalQuery, setInternalQuery] = react.useState('');
|
|
25
|
+
const query = inputValue ?? internalQuery;
|
|
26
|
+
const setQuery = (v) => {
|
|
27
|
+
onInputChange?.(v);
|
|
28
|
+
if (inputValue === undefined)
|
|
29
|
+
setInternalQuery(v);
|
|
30
|
+
};
|
|
31
|
+
const listboxId = react.useId();
|
|
32
|
+
// NOTE:
|
|
33
|
+
// - virtualization을 제대로 하려면 options data(items)가 Root에 필요하지만,
|
|
34
|
+
// compound API 유지를 위해 Options에서 items를 주입받아 Root에서 filtered를 만들기 어렵다.
|
|
35
|
+
// 그래서 Root에서는 "filtered"를 Options에서 제공할 수 있게 설계하면 복잡해짐.
|
|
36
|
+
// ✅ 해결: Options에 items를 주면 Root가 접근할 수 있도록 "itemsRef"를 둔다.
|
|
37
|
+
const itemsRef = react.useRef([]);
|
|
38
|
+
const setItems = (items) => {
|
|
39
|
+
itemsRef.current = items;
|
|
40
|
+
};
|
|
41
|
+
const filtered = react.useMemo(() => {
|
|
42
|
+
const src = itemsRef.current ?? [];
|
|
43
|
+
if (!query.trim())
|
|
44
|
+
return src;
|
|
45
|
+
return src.filter((it) => filterFn(it, query));
|
|
46
|
+
}, [query, filterFn]);
|
|
47
|
+
const close = () => {
|
|
48
|
+
setOpen(false);
|
|
49
|
+
setActiveIndex(-1);
|
|
50
|
+
};
|
|
51
|
+
const commitByIndex = (index) => {
|
|
52
|
+
const item = filtered[index];
|
|
53
|
+
if (!item || item.disabled)
|
|
54
|
+
return;
|
|
55
|
+
onChange(item.value);
|
|
56
|
+
setQuery(item.label);
|
|
57
|
+
close();
|
|
58
|
+
};
|
|
59
|
+
// 외부 value 변경 시 input label 동기화
|
|
60
|
+
react.useEffect(() => {
|
|
61
|
+
if (!value)
|
|
62
|
+
return;
|
|
63
|
+
const found = itemsRef.current.find((i) => i.value === value);
|
|
64
|
+
if (found)
|
|
65
|
+
setQuery(found.label);
|
|
66
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
67
|
+
}, [value]);
|
|
68
|
+
const statusText = react.useMemo(() => {
|
|
69
|
+
if (!open)
|
|
70
|
+
return '';
|
|
71
|
+
const n = filtered.length;
|
|
72
|
+
if (n === 0)
|
|
73
|
+
return 'No results.';
|
|
74
|
+
if (n === 1)
|
|
75
|
+
return '1 result available.';
|
|
76
|
+
return `${n} results available.`;
|
|
77
|
+
}, [open, filtered.length]);
|
|
78
|
+
return (jsxRuntime.jsxs(AutocompleteContext.Provider, { value: {
|
|
79
|
+
open,
|
|
80
|
+
setOpen,
|
|
81
|
+
selectedValue: value,
|
|
82
|
+
setSelectedValue: onChange,
|
|
83
|
+
query,
|
|
84
|
+
setQuery,
|
|
85
|
+
disabled,
|
|
86
|
+
inputRef,
|
|
87
|
+
listboxId,
|
|
88
|
+
activeIndex,
|
|
89
|
+
setActiveIndex,
|
|
90
|
+
filtered,
|
|
91
|
+
statusText,
|
|
92
|
+
commitByIndex,
|
|
93
|
+
close,
|
|
94
|
+
}, children: [jsxRuntime.jsx(ItemsBridge, { onItems: setItems }), children] }));
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Options에서 items를 주입해주기 위한 브릿지(보이지 않는 컴포넌트)
|
|
98
|
+
* - Options가 items prop을 받으면, 내부에서 window.__ 같은 걸 쓰지 않고 Root ref에 주입
|
|
99
|
+
*/
|
|
100
|
+
const ItemsBridgeContext = react.createContext(null);
|
|
101
|
+
const ItemsBridge = ({ onItems }) => {
|
|
102
|
+
return jsxRuntime.jsx(ItemsBridgeContext.Provider, { value: onItems });
|
|
103
|
+
};
|
|
104
|
+
const useItemsBridge = () => react.useContext(ItemsBridgeContext);
|
|
105
|
+
/**
|
|
106
|
+
* Input (Combobox Trigger)
|
|
107
|
+
* - 포커스는 input 유지
|
|
108
|
+
* - aria-activedescendant로 active option을 알려줌
|
|
109
|
+
*/
|
|
110
|
+
// ...생략
|
|
111
|
+
const Input = ({ onKeyDown, onFocus, onChange, onCompositionStart, onCompositionEnd, ...props }) => {
|
|
112
|
+
const { open, setOpen, query, setQuery, disabled, listboxId, activeIndex, setActiveIndex, filtered, commitByIndex, close, inputRef, } = useAutocomplete();
|
|
113
|
+
// ✅ IME 조합 중에는 방향키/엔터로 옵션 선택하지 않게 막기
|
|
114
|
+
const composingRef = react.useRef(false);
|
|
115
|
+
const activeId = activeIndex >= 0 ? `${listboxId}-opt-${activeIndex}` : undefined;
|
|
116
|
+
const move = (delta) => {
|
|
117
|
+
if (!filtered.length)
|
|
118
|
+
return;
|
|
119
|
+
setOpen(true);
|
|
120
|
+
setActiveIndex(activeIndex < 0 ? 0 : (activeIndex + delta + filtered.length) % filtered.length);
|
|
121
|
+
};
|
|
122
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(TextInput, { ref: inputRef, role: 'combobox', "aria-autocomplete": 'list', "aria-expanded": open, "aria-controls": listboxId, "aria-activedescendant": activeId, disabled: disabled, value: query, onFocus: (e) => {
|
|
123
|
+
if (!disabled) {
|
|
124
|
+
setOpen(true);
|
|
125
|
+
setActiveIndex(filtered.length ? 0 : -1);
|
|
126
|
+
}
|
|
127
|
+
onFocus?.(e);
|
|
128
|
+
}, onChange: (e) => {
|
|
129
|
+
if (disabled)
|
|
130
|
+
return;
|
|
131
|
+
setQuery(e.target.value);
|
|
132
|
+
setOpen(true);
|
|
133
|
+
setActiveIndex(0);
|
|
134
|
+
onChange?.(e);
|
|
135
|
+
}, onCompositionStart: (e) => {
|
|
136
|
+
composingRef.current = true;
|
|
137
|
+
onCompositionStart?.(e);
|
|
138
|
+
}, onCompositionEnd: (e) => {
|
|
139
|
+
composingRef.current = false;
|
|
140
|
+
onCompositionEnd?.(e);
|
|
141
|
+
}, onKeyDown: (e) => {
|
|
142
|
+
if (disabled)
|
|
143
|
+
return;
|
|
144
|
+
// ✅ 조합중이면 Autocomplete 키처리 하지 않음
|
|
145
|
+
if (composingRef.current) {
|
|
146
|
+
onKeyDown?.(e);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
switch (e.key) {
|
|
150
|
+
case 'ArrowDown':
|
|
151
|
+
e.preventDefault();
|
|
152
|
+
move(1);
|
|
153
|
+
break;
|
|
154
|
+
case 'ArrowUp':
|
|
155
|
+
e.preventDefault();
|
|
156
|
+
move(-1);
|
|
157
|
+
break;
|
|
158
|
+
case 'Enter':
|
|
159
|
+
if (open && activeIndex >= 0) {
|
|
160
|
+
e.preventDefault();
|
|
161
|
+
commitByIndex(activeIndex);
|
|
162
|
+
}
|
|
163
|
+
break;
|
|
164
|
+
case 'Escape':
|
|
165
|
+
e.preventDefault();
|
|
166
|
+
close();
|
|
167
|
+
break;
|
|
168
|
+
case 'Tab':
|
|
169
|
+
close();
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
onKeyDown?.(e);
|
|
173
|
+
}, ...props }), jsxRuntime.jsx("span", { "aria-live": 'polite', style: {
|
|
174
|
+
position: 'absolute',
|
|
175
|
+
width: 1,
|
|
176
|
+
height: 1,
|
|
177
|
+
overflow: 'hidden',
|
|
178
|
+
clip: 'rect(0 0 0 0)',
|
|
179
|
+
whiteSpace: 'nowrap',
|
|
180
|
+
}, children: open ? `${filtered.length} results.` : '' })] }));
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Options
|
|
184
|
+
* - portal
|
|
185
|
+
* - outside click close
|
|
186
|
+
* - virtualization (items + renderItem provided)
|
|
187
|
+
*/
|
|
188
|
+
const Options = ({ items, renderItem, itemHeight = 36, maxVisibleItems = 8, overscan = 3, children, ...props }) => {
|
|
189
|
+
const bridge = useItemsBridge();
|
|
190
|
+
const { open, setOpen, close, inputRef, listboxId, filtered, activeIndex, setActiveIndex, commitByIndex, } = useAutocomplete();
|
|
191
|
+
// items 주입(가상화 모드)
|
|
192
|
+
react.useEffect(() => {
|
|
193
|
+
if (items && bridge)
|
|
194
|
+
bridge(items);
|
|
195
|
+
}, [items, bridge]);
|
|
196
|
+
const popoverRef = react.useRef(null);
|
|
197
|
+
const triggerWidth = inputRef.current?.getBoundingClientRect().width;
|
|
198
|
+
// outside click
|
|
199
|
+
react.useEffect(() => {
|
|
200
|
+
if (!open)
|
|
201
|
+
return;
|
|
202
|
+
const onDown = (e) => {
|
|
203
|
+
const t = e.target;
|
|
204
|
+
if (inputRef.current?.contains(t) || popoverRef.current?.contains(t))
|
|
205
|
+
return;
|
|
206
|
+
close();
|
|
207
|
+
};
|
|
208
|
+
document.addEventListener('mousedown', onDown);
|
|
209
|
+
return () => document.removeEventListener('mousedown', onDown);
|
|
210
|
+
}, [open, close, inputRef]);
|
|
211
|
+
// scroll container ref for virtualization
|
|
212
|
+
const scrollRef = react.useRef(null);
|
|
213
|
+
// active option이 항상 보이게 스크롤 보정
|
|
214
|
+
react.useEffect(() => {
|
|
215
|
+
if (!open)
|
|
216
|
+
return;
|
|
217
|
+
if (!scrollRef.current)
|
|
218
|
+
return;
|
|
219
|
+
if (activeIndex < 0)
|
|
220
|
+
return;
|
|
221
|
+
const top = activeIndex * itemHeight;
|
|
222
|
+
const bottom = top + itemHeight;
|
|
223
|
+
const viewTop = scrollRef.current.scrollTop;
|
|
224
|
+
const viewBottom = viewTop + scrollRef.current.clientHeight;
|
|
225
|
+
if (top < viewTop)
|
|
226
|
+
scrollRef.current.scrollTop = top;
|
|
227
|
+
else if (bottom > viewBottom)
|
|
228
|
+
scrollRef.current.scrollTop = bottom - scrollRef.current.clientHeight;
|
|
229
|
+
}, [open, activeIndex, itemHeight]);
|
|
230
|
+
// virtualization range
|
|
231
|
+
const total = filtered.length;
|
|
232
|
+
const viewportCount = Math.min(maxVisibleItems, Math.max(1, total));
|
|
233
|
+
const viewportHeight = viewportCount * itemHeight;
|
|
234
|
+
const [scrollTop, setScrollTop] = react.useState(0);
|
|
235
|
+
const startIndex = Math.max(0, Math.floor(scrollTop / itemHeight) - overscan);
|
|
236
|
+
const endIndex = Math.min(total, Math.ceil((scrollTop + viewportHeight) / itemHeight) + overscan);
|
|
237
|
+
const visible = filtered.slice(startIndex, endIndex);
|
|
238
|
+
const { portal } = usePortal({
|
|
239
|
+
visible: open,
|
|
240
|
+
targetRef: inputRef,
|
|
241
|
+
popoverRef,
|
|
242
|
+
direction: 'bottom',
|
|
243
|
+
gap: 4,
|
|
244
|
+
content: (jsxRuntime.jsx("div", { ref: popoverRef, style: { width: triggerWidth }, ...props, children: items && renderItem ? (jsxRuntime.jsx("div", { id: listboxId, role: 'listbox', ref: scrollRef, style: { maxHeight: viewportHeight, overflow: 'auto', position: 'relative' }, onScroll: (e) => setScrollTop(e.target.scrollTop), children: jsxRuntime.jsx("div", { style: { height: total * itemHeight, position: 'relative' }, children: visible.map((item, i) => {
|
|
245
|
+
const index = startIndex + i; // filtered index
|
|
246
|
+
const isActive = index === activeIndex;
|
|
247
|
+
const isSelected = item.value === undefined; // selection 표시를 더 강하게 원하면 ctx.selectedValue 비교해서 쓰면 됨
|
|
248
|
+
return (jsxRuntime.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) => {
|
|
249
|
+
// 클릭 시 input blur 방지(중요)
|
|
250
|
+
e.preventDefault();
|
|
251
|
+
}, onClick: () => commitByIndex(index), style: {
|
|
252
|
+
position: 'absolute',
|
|
253
|
+
top: index * itemHeight,
|
|
254
|
+
left: 0,
|
|
255
|
+
right: 0,
|
|
256
|
+
height: itemHeight,
|
|
257
|
+
display: 'flex',
|
|
258
|
+
alignItems: 'center',
|
|
259
|
+
}, children: renderItem(item) }, item.value));
|
|
260
|
+
}) }) })) : (
|
|
261
|
+
/* ✅ children 모드(비가상화) */
|
|
262
|
+
jsxRuntime.jsx("div", { id: listboxId, role: 'listbox', children: children })) })),
|
|
263
|
+
});
|
|
264
|
+
return open ? portal : null;
|
|
265
|
+
};
|
|
266
|
+
/**
|
|
267
|
+
* Option (children 모드 전용 / small list)
|
|
268
|
+
* - a11y option role/ids만 최소 보장
|
|
269
|
+
* - 가상화는 여기엔 적용하지 않음
|
|
270
|
+
*/
|
|
271
|
+
const Option = ({ value, label, disabled, children, ...props }) => {
|
|
272
|
+
const { listboxId, filtered, query, open, setOpen, setQuery, setSelectedValue, activeIndex, setActiveIndex, } = useAutocomplete();
|
|
273
|
+
// children 모드에서 필터링은 “간단 버전”
|
|
274
|
+
const visible = react.useMemo(() => {
|
|
275
|
+
if (!query.trim())
|
|
276
|
+
return true;
|
|
277
|
+
return label.toLowerCase().includes(query.trim().toLowerCase());
|
|
278
|
+
}, [label, query]);
|
|
279
|
+
react.useMemo(() => {
|
|
280
|
+
// filtered는 items 모드에서만 의미있음.
|
|
281
|
+
// children 모드는 간단히 -1 처리(aria-activedescendant는 items 모드가 권장)
|
|
282
|
+
return -1;
|
|
283
|
+
}, []);
|
|
284
|
+
if (!visible)
|
|
285
|
+
return null;
|
|
286
|
+
return (jsxRuntime.jsx("div", { role: "option", "aria-disabled": disabled, "aria-selected": false, tabIndex: -1, onMouseDown: (e) => e.preventDefault(), onClick: () => {
|
|
287
|
+
if (disabled)
|
|
288
|
+
return;
|
|
289
|
+
setSelectedValue(value);
|
|
290
|
+
setQuery(label);
|
|
291
|
+
setOpen(false);
|
|
292
|
+
setActiveIndex(-1);
|
|
293
|
+
}, ...props, children: children ?? label }));
|
|
294
|
+
};
|
|
295
|
+
Object.assign(AutocompleteContainer, {
|
|
296
|
+
Input,
|
|
297
|
+
Options,
|
|
298
|
+
Option,
|
|
299
|
+
});
|
|
@@ -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,79 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
require('react-dom');
|
|
6
|
+
var useDebounce = require('../hooks/useDebounce.js');
|
|
7
|
+
var useThrottle = require('../hooks/useThrottle.js');
|
|
8
|
+
|
|
9
|
+
function mergeRefs(...refs) {
|
|
10
|
+
return (value) => {
|
|
11
|
+
refs.forEach((ref) => {
|
|
12
|
+
if (!ref)
|
|
13
|
+
return;
|
|
14
|
+
if (typeof ref === 'function')
|
|
15
|
+
ref(value);
|
|
16
|
+
else
|
|
17
|
+
ref.current = value;
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const TextInput = react.forwardRef(({ maxLength, onChange, pattern, onValidate, validator, onCompositionStart, onCompositionEnd, disallowPattern, trimWhitespace, debounceMs, throttleMs, onDebouncedChange, onThrottledChange, onBlur, ...props }, ref) => {
|
|
22
|
+
const [isComposing, setIsComposing] = react.useState(false);
|
|
23
|
+
const innerRef = react.useRef(null);
|
|
24
|
+
const combinedRef = react.useMemo(() => mergeRefs(innerRef, ref), [ref]);
|
|
25
|
+
const debouncedChange = useDebounce.useDebounce((value) => onDebouncedChange?.(value), debounceMs || 0);
|
|
26
|
+
const throttledChange = useThrottle.useThrottle((value) => onThrottledChange?.(value), throttleMs || 0);
|
|
27
|
+
const handleCompositionStart = (e) => {
|
|
28
|
+
setIsComposing(true);
|
|
29
|
+
onCompositionStart?.(e);
|
|
30
|
+
};
|
|
31
|
+
const handleCompositionEnd = (e) => {
|
|
32
|
+
setIsComposing(false);
|
|
33
|
+
onCompositionEnd?.(e);
|
|
34
|
+
};
|
|
35
|
+
const handleChange = (e) => {
|
|
36
|
+
if (maxLength && !isComposing && e.target.value.length > maxLength)
|
|
37
|
+
return;
|
|
38
|
+
if (pattern) {
|
|
39
|
+
const regex = new RegExp(pattern);
|
|
40
|
+
if (!regex.test(e.target.value))
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (disallowPattern && !disallowPattern.test(e.target.value))
|
|
44
|
+
return;
|
|
45
|
+
if (debounceMs && onDebouncedChange)
|
|
46
|
+
debouncedChange(e.target.value);
|
|
47
|
+
if (throttleMs && onThrottledChange)
|
|
48
|
+
throttledChange(e.target.value);
|
|
49
|
+
if (validator) {
|
|
50
|
+
const result = validator(e.target.value);
|
|
51
|
+
const isValid = typeof result === 'boolean' ? result : true;
|
|
52
|
+
const error = typeof result === 'string' ? result : undefined;
|
|
53
|
+
onValidate?.(isValid, error);
|
|
54
|
+
if (!isValid)
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
onChange?.(e);
|
|
58
|
+
};
|
|
59
|
+
const handleBlur = (e) => {
|
|
60
|
+
if (trimWhitespace && innerRef.current) {
|
|
61
|
+
const trimmedValue = e.target.value.trim();
|
|
62
|
+
if (trimmedValue !== e.target.value) {
|
|
63
|
+
innerRef.current.value = trimmedValue;
|
|
64
|
+
const syntheticEvent = {
|
|
65
|
+
...e,
|
|
66
|
+
target: innerRef.current,
|
|
67
|
+
currentTarget: innerRef.current,
|
|
68
|
+
type: 'change',
|
|
69
|
+
};
|
|
70
|
+
onChange?.(syntheticEvent);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
onBlur?.(e);
|
|
74
|
+
};
|
|
75
|
+
return (jsxRuntime.jsx("input", { ref: combinedRef, ...props, onBlur: handleBlur, onChange: handleChange, onCompositionStart: handleCompositionStart, onCompositionEnd: handleCompositionEnd }));
|
|
76
|
+
});
|
|
77
|
+
TextInput.displayName = 'TextInput';
|
|
78
|
+
|
|
79
|
+
module.exports = TextInput;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChangeEvent, CompositionEvent,
|
|
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
|
|
12
|
+
export interface TextInputProps extends InputHTMLAttributes<HTMLInputElement> {
|
|
13
13
|
/**
|
|
14
14
|
* 입력값 검증 함수
|
|
15
15
|
*
|
|
@@ -6,7 +6,9 @@ require('react-dom');
|
|
|
6
6
|
var useDebounce = require('./hooks/useDebounce.js');
|
|
7
7
|
var useThrottle = require('./hooks/useThrottle.js');
|
|
8
8
|
var Tooltip = require('./Tooltip/Tooltip.js');
|
|
9
|
+
require('./Input/TextInput.js');
|
|
9
10
|
var Select = require('./Select/Select.js');
|
|
11
|
+
require('./Autocomplete/Autocomplete.js');
|
|
10
12
|
|
|
11
13
|
|
|
12
14
|
|
|
@@ -4,4 +4,6 @@ import 'react-dom';
|
|
|
4
4
|
export { useDebounce } from './hooks/useDebounce.js';
|
|
5
5
|
export { useThrottle } from './hooks/useThrottle.js';
|
|
6
6
|
export { Tooltip } from './Tooltip/Tooltip.js';
|
|
7
|
+
import './Input/TextInput.js';
|
|
7
8
|
export { useSelectContext } from './Select/Select.js';
|
|
9
|
+
import './Autocomplete/Autocomplete.js';
|
package/package.json
CHANGED
|
@@ -1,57 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jy-headless",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.12",
|
|
4
4
|
"description": "A lightweight and customizable headless UI library for React components",
|
|
5
|
-
"
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
6
8
|
"repository": "https://github.com/yCZwIqY/jy-headless",
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": " rollup -c",
|
|
11
|
+
"build-publish": "pnpm run build && node setupPackage.mjs && cd dist && npm publish",
|
|
12
|
+
"storybook": "storybook dev -p 6006",
|
|
13
|
+
"build-storybook": "storybook build"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
10
18
|
"exports": {
|
|
11
19
|
".": {
|
|
12
|
-
"import": "./index.js",
|
|
13
|
-
"require": "./cjs/index.js",
|
|
14
|
-
"types": "./index.d.ts"
|
|
15
|
-
},
|
|
16
|
-
"./Popover": {
|
|
17
|
-
"import": "./cjs/Popover/Popover.js",
|
|
18
|
-
"require": "./cjs/cjs/Popover/Popover.js",
|
|
19
|
-
"types": "./cjs/Popover/Popover.d.ts"
|
|
20
|
-
},
|
|
21
|
-
"./Select": {
|
|
22
|
-
"import": "./cjs/Select/Select.js",
|
|
23
|
-
"require": "./cjs/cjs/Select/Select.js",
|
|
24
|
-
"types": "./cjs/Select/Select.d.ts"
|
|
25
|
-
},
|
|
26
|
-
"./Tooltip": {
|
|
27
|
-
"import": "./cjs/Tooltip/Tooltip.js",
|
|
28
|
-
"require": "./cjs/cjs/Tooltip/Tooltip.js",
|
|
29
|
-
"types": "./cjs/Tooltip/Tooltip.d.ts"
|
|
30
|
-
},
|
|
31
|
-
"./cjs": {
|
|
32
|
-
"import": "./cjs/index.js",
|
|
33
|
-
"require": "./cjs/cjs/index.js",
|
|
34
|
-
"types": "./cjs/index.d.ts"
|
|
35
|
-
},
|
|
36
|
-
"./useDebounce": {
|
|
37
|
-
"import": "./hooks/useDebounce.js",
|
|
38
|
-
"require": "./cjs/hooks/useDebounce.js",
|
|
39
|
-
"types": "./hooks/useDebounce.d.ts"
|
|
40
|
-
},
|
|
41
|
-
"./usePortal": {
|
|
42
|
-
"import": "./hooks/usePortal.js",
|
|
43
|
-
"require": "./cjs/hooks/usePortal.js",
|
|
44
|
-
"types": "./hooks/usePortal.d.ts"
|
|
45
|
-
},
|
|
46
|
-
"./useThrottle": {
|
|
47
|
-
"import": "./hooks/useThrottle.js",
|
|
48
|
-
"require": "./cjs/hooks/useThrottle.js",
|
|
49
|
-
"types": "./hooks/useThrottle.d.ts"
|
|
50
|
-
},
|
|
51
|
-
"./index": {
|
|
52
|
-
"import": "./index.js",
|
|
53
|
-
"require": "./cjs/index.js",
|
|
54
|
-
"types": "./index.d.ts"
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"require": "./dist/cjs/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts"
|
|
55
23
|
}
|
|
56
24
|
},
|
|
57
25
|
"keywords": [
|
|
@@ -61,5 +29,53 @@
|
|
|
61
29
|
"ui-library",
|
|
62
30
|
"tailwind",
|
|
63
31
|
"storybook"
|
|
64
|
-
]
|
|
65
|
-
|
|
32
|
+
],
|
|
33
|
+
"author": "",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"type": "module",
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@babel/core": "^7.26.10",
|
|
38
|
+
"@babel/preset-env": "^7.26.7",
|
|
39
|
+
"@babel/preset-react": "^7.26.3",
|
|
40
|
+
"@chromatic-com/storybook": "3.2.4",
|
|
41
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
42
|
+
"@rollup/plugin-commonjs": "^28.0.2",
|
|
43
|
+
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
44
|
+
"@storybook/addon-essentials": "^8.5.1",
|
|
45
|
+
"@storybook/addon-interactions": "^8.5.1",
|
|
46
|
+
"@storybook/addon-onboarding": "^8.5.1",
|
|
47
|
+
"@storybook/addon-postcss": "^2.0.0",
|
|
48
|
+
"@storybook/blocks": "^8.5.1",
|
|
49
|
+
"@storybook/react": "^8.5.1",
|
|
50
|
+
"@storybook/react-vite": "^8.5.1",
|
|
51
|
+
"@storybook/test": "^8.5.1",
|
|
52
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
53
|
+
"@testing-library/react": "^16.2.0",
|
|
54
|
+
"@types/jest": "^29.5.14",
|
|
55
|
+
"@types/react": "^19.0.7",
|
|
56
|
+
"@types/react-dom": "^19.0.3",
|
|
57
|
+
"babel-jest": "^29.7.0",
|
|
58
|
+
"chromatic": "^11.25.1",
|
|
59
|
+
"jest": "^29.7.0",
|
|
60
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
61
|
+
"postcss": "^8.5.1",
|
|
62
|
+
"prettier": "^3.4.2",
|
|
63
|
+
"react": "^19.0.0",
|
|
64
|
+
"react-dom": "^19.0.0",
|
|
65
|
+
"rollup": "^4.31.0",
|
|
66
|
+
"rollup-plugin-postcss": "^4.0.2",
|
|
67
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
68
|
+
"storybook": "^8.5.1",
|
|
69
|
+
"ts-jest": "^29.2.5",
|
|
70
|
+
"typescript": "^5.7.3"
|
|
71
|
+
},
|
|
72
|
+
"dependencies": {
|
|
73
|
+
"@testing-library/user-event": "^14.6.1",
|
|
74
|
+
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
75
|
+
"tslib": "^2.8.1"
|
|
76
|
+
},
|
|
77
|
+
"peerDependencies": {
|
|
78
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
79
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
80
|
+
}
|
|
81
|
+
}
|
package/Input/TextInput.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { TextInputProps } from './TextInput.type';
|
|
2
|
-
declare const TextInput: ({ maxLength, onChange, pattern, onValidate, validator, onCompositionStart, onCompositionEnd, disallowPattern, trimWhitespace, debounceMs, throttleMs, onDebouncedChange, onThrottledChange, onBlur, ...props }: TextInputProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
|
-
export default TextInput;
|
package/Popover/Popover.d.ts
DELETED
package/Popover/Popover.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { jsxs } from 'react/jsx-runtime';
|
|
2
|
-
import { useState, useRef } from 'react';
|
|
3
|
-
import usePortal from '../hooks/usePortal.js';
|
|
4
|
-
|
|
5
|
-
const Popover = ({ direction = 'top', popover, children, key, gap = 0, autoFlip = true }) => {
|
|
6
|
-
const [visible, setVisible] = useState(false);
|
|
7
|
-
const targetRef = useRef(null);
|
|
8
|
-
const popoverRef = useRef(null);
|
|
9
|
-
const { portal, rootDom } = usePortal({
|
|
10
|
-
content: popover,
|
|
11
|
-
key,
|
|
12
|
-
visible,
|
|
13
|
-
targetRef,
|
|
14
|
-
popoverRef,
|
|
15
|
-
direction,
|
|
16
|
-
gap,
|
|
17
|
-
autoFlip,
|
|
18
|
-
});
|
|
19
|
-
const handleMouseEnter = () => {
|
|
20
|
-
setVisible(true);
|
|
21
|
-
};
|
|
22
|
-
const handleMouseLeave = () => {
|
|
23
|
-
setVisible(false);
|
|
24
|
-
};
|
|
25
|
-
return (jsxs("span", { onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, ref: targetRef, children: [children, rootDom && visible && portal] }));
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export { Popover };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import { Direction } from '../hooks';
|
|
3
|
-
export interface PopoverProps {
|
|
4
|
-
children: ReactNode;
|
|
5
|
-
popover: ReactNode;
|
|
6
|
-
direction: Direction;
|
|
7
|
-
targetId?: string;
|
|
8
|
-
domNode?: Element;
|
|
9
|
-
key?: string;
|
|
10
|
-
gap?: number;
|
|
11
|
-
autoFlip?: boolean;
|
|
12
|
-
}
|
package/Popover/index.d.ts
DELETED
package/cjs/Input/TextInput.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { TextInputProps } from './TextInput.type';
|
|
2
|
-
declare const TextInput: ({ maxLength, onChange, pattern, onValidate, validator, onCompositionStart, onCompositionEnd, disallowPattern, trimWhitespace, debounceMs, throttleMs, onDebouncedChange, onThrottledChange, onBlur, ...props }: TextInputProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
|
-
export default TextInput;
|
package/cjs/Popover/Popover.d.ts
DELETED