-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**Breaking:** Fix operational context (#921)
* Make operational-context class compatible * Remove windowSize in context and usages * Add useWindowSize for later :) * Refactored Tooltip with hooks, didn't change logic * Make styleguidist recognize React component in Tooltip.tsx * Coerce colors to strings for safety * Move windowsize hook * Move useURLState hook * Move hooks * Move context examples * Fix test regex matcher * Fix onTabChange warning
- Loading branch information
1 parent
80ac447
commit d9ab7e5
Showing
18 changed files
with
251 additions
and
245 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
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 was deleted.
Oops, something went wrong.
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,20 +1,38 @@ | ||
import * as React from "react" | ||
|
||
import { Context, IMessage, MessageType, useOperationalContext, WindowSize } from "./OperationalContext.init" | ||
export type MessageType = "info" | "success" | "error" | ||
|
||
export interface Props { | ||
children: (operationalContext: Context) => undefined | React.ReactNode | ||
export interface IMessage { | ||
body: string | ||
type: MessageType | ||
onClick?: () => void | ||
} | ||
|
||
export interface Context { | ||
pushState?: (url: string) => void | ||
replaceState?: (url: string) => void | ||
pushMessage: (message: IMessage) => void | ||
loading: boolean | ||
setLoading: (isLoading: boolean) => void | ||
} | ||
|
||
/** | ||
* This component simply wraps OperationalContext in order to allow styleguidist to pick up on | ||
* it and display it in the documentation page. | ||
* Defining a default context value here, used below when instantiating | ||
* the context consumer and provider below in order for context to be | ||
* correctly detected throughout the application. | ||
*/ | ||
const OperationalContext: React.SFC<Props> = props => { | ||
const ctx = useOperationalContext() | ||
return <>{props.children({ ...ctx })}</> | ||
const defaultContext: Context = { | ||
pushState: undefined, | ||
replaceState: undefined, | ||
pushMessage: (_: IMessage) => void 0, | ||
loading: false, | ||
setLoading: (_: boolean) => void 0, | ||
} | ||
|
||
export default OperationalContext | ||
const ctx = React.createContext(defaultContext) | ||
|
||
export { Context, WindowSize, IMessage, MessageType, useOperationalContext } | ||
export const { Consumer: OperationalContext, Provider } = ctx | ||
|
||
export const useOperationalContext = () => React.useContext(ctx) | ||
|
||
export default OperationalContext |
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.