diff --git a/src/Components/Category/Category.tsx b/src/Components/Category/Category.tsx new file mode 100644 index 0000000..1dfdd21 --- /dev/null +++ b/src/Components/Category/Category.tsx @@ -0,0 +1,60 @@ +import { ChevronRightIcon } from '@heroicons/react/outline'; +import React, { useState } from 'react'; +import { TruncateString } from '../../utils/stringtools'; + +interface ICategoryProps { + children: JSX.Element | JSX.Element[] + category: string +} + +export function Category(props: ICategoryProps): JSX.Element { + const [isOpen, setIsOpen] = useState(false); + + if (isOpen) { + return ( + + ); + } + + return ( + + ); +} diff --git a/src/Components/Sidebar/Sidebar.tsx b/src/Components/Sidebar/Sidebar.tsx index fa2bbbb..da22551 100644 --- a/src/Components/Sidebar/Sidebar.tsx +++ b/src/Components/Sidebar/Sidebar.tsx @@ -1,6 +1,8 @@ +import { ChevronRightIcon } from '@heroicons/react/outline'; import * as React from 'react'; import { IAvailableContainer } from '../../Interfaces/IAvailableContainer'; import { TruncateString } from '../../utils/stringtools'; +import { Category } from '../Category/Category'; interface ISidebarProps { componentOptions: IAvailableContainer[] @@ -13,10 +15,16 @@ function HandleDragStart(event: React.DragEvent): void { } export function Sidebar(props: ISidebarProps): JSX.Element { - const listElements = props.componentOptions.map(componentOption => - componentOption.IsHidden !== true && - - ); + ); + if (componentOption.Category === null || componentOption.Category === undefined) { + rootElements.push(componentButton); + return; + } + + if (categories.get(componentOption.Category) === undefined) { + categories.set(componentOption.Category, []); + } + + const category = categories.get(componentOption.Category); + + if (category === undefined) { + // should never go here + return; + } + + category.push(componentButton); + }); + + // build the categories + categories.forEach((options, category) => { + rootElements.unshift( + + { options } + ); + }); const isOpenClasses = props.isOpen ? 'left-16' : '-left-64'; return ( @@ -38,7 +71,7 @@ export function Sidebar(props: ISidebarProps): JSX.Element {
- {listElements} + {rootElements}
); diff --git a/src/Interfaces/IAvailableContainer.ts b/src/Interfaces/IAvailableContainer.ts index 0f6e36b..027f10c 100644 --- a/src/Interfaces/IAvailableContainer.ts +++ b/src/Interfaces/IAvailableContainer.ts @@ -10,6 +10,9 @@ export interface IAvailableContainer { /** type */ Type: string + /** category */ + Category?: string + /** horizontal offset */ X?: number diff --git a/src/index.scss b/src/index.scss index 988f4e1..58b95cd 100644 --- a/src/index.scss +++ b/src/index.scss @@ -11,6 +11,14 @@ @apply transition-all px-2 py-6 text-sm rounded-lg bg-slate-300/60 hover:bg-blue-500 hover:text-slate-50 } + .sidebar-component-left { + @apply transition-all px-2 py-6 text-sm rounded-l-lg bg-slate-300/60 group-hover:bg-blue-500 group-hover:text-slate-50 + } + + .sidebar-component-right { + @apply transition-all px-2 py-6 text-sm rounded-r-lg bg-slate-400/60 group-hover:bg-blue-600 group-hover:text-slate-50 + } + .sidebar-component-card { @apply transition-all overflow-hidden text-sm rounded-lg bg-slate-300/60 hover:bg-slate-300 } diff --git a/test-server/http.js b/test-server/http.js index be800ae..3287382 100644 --- a/test-server/http.js +++ b/test-server/http.js @@ -65,6 +65,7 @@ const GetSVGLayoutConfiguration = () => { }, ShowSelfDimensions: true, IsDimensionBorrower: true, + Category: "Category" }, { Type: 'Trou', @@ -82,7 +83,8 @@ const GetSVGLayoutConfiguration = () => { strokeWidth: 2, stroke: 'green', fill: 'white' - } + }, + Category: "Category" }, { Type: 'Remplissage',