1
- import {
2
- useMemo ,
3
- Children ,
4
- useState ,
5
- isValidElement ,
6
- useCallback ,
7
- } from 'react' ;
1
+ import { useMemo , Children , useState , useCallback } from 'react' ;
8
2
import type { ReactNode , ReactElement } from 'react' ;
9
3
10
- import { ComboboxOption } from './Option/Option' ;
11
- import { ComboboxCustom } from './Custom' ;
12
4
import type { ComboboxOptionProps } from './Option/Option' ;
13
5
import type { ComboboxProps } from './Combobox' ;
14
6
import type { ComboboxCustomProps } from './Custom' ;
7
+ import {
8
+ isComboboxOption ,
9
+ isInteractiveComboboxCustom ,
10
+ prefix ,
11
+ } from './utilities' ;
15
12
16
13
export type UseComboboxProps = {
17
14
children : ReactNode ;
@@ -30,40 +27,7 @@ export type Option = {
30
27
31
28
const isOption = ( option : Option | undefined ) : option is Option => ! ! option ;
32
29
33
- export function isComboboxOption (
34
- child : ReactNode ,
35
- ) : child is ReactElement < ComboboxOptionProps > {
36
- return isValidElement ( child ) && child . type === ComboboxOption ;
37
- }
38
-
39
- export function isComboboxCustom (
40
- child : ReactNode ,
41
- ) : child is ReactElement < ComboboxCustomProps > {
42
- return isValidElement ( child ) && child . type === ComboboxCustom ;
43
- }
44
-
45
- export function isInteractiveComboboxCustom (
46
- child : ReactNode ,
47
- ) : child is ReactElement < ComboboxCustomProps > {
48
- return isComboboxCustom ( child ) && child . props . interactive === true ;
49
- }
50
-
51
- const INTERNAL_OPTION_PREFIX = 'internal-option-' ;
52
-
53
- /**
54
- * We use this function to prefix the value of the options so we can make sure numbers as strings are not parsed as numbers in objects
55
- * @param value
56
- * @returns
57
- */
58
- export const prefix = ( value ?: string ) : string => {
59
- return INTERNAL_OPTION_PREFIX + value ;
60
- } ;
61
-
62
- export const removePrefix = ( value : string ) : string => {
63
- return value . slice ( INTERNAL_OPTION_PREFIX . length ) ;
64
- } ;
65
-
66
- export default function useCombobox ( {
30
+ export function useCombobox ( {
67
31
children,
68
32
inputValue,
69
33
multiple,
0 commit comments