-
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.
feat(components): add proportion selector to mutations
- Loading branch information
1 parent
59d785b
commit 74cfdac
Showing
9 changed files
with
229 additions
and
28 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
67 changes: 67 additions & 0 deletions
67
components/src/preact/components/proportion-selector-dropdown.stories.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,67 @@ | ||
import { Meta, StoryObj } from '@storybook/preact'; | ||
import { ProportionSelector } from './proportion-selector'; | ||
import { ProportionSelectorDropdown, ProportionSelectorDropdownProps } from './proportion-selector-dropdown'; | ||
import { FunctionComponent } from 'preact'; | ||
import { useState } from 'preact/hooks'; | ||
import { expect, fn, userEvent, within } from '@storybook/test'; | ||
|
||
const meta: Meta<ProportionSelectorDropdownProps> = { | ||
title: 'Component/Proportion selector dropdown', | ||
component: ProportionSelector, | ||
parameters: { fetchMock: {} }, | ||
}; | ||
|
||
export default meta; | ||
|
||
const WrapperWithState: FunctionComponent<{ | ||
setMinProportion: (value: number) => void; | ||
setMaxProportion: (value: number) => void; | ||
}> = ({ setMinProportion, setMaxProportion }) => { | ||
const [wrapperMinProportion, setWrapperMinProportion] = useState(0.05); | ||
const [wrapperMaxProportion, setWrapperMaxProportion] = useState(1); | ||
|
||
return ( | ||
<ProportionSelectorDropdown | ||
minProportion={wrapperMinProportion} | ||
maxProportion={wrapperMaxProportion} | ||
setMinProportion={(value: number) => { | ||
setWrapperMinProportion(value); | ||
setMinProportion(value); | ||
}} | ||
setMaxProportion={(value: number) => { | ||
setWrapperMaxProportion(value); | ||
setMaxProportion(value); | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
export const ProportionSelectorStory: StoryObj<ProportionSelectorDropdownProps> = { | ||
render: (args) => { | ||
return <WrapperWithState setMinProportion={args.setMinProportion} setMaxProportion={args.setMaxProportion} />; | ||
}, | ||
args: { | ||
setMinProportion: fn(), | ||
setMaxProportion: fn(), | ||
}, | ||
play: async ({ canvasElement, step, args }) => { | ||
const canvas = within(canvasElement); | ||
|
||
await step('Expect initial proportion to show on the button', async () => { | ||
const button = canvas.getByRole('button'); | ||
await expect(button).toHaveTextContent('Proportion 5.0% - 100.0%'); | ||
}); | ||
|
||
await step('Change min proportion and expect it to show on the button', async () => { | ||
const button = canvas.getByRole('button'); | ||
await userEvent.click(button); | ||
|
||
const minInput = canvas.getAllByLabelText('%')[0]; | ||
await userEvent.clear(minInput); | ||
await userEvent.type(minInput, '10'); | ||
|
||
await expect(button).toHaveTextContent('Proportion 10.0% - 100.0%'); | ||
await expect(args.setMinProportion).toHaveBeenCalledWith(0.1); | ||
}); | ||
}, | ||
}; |
34 changes: 34 additions & 0 deletions
34
components/src/preact/components/proportion-selector-dropdown.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,34 @@ | ||
import { FunctionComponent } from 'preact'; | ||
import { ProportionSelector, ProportionSelectorProps } from './proportion-selector'; | ||
|
||
export interface ProportionSelectorDropdownProps extends ProportionSelectorProps { | ||
openDirection?: 'left' | 'right'; | ||
} | ||
|
||
export const ProportionSelectorDropdown: FunctionComponent<ProportionSelectorDropdownProps> = ({ | ||
minProportion, | ||
maxProportion, | ||
setMinProportion, | ||
setMaxProportion, | ||
openDirection = 'right', | ||
}) => { | ||
const label = `${(minProportion * 100).toFixed(1)}% - ${(maxProportion * 100).toFixed(1)}%`; | ||
|
||
return ( | ||
<div class={`dropdown ${openDirection === 'left' ? 'dropdown-end' : ''}`}> | ||
<div tabIndex={0} role='button' class='btn btn-xs whitespace-nowrap'> | ||
Proportion {label} | ||
</div> | ||
<ul tabIndex={0} class='p-2 shadow menu dropdown-content z-[1] bg-base-100 rounded-box w-72'> | ||
<div class='mb-2 ml-2'> | ||
<ProportionSelector | ||
minProportion={minProportion} | ||
maxProportion={maxProportion} | ||
setMinProportion={setMinProportion} | ||
setMaxProportion={setMaxProportion} | ||
/> | ||
</div> | ||
</ul> | ||
</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
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
Binary file modified
BIN
-10 KB
(82%)
...y-visualization-mutations--default-should-match-screenshot-1-chromium-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-11 KB
(85%)
...ry-visualization-mutations--default-should-match-screenshot-1-firefox-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.