-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from hbcarlos/grid
commit 323d3ec Merge: aa8ca1a a5d9d27 Author: Carlos Herrero <[email protected]> Date: Fri Jan 13 11:45:14 2023 +0100 Merge pull request #94 from hbcarlos/grid Toolbar for configuring the grid and axes commit a5d9d27 Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Date: Fri Jan 13 10:40:49 2023 +0000 Update Playwright Snapshots commit af0784d Author: Carlos Herrero <[email protected]> Date: Thu Jan 12 12:25:05 2023 +0100 Small fix commit 96fff01 Author: Carlos Herrero <[email protected]> Date: Thu Jan 12 12:16:52 2023 +0100 Review commit 2726f3e Author: Carlos Herrero <[email protected]> Date: Thu Jan 12 12:08:12 2023 +0100 Update src/toolbar/helpertoolbar.tsx Co-authored-by: Duc Trung Le <[email protected]> commit aa6259e Author: Carlos Herrero <[email protected]> Date: Thu Jan 12 12:08:02 2023 +0100 Update src/toolbar/helpertoolbar.tsx Co-authored-by: Duc Trung Le <[email protected]> commit 80dabca Author: Carlos Herrero <[email protected]> Date: Thu Jan 12 12:07:53 2023 +0100 Update src/toolbar/helpertoolbar.tsx Co-authored-by: Duc Trung Le <[email protected]> commit e1c1003 Author: Carlos Herrero <[email protected]> Date: Thu Jan 12 09:07:20 2023 +0100 Removes axe from schemas commit d428486 Author: Carlos Herrero <[email protected]> Date: Thu Jan 12 09:06:36 2023 +0100 Removes grid commit 7164149 Author: Carlos Herrero <[email protected]> Date: Thu Jan 12 08:52:14 2023 +0100 Remove view-related properties from the DocumentModel commit 0f5f9f2 Author: Carlos Herrero <[email protected]> Date: Wed Jan 11 16:44:14 2023 +0100 Lint commit 682c469 Author: Carlos Herrero <[email protected]> Date: Wed Jan 11 16:37:14 2023 +0100 Create a configurable axe commit d642f18 Author: Carlos Herrero <[email protected]> Date: Wed Jan 11 14:59:33 2023 +0100 Creates a toolbar to configure the grid helper
- Loading branch information
1 parent
aa8ca1a
commit f36a3dd
Showing
21 changed files
with
206 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import { Button } from '@jupyterlab/ui-components'; | ||
|
||
import * as React from 'react'; | ||
|
||
import { AxeHelper, IDict } from '../types'; | ||
import { JupyterCadPanel } from '../widget'; | ||
import { FormDialog } from './formdialog'; | ||
import { ToolbarModel } from './model'; | ||
|
||
interface IProps { | ||
toolbarModel: ToolbarModel; | ||
} | ||
|
||
interface IState { | ||
Axes: IDict; | ||
} | ||
|
||
const FORM_SCHEMA = { | ||
type: 'object', | ||
required: ['Size', 'Visible'], | ||
additionalProperties: false, | ||
properties: { | ||
Size: { | ||
type: 'number', | ||
description: 'Size of the axes' | ||
}, | ||
Visible: { | ||
type: 'boolean', | ||
description: 'Whether the axes are visible or not' | ||
} | ||
} | ||
}; | ||
|
||
export class HelpersToolbarReact extends React.Component<IProps, IState> { | ||
private _panel: JupyterCadPanel; | ||
|
||
constructor(props: IProps) { | ||
super(props); | ||
this._panel = this.props.toolbarModel.panel; | ||
this.state = this._createSchema(); | ||
} | ||
|
||
componentDidMount(): void { | ||
this._panel.viewChanged.connect(this._updateSchema, this); | ||
} | ||
|
||
componentWillUnmount(): void { | ||
this._panel.viewChanged.disconnect(this._updateSchema, this); | ||
} | ||
|
||
private _createSchema(): IState { | ||
let axes = this._panel.getAxes(); | ||
|
||
if (!axes) { | ||
axes = { | ||
size: 5, | ||
visible: false | ||
}; | ||
this._panel.setAxes(axes); | ||
} | ||
|
||
return { | ||
Axes: { | ||
title: 'Axes Helper', | ||
shape: 'Axe::Helper', | ||
schema: FORM_SCHEMA, | ||
default: { | ||
Size: axes?.size ?? 5, | ||
Visible: axes?.visible ?? true | ||
}, | ||
syncData: (props: IDict) => { | ||
const { Size, Visible } = props; | ||
const axe: AxeHelper = { | ||
size: Size, | ||
visible: Visible | ||
}; | ||
this._panel.setAxes(axe); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
private _updateSchema(): void { | ||
const axe = this._panel.getAxes(); | ||
const { Axes } = this.state; | ||
Axes['default'] = { | ||
Size: axe?.size ?? 5, | ||
Visible: axe?.visible ?? true | ||
}; | ||
|
||
this.setState({ Axes }); | ||
} | ||
|
||
render(): React.ReactNode { | ||
return ( | ||
<div style={{ paddingLeft: '10px', display: 'flex' }}> | ||
{Object.entries(this.state).map(([key, value]) => { | ||
return ( | ||
<Button | ||
className={'jp-ToolbarButtonComponent'} | ||
style={{ color: 'var(--jp-ui-font-color1)' }} | ||
onClick={async () => { | ||
const dialog = new FormDialog({ | ||
toolbarModel: this.props.toolbarModel, | ||
title: value.title, | ||
sourceData: value.default, | ||
schema: value.schema, | ||
syncData: value.syncData, | ||
cancelButton: true | ||
}); | ||
await dialog.launch(); | ||
}} | ||
> | ||
{key} | ||
</Button> | ||
); | ||
})} | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.