feat: builds a way to inject custom React providers into admin UI

* fix: rich text textarea height

* feat: custom providers for admin panel

* docs: custom provider component
This commit is contained in:
Dan Ribbens
2022-03-28 11:23:22 -04:00
committed by GitHub
parent 45f70114e6
commit 5a7e8a980b
9 changed files with 100 additions and 4 deletions

View File

@@ -272,6 +272,7 @@ const RichText: React.FC<Props> = (props) => {
ref={editorRef}
>
<Editable
className={`${baseClass}__input`}
renderElement={renderElement}
renderLeaf={renderLeaf}
placeholder={placeholder}

View File

@@ -17,7 +17,6 @@
}
&__editor {
min-height: base(10);
[data-slate-node=element] {
margin-bottom: base(0.25);
@@ -31,6 +30,10 @@
}
}
&__input {
min-height: base(10);
}
&__wrap {
width: 100%;
position: relative;

View File

@@ -0,0 +1,48 @@
import React from 'react';
import { useConfig } from '@payloadcms/config-provider';
const NestProviders = ({ providers, children }) => {
const Component = providers[0];
if (providers.length > 1) {
return (
<Component>
<NestProviders
providers={providers.slice(1)}
>
{children}
</NestProviders>
</Component>
);
}
return (
<Component>
{children}
</Component>
);
};
export const CustomProvider: React.FC<{ children }> = ({ children }) => {
const config = useConfig();
const {
admin: {
components: {
providers,
},
},
} = config;
if (Array.isArray(providers) && providers.length > 0) {
return (
<NestProviders providers={providers}>
{children}
</NestProviders>
);
}
return (
<React.Fragment>
{children}
</React.Fragment>
);
};

View File

@@ -10,6 +10,7 @@ import { ModalProvider, ModalContainer } from '@faceless-ui/modal';
import { ToastContainer, Slide } from 'react-toastify';
import { ConfigProvider, AuthProvider } from '@payloadcms/config-provider';
import { PreferencesProvider } from './components/utilities/Preferences';
import { CustomProvider } from './components/utilities/CustomProvider';
import { SearchParamsProvider } from './components/utilities/SearchParams';
import { LocaleProvider } from './components/utilities/Locale';
import Routes from './components/Routes';
@@ -38,7 +39,9 @@ const Index = () => (
<SearchParamsProvider>
<LocaleProvider>
<StepNavProvider>
<Routes />
<CustomProvider>
<Routes />
</CustomProvider>
</StepNavProvider>
</LocaleProvider>
</SearchParamsProvider>