-
Notifications
You must be signed in to change notification settings - Fork 0
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 #90 from commitd/sh/layout
feat: add a flag to layout on change
- Loading branch information
Showing
12 changed files
with
154 additions
and
12 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
24 changes: 24 additions & 0 deletions
24
packages/react/src/components/GraphToolbar/ReLayout.test.tsx
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,24 @@ | ||
import React from 'react' | ||
import { renderLight, screen, userEvent } from '../../test/setup' | ||
import { Relayout } from './GraphToolbar.test' | ||
|
||
it('Can select to size by', () => { | ||
renderLight(<Relayout withGraph={false} />) | ||
userEvent.tab() | ||
userEvent.keyboard('{enter}') | ||
expect( | ||
screen | ||
.getByRole('menuitemcheckbox', { name: /Layout on change/i }) | ||
.getAttribute('aria-checked') | ||
).toBe('true') | ||
userEvent.click( | ||
screen.getByRole('menuitemcheckbox', { name: /Layout on change/i }) | ||
) | ||
userEvent.tab() | ||
userEvent.keyboard('{enter}') | ||
expect( | ||
screen | ||
.getByRole('menuitemcheckbox', { name: /Layout on change/i }) | ||
.getAttribute('aria-checked') | ||
).toBe('false') | ||
}) |
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,50 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
import { CSSProps, MenuCheckboxItem, VariantProps } from '@committed/components' | ||
import { GraphModel } from '@committed/graph' | ||
import React, { useCallback } from 'react' | ||
|
||
export type ReLayoutProps = CSSProps & | ||
VariantProps<typeof MenuCheckboxItem> & { | ||
/** Declarative definition of graph state */ | ||
model: GraphModel | ||
/** The graph model change callback */ | ||
onModelChange: ( | ||
model: GraphModel | ((model2: GraphModel) => GraphModel) | ||
) => void | ||
} | ||
|
||
/** | ||
* A GraphToolbar sub-component to relayout on graph change | ||
*/ | ||
export const ReLayout: React.FC<ReLayoutProps> = ({ | ||
model, | ||
onModelChange, | ||
css, | ||
...props | ||
}) => { | ||
const handleToggle = useCallback((): void => { | ||
onModelChange( | ||
GraphModel.applyLayout( | ||
model, | ||
model | ||
.getCurrentLayout() | ||
.setOnChange(!model.getCurrentLayout().isOnChange()) | ||
) | ||
) | ||
}, [model, onModelChange]) | ||
|
||
return ( | ||
<> | ||
<MenuCheckboxItem | ||
css={css as any} | ||
{...props} | ||
key="hideEdgeLabels" | ||
checked={model.getCurrentLayout().isOnChange()} | ||
onCheckedChange={handleToggle} | ||
> | ||
Layout on change | ||
</MenuCheckboxItem> | ||
</> | ||
) | ||
} |
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