Skip to content

Commit

Permalink
Merge pull request #364 from qoretechnologies/feature/rework-sidebar
Browse files Browse the repository at this point in the history
Remove Sidebar component in favor of improved `ReqoreMenu`
  • Loading branch information
Foxhoundn authored Mar 18, 2024
2 parents 47c0ce6 + 5d8a8c3 commit 0ce5c02
Show file tree
Hide file tree
Showing 11 changed files with 299 additions and 1,373 deletions.
225 changes: 0 additions & 225 deletions __tests__/sidebar.test.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@qoretechnologies/reqore",
"version": "0.39.0",
"version": "0.40.0",
"description": "ReQore is a highly theme-able and modular UI library for React",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
12 changes: 8 additions & 4 deletions src/components/ControlGroup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ import { StyledEffect } from '../Effect';
import { StyledHeader } from '../Header';
import { StyledParagraph } from '../Paragraph';

export interface IReqoreControlGroupProps
extends React.HTMLAttributes<HTMLDivElement>,
IWithReqoreFlat,
export interface IReqoreControlGroupComponentProps
extends IWithReqoreFlat,
IWithReqoreSize,
IWithReqoreMinimal,
IReqoreIntent,
IWithReqoreFluid,
IWithReqoreCustomTheme {
stack?: boolean;
children: any;
fixed?: boolean;
rounded?: boolean;
responsive?: boolean;
Expand Down Expand Up @@ -54,6 +52,12 @@ export interface IReqoreControlGroupProps
fill?: boolean;
}

export interface IReqoreControlGroupProps
extends React.HTMLAttributes<HTMLDivElement>,
IReqoreControlGroupComponentProps {
children: any;
}

export interface IReqoreControlGroupStyle extends IReqoreControlGroupProps {
theme: IReqoreTheme;
}
Expand Down
82 changes: 82 additions & 0 deletions src/components/Menu/section.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import React, { useCallback, useEffect, useState } from 'react';
import { TReqoreIntent } from '../../constants/theme';
import { IReqoreComponent } from '../../types/global';
import ReqoreButton, { IReqoreButtonProps } from '../Button';
import ReqoreControlGroup from '../ControlGroup';

export interface IReqoreMenuSectionProps extends IReqoreComponent, IReqoreButtonProps {
children: any;
collapsible?: boolean;
isCollapsed?: boolean;
onCollapseChange?: (collapsed: boolean) => void;
activeIntent?: TReqoreIntent;
}

export const ReqoreMenuSection = ({
children,
_insidePopover,
_popoverId,
customTheme,
wrap,
flat,
minimal,
collapsible = true,
isCollapsed,
activeIntent,
onCollapseChange,
...rest
}: IReqoreMenuSectionProps) => {
const [_isCollapsed, setIsCollapsed] = useState(isCollapsed);

useEffect(() => {
setIsCollapsed(isCollapsed);
}, [isCollapsed]);

const handleCollapseChange = useCallback(
(event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
if (collapsible) {
setIsCollapsed(!_isCollapsed);
onCollapseChange?.(!_isCollapsed);
}

rest.onClick?.(event);
},
[_isCollapsed, onCollapseChange, collapsible, rest.onClick]
);

return (
<ReqoreControlGroup vertical fluid className='reqore-menu-section'>
<ReqoreButton
wrap={wrap}
flat={flat}
minimal={minimal}
active={collapsible && !_isCollapsed}
{...rest}
className={`${rest.className || ''} reqore-menu-section-toggle`}
intent={collapsible && !_isCollapsed ? activeIntent : rest.intent}
fluid
onClick={handleCollapseChange}
rightIcon={rest.rightIcon || (collapsible ? 'ArrowRightSLine' : 'ArrowDownSLine')}
rightIconProps={{
rotation: collapsible && !_isCollapsed ? 90 : 0,
}}
/>
{!_isCollapsed || !collapsible ? (
<ReqoreControlGroup vertical fluid style={{ paddingLeft: '10px' }}>
{React.Children.map(children, (child) => {
return child
? React.cloneElement(child, {
_insidePopover: child.props?._insidePopover ?? _insidePopover,
_popoverId: child.props?._popoverId ?? _popoverId,
customTheme: child.props?.customTheme || customTheme,
wrap: 'wrap' in (child.props || {}) ? child.props.wrap : wrap,
flat: 'flat' in (child.props || {}) ? child.props.flat : flat,
minimal: 'minimal' in (child.props || {}) ? child.props.minimal : minimal,
})
: null;
})}
</ReqoreControlGroup>
) : null}
</ReqoreControlGroup>
);
};
Loading

0 comments on commit 0ce5c02

Please sign in to comment.