Skip to content

Commit

Permalink
feat: Allow sidebar override
Browse files Browse the repository at this point in the history
  • Loading branch information
JonaszJestem committed Jan 25, 2021
1 parent 7dc2e70 commit d670a52
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
26 changes: 16 additions & 10 deletions src/frontend/components/app/sidebar/sidebar.tsx
Expand Up @@ -11,10 +11,11 @@ import { ReduxState } from '../../../store/store'
import SidebarFooter from './sidebar-footer'

import SidebarResourceSection from './sidebar-resource-section'
import allowOverride from '../../../hoc/allow-override'

type Props = {
isVisible: boolean;
}
};

const StyledSidebar = styled(Box)`
transition: left 0.3s;
Expand All @@ -41,18 +42,20 @@ StyledSidebar.defaultProps = {
bg: 'white',
}

const Sidebar: React.FC<Props> = (props) => {
const SidebarOriginal: React.FC<Props> = (props) => {
const { isVisible } = props
const [branding, resources, pages]: [BrandingOptions, ResourceJSON[], PageJSON[]] = useSelector(
(state: ReduxState) => [
state.branding, state.resources, state.pages,
],
)
const [branding, resources, pages]: [
BrandingOptions,
ResourceJSON[],
PageJSON[]
] = useSelector((state: ReduxState) => [
state.branding,
state.resources,
state.pages,
])

return (
<StyledSidebar
className={isVisible ? 'visible' : 'hidden'}
>
<StyledSidebar className={isVisible ? 'visible' : 'hidden'}>
<SidebarBranding branding={branding} />
<Box flexGrow={1} className={cssClass('Resources')}>
<SidebarResourceSection resources={resources} />
Expand All @@ -63,4 +66,7 @@ const Sidebar: React.FC<Props> = (props) => {
)
}

const Sidebar = allowOverride(SidebarOriginal, 'Sidebar')

export { Sidebar }
export default Sidebar
6 changes: 4 additions & 2 deletions src/frontend/utils/overridable-component.ts
@@ -1,16 +1,18 @@
export type OverridableComponent = 'LoggedIn'
export type OverridableComponent =
| 'LoggedIn'
| 'NoRecords'
| 'SidebarResourceSection'
| 'SidebarFooter'
| 'SidebarBranding'

| 'Sidebar';

/**
* Name of the components which can be overridden by AdminBro.bundle. It currently following
* components can be override:
*
* - LoggedIn
* - NoRecords
* - Sidebar
* - SidebarResourceSection
* - SidebarFooter
* - SidebarBranding
Expand Down

0 comments on commit d670a52

Please sign in to comment.