@chayns-components/core 5.0.0-beta.396 → 5.0.0-beta.397
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/lib/components/search-box/SearchBox.d.ts +4 -0
- package/lib/components/search-box/SearchBox.js +72 -5
- package/lib/components/search-box/SearchBox.js.map +1 -1
- package/lib/components/search-box/search-box-item/SearchBoxItem.js +2 -1
- package/lib/components/search-box/search-box-item/SearchBoxItem.js.map +1 -1
- package/lib/components/search-box/search-box-item/SearchBoxItem.styles.js +11 -2
- package/lib/components/search-box/search-box-item/SearchBoxItem.styles.js.map +1 -1
- package/package.json +2 -2
|
@@ -25,6 +25,10 @@ export type SearchBoxProps = {
|
|
|
25
25
|
* Control the selected item. If you use this prop, make sure to update it when the user selects an item.
|
|
26
26
|
*/
|
|
27
27
|
selectedId?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Whether the full list of items should be displayed if the input is empty.
|
|
30
|
+
*/
|
|
31
|
+
shouldShowContentOnEmptyInput?: boolean;
|
|
28
32
|
};
|
|
29
33
|
declare const SearchBox: FC<SearchBoxProps>;
|
|
30
34
|
export default SearchBox;
|
|
@@ -21,13 +21,15 @@ const SearchBox = _ref => {
|
|
|
21
21
|
onChange,
|
|
22
22
|
onBlur,
|
|
23
23
|
onSelect,
|
|
24
|
-
selectedId
|
|
24
|
+
selectedId,
|
|
25
|
+
shouldShowContentOnEmptyInput = true
|
|
25
26
|
} = _ref;
|
|
26
27
|
const [matchingItems, setMatchingItems] = (0, _react.useState)([]);
|
|
27
28
|
const [value, setValue] = (0, _react.useState)('');
|
|
28
29
|
const [isAnimating, setIsAnimating] = (0, _react.useState)(false);
|
|
29
30
|
const [height, setHeight] = (0, _react.useState)(0);
|
|
30
31
|
const [width, setWidth] = (0, _react.useState)(0);
|
|
32
|
+
const [focusedIndex, setFocusedIndex] = (0, _react.useState)(null);
|
|
31
33
|
const boxRef = (0, _react.useRef)(null);
|
|
32
34
|
const contentRef = (0, _react.useRef)(null);
|
|
33
35
|
const inputRef = (0, _react.useRef)(null);
|
|
@@ -87,6 +89,19 @@ const SearchBox = _ref => {
|
|
|
87
89
|
}
|
|
88
90
|
}, [list, selectedId]);
|
|
89
91
|
|
|
92
|
+
/**
|
|
93
|
+
* This function sets the items on focus if shouldShowContentOnEmptyInput
|
|
94
|
+
*/
|
|
95
|
+
const handleFocus = (0, _react.useCallback)(() => {
|
|
96
|
+
if (shouldShowContentOnEmptyInput) {
|
|
97
|
+
setMatchingItems((0, _utils.searchList)({
|
|
98
|
+
items: list,
|
|
99
|
+
searchString: value
|
|
100
|
+
}));
|
|
101
|
+
setIsAnimating(true);
|
|
102
|
+
}
|
|
103
|
+
}, [list, shouldShowContentOnEmptyInput, value]);
|
|
104
|
+
|
|
90
105
|
/**
|
|
91
106
|
* This function handles changes of the input
|
|
92
107
|
*/
|
|
@@ -95,13 +110,17 @@ const SearchBox = _ref => {
|
|
|
95
110
|
items: list,
|
|
96
111
|
searchString: event.target.value
|
|
97
112
|
});
|
|
98
|
-
|
|
99
|
-
|
|
113
|
+
if (!shouldShowContentOnEmptyInput && !event.target.value) {
|
|
114
|
+
setMatchingItems([]);
|
|
115
|
+
} else {
|
|
116
|
+
setMatchingItems(searchedItems);
|
|
117
|
+
setIsAnimating(searchedItems.length !== 0);
|
|
118
|
+
}
|
|
100
119
|
setValue(event.target.value);
|
|
101
120
|
if (typeof onChange === 'function') {
|
|
102
121
|
onChange(event);
|
|
103
122
|
}
|
|
104
|
-
}, [list, onChange]);
|
|
123
|
+
}, [list, onChange, shouldShowContentOnEmptyInput]);
|
|
105
124
|
|
|
106
125
|
/**
|
|
107
126
|
* This function handles the blur event of the input
|
|
@@ -139,6 +158,53 @@ const SearchBox = _ref => {
|
|
|
139
158
|
});
|
|
140
159
|
return items;
|
|
141
160
|
}, [handleSelect, matchingItems]);
|
|
161
|
+
(0, _react.useEffect)(() => {
|
|
162
|
+
const handleKeyDown = e => {
|
|
163
|
+
if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
|
|
164
|
+
e.preventDefault();
|
|
165
|
+
const children = contentRef.current?.children;
|
|
166
|
+
if (children && children.length > 0) {
|
|
167
|
+
const newIndex = focusedIndex !== null ? (focusedIndex + (e.key === 'ArrowUp' ? -1 : 1) + children.length) % children.length : 0;
|
|
168
|
+
if (focusedIndex !== null) {
|
|
169
|
+
const prevElement = children[focusedIndex];
|
|
170
|
+
prevElement.tabIndex = -1;
|
|
171
|
+
}
|
|
172
|
+
setFocusedIndex(newIndex);
|
|
173
|
+
const newElement = children[newIndex];
|
|
174
|
+
newElement.tabIndex = 0;
|
|
175
|
+
newElement.focus();
|
|
176
|
+
}
|
|
177
|
+
} else if (e.key === 'Enter' && focusedIndex !== null) {
|
|
178
|
+
const element = contentRef.current?.children[focusedIndex];
|
|
179
|
+
if (!element) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const {
|
|
183
|
+
id,
|
|
184
|
+
textContent
|
|
185
|
+
} = element;
|
|
186
|
+
handleSelect({
|
|
187
|
+
id: id.replace('search-box-item__', ''),
|
|
188
|
+
text: textContent ?? ''
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
193
|
+
return () => {
|
|
194
|
+
document.removeEventListener('keydown', handleKeyDown);
|
|
195
|
+
};
|
|
196
|
+
}, [focusedIndex, handleSelect]);
|
|
197
|
+
const handleKeyPress = (0, _react.useCallback)(event => {
|
|
198
|
+
if (event.keyCode === 27) {
|
|
199
|
+
setMatchingItems([]);
|
|
200
|
+
}
|
|
201
|
+
}, []);
|
|
202
|
+
(0, _react.useEffect)(() => {
|
|
203
|
+
document.addEventListener('keydown', handleKeyPress);
|
|
204
|
+
return () => {
|
|
205
|
+
document.addEventListener('keydown', handleKeyPress);
|
|
206
|
+
};
|
|
207
|
+
}, [handleKeyPress]);
|
|
142
208
|
return (0, _react.useMemo)(() => /*#__PURE__*/_react.default.createElement(_SearchBox.StyledSearchBox, {
|
|
143
209
|
ref: boxRef
|
|
144
210
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -147,6 +213,7 @@ const SearchBox = _ref => {
|
|
|
147
213
|
ref: inputRef,
|
|
148
214
|
onChange: handleChange,
|
|
149
215
|
onBlur: handleBlur,
|
|
216
|
+
onFocus: handleFocus,
|
|
150
217
|
placeholder: placeholder,
|
|
151
218
|
value: value
|
|
152
219
|
})), /*#__PURE__*/_react.default.createElement(_framerMotion.AnimatePresence, {
|
|
@@ -172,7 +239,7 @@ const SearchBox = _ref => {
|
|
|
172
239
|
}
|
|
173
240
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
174
241
|
ref: contentRef
|
|
175
|
-
}, content)))), [content, handleBlur, handleChange, height, isAnimating, placeholder, value, width]);
|
|
242
|
+
}, content)))), [content, handleBlur, handleChange, handleFocus, height, isAnimating, placeholder, value, width]);
|
|
176
243
|
};
|
|
177
244
|
SearchBox.displayName = 'SearchBox';
|
|
178
245
|
var _default = exports.default = SearchBox;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchBox.js","names":["_framerMotion","require","_react","_interopRequireWildcard","_calculate","_Input","_interopRequireDefault","_SearchBoxItem","_SearchBox","_utils","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","SearchBox","_ref","placeholder","list","onChange","onBlur","onSelect","selectedId","matchingItems","setMatchingItems","useState","value","setValue","isAnimating","setIsAnimating","height","setHeight","width","setWidth","boxRef","useRef","contentRef","inputRef","handleOutsideClick","useCallback","event","current","contains","target","useEffect","document","addEventListener","removeEventListener","textArray","map","_ref2","text","calculateContentHeight","input","getElementById","offsetWidth","selectedItem","find","_ref3","id","handleChange","searchedItems","searchList","items","searchString","length","handleBlur","handleSelect","item","content","useMemo","sort","b","localeCompare","forEach","_ref4","push","createElement","key","StyledSearchBox","ref","AnimatePresence","initial","StyledMotionSearchBoxBody","opacity","animate","transition","duration","type","displayName","_default","exports"],"sources":["../../../src/components/search-box/SearchBox.tsx"],"sourcesContent":["import { AnimatePresence } from 'framer-motion';\nimport React, {\n ChangeEvent,\n ChangeEventHandler,\n FC,\n FocusEvent,\n FocusEventHandler,\n ReactElement,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { calculateContentHeight } from '../../utils/calculate';\nimport Input from '../input/Input';\nimport SearchBoxItem from './search-box-item/SearchBoxItem';\nimport { StyledMotionSearchBoxBody, StyledSearchBox } from './SearchBox.styles';\nimport type { ISearchBoxItem } from './types';\nimport { searchList } from './utils';\n\nexport type SearchBoxProps = {\n /**\n * A list of items that can be searched.\n */\n list: ISearchBoxItem[];\n /**\n * The placeholder that should be displayed.\n */\n placeholder?: string;\n /**\n * Function to be executed when the input lost focus.\n */\n onBlur?: FocusEventHandler<HTMLInputElement>;\n /**\n * Function to be executed when the input is changed.\n */\n onChange?: ChangeEventHandler<HTMLInputElement>;\n /**\n * Function to be executed when an item is selected.\n */\n onSelect?: (item: ISearchBoxItem) => void;\n /**\n * Control the selected item. If you use this prop, make sure to update it when the user selects an item.\n */\n selectedId?: string;\n};\n\nconst SearchBox: FC<SearchBoxProps> = (\n {\n placeholder,\n list,\n onChange,\n onBlur,\n onSelect,\n selectedId\n }) => {\n const [matchingItems, setMatchingItems] = useState<ISearchBoxItem[]>([]);\n const [value, setValue] = useState('');\n const [isAnimating, setIsAnimating] = useState(false);\n const [height, setHeight] = useState<number>(0);\n const [width, setWidth] = useState(0);\n\n const boxRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement | null>(null);\n const inputRef = useRef<HTMLInputElement | null>(null);\n\n /**\n * This function closes the list of items\n */\n const handleOutsideClick = useCallback(\n (event: MouseEvent) => {\n if (boxRef.current && !boxRef.current.contains(event.target as Node)) {\n setIsAnimating(false);\n }\n },\n [boxRef]\n );\n\n /**\n * This hook listens for clicks\n */\n useEffect(() => {\n document.addEventListener('click', handleOutsideClick);\n\n return () => {\n document.removeEventListener('click', handleOutsideClick);\n };\n }, [handleOutsideClick, boxRef]);\n\n /**\n * This hook calculates the height\n */\n useEffect(() => {\n const textArray = list.map(({ text }) => text);\n\n setHeight(calculateContentHeight(textArray));\n }, [list, placeholder]);\n\n /**\n * This hook calculates the width\n */\n useEffect(() => {\n const input = document.getElementById('search_box_input');\n\n if (input) {\n setWidth(input.offsetWidth);\n }\n }, []);\n\n useEffect(() => {\n if (selectedId) {\n const selectedItem = list.find(({ id }) => id === selectedId);\n\n if (selectedItem) {\n setValue(selectedItem.text);\n }\n }\n }, [list, selectedId]);\n\n /**\n * This function handles changes of the input\n */\n const handleChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n const searchedItems = searchList({ items: list, searchString: event.target.value });\n\n setMatchingItems(searchedItems);\n setIsAnimating(searchedItems.length !== 0);\n setValue(event.target.value);\n\n if (typeof onChange === 'function') {\n onChange(event);\n }\n },\n [list, onChange]\n );\n\n /**\n * This function handles the blur event of the input\n */\n const handleBlur = useCallback(\n (event: FocusEvent<HTMLInputElement>) => {\n if (typeof onBlur === 'function') {\n onBlur(event);\n }\n },\n [onBlur]\n );\n\n /**\n * This function handles the item selection\n */\n const handleSelect = useCallback(\n (item: ISearchBoxItem) => {\n setValue(item.text);\n setIsAnimating(false);\n\n if (typeof onSelect === 'function') {\n onSelect(item);\n }\n },\n [onSelect]\n );\n\n const content = useMemo(() => {\n const items: ReactElement[] = [];\n\n matchingItems.sort((a, b) => a.text.localeCompare(b.text));\n\n matchingItems.forEach(({ id, text }) => {\n items.push(<SearchBoxItem key={id} text={text} id={id} onSelect={handleSelect}/>);\n });\n\n return items;\n }, [handleSelect, matchingItems]);\n\n return useMemo(\n () => (\n <StyledSearchBox ref={boxRef}>\n <div id=\"search_box_input\">\n <Input\n ref={inputRef}\n onChange={handleChange}\n onBlur={handleBlur}\n placeholder={placeholder}\n value={value}\n />\n </div>\n <AnimatePresence initial={false}>\n <StyledMotionSearchBoxBody\n key=\"content\"\n height={height}\n width={width}\n initial={{ height: 0, opacity: 0 }}\n animate={\n isAnimating\n ? { height: 'fit-content', opacity: 1 }\n : { height: 0, opacity: 0 }\n }\n transition={{\n duration: 0.2,\n type: 'tween',\n }}\n >\n <div ref={contentRef}>{content}</div>\n </StyledMotionSearchBoxBody>\n </AnimatePresence>\n </StyledSearchBox>\n ),\n [content, handleBlur, handleChange, height, isAnimating, placeholder, value, width]\n );\n};\n\nSearchBox.displayName = 'SearchBox';\n\nexport default SearchBox;\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,uBAAA,CAAAF,OAAA;AAaA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,cAAA,GAAAD,sBAAA,CAAAL,OAAA;AACA,IAAAO,UAAA,GAAAP,OAAA;AAEA,IAAAQ,MAAA,GAAAR,OAAA;AAAqC,SAAAK,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAX,wBAAAW,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAH,UAAA,SAAAG,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAF,OAAA,EAAAE,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAC,GAAA,CAAAJ,CAAA,UAAAG,CAAA,CAAA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kG,eAAe;IAACC,OAAO,EAAE;EAAM,gBAC5BjG,MAAA,CAAAU,OAAA,CAAAkF,aAAA,CAACtF,UAAA,CAAA4F,yBAAyB;IACtBL,GAAG,EAAC,SAAS;IACbhD,MAAM,EAAEA,MAAO;IACfE,KAAK,EAAEA,KAAM;IACbkD,OAAO,EAAE;MAAEpD,MAAM,EAAE,CAAC;MAAEsD,OAAO,EAAE;IAAE,CAAE;IACnCC,OAAO,EACHzD,WAAW,GACL;MAAEE,MAAM,EAAE,aAAa;MAAEsD,OAAO,EAAE;IAAE,CAAC,GACrC;MAAEtD,MAAM,EAAE,CAAC;MAAEsD,OAAO,EAAE;IAAE,CACjC;IACDE,UAAU,EAAE;MACRC,QAAQ,EAAE,GAAG;MACbC,IAAI,EAAE;IACV;EAAE,gBAEFvG,MAAA,CAAAU,OAAA,CAAAkF,aAAA;IAAKG,GAAG,EAAE5C;EAAW,GAAEiC,OAAa,CACb,CACd,CACJ,CACpB,EACD,CAACA,OAAO,EAAEH,UAAU,EAAEN,YAAY,EAAE9B,MAAM,EAAEF,WAAW,EAAEX,WAAW,EAAES,KAAK,EAAEM,KAAK,CACtF,CAAC;AACL,CAAC;AAEDjB,SAAS,CAAC0E,WAAW,GAAG,WAAW;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAhG,OAAA,GAErBoB,SAAS"}
|
|
1
|
+
{"version":3,"file":"SearchBox.js","names":["_framerMotion","require","_react","_interopRequireWildcard","_calculate","_Input","_interopRequireDefault","_SearchBoxItem","_SearchBox","_utils","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","SearchBox","_ref","placeholder","list","onChange","onBlur","onSelect","selectedId","shouldShowContentOnEmptyInput","matchingItems","setMatchingItems","useState","value","setValue","isAnimating","setIsAnimating","height","setHeight","width","setWidth","focusedIndex","setFocusedIndex","boxRef","useRef","contentRef","inputRef","handleOutsideClick","useCallback","event","current","contains","target","useEffect","document","addEventListener","removeEventListener","textArray","map","_ref2","text","calculateContentHeight","input","getElementById","offsetWidth","selectedItem","find","_ref3","id","handleFocus","searchList","items","searchString","handleChange","searchedItems","length","handleBlur","handleSelect","item","content","useMemo","sort","b","localeCompare","forEach","_ref4","push","createElement","key","handleKeyDown","preventDefault","children","newIndex","prevElement","tabIndex","newElement","focus","element","textContent","replace","handleKeyPress","keyCode","StyledSearchBox","ref","onFocus","AnimatePresence","initial","StyledMotionSearchBoxBody","opacity","animate","transition","duration","type","displayName","_default","exports"],"sources":["../../../src/components/search-box/SearchBox.tsx"],"sourcesContent":["import { AnimatePresence } from 'framer-motion';\nimport React, {\n ChangeEvent,\n ChangeEventHandler,\n FC,\n FocusEvent,\n FocusEventHandler,\n ReactElement,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { calculateContentHeight } from '../../utils/calculate';\nimport Input from '../input/Input';\nimport SearchBoxItem from './search-box-item/SearchBoxItem';\nimport { StyledMotionSearchBoxBody, StyledSearchBox } from './SearchBox.styles';\nimport type { ISearchBoxItem } from './types';\nimport { searchList } from './utils';\n\nexport type SearchBoxProps = {\n /**\n * A list of items that can be searched.\n */\n list: ISearchBoxItem[];\n /**\n * The placeholder that should be displayed.\n */\n placeholder?: string;\n /**\n * Function to be executed when the input lost focus.\n */\n onBlur?: FocusEventHandler<HTMLInputElement>;\n /**\n * Function to be executed when the input is changed.\n */\n onChange?: ChangeEventHandler<HTMLInputElement>;\n /**\n * Function to be executed when an item is selected.\n */\n onSelect?: (item: ISearchBoxItem) => void;\n /**\n * Control the selected item. If you use this prop, make sure to update it when the user selects an item.\n */\n selectedId?: string;\n /**\n * Whether the full list of items should be displayed if the input is empty.\n */\n shouldShowContentOnEmptyInput?: boolean;\n};\n\nconst SearchBox: FC<SearchBoxProps> = ({\n placeholder,\n list,\n onChange,\n onBlur,\n onSelect,\n selectedId,\n shouldShowContentOnEmptyInput = true,\n}) => {\n const [matchingItems, setMatchingItems] = useState<ISearchBoxItem[]>([]);\n const [value, setValue] = useState('');\n const [isAnimating, setIsAnimating] = useState(false);\n const [height, setHeight] = useState<number>(0);\n const [width, setWidth] = useState(0);\n const [focusedIndex, setFocusedIndex] = useState<number | null>(null);\n\n const boxRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement | null>(null);\n const inputRef = useRef<HTMLInputElement | null>(null);\n\n /**\n * This function closes the list of items\n */\n const handleOutsideClick = useCallback(\n (event: MouseEvent) => {\n if (boxRef.current && !boxRef.current.contains(event.target as Node)) {\n setIsAnimating(false);\n }\n },\n [boxRef]\n );\n\n /**\n * This hook listens for clicks\n */\n useEffect(() => {\n document.addEventListener('click', handleOutsideClick);\n\n return () => {\n document.removeEventListener('click', handleOutsideClick);\n };\n }, [handleOutsideClick, boxRef]);\n\n /**\n * This hook calculates the height\n */\n useEffect(() => {\n const textArray = list.map(({ text }) => text);\n\n setHeight(calculateContentHeight(textArray));\n }, [list, placeholder]);\n\n /**\n * This hook calculates the width\n */\n useEffect(() => {\n const input = document.getElementById('search_box_input');\n\n if (input) {\n setWidth(input.offsetWidth);\n }\n }, []);\n\n useEffect(() => {\n if (selectedId) {\n const selectedItem = list.find(({ id }) => id === selectedId);\n\n if (selectedItem) {\n setValue(selectedItem.text);\n }\n }\n }, [list, selectedId]);\n\n /**\n * This function sets the items on focus if shouldShowContentOnEmptyInput\n */\n const handleFocus = useCallback(() => {\n if (shouldShowContentOnEmptyInput) {\n setMatchingItems(searchList({ items: list, searchString: value }));\n setIsAnimating(true);\n }\n }, [list, shouldShowContentOnEmptyInput, value]);\n\n /**\n * This function handles changes of the input\n */\n const handleChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n const searchedItems = searchList({ items: list, searchString: event.target.value });\n\n if (!shouldShowContentOnEmptyInput && !event.target.value) {\n setMatchingItems([]);\n } else {\n setMatchingItems(searchedItems);\n setIsAnimating(searchedItems.length !== 0);\n }\n\n setValue(event.target.value);\n\n if (typeof onChange === 'function') {\n onChange(event);\n }\n },\n [list, onChange, shouldShowContentOnEmptyInput]\n );\n\n /**\n * This function handles the blur event of the input\n */\n const handleBlur = useCallback(\n (event: FocusEvent<HTMLInputElement>) => {\n if (typeof onBlur === 'function') {\n onBlur(event);\n }\n },\n [onBlur]\n );\n\n /**\n * This function handles the item selection\n */\n const handleSelect = useCallback(\n (item: ISearchBoxItem) => {\n setValue(item.text);\n setIsAnimating(false);\n\n if (typeof onSelect === 'function') {\n onSelect(item);\n }\n },\n [onSelect]\n );\n\n const content = useMemo(() => {\n const items: ReactElement[] = [];\n\n matchingItems.sort((a, b) => a.text.localeCompare(b.text));\n\n matchingItems.forEach(({ id, text }) => {\n items.push(<SearchBoxItem key={id} text={text} id={id} onSelect={handleSelect} />);\n });\n\n return items;\n }, [handleSelect, matchingItems]);\n\n useEffect(() => {\n const handleKeyDown = (e: KeyboardEvent) => {\n if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {\n e.preventDefault();\n const children = contentRef.current?.children;\n if (children && children.length > 0) {\n const newIndex =\n focusedIndex !== null\n ? (focusedIndex + (e.key === 'ArrowUp' ? -1 : 1) + children.length) %\n children.length\n : 0;\n\n if (focusedIndex !== null) {\n const prevElement = children[focusedIndex] as HTMLDivElement;\n prevElement.tabIndex = -1;\n }\n\n setFocusedIndex(newIndex);\n\n const newElement = children[newIndex] as HTMLDivElement;\n newElement.tabIndex = 0;\n newElement.focus();\n }\n } else if (e.key === 'Enter' && focusedIndex !== null) {\n const element = contentRef.current?.children[focusedIndex];\n\n if (!element) {\n return;\n }\n\n const { id, textContent } = element;\n\n handleSelect({ id: id.replace('search-box-item__', ''), text: textContent ?? '' });\n }\n };\n\n document.addEventListener('keydown', handleKeyDown);\n\n return () => {\n document.removeEventListener('keydown', handleKeyDown);\n };\n }, [focusedIndex, handleSelect]);\n\n const handleKeyPress = useCallback((event: KeyboardEvent) => {\n if (event.keyCode === 27) {\n setMatchingItems([]);\n }\n }, []);\n\n useEffect(() => {\n document.addEventListener('keydown', handleKeyPress);\n\n return () => {\n document.addEventListener('keydown', handleKeyPress);\n };\n }, [handleKeyPress]);\n\n return useMemo(\n () => (\n <StyledSearchBox ref={boxRef}>\n <div id=\"search_box_input\">\n <Input\n ref={inputRef}\n onChange={handleChange}\n onBlur={handleBlur}\n onFocus={handleFocus}\n placeholder={placeholder}\n value={value}\n />\n </div>\n <AnimatePresence initial={false}>\n <StyledMotionSearchBoxBody\n key=\"content\"\n height={height}\n width={width}\n initial={{ height: 0, opacity: 0 }}\n animate={\n isAnimating\n ? { height: 'fit-content', opacity: 1 }\n : { height: 0, opacity: 0 }\n }\n transition={{\n duration: 0.2,\n type: 'tween',\n }}\n >\n <div ref={contentRef}>{content}</div>\n </StyledMotionSearchBoxBody>\n </AnimatePresence>\n </StyledSearchBox>\n ),\n [\n content,\n handleBlur,\n handleChange,\n handleFocus,\n height,\n isAnimating,\n placeholder,\n value,\n width,\n ]\n );\n};\n\nSearchBox.displayName = 'SearchBox';\n\nexport default SearchBox;\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,uBAAA,CAAAF,OAAA;AAaA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,cAAA,GAAAD,sBAAA,CAAAL,OAAA;AACA,IAAAO,UAAA,GAAAP,OAAA;AAEA,IAAAQ,MAAA,GAAAR,OAAA;AAAqC,SAAAK,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAX,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oxItem = _ref => {
|
|
|
21
21
|
});
|
|
22
22
|
}, [id, onSelect, text]);
|
|
23
23
|
return (0, _react.useMemo)(() => /*#__PURE__*/_react.default.createElement(_SearchBoxItem.StyledSearchBoxItem, {
|
|
24
|
+
id: `search-box-item__${id}`,
|
|
24
25
|
onClick: handleClick
|
|
25
|
-
}, /*#__PURE__*/_react.default.createElement(_SearchBoxItem.StyledSearchBoxItemText, null, text)), [handleClick, text]);
|
|
26
|
+
}, /*#__PURE__*/_react.default.createElement(_SearchBoxItem.StyledSearchBoxItemText, null, text)), [handleClick, id, text]);
|
|
26
27
|
};
|
|
27
28
|
SearchBoxItem.displayName = 'SearchBoxItem';
|
|
28
29
|
var _default = exports.default = SearchBoxItem;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchBoxItem.js","names":["_react","_interopRequireWildcard","require","_SearchBoxItem","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","SearchBoxItem","_ref","id","text","onSelect","handleClick","useCallback","useMemo","createElement","StyledSearchBoxItem","onClick","StyledSearchBoxItemText","displayName","_default","exports"],"sources":["../../../../src/components/search-box/search-box-item/SearchBoxItem.tsx"],"sourcesContent":["import React, { FC, useCallback, useMemo } from 'react';\nimport type { ISearchBoxItem } from '../types';\nimport { StyledSearchBoxItem, StyledSearchBoxItemText } from './SearchBoxItem.styles';\n\nexport type SearchBoxItemProps = {\n onSelect: (item: ISearchBoxItem) => void;\n id: ISearchBoxItem['id'];\n text: ISearchBoxItem['text'];\n};\n\nconst SearchBoxItem: FC<SearchBoxItemProps> = ({ id, text, onSelect }) => {\n const handleClick = useCallback(() => {\n onSelect({ id, text });\n }, [id, onSelect, text]);\n\n return useMemo(\n () => (\n <StyledSearchBoxItem onClick={handleClick}>\n <StyledSearchBoxItemText>{text}</StyledSearchBoxItemText>\n </StyledSearchBoxItem>\n ),\n [handleClick, text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AA,EAAAQ,CAAA,GAAAA,CAAA;AAQtF,MAAMY,aAAqC,GAAGC,IAAA,IAA4B;EAAA,IAA3B;IAAEC,EAAE;IAAEC,IAAI;IAAEC;EAAS,CAAC,GAAAH,IAAA;EACjE,MAAMI,WAAW,GAAG,IAAAC,kBAAW,EAAC,MAAM;IAClCF,QAAQ,CAAC;MAAEF,EAAE;MAAEC;IAAK,CAAC,CAAC;EAC1B,CAAC,EAAE,CAACD,EAAE,EAAEE,QAAQ,EAAED,IAAI,CAAC,CAAC;EAExB,OAAO,IAAAI,cAAO,EACV,mBACIhC,MAAA,CAAAU,OAAA,CAAAuB,aAAA,CAAC9B,cAAA,CAAA+B,mBAAmB;
|
|
1
|
+
{"version":3,"file":"SearchBoxItem.js","names":["_react","_interopRequireWildcard","require","_SearchBoxItem","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","SearchBoxItem","_ref","id","text","onSelect","handleClick","useCallback","useMemo","createElement","StyledSearchBoxItem","onClick","StyledSearchBoxItemText","displayName","_default","exports"],"sources":["../../../../src/components/search-box/search-box-item/SearchBoxItem.tsx"],"sourcesContent":["import React, { FC, useCallback, useMemo } from 'react';\nimport type { ISearchBoxItem } from '../types';\nimport { StyledSearchBoxItem, StyledSearchBoxItemText } from './SearchBoxItem.styles';\n\nexport type SearchBoxItemProps = {\n onSelect: (item: ISearchBoxItem) => void;\n id: ISearchBoxItem['id'];\n text: ISearchBoxItem['text'];\n};\n\nconst SearchBoxItem: FC<SearchBoxItemProps> = ({ id, text, onSelect }) => {\n const handleClick = useCallback(() => {\n onSelect({ id, text });\n }, [id, onSelect, text]);\n\n return useMemo(\n () => (\n <StyledSearchBoxItem id={`search-box-item__${id}`} onClick={handleClick}>\n <StyledSearchBoxItemText>{text}</StyledSearchBoxItemText>\n </StyledSearchBoxItem>\n ),\n [handleClick, id, text]\n );\n};\n\nSearchBoxItem.displ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CAAA;AAQtF,MAAMY,aAAqC,GAAGC,IAAA,IAA4B;EAAA,IAA3B;IAAEC,EAAE;IAAEC,IAAI;IAAEC;EAAS,CAAC,GAAAH,IAAA;EACjE,MAAMI,WAAW,GAAG,IAAAC,kBAAW,EAAC,MAAM;IAClCF,QAAQ,CAAC;MAAEF,EAAE;MAAEC;IAAK,CAAC,CAAC;EAC1B,CAAC,EAAE,CAACD,EAAE,EAAEE,QAAQ,EAAED,IAAI,CAAC,CAAC;EAExB,OAAO,IAAAI,cAAO,EACV,mBACIhC,MAAA,CAAAU,OAAA,CAAAuB,aAAA,CAAC9B,cAAA,CAAA+B,mBAAmB;IAACP,EAAE,EAAG,oBAAmBA,EAAG,EAAE;IAACQ,OAAO,EAAEL;EAAY,gBACpE9B,MAAA,CAAAU,OAAA,CAAAuB,aAAA,CAAC9B,cAAA,CAAAiC,uBAAuB,QAAER,IAA8B,CACvC,CACxB,EACD,CAACE,WAAW,EAAEH,EAAE,EAAEC,IAAI,CAC1B,CAAC;AACL,CAAC;AAEDH,aAAa,CAACY,WAAW,GAAG,eAAe;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAA7B,OAAA,GAE7Be,aAAa"}
|
|
@@ -13,14 +13,23 @@ const StyledSearchBoxItem = exports.StyledSearchBoxItem = _styledComponents.defa
|
|
|
13
13
|
theme
|
|
14
14
|
} = _ref;
|
|
15
15
|
return theme['secondary-103'];
|
|
16
|
+
}};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
&:focus {
|
|
20
|
+
background: ${_ref2 => {
|
|
21
|
+
let {
|
|
22
|
+
theme
|
|
23
|
+
} = _ref2;
|
|
24
|
+
return theme['secondary-103'];
|
|
16
25
|
}};
|
|
17
26
|
}
|
|
18
27
|
`;
|
|
19
28
|
const StyledSearchBoxItemText = exports.StyledSearchBoxItemText = _styledComponents.default.p`
|
|
20
|
-
color: ${
|
|
29
|
+
color: ${_ref3 => {
|
|
21
30
|
let {
|
|
22
31
|
theme
|
|
23
|
-
} =
|
|
32
|
+
} = _ref3;
|
|
24
33
|
return theme.text;
|
|
25
34
|
}};
|
|
26
35
|
margin: 5px;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchBoxItem.styles.js","names":["_styledComponents","_interopRequireDefault","require","obj","__esModule","default","StyledSearchBoxItem","exports","styled","div","_ref","theme","StyledSearchBoxItemText","p","
|
|
1
|
+
{"version":3,"file":"SearchBoxItem.styles.js","names":["_styledComponents","_interopRequireDefault","require","obj","__esModule","default","StyledSearchBoxItem","exports","styled","div","_ref","theme","_ref2","StyledSearchBoxItemText","p","_ref3","text"],"sources":["../../../../src/components/search-box/search-box-item/SearchBoxItem.styles.ts"],"sourcesContent":["import styled from 'styled-components';\nimport type { WithTheme } from '../../color-scheme-provider/ColorSchemeProvider';\n\ntype StyledSearchBoxItemProps = WithTheme<unknown>;\nexport const StyledSearchBoxItem = styled.div<StyledSearchBoxItemProps>`\n &:hover {\n background: ${({ theme }: StyledSearchBoxItemProps) => theme['secondary-103']};\n }\n\n &:focus {\n background: ${({ theme }: StyledSearchBoxItemProps) => theme['secondary-103']};\n }\n`;\n\ntype StyledSearchBoxItemTextProps = WithTheme<unknown>;\n\nexport const StyledSearchBoxItemText = styled.p<StyledSearchBoxItemTextProps>`\n color: ${({ theme }: StyledSearchBoxItemTextProps) => theme.text};\n margin: 5px;\n`;\n"],"mappings":";;;;;;AAAA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAuC,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAIhC,MAAMG,mBAAmB,GAAAC,OAAA,CAAAD,mBAAA,GAAGE,yBAAM,CAACC,GAA8B;AACxE;AACA,sBAAsBC,IAAA;EAAA,IAAC;IAAEC;EAAgC,CAAC,GAAAD,IAAA;EAAA,OAAKC,KAAK,CAAC,eAAe,CAAC;AAAA,CAAC;AACtF;AACA;AACA;AACA,sBAAsBC,KAAA;EAAA,IAAC;IAAED;EAAgC,CAAC,GAAAC,KAAA;EAAA,OAAKD,KAAK,CAAC,eAAe,CAAC;AAAA,CAAC;AACtF;AACA,CAAC;AAIM,MAAME,uBAAuB,GAAAN,OAAA,CAAAM,uBAAA,GAAGL,yBAAM,CAACM,CAAgC;AAC9E,aAAaC,KAAA;EAAA,IAAC;IAAEJ;EAAoC,CAAC,GAAAI,KAAA;EAAA,OAAKJ,KAAK,CAACK,IAAI;AAAA,CAAC;AACrE;AACA,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chayns-components/core",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.397",
|
|
4
4
|
"description": "A set of beautiful React components for developing your own applications with chayns.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chayns",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"publishConfig": {
|
|
71
71
|
"access": "public"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "e96612871ca1fa076b0057cb2fcd14163f410a7b"
|
|
74
74
|
}
|