-
Notifications
You must be signed in to change notification settings - Fork 217
feat: Add custom size props to modal #4252
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
base: dev-v3-amanabiy-modal-top-position
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import React, { useState } from 'react'; | ||
|
|
||
| import { Button, FormField, Input, Modal, SpaceBetween } from '~components'; | ||
|
|
||
| import { useAppContext } from '../app/app-context'; | ||
| import { SimplePage } from '../app/templates'; | ||
| import ScreenshotArea from '../utils/screenshot-area'; | ||
|
|
||
| export default function () { | ||
| const { urlParams, setUrlParams } = useAppContext(); | ||
| const [visible, setVisible] = useState(false); | ||
|
|
||
| return ( | ||
| <SimplePage | ||
| title="Modal with custom dimensions" | ||
| settings={ | ||
| <SpaceBetween size="m"> | ||
| <FormField label="Width (px)"> | ||
| <Input | ||
| value={urlParams.width ? String(urlParams.width) : ''} | ||
| onChange={e => setUrlParams({ width: e.detail.value })} | ||
| type="number" | ||
| /> | ||
| </FormField> | ||
| <FormField label="Height (px)"> | ||
| <Input | ||
| value={urlParams.height ? String(urlParams.height) : ''} | ||
| onChange={e => setUrlParams({ height: e.detail.value })} | ||
| type="number" | ||
| /> | ||
| </FormField> | ||
| </SpaceBetween> | ||
| } | ||
| > | ||
| <Button data-testid="modal-trigger" onClick={() => setVisible(true)}> | ||
| Show modal | ||
| </Button> | ||
| <ScreenshotArea> | ||
| <Modal | ||
| header="Custom dimensions modal" | ||
| visible={visible} | ||
| onDismiss={() => setVisible(false)} | ||
| width={urlParams.width ? Number(urlParams.width) : undefined} | ||
| height={urlParams.height ? Number(urlParams.height) : undefined} | ||
| footer={ | ||
| <span style={{ display: 'flex', justifyContent: 'flex-end' }}> | ||
| <Button variant="primary">OK</Button> | ||
| </span> | ||
| } | ||
| > | ||
| {Array(100) | ||
| .fill(0) | ||
| .map((value, index) => ( | ||
| <div key={index}> | ||
| <span>Text content {index}</span> | ||
| </div> | ||
| ))} | ||
| <input data-testid="final-input" /> | ||
| </Modal> | ||
| </ScreenshotArea> | ||
| </SimplePage> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import React, { useState } from 'react'; | ||
|
|
||
| import { Button, Modal } from '~components'; | ||
|
|
||
| import { SimplePage } from '../app/templates'; | ||
| import ScreenshotArea from '../utils/screenshot-area'; | ||
|
|
||
| function getUrlParams() { | ||
| const hashParts = window.location.hash.split('?'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still using the custom URL parameters logic here instead of the existing context hooks :) Actually could this page be instead implemented as an extra parameter in the other dev page (
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Done |
||
| const params = new URLSearchParams(hashParts[1] || ''); | ||
| return { | ||
| height: params.get('height') ? Number(params.get('height')) : undefined, | ||
| }; | ||
| } | ||
|
|
||
| export default function () { | ||
| const [visible, setVisible] = useState(false); | ||
| const { height } = getUrlParams(); | ||
|
|
||
| return ( | ||
| <SimplePage title="Modal with custom height and no footer"> | ||
| <Button data-testid="modal-trigger" onClick={() => setVisible(true)}> | ||
| Show modal | ||
| </Button> | ||
| <ScreenshotArea> | ||
| <Modal | ||
| header="Custom height modal without footer" | ||
| visible={visible} | ||
| onDismiss={() => setVisible(false)} | ||
| height={height} | ||
| > | ||
| {Array(100) | ||
| .fill(0) | ||
| .map((value, index) => ( | ||
| <div key={index}>Line {index + 1}: Content</div> | ||
| ))} | ||
| </Modal> | ||
| </ScreenshotArea> | ||
| </SimplePage> | ||
| ); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: actually the ScreenshotArea in these pages does nothing, because the modal is positioned visually outside of it. For this reason we need to use
captureViewportin the modal visual regression tests and notcaptureScreenshotArea.