Improve history style (#5)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: https://git.siklos-chaneru.duckdns.org/Siklos/svg-layout-designer-react/pulls/5
This commit is contained in:
parent
86535f9940
commit
72dfb4f9bb
3 changed files with 86 additions and 11 deletions
42
src/App.tsx
42
src/App.tsx
|
@ -21,6 +21,7 @@ export interface IHistoryState {
|
||||||
interface IAppState {
|
interface IAppState {
|
||||||
isSidebarOpen: boolean,
|
isSidebarOpen: boolean,
|
||||||
isSVGSidebarOpen: boolean,
|
isSVGSidebarOpen: boolean,
|
||||||
|
isHistoryOpen: boolean,
|
||||||
configuration: Configuration,
|
configuration: Configuration,
|
||||||
history: Array<IHistoryState>,
|
history: Array<IHistoryState>,
|
||||||
historyCurrentStep: 0
|
historyCurrentStep: 0
|
||||||
|
@ -34,6 +35,7 @@ class App extends React.Component<IAppProps> {
|
||||||
this.state = {
|
this.state = {
|
||||||
isSidebarOpen: true,
|
isSidebarOpen: true,
|
||||||
isSVGSidebarOpen: false,
|
isSVGSidebarOpen: false,
|
||||||
|
isHistoryOpen: false,
|
||||||
configuration: {
|
configuration: {
|
||||||
AvailableContainers: [],
|
AvailableContainers: [],
|
||||||
AvailableSymbols: [],
|
AvailableSymbols: [],
|
||||||
|
@ -110,6 +112,15 @@ class App extends React.Component<IAppProps> {
|
||||||
} as IAppState);
|
} as IAppState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggle the elements
|
||||||
|
*/
|
||||||
|
public ToggleHistory() {
|
||||||
|
this.setState({
|
||||||
|
isHistoryOpen: !this.state.isHistoryOpen
|
||||||
|
} as IAppState);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Select a container
|
* Select a container
|
||||||
* @param container Selected container
|
* @param container Selected container
|
||||||
|
@ -293,20 +304,45 @@ class App extends React.Component<IAppProps> {
|
||||||
onClick={() => this.ToggleSidebar()}
|
onClick={() => this.ToggleSidebar()}
|
||||||
buttonOnClick={(type: string) => this.AddContainer(type)}
|
buttonOnClick={(type: string) => this.AddContainer(type)}
|
||||||
/>
|
/>
|
||||||
<button className='fixed z-10 top-4 left-4 text-lg bg-blue-200 hover:bg-blue-300 transition-all drop-shadow-md hover:drop-shadow-lg py-2 px-3 rounded-lg' onClick={() => this.ToggleSidebar()}>☰ Components</button>
|
<button
|
||||||
|
className='fixed z-10 top-4 left-4 text-lg bg-blue-200 hover:bg-blue-300 transition-all drop-shadow-md hover:drop-shadow-lg py-2 px-3 rounded-lg'
|
||||||
|
onClick={() => this.ToggleSidebar()}
|
||||||
|
>
|
||||||
|
☰ Components
|
||||||
|
</button>
|
||||||
|
|
||||||
<ElementsSidebar
|
<ElementsSidebar
|
||||||
MainContainer={current.MainContainer}
|
MainContainer={current.MainContainer}
|
||||||
SelectedContainer={current.SelectedContainer}
|
SelectedContainer={current.SelectedContainer}
|
||||||
isOpen={this.state.isSVGSidebarOpen}
|
isOpen={this.state.isSVGSidebarOpen}
|
||||||
|
isHistoryOpen={this.state.isHistoryOpen}
|
||||||
onClick={() => this.ToggleElementsSidebar()}
|
onClick={() => this.ToggleElementsSidebar()}
|
||||||
onPropertyChange={(key: string, value: string) => this.OnPropertyChange(key, value)}
|
onPropertyChange={(key: string, value: string) => this.OnPropertyChange(key, value)}
|
||||||
selectContainer={(container: ContainerModel) => this.SelectContainer(container)}
|
selectContainer={(container: ContainerModel) => this.SelectContainer(container)}
|
||||||
/>
|
/>
|
||||||
<button className='fixed z-10 top-4 right-12 text-lg bg-slate-200 hover:bg-slate-300 transition-all drop-shadow-md hover:drop-shadow-lg py-2 px-3 rounded-lg' onClick={() => this.ToggleElementsSidebar()}>☰ Elements</button>
|
<button
|
||||||
|
className='fixed z-10 top-4 right-12 text-lg bg-slate-200 hover:bg-slate-300 transition-all drop-shadow-md hover:drop-shadow-lg py-2 px-3 rounded-lg'
|
||||||
|
onClick={() => this.ToggleElementsSidebar()}
|
||||||
|
>
|
||||||
|
☰ Elements
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<History
|
||||||
|
history={this.state.history}
|
||||||
|
historyCurrentStep={this.state.historyCurrentStep}
|
||||||
|
isOpen={this.state.isHistoryOpen}
|
||||||
|
onClick={() => this.ToggleHistory()}
|
||||||
|
jumpTo={(move) => { this.jumpTo(move); }}
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
className='fixed z-10 top-4 right-72 text-lg bg-slate-200 hover:bg-slate-300 transition-all drop-shadow-md hover:drop-shadow-lg py-2 px-3 rounded-lg'
|
||||||
|
onClick={() => this.ToggleHistory()}>
|
||||||
|
☰ History
|
||||||
|
</button>
|
||||||
|
|
||||||
<SVG selected={current.SelectedContainer}>
|
<SVG selected={current.SelectedContainer}>
|
||||||
{ current.MainContainer }
|
{ current.MainContainer }
|
||||||
</SVG>
|
</SVG>
|
||||||
<History history={this.state.history} jumpTo={(move) => { this.jumpTo(move); }} />
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import { IContainerModel, getDepth, MakeIterator } from '../SVG/Elements/Contain
|
||||||
interface IElementsSidebarProps {
|
interface IElementsSidebarProps {
|
||||||
MainContainer: IContainerModel | null,
|
MainContainer: IContainerModel | null,
|
||||||
isOpen: boolean,
|
isOpen: boolean,
|
||||||
|
isHistoryOpen: boolean
|
||||||
SelectedContainer: IContainerModel | null,
|
SelectedContainer: IContainerModel | null,
|
||||||
onClick: () => void,
|
onClick: () => void,
|
||||||
onPropertyChange: (key: string, value: string) => void,
|
onPropertyChange: (key: string, value: string) => void,
|
||||||
|
@ -25,7 +26,12 @@ export class ElementsSidebar extends React.Component<IElementsSidebarProps> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public render() {
|
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[] = [];
|
const containerRows: React.ReactNode[] = [];
|
||||||
this.iterateChilds((container: IContainerModel) => {
|
this.iterateChilds((container: IContainerModel) => {
|
||||||
|
|
|
@ -3,26 +3,59 @@ import { IHistoryState } from '../../App';
|
||||||
|
|
||||||
interface IHistoryProps {
|
interface IHistoryProps {
|
||||||
history: IHistoryState[],
|
history: IHistoryState[],
|
||||||
|
historyCurrentStep: number,
|
||||||
|
isOpen: boolean,
|
||||||
|
onClick: () => void,
|
||||||
jumpTo: (move: number) => void
|
jumpTo: (move: number) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export class History extends React.Component<IHistoryProps> {
|
export class History extends React.Component<IHistoryProps> {
|
||||||
public render() {
|
public render() {
|
||||||
|
const isOpenClasses = this.props.isOpen ? 'right-0' : '-right-64';
|
||||||
|
|
||||||
const states = this.props.history.map((step, move) => {
|
const states = this.props.history.map((step, move) => {
|
||||||
const desc = move
|
const desc = move
|
||||||
? `Go back at turn n°${move}`
|
? `Go to modification n°${move}`
|
||||||
: 'Go back at the beginning';
|
: '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 (
|
return (
|
||||||
<li key={move}>
|
|
||||||
<button onClick={() => this.props.jumpTo(move)}>{desc}</button>
|
<button
|
||||||
</li>
|
key={move}
|
||||||
|
onClick={() => this.props.jumpTo(move)}
|
||||||
|
className={
|
||||||
|
`w-full elements-sidebar-row whitespace-pre
|
||||||
|
text-left text-sm font-medium transition-all ${selectedClass}`
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{desc}{isCurrentText}
|
||||||
|
</button>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// recent first
|
||||||
|
states.reverse();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className={`fixed flex flex-col bg-slate-400 text-white transition-all h-screen w-64 overflow-y-auto z-20 ${isOpenClasses}`}>
|
||||||
{ states }
|
<button className='close-button bg-slate-500 hover:bg-slate-700 justify-start' onClick={this.props.onClick}>
|
||||||
|
× Close
|
||||||
|
</button>
|
||||||
|
<div className='bg-slate-600 sidebar-row'>
|
||||||
|
History
|
||||||
|
</div>
|
||||||
|
<div className='overflow-y-auto overflow-x-hidden text-slate-300 flex-grow divide-y divide-solid divide-slate-600'>
|
||||||
|
{ states }
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue