-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #268 from anubra266/fix/utils
Remove utils dependency
- Loading branch information
Showing
13 changed files
with
308 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,33 @@ | ||
import { createContext } from "@chakra-ui/react-utils"; | ||
import * as React from "react"; | ||
import { UseAutoCompleteReturn } from "./types"; | ||
|
||
export const [AutoCompleteProvider, useAutoCompleteContext] = createContext< | ||
UseAutoCompleteReturn | ||
>({ | ||
name: "AutoCompleteContext", | ||
errorMessage: | ||
"useAutoCompleteContext: `context` is undefined. Seems you forgot to wrap all autoomplete components within `<AutoComplete />`", | ||
}); | ||
>(); | ||
|
||
type CreateContextReturn<T> = [React.Provider<T>, () => T, React.Context<T>]; | ||
|
||
export function createContext<ContextType>() { | ||
const Context = React.createContext<ContextType | undefined>(undefined); | ||
|
||
Context.displayName = "AutoCompleteContext"; | ||
|
||
function useContext() { | ||
const context = React.useContext(Context); | ||
const errorMessage = | ||
"useAutoCompleteContext: `context` is undefined. Seems you forgot to wrap all autoomplete components within `<AutoComplete />`"; | ||
|
||
if (!context) { | ||
const error = new Error(errorMessage); | ||
error.name = "ContextError"; | ||
Error.captureStackTrace?.(error, useContext); | ||
throw error; | ||
} | ||
|
||
return context; | ||
} | ||
|
||
return [Context.Provider, useContext, Context] as CreateContextReturn< | ||
ContextType | ||
>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.