forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution][Expandable flyout] add multi flyout support to kb…
…n-expandable-flyout package (elastic#176457)
- Loading branch information
1 parent
77c7d91
commit 6e17a8d
Showing
17 changed files
with
989 additions
and
252 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 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,63 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React, { createContext, memo, useContext, useMemo } from 'react'; | ||
|
||
export interface ExpandableFlyoutContext { | ||
/** | ||
* Unique key to be used as url parameter to store the state of the flyout | ||
*/ | ||
urlKey: string | undefined; | ||
} | ||
|
||
export const ExpandableFlyoutContext = createContext<ExpandableFlyoutContext | undefined>( | ||
undefined | ||
); | ||
|
||
export interface ExpandableFlyoutContextProviderProps { | ||
/** | ||
* Unique key to be used as url parameter to store the state of the flyout | ||
*/ | ||
urlKey: string | undefined; | ||
/** | ||
* React components to render | ||
*/ | ||
children: React.ReactNode; | ||
} | ||
|
||
/** | ||
* Context used to share the value of the urlKey to the rest of the expandable flyout's code | ||
*/ | ||
export const ExpandableFlyoutContextProvider = memo<ExpandableFlyoutContextProviderProps>( | ||
({ urlKey, children }) => { | ||
const contextValue = useMemo( | ||
() => ({ | ||
urlKey, | ||
}), | ||
[urlKey] | ||
); | ||
|
||
return ( | ||
<ExpandableFlyoutContext.Provider value={contextValue}> | ||
{children} | ||
</ExpandableFlyoutContext.Provider> | ||
); | ||
} | ||
); | ||
|
||
ExpandableFlyoutContextProvider.displayName = 'ExpandableFlyoutContextProvider'; | ||
|
||
export const useExpandableFlyoutContext = () => { | ||
const context = useContext(ExpandableFlyoutContext); | ||
if (context === undefined) { | ||
throw new Error( | ||
'ExpandableFlyoutContext can only be used within ExpandableFlyoutContext provider' | ||
); | ||
} | ||
return context; | ||
}; |
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.