-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Core: Zoom tool reimplementation #33375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
925b05f
Move zoom tool to right side of the toolbar
ghengeveld 9cc40e7
Pull Shortcut component out of Menu, so it can be reused
ghengeveld 7b4e9fe
Refactor Zoom component to improve zoom functionality and UI interact…
ghengeveld f78ab97
Add custom zoom level input, fix aria labels and add stories
ghengeveld 291dc4d
Make viewports handle scaling properly, and reuse shared NumericInput…
ghengeveld 9f1f031
Prevent secondary scrollbar in bundle analyzer story
ghengeveld 61d98a7
Prevent 'responsive' viewport from scaling the canvas
ghengeveld f5b126c
Show viewport size on draghandle
ghengeveld e8132aa
Fix setAddonShortcut race condition
ghengeveld 51890fc
Fix types
ghengeveld 77a8272
Merge branch 'viewport-viewer' into zoom-tool
ghengeveld 25cf339
Fix mock store
ghengeveld ca968fd
Fix aria issues
ghengeveld 80cbd5b
Merge branch 'viewport-viewer' into zoom-tool
ghengeveld 1c82440
Use more appropriate element for keyboard shortcuts
ghengeveld 1e0c80b
Clamp zoomLevel value between 1 and 1000, and enforce non-negative va…
ghengeveld 56eaf1f
Add 90% and 110% to built-in zoom levels
ghengeveld dfc576b
Add disabled and active states
ghengeveld 59eee1c
Fix input width
ghengeveld File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,36 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { shortcutToHumanString } from 'storybook/manager-api'; | ||
| import { styled } from 'storybook/theming'; | ||
|
|
||
| const Wrapper = styled.span(({ theme }) => ({ | ||
| display: 'inline-flex', | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| height: 16, | ||
| fontSize: '11px', | ||
| fontWeight: theme.typography.weight.regular, | ||
| background: theme.base === 'light' ? 'rgba(0,0,0,0.05)' : 'rgba(255,255,255,0.05)', | ||
| color: theme.base === 'light' ? theme.color.dark : theme.textMutedColor, | ||
| borderRadius: 2, | ||
| userSelect: 'none', | ||
| pointerEvents: 'none', | ||
| padding: '0 4px', | ||
| })); | ||
|
|
||
| const Key = styled.kbd(({ theme }) => ({ | ||
| padding: 0, | ||
| fontFamily: theme.typography.fonts.base, | ||
| verticalAlign: 'middle', | ||
| '& + &': { | ||
| marginLeft: 6, | ||
| }, | ||
| })); | ||
|
|
||
| export const Shortcut = ({ keys }: { keys: string[] }) => ( | ||
| <Wrapper> | ||
| {keys.map((key) => ( | ||
| <Key key={key}>{shortcutToHumanString([key])}</Key> | ||
| ))} | ||
| </Wrapper> | ||
| ); |
105 changes: 105 additions & 0 deletions
105
code/core/src/manager/components/preview/NumericInput.stories.tsx
This file contains hidden or 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,105 @@ | ||
| import { expect, fireEvent, fn } from 'storybook/test'; | ||
|
|
||
| import preview from '../../../../../.storybook/preview'; | ||
| import { NumericInput } from './NumericInput'; | ||
|
|
||
| const meta = preview.meta({ | ||
| component: NumericInput, | ||
| tags: ['autodocs'], | ||
| args: { | ||
| setValue: fn(), | ||
| }, | ||
| }); | ||
|
|
||
| export default meta; | ||
|
|
||
| export const Default = meta.story({ | ||
| args: { | ||
| value: '10', | ||
| }, | ||
| play: async ({ args, canvas }) => { | ||
| const input = await canvas.findByRole('textbox'); | ||
| fireEvent.keyDown(input, { key: 'ArrowUp' }); | ||
| fireEvent.keyDown(input, { key: 'ArrowUp' }); | ||
| fireEvent.keyDown(input, { key: 'ArrowDown' }); | ||
| expect(input).toHaveValue('11'); | ||
| expect(args.setValue).toHaveBeenNthCalledWith(1, '11'); | ||
| expect(args.setValue).toHaveBeenNthCalledWith(2, '12'); | ||
| expect(args.setValue).toHaveBeenNthCalledWith(3, '11'); | ||
| }, | ||
| }); | ||
|
|
||
| export const WithParsedUnit = meta.story({ | ||
| args: { | ||
| value: '10em', | ||
| }, | ||
| play: async ({ args, canvas }) => { | ||
| const input = await canvas.findByRole('textbox'); | ||
| fireEvent.keyDown(input, { key: 'ArrowUp' }); | ||
| fireEvent.keyDown(input, { key: 'ArrowUp' }); | ||
| fireEvent.keyDown(input, { key: 'ArrowDown' }); | ||
| expect(input).toHaveValue('11em'); | ||
| expect(args.setValue).toHaveBeenNthCalledWith(1, '11em'); | ||
| expect(args.setValue).toHaveBeenNthCalledWith(2, '12em'); | ||
| expect(args.setValue).toHaveBeenNthCalledWith(3, '11em'); | ||
| }, | ||
| }); | ||
|
|
||
| export const WithExplicitUnit = meta.story({ | ||
| args: { | ||
| value: '10', | ||
| unit: 'vw', | ||
| }, | ||
| play: async ({ args, canvas }) => { | ||
| const input = await canvas.findByRole('textbox'); | ||
| fireEvent.keyDown(input, { key: 'ArrowUp' }); | ||
| fireEvent.keyDown(input, { key: 'ArrowUp' }); | ||
| fireEvent.keyDown(input, { key: 'ArrowDown' }); | ||
| expect(input).toHaveValue('11vw'); | ||
| expect(args.setValue).toHaveBeenNthCalledWith(1, '11vw'); | ||
| expect(args.setValue).toHaveBeenNthCalledWith(2, '12vw'); | ||
| expect(args.setValue).toHaveBeenNthCalledWith(3, '11vw'); | ||
| }, | ||
| }); | ||
|
|
||
| export const WithBaseUnit = meta.story({ | ||
| args: { | ||
| value: '10em', | ||
| baseUnit: 'em', | ||
| }, | ||
| play: async ({ args, canvas }) => { | ||
| const input = await canvas.findByRole('textbox'); | ||
| fireEvent.keyDown(input, { key: 'ArrowUp' }); | ||
| fireEvent.keyDown(input, { key: 'ArrowUp' }); | ||
| fireEvent.keyDown(input, { key: 'ArrowDown' }); | ||
| expect(input).toHaveValue('11'); | ||
| expect(args.setValue).toHaveBeenNthCalledWith(1, '11em'); | ||
| expect(args.setValue).toHaveBeenNthCalledWith(2, '12em'); | ||
| expect(args.setValue).toHaveBeenNthCalledWith(3, '11em'); | ||
| }, | ||
| }); | ||
|
|
||
| export const WithMinAndMax = meta.story({ | ||
| args: { | ||
| value: '10em', | ||
| minValue: 9, | ||
| maxValue: 11, | ||
| }, | ||
| play: async ({ args, canvas }) => { | ||
| const input = await canvas.findByRole('textbox'); | ||
| fireEvent.keyDown(input, { key: 'ArrowUp' }); | ||
| fireEvent.keyDown(input, { key: 'ArrowUp' }); | ||
| fireEvent.keyDown(input, { key: 'ArrowUp' }); | ||
| expect(input).toHaveValue('11em'); | ||
| fireEvent.keyDown(input, { key: 'ArrowDown' }); | ||
| fireEvent.keyDown(input, { key: 'ArrowDown' }); | ||
| fireEvent.keyDown(input, { key: 'ArrowDown' }); | ||
| expect(input).toHaveValue('9em'); | ||
| expect(args.setValue).toHaveBeenNthCalledWith(1, '11em'); | ||
| expect(args.setValue).toHaveBeenNthCalledWith(2, '11em'); | ||
| expect(args.setValue).toHaveBeenNthCalledWith(3, '11em'); | ||
| expect(args.setValue).toHaveBeenNthCalledWith(4, '10em'); | ||
| expect(args.setValue).toHaveBeenNthCalledWith(5, '9em'); | ||
| expect(args.setValue).toHaveBeenNthCalledWith(6, '9em'); | ||
| }, | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.