Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: James Talton <jtalton@redhat.com>
- Loading branch information
1 parent
61a169e
commit 0d365d3
Showing
4 changed files
with
93 additions
and
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { createContext, ReactNode, useContext, useState } from 'react' | ||
|
||
/* | ||
Show validation is used to indicate is that controls shoud show validation. | ||
Initially it is false, but on a wizard step upon clicking next validation should show for that step. | ||
When a wizard gets to the review step, validation errors for the whole wizard should show. | ||
*/ | ||
|
||
const SetShowValidationContext = createContext<(show: boolean) => void>(() => null) | ||
export function useSetShowValidation() { | ||
return useContext(SetShowValidationContext) | ||
} | ||
|
||
const ShowValidationContext = createContext(false) | ||
export function useShowValidation() { | ||
return useContext(ShowValidationContext) | ||
} | ||
|
||
export function ShowValidationProvider(props: { children?: ReactNode }) { | ||
const [showValidation, setShowValidation] = useState(false) | ||
const parentShowValidationContext = useContext(ShowValidationContext) | ||
const activeShowValidation = showValidation || parentShowValidationContext | ||
return ( | ||
<SetShowValidationContext.Provider value={setShowValidation}> | ||
<ShowValidationContext.Provider value={activeShowValidation}>{props.children}</ShowValidationContext.Provider> | ||
</SetShowValidationContext.Provider> | ||
) | ||
} |
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