mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Update to remove provider composer; prep for commit
This commit is contained in:
parent
07103a02dd
commit
50f0d3ad08
7 changed files with 36 additions and 81 deletions
|
@ -8,7 +8,7 @@
|
|||
|
||||
import React, { FC } from 'react';
|
||||
import type { I18nStart } from '@kbn/core-i18n-browser';
|
||||
import { composeProviders, KibanaThemeProvider } from '@kbn/react-kibana-context';
|
||||
import { KibanaThemeProvider } from '@kbn/react-kibana-context';
|
||||
import { ThemeServiceStart } from '@kbn/core-theme-browser/src/types';
|
||||
|
||||
interface CoreContextProviderProps {
|
||||
|
@ -18,7 +18,7 @@ interface CoreContextProviderProps {
|
|||
}
|
||||
|
||||
/**
|
||||
* Utility component exposing all the context providers required by core when integrating with React.
|
||||
* Utility component exposing all the context providers required by Kibana when integrating with React.
|
||||
**/
|
||||
export const CoreContextProvider: FC<CoreContextProviderProps> = ({
|
||||
i18n,
|
||||
|
@ -26,11 +26,11 @@ export const CoreContextProvider: FC<CoreContextProviderProps> = ({
|
|||
theme,
|
||||
globalStyles = false,
|
||||
}) => {
|
||||
const Provider = composeProviders([i18n.Context, KibanaThemeProvider]);
|
||||
|
||||
return (
|
||||
<Provider theme$={theme.theme$} {...{ globalStyles }}>
|
||||
{children}
|
||||
</Provider>
|
||||
<i18n.Context>
|
||||
<KibanaThemeProvider theme$={theme.theme$} {...{ globalStyles }}>
|
||||
{children}
|
||||
</KibanaThemeProvider>
|
||||
</i18n.Context>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -12,5 +12,3 @@ export {
|
|||
withKibanaContextProvider,
|
||||
type KibanaContextProviderProps,
|
||||
} from './provider';
|
||||
|
||||
export { composeProviders } from './utils';
|
||||
|
|
|
@ -6,8 +6,4 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
export {
|
||||
KibanaContextProvider,
|
||||
withKibanaContextProvider,
|
||||
type KibanaContextProviderProps,
|
||||
} from './kibana_provider';
|
||||
export { KibanaContextProvider, type KibanaContextProviderProps } from './kibana_provider';
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
/*
|
||||
* 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 { I18nProvider } from '@kbn/i18n-react';
|
||||
import { ComponentPropsWithoutRef } from 'react';
|
||||
|
||||
import { KibanaThemeProvider } from '../theme';
|
||||
import { composeProviders } from '../utils';
|
||||
import { ComposeProvidersFn } from '../utils/compose';
|
||||
|
||||
export const KibanaContextProvider = composeProviders([I18nProvider, KibanaThemeProvider]);
|
||||
export type KibanaContextProviderProps = ComponentPropsWithoutRef<typeof KibanaContextProvider>;
|
||||
|
||||
export const withKibanaContextProvider: ComposeProvidersFn = (providers) =>
|
||||
composeProviders([KibanaContextProvider, ...providers]);
|
28
packages/react/kibana_context/provider/kibana_provider.tsx
Normal file
28
packages/react/kibana_context/provider/kibana_provider.tsx
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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, { FC } from 'react';
|
||||
import { I18nProvider } from '@kbn/i18n-react';
|
||||
|
||||
import { KibanaThemeProvider, type KibanaThemeProviderProps } from '../theme';
|
||||
|
||||
/** Props for the KibanaContextProvider */
|
||||
export type KibanaContextProviderProps = KibanaThemeProviderProps;
|
||||
|
||||
/**
|
||||
* The `KibanaContextProvider` provides the necessary context for Kibana's React components, including
|
||||
* the theme and i18n context. In almost all cases, this provider should appear early in any plugin's
|
||||
* React trees.
|
||||
*/
|
||||
export const KibanaContextProvider: FC<KibanaContextProviderProps> = ({ children, ...props }) => {
|
||||
return (
|
||||
<I18nProvider>
|
||||
<KibanaThemeProvider {...props}>{children}</KibanaThemeProvider>
|
||||
</I18nProvider>
|
||||
);
|
||||
};
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* 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, { PropsWithChildren, FC, ComponentPropsWithoutRef } from 'react';
|
||||
|
||||
export type UnionToIntersection<U> = (U extends unknown ? (u: U) => void : never) extends (
|
||||
i: infer I
|
||||
) => void
|
||||
? I
|
||||
: never;
|
||||
|
||||
type CombinedProps<P extends Array<FC<any>>> = PropsWithChildren<
|
||||
UnionToIntersection<ComponentPropsWithoutRef<P[number]>>
|
||||
>;
|
||||
|
||||
const compose = <P extends Array<FC<any>>>(providers: P, props: CombinedProps<P>): FC<{}> => {
|
||||
return ({ children }) => (
|
||||
<>
|
||||
{providers.reduceRight((acc, ContextProvider) => {
|
||||
return <ContextProvider {...props}>{acc}</ContextProvider>;
|
||||
}, children)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export const composeProviders = <P extends Array<FC<any>>>(providers: P): FC<CombinedProps<P>> => {
|
||||
return (props: CombinedProps<P>) => {
|
||||
const ContextProvider = compose(providers, props);
|
||||
return <ContextProvider>{props.children}</ContextProvider>;
|
||||
};
|
||||
};
|
||||
|
||||
export type ComposeProvidersFn = typeof composeProviders;
|
|
@ -1,9 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export { composeProviders } from './compose';
|
Loading…
Add table
Add a link
Reference in a new issue