@designbasekorea/ui 0.1.42 → 0.1.44
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/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.esm.css +1 -1
- package/dist/index.esm.css.map +1 -1
- package/dist/index.esm.js +107 -5
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +107 -5
- package/dist/index.js.map +1 -1
- package/dist/index.umd.css +1 -1
- package/dist/index.umd.css.map +1 -1
- package/dist/index.umd.js +107 -5
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -8145,10 +8145,48 @@
|
|
|
8145
8145
|
})), currentIndex: selectedImageIndex, isOpen: true, onOpenChange: handleLightboxClose, onImageChange: handleLightboxNavigate }))] }));
|
|
8146
8146
|
};
|
|
8147
8147
|
|
|
8148
|
-
const SearchBar = ({ value, defaultValue = '', placeholder = '검색...', size = 'm', variant = 'default', disabled = false, readOnly = false, fullWidth = false, searchIcon: SearchIconComponent = icons.SearchIcon, clearIcon: ClearIconComponent = icons.CloseIcon, onChange, onSearch, onFocus, onBlur, onKeyDown, className, ...props }) => {
|
|
8148
|
+
const SearchBar = ({ value, defaultValue = '', placeholder = '검색...', size = 'm', variant = 'default', disabled = false, readOnly = false, fullWidth = false, searchIcon: SearchIconComponent = icons.SearchIcon, clearIcon: ClearIconComponent = icons.CloseIcon, enableRecentSearches = false, recentSearchesKey = 'searchbar-recent-searches', suggestedSearches = [], suggestionRollingInterval = 5000, onChange, onSearch, onFocus, onBlur, onKeyDown, className, ...props }) => {
|
|
8149
8149
|
const [internalValue, setInternalValue] = React.useState(defaultValue);
|
|
8150
|
+
const [recentSearches, setRecentSearches] = React.useState([]);
|
|
8151
|
+
const [showRecentSearches, setShowRecentSearches] = React.useState(false);
|
|
8152
|
+
const [currentSuggestion, setCurrentSuggestion] = React.useState(0);
|
|
8153
|
+
const [isFocused, setIsFocused] = React.useState(false);
|
|
8150
8154
|
const inputRef = React.useRef(null);
|
|
8155
|
+
const suggestionIntervalRef = React.useRef(null);
|
|
8151
8156
|
const currentValue = value !== undefined ? value : internalValue;
|
|
8157
|
+
// 최근 검색어 로드
|
|
8158
|
+
React.useEffect(() => {
|
|
8159
|
+
if (enableRecentSearches) {
|
|
8160
|
+
try {
|
|
8161
|
+
const stored = localStorage.getItem(recentSearchesKey);
|
|
8162
|
+
if (stored) {
|
|
8163
|
+
setRecentSearches(JSON.parse(stored));
|
|
8164
|
+
}
|
|
8165
|
+
}
|
|
8166
|
+
catch (error) {
|
|
8167
|
+
console.warn('최근 검색어를 불러올 수 없습니다:', error);
|
|
8168
|
+
}
|
|
8169
|
+
}
|
|
8170
|
+
}, [enableRecentSearches, recentSearchesKey]);
|
|
8171
|
+
// 추천 검색어 롤링 (포커스 없이도 계속)
|
|
8172
|
+
React.useEffect(() => {
|
|
8173
|
+
if (suggestedSearches.length > 0 && !currentValue) {
|
|
8174
|
+
suggestionIntervalRef.current = setInterval(() => {
|
|
8175
|
+
setCurrentSuggestion(prev => (prev + 1) % suggestedSearches.length);
|
|
8176
|
+
}, suggestionRollingInterval);
|
|
8177
|
+
}
|
|
8178
|
+
else {
|
|
8179
|
+
if (suggestionIntervalRef.current) {
|
|
8180
|
+
clearInterval(suggestionIntervalRef.current);
|
|
8181
|
+
suggestionIntervalRef.current = null;
|
|
8182
|
+
}
|
|
8183
|
+
}
|
|
8184
|
+
return () => {
|
|
8185
|
+
if (suggestionIntervalRef.current) {
|
|
8186
|
+
clearInterval(suggestionIntervalRef.current);
|
|
8187
|
+
}
|
|
8188
|
+
};
|
|
8189
|
+
}, [suggestedSearches.length, currentValue, suggestionRollingInterval]);
|
|
8152
8190
|
React.useEffect(() => {
|
|
8153
8191
|
if (value !== undefined) {
|
|
8154
8192
|
setInternalValue(value);
|
|
@@ -8164,9 +8202,24 @@
|
|
|
8164
8202
|
onChange?.('');
|
|
8165
8203
|
inputRef.current?.focus();
|
|
8166
8204
|
};
|
|
8167
|
-
const handleSearch = () => {
|
|
8168
|
-
|
|
8169
|
-
|
|
8205
|
+
const handleSearch = (searchValue) => {
|
|
8206
|
+
const searchTerm = searchValue || currentValue.trim();
|
|
8207
|
+
if (searchTerm) {
|
|
8208
|
+
onSearch?.(searchTerm);
|
|
8209
|
+
// 최근 검색어 저장
|
|
8210
|
+
if (enableRecentSearches) {
|
|
8211
|
+
const newRecentSearches = [
|
|
8212
|
+
searchTerm,
|
|
8213
|
+
...recentSearches.filter(item => item !== searchTerm)
|
|
8214
|
+
].slice(0, 10); // 최대 10개
|
|
8215
|
+
setRecentSearches(newRecentSearches);
|
|
8216
|
+
try {
|
|
8217
|
+
localStorage.setItem(recentSearchesKey, JSON.stringify(newRecentSearches));
|
|
8218
|
+
}
|
|
8219
|
+
catch (error) {
|
|
8220
|
+
console.warn('최근 검색어를 저장할 수 없습니다:', error);
|
|
8221
|
+
}
|
|
8222
|
+
}
|
|
8170
8223
|
}
|
|
8171
8224
|
};
|
|
8172
8225
|
const handleKeyDown = (e) => {
|
|
@@ -8175,6 +8228,49 @@
|
|
|
8175
8228
|
}
|
|
8176
8229
|
onKeyDown?.(e);
|
|
8177
8230
|
};
|
|
8231
|
+
const handleFocus = (e) => {
|
|
8232
|
+
setIsFocused(true);
|
|
8233
|
+
setShowRecentSearches(enableRecentSearches && recentSearches.length > 0);
|
|
8234
|
+
onFocus?.(e);
|
|
8235
|
+
};
|
|
8236
|
+
const handleBlur = (e) => {
|
|
8237
|
+
setIsFocused(false);
|
|
8238
|
+
// 약간의 지연을 두어 클릭 이벤트가 처리되도록 함
|
|
8239
|
+
setTimeout(() => {
|
|
8240
|
+
setShowRecentSearches(false);
|
|
8241
|
+
}, 200);
|
|
8242
|
+
onBlur?.(e);
|
|
8243
|
+
};
|
|
8244
|
+
const handleRecentSearchClick = (searchTerm) => {
|
|
8245
|
+
setInternalValue(searchTerm);
|
|
8246
|
+
onChange?.(searchTerm);
|
|
8247
|
+
setShowRecentSearches(false);
|
|
8248
|
+
handleSearch(searchTerm);
|
|
8249
|
+
};
|
|
8250
|
+
const handleRemoveRecentSearch = (searchTerm) => {
|
|
8251
|
+
const newRecentSearches = recentSearches.filter(item => item !== searchTerm);
|
|
8252
|
+
setRecentSearches(newRecentSearches);
|
|
8253
|
+
try {
|
|
8254
|
+
localStorage.setItem(recentSearchesKey, JSON.stringify(newRecentSearches));
|
|
8255
|
+
}
|
|
8256
|
+
catch (error) {
|
|
8257
|
+
console.warn('최근 검색어를 삭제할 수 없습니다:', error);
|
|
8258
|
+
}
|
|
8259
|
+
};
|
|
8260
|
+
const handleClearAllRecentSearches = () => {
|
|
8261
|
+
setRecentSearches([]);
|
|
8262
|
+
try {
|
|
8263
|
+
localStorage.removeItem(recentSearchesKey);
|
|
8264
|
+
}
|
|
8265
|
+
catch (error) {
|
|
8266
|
+
console.warn('최근 검색어를 모두 삭제할 수 없습니다:', error);
|
|
8267
|
+
}
|
|
8268
|
+
};
|
|
8269
|
+
const handleSuggestionClick = (suggestion) => {
|
|
8270
|
+
setInternalValue(suggestion);
|
|
8271
|
+
onChange?.(suggestion);
|
|
8272
|
+
handleSearch(suggestion);
|
|
8273
|
+
};
|
|
8178
8274
|
const classes = clsx('designbase-search-bar', `designbase-search-bar--${size}`, `designbase-search-bar--${variant}`, {
|
|
8179
8275
|
'designbase-search-bar--disabled': disabled,
|
|
8180
8276
|
'designbase-search-bar--readonly': readOnly,
|
|
@@ -8185,7 +8281,13 @@
|
|
|
8185
8281
|
'designbase-search-bar__input--disabled': disabled,
|
|
8186
8282
|
'designbase-search-bar__input--readonly': readOnly,
|
|
8187
8283
|
});
|
|
8188
|
-
|
|
8284
|
+
// 현재 플레이스홀더 (추천 검색어가 있으면 롤링)
|
|
8285
|
+
const currentPlaceholder = suggestedSearches.length > 0 && !currentValue
|
|
8286
|
+
? suggestedSearches[currentSuggestion]
|
|
8287
|
+
: placeholder;
|
|
8288
|
+
return (jsxRuntime.jsxs("div", { className: classes, role: "search", children: [jsxRuntime.jsxs("div", { className: "designbase-search-bar__container", children: [jsxRuntime.jsx("div", { className: "designbase-search-bar__search-icon", children: jsxRuntime.jsx(SearchIconComponent, { size: size === 's' ? 16 : size === 'l' ? 24 : 20 }) }), jsxRuntime.jsx("input", { ref: inputRef, type: "text", className: inputClasses, value: currentValue, placeholder: currentPlaceholder, disabled: disabled, readOnly: readOnly, onChange: handleChange, onFocus: handleFocus, onBlur: handleBlur, onKeyDown: handleKeyDown, "aria-label": "\uAC80\uC0C9\uC5B4 \uC785\uB825", ...props }), currentValue && currentValue.length > 0 && !disabled && !readOnly && (jsxRuntime.jsx("button", { type: "button", className: "designbase-search-bar__clear-button", onClick: handleClear, "aria-label": "\uAC80\uC0C9\uC5B4 \uC9C0\uC6B0\uAE30", children: jsxRuntime.jsx(ClearIconComponent, { size: size === 's' ? 16 : size === 'l' ? 24 : 20 }) }))] }), showRecentSearches && recentSearches.length > 0 && (jsxRuntime.jsxs("div", { className: "designbase-search-bar__recent-searches", children: [jsxRuntime.jsxs("div", { className: "designbase-search-bar__recent-header", children: [jsxRuntime.jsx("span", { className: "designbase-search-bar__recent-title", children: "\uCD5C\uADFC \uAC80\uC0C9\uC5B4" }), jsxRuntime.jsx("button", { type: "button", className: "designbase-search-bar__clear-all-button", onClick: handleClearAllRecentSearches, "aria-label": "\uBAA8\uB4E0 \uCD5C\uADFC \uAC80\uC0C9\uC5B4 \uC0AD\uC81C", children: "\uC804\uCCB4 \uC0AD\uC81C" })] }), jsxRuntime.jsx("div", { className: "designbase-search-bar__recent-list", children: recentSearches.map((searchTerm, index) => (jsxRuntime.jsxs("div", { className: "designbase-search-bar__recent-item", children: [jsxRuntime.jsx("button", { type: "button", className: "designbase-search-bar__recent-search-button", onClick: () => handleRecentSearchClick(searchTerm), children: searchTerm }), jsxRuntime.jsx("button", { type: "button", className: "designbase-search-bar__recent-remove-button", onClick: () => handleRemoveRecentSearch(searchTerm), "aria-label": `${searchTerm} 삭제`, children: jsxRuntime.jsx(icons.CloseIcon, { size: 16 }) })] }, index))) })] })), suggestedSearches.length > 0 && isFocused && !currentValue && (jsxRuntime.jsxs("div", { className: "designbase-search-bar__suggestions", children: [jsxRuntime.jsx("div", { className: "designbase-search-bar__suggestions-header", children: jsxRuntime.jsx("span", { className: "designbase-search-bar__suggestions-title", children: "\uCD94\uCC9C \uAC80\uC0C9\uC5B4" }) }), jsxRuntime.jsx("div", { className: "designbase-search-bar__suggestions-list", children: suggestedSearches.map((suggestion, index) => (jsxRuntime.jsx("button", { type: "button", className: clsx('designbase-search-bar__suggestion-item', {
|
|
8289
|
+
'designbase-search-bar__suggestion-item--active': index === currentSuggestion
|
|
8290
|
+
}), onClick: () => handleSuggestionClick(suggestion), children: suggestion }, index))) })] }))] }));
|
|
8189
8291
|
};
|
|
8190
8292
|
SearchBar.displayName = 'SearchBar';
|
|
8191
8293
|
|