mirror of https://github.com/buster-so/buster.git
aside and main logic
This commit is contained in:
parent
4418f7c2c4
commit
a13aa3e831
|
@ -54,6 +54,8 @@ export const AppLayout: React.FC<
|
||||||
leftChildren={sidebar}
|
leftChildren={sidebar}
|
||||||
rightChildren={PageContent}
|
rightChildren={PageContent}
|
||||||
initialLayout={initialLayout}
|
initialLayout={initialLayout}
|
||||||
|
leftPanelElement="aside"
|
||||||
|
rightPanelElement="main"
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -145,6 +145,8 @@ const AppSplitterBase = forwardRef<
|
||||||
leftChildren,
|
leftChildren,
|
||||||
rightChildren,
|
rightChildren,
|
||||||
defaultLayout,
|
defaultLayout,
|
||||||
|
leftPanelElement = 'div',
|
||||||
|
rightPanelElement = 'div',
|
||||||
leftPanelMinSize = 0,
|
leftPanelMinSize = 0,
|
||||||
rightPanelMinSize = 0,
|
rightPanelMinSize = 0,
|
||||||
leftPanelMaxSize,
|
leftPanelMaxSize,
|
||||||
|
@ -646,6 +648,7 @@ const AppSplitterBase = forwardRef<
|
||||||
width={isVertical ? leftSize : 'auto'}
|
width={isVertical ? leftSize : 'auto'}
|
||||||
height={!isVertical ? leftSize : 'auto'}
|
height={!isVertical ? leftSize : 'auto'}
|
||||||
hidden={leftHidden}
|
hidden={leftHidden}
|
||||||
|
as={leftPanelElement}
|
||||||
>
|
>
|
||||||
{leftChildren}
|
{leftChildren}
|
||||||
</Panel>
|
</Panel>
|
||||||
|
@ -664,6 +667,7 @@ const AppSplitterBase = forwardRef<
|
||||||
width={isVertical ? rightSize : 'auto'}
|
width={isVertical ? rightSize : 'auto'}
|
||||||
height={!isVertical ? rightSize : 'auto'}
|
height={!isVertical ? rightSize : 'auto'}
|
||||||
hidden={rightHidden}
|
hidden={rightHidden}
|
||||||
|
as={rightPanelElement}
|
||||||
>
|
>
|
||||||
{rightChildren}
|
{rightChildren}
|
||||||
</Panel>
|
</Panel>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
export type PanelSize = `${number}px` | `${number}%` | 'auto' | number;
|
export type PanelSize = `${number}px` | `${number}%` | 'auto' | number;
|
||||||
type PanelSizeWithAuto = Exclude<PanelSize, 'auto'>;
|
type PanelSizeWithAuto = Exclude<PanelSize, 'auto'>;
|
||||||
export type LayoutSize = ['auto', PanelSizeWithAuto] | [PanelSizeWithAuto, 'auto'];
|
export type LayoutSize = ['auto', PanelSizeWithAuto] | [PanelSizeWithAuto, 'auto'];
|
||||||
|
export type PanelElement = 'aside' | 'div' | 'main';
|
||||||
|
|
||||||
export interface IAppSplitterProps {
|
export interface IAppSplitterProps {
|
||||||
/** Content to display in the left panel */
|
/** Content to display in the left panel */
|
||||||
|
@ -102,6 +103,12 @@ export interface IAppSplitterProps {
|
||||||
|
|
||||||
/** Additional CSS classes for the right panel */
|
/** Additional CSS classes for the right panel */
|
||||||
rightPanelClassName?: string;
|
rightPanelClassName?: string;
|
||||||
|
|
||||||
|
/** HTML element type for the left panel. Defaults to 'div' */
|
||||||
|
leftPanelElement?: PanelElement;
|
||||||
|
|
||||||
|
/** HTML element type for the right panel. Defaults to 'div' */
|
||||||
|
rightPanelElement?: PanelElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { cn } from '@/lib/classMerge';
|
import { cn } from '@/lib/classMerge';
|
||||||
|
import type { PanelElement } from './AppSplitter.types';
|
||||||
|
|
||||||
interface IPanelProps {
|
interface IPanelProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
|
@ -12,10 +13,11 @@ interface IPanelProps {
|
||||||
className?: string;
|
className?: string;
|
||||||
hidden?: boolean;
|
hidden?: boolean;
|
||||||
style?: React.CSSProperties;
|
style?: React.CSSProperties;
|
||||||
|
as?: PanelElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Panel: React.FC<IPanelProps> = React.memo(
|
export const Panel: React.FC<IPanelProps> = React.memo(
|
||||||
({ children, width, height, minSize, maxSize, className, hidden, style }) => {
|
({ children, width, height, minSize, maxSize, className, hidden, style, as = 'div' }) => {
|
||||||
if (hidden) return null;
|
if (hidden) return null;
|
||||||
|
|
||||||
const panelStyle: React.CSSProperties = {
|
const panelStyle: React.CSSProperties = {
|
||||||
|
@ -26,18 +28,19 @@ export const Panel: React.FC<IPanelProps> = React.memo(
|
||||||
...(maxSize !== undefined && { maxWidth: `${maxSize}px`, maxHeight: `${maxSize}px` }),
|
...(maxSize !== undefined && { maxWidth: `${maxSize}px`, maxHeight: `${maxSize}px` }),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const Component = as;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<Component
|
||||||
className={cn(
|
className={cn(
|
||||||
'panel overflow-hidden',
|
'panel overflow-hidden',
|
||||||
// When we have a specific width or height, we should not grow/shrink
|
|
||||||
width !== 'auto' || height !== 'auto' ? 'flex-shrink-0 flex-grow-0' : 'flex-1',
|
width !== 'auto' || height !== 'auto' ? 'flex-shrink-0 flex-grow-0' : 'flex-1',
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
style={panelStyle}
|
style={panelStyle}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</Component>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -2,7 +2,7 @@ import type React from 'react';
|
||||||
import { SidebarPrimary } from '@/components/features/sidebars/SidebarPrimary';
|
import { SidebarPrimary } from '@/components/features/sidebars/SidebarPrimary';
|
||||||
import { AppLayout, type LayoutSize } from '@/components/ui/layouts/AppLayout';
|
import { AppLayout, type LayoutSize } from '@/components/ui/layouts/AppLayout';
|
||||||
|
|
||||||
export const PRIMARY_APP_LAYOUT_ID = 'app-layout';
|
export const PRIMARY_APP_LAYOUT_ID = 'primary-sidebar';
|
||||||
|
|
||||||
const DEFAULT_LAYOUT: LayoutSize = ['230px', 'auto'];
|
const DEFAULT_LAYOUT: LayoutSize = ['230px', 'auto'];
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ function RouteComponent() {
|
||||||
<AppSplitter
|
<AppSplitter
|
||||||
preserveSide="right"
|
preserveSide="right"
|
||||||
defaultLayout={['50%', 'auto']}
|
defaultLayout={['50%', 'auto']}
|
||||||
autoSaveId="test0"
|
autoSaveId={layoutId}
|
||||||
leftChildren={<div>Left</div>}
|
leftChildren={<div>Left</div>}
|
||||||
rightChildren={<RightPanel />}
|
rightChildren={<RightPanel />}
|
||||||
initialLayout={initialLayout}
|
initialLayout={initialLayout}
|
||||||
|
|
|
@ -32,6 +32,7 @@ export const Route = createFileRoute('/app')({
|
||||||
},
|
},
|
||||||
component: () => {
|
component: () => {
|
||||||
const { initialLayout } = Route.useLoaderData();
|
const { initialLayout } = Route.useLoaderData();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AppProviders>
|
<AppProviders>
|
||||||
<PrimaryAppLayout initialLayout={initialLayout}>
|
<PrimaryAppLayout initialLayout={initialLayout}>
|
||||||
|
|
Loading…
Reference in New Issue