From ce61aebc605b573c930ba9f7415a14cbf5b64d67 Mon Sep 17 00:00:00 2001 From: Siklos Date: Thu, 4 Aug 2022 14:13:14 +0200 Subject: [PATCH] Improve history style --- src/App.tsx | 42 +++++++++++++++-- .../ElementsSidebar/ElementsSidebar.tsx | 8 +++- src/Components/History/History.tsx | 47 ++++++++++++++++--- 3 files changed, 86 insertions(+), 11 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index ed36af1..3db4ae4 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -21,6 +21,7 @@ export interface IHistoryState { interface IAppState { isSidebarOpen: boolean, isSVGSidebarOpen: boolean, + isHistoryOpen: boolean, configuration: Configuration, history: Array, historyCurrentStep: 0 @@ -34,6 +35,7 @@ class App extends React.Component { this.state = { isSidebarOpen: true, isSVGSidebarOpen: false, + isHistoryOpen: false, configuration: { AvailableContainers: [], AvailableSymbols: [], @@ -110,6 +112,15 @@ class App extends React.Component { } as IAppState); } + /** + * Toggle the elements + */ + public ToggleHistory() { + this.setState({ + isHistoryOpen: !this.state.isHistoryOpen + } as IAppState); + } + /** * Select a container * @param container Selected container @@ -293,20 +304,45 @@ class App extends React.Component { onClick={() => this.ToggleSidebar()} buttonOnClick={(type: string) => this.AddContainer(type)} /> - + + this.ToggleElementsSidebar()} onPropertyChange={(key: string, value: string) => this.OnPropertyChange(key, value)} selectContainer={(container: ContainerModel) => this.SelectContainer(container)} /> - + + + this.ToggleHistory()} + jumpTo={(move) => { this.jumpTo(move); }} + /> + + { current.MainContainer } - { this.jumpTo(move); }} /> ); } diff --git a/src/Components/ElementsSidebar/ElementsSidebar.tsx b/src/Components/ElementsSidebar/ElementsSidebar.tsx index 3caea25..e93f527 100644 --- a/src/Components/ElementsSidebar/ElementsSidebar.tsx +++ b/src/Components/ElementsSidebar/ElementsSidebar.tsx @@ -6,6 +6,7 @@ import { IContainerModel, getDepth, MakeIterator } from '../SVG/Elements/Contain interface IElementsSidebarProps { MainContainer: IContainerModel | null, isOpen: boolean, + isHistoryOpen: boolean SelectedContainer: IContainerModel | null, onClick: () => void, onPropertyChange: (key: string, value: string) => void, @@ -25,7 +26,12 @@ export class ElementsSidebar extends React.Component { } public render() { - const isOpenClasses = this.props.isOpen ? 'right-0' : '-right-64'; + let isOpenClasses = '-right-64'; + if (this.props.isOpen) { + isOpenClasses = this.props.isHistoryOpen + ? 'right-64' + : 'right-0'; + } const containerRows: React.ReactNode[] = []; this.iterateChilds((container: IContainerModel) => { diff --git a/src/Components/History/History.tsx b/src/Components/History/History.tsx index 6f6d49e..750fcc7 100644 --- a/src/Components/History/History.tsx +++ b/src/Components/History/History.tsx @@ -3,26 +3,59 @@ import { IHistoryState } from '../../App'; interface IHistoryProps { history: IHistoryState[], + historyCurrentStep: number, + isOpen: boolean, + onClick: () => void, jumpTo: (move: number) => void } export class History extends React.Component { public render() { + const isOpenClasses = this.props.isOpen ? 'right-0' : '-right-64'; + const states = this.props.history.map((step, move) => { const desc = move - ? `Go back at turn n°${move}` - : 'Go back at the beginning'; + ? `Go to modification n°${move}` + : 'Go to the beginning'; + const isCurrent = move === this.props.historyCurrentStep; + + const selectedClass = isCurrent + ? 'bg-blue-500 hover:bg-blue-600' + : 'bg-slate-500 hover:bg-slate-700'; + + const isCurrentText = isCurrent + ? ' (current)' + : ''; return ( -
  • - -
  • + + ); }); + // recent first + states.reverse(); + return ( -
    - { states } +
    + +
    + History +
    +
    + { states } +
    ); }