-
Notifications
You must be signed in to change notification settings - Fork 3
feat(lib): change preview dimension #463
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
11 commits
Select commit
Hold shift + click to select a range
47ed4a4
feat: change preview dimension
johannes-lindgren 926cb49
feat: sandbox and demo
johannes-lindgren 5d8cb27
feat: add custom option to preview dimension selection
johannes-lindgren b4c727e
docs: comment
johannes-lindgren 6c989d4
feat: update custom preview dimension width to dynamic value
johannes-lindgren 98ea17c
feat: reorganize the custom width on preview
fernandacanto 9bbe664
feat: create the dimension type
fernandacanto a087aab
chore: run prettier
fernandacanto bed4f89
chore: remove pure-parse and add valibot
fernandacanto f46e28a
chore: add custom label on sandbox
fernandacanto f7da506
feat: remove preview dimension callback from the queue list
demetriusfeijoo 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { Button, Input, Stack, Typography, InputLabel } from '@mui/material' | ||
import { PluginComponent } from './FieldPluginDemo' | ||
import { useState } from 'react' | ||
|
||
export const PreviewDimension: PluginComponent = (props) => { | ||
const { data, actions } = props | ||
|
||
const [width, setWidth] = useState(300) | ||
|
||
const handleClickMobile = () => { | ||
actions.setPreviewDimension({ | ||
tag: 'mobile', | ||
}) | ||
} | ||
const handleClickTablet = () => { | ||
actions.setPreviewDimension({ | ||
tag: 'tablet', | ||
}) | ||
} | ||
const handleClickDesktop = () => { | ||
actions.setPreviewDimension({ | ||
tag: 'desktop', | ||
}) | ||
} | ||
const handleClickCustom = () => { | ||
actions.setPreviewDimension({ | ||
tag: 'custom', | ||
width: width, | ||
}) | ||
} | ||
|
||
return ( | ||
<Stack gap={2}> | ||
<Typography variant="subtitle1">Dimension</Typography> | ||
<Button | ||
variant="outlined" | ||
color="secondary" | ||
onClick={handleClickMobile} | ||
> | ||
Mobile | ||
</Button> | ||
<Button | ||
variant="outlined" | ||
color="secondary" | ||
onClick={handleClickTablet} | ||
> | ||
Tablet | ||
</Button> | ||
<Button | ||
variant="outlined" | ||
color="secondary" | ||
onClick={handleClickDesktop} | ||
> | ||
Desktop | ||
</Button> | ||
<InputLabel | ||
htmlFor="field-plugin-custom-width" | ||
shrink | ||
> | ||
Set custom width: | ||
</InputLabel> | ||
<Stack direction="row" spacing={2} > | ||
<Input | ||
id="field-plugin-custom-width" | ||
fullWidth | ||
type="number" | ||
value={width} | ||
onChange={(e) => setWidth(Number(e.target.value))} | ||
placeholder="Custom Width" | ||
/> | ||
<Button | ||
fullWidth | ||
variant="outlined" | ||
color="secondary" | ||
onClick={handleClickCustom} | ||
> | ||
Custom | ||
</Button> | ||
</Stack> | ||
</Stack> | ||
) | ||
} |
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 |
---|---|---|
|
@@ -54,5 +54,8 @@ | |
"vite": "5.4.16", | ||
"vite-plugin-dts": "4.2.1", | ||
"vitest": "2.1.9" | ||
}, | ||
"dependencies": { | ||
"valibot": "1.1.0" | ||
} | ||
} |
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
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
32 changes: 32 additions & 0 deletions
32
.../messaging/pluginMessage/containerToPluginMessage/PreviewDimensionResponseMessage.test.ts
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,32 @@ | ||
import { | ||
type PreviewDimensionResponseMessage, | ||
isPreviewDimensionResponse, | ||
} from './PreviewDimensionResponseMessage' | ||
|
||
const stub: PreviewDimensionResponseMessage = { | ||
action: 'preview-dimension', | ||
uid: '-preview', | ||
callbackId: 'test-callback-id', | ||
} | ||
|
||
describe('PreviewDimensionResponseMessage', function () { | ||
it('is a message to plugin', () => { | ||
expect(isPreviewDimensionResponse(stub)).toEqual(true) | ||
}) | ||
describe('the action property', () => { | ||
it('equals "preview-dimension"', () => { | ||
expect( | ||
isPreviewDimensionResponse({ | ||
...stub, | ||
action: 'preview-dimension', | ||
}), | ||
).toEqual(true) | ||
expect( | ||
isPreviewDimensionResponse({ | ||
...stub, | ||
action: 'something-else', | ||
}), | ||
).toEqual(false) | ||
}) | ||
}) | ||
}) |
9 changes: 9 additions & 0 deletions
9
...n/src/messaging/pluginMessage/containerToPluginMessage/PreviewDimensionResponseMessage.ts
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,9 @@ | ||
import { isMessageToPlugin, type MessageToPlugin } from './MessageToPlugin' | ||
|
||
export type PreviewDimensionResponseMessage = | ||
MessageToPlugin<'preview-dimension'> | ||
|
||
export const isPreviewDimensionResponse = ( | ||
data: unknown, | ||
): data is PreviewDimensionResponseMessage => | ||
isMessageToPlugin(data) && data.action === 'preview-dimension' |
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
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.