-
Notifications
You must be signed in to change notification settings - Fork 36
feat(Tearsheet): Implement new Tearsheet component #954
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
140d089
05ab49f
af55c44
d93b8fe
690e2fe
d0be617
97ac9f5
0047ae8
fe6c124
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,71 @@ | ||||||||||||
| --- | ||||||||||||
| # Sidenav top-level section | ||||||||||||
| # should be the same for all markdown files | ||||||||||||
| section: extensions | ||||||||||||
| subsection: component-groups | ||||||||||||
| # Sidenav secondary level section | ||||||||||||
| # should be the same for all markdown files | ||||||||||||
| id: Tearsheet | ||||||||||||
| # Tab (react | react-demos | html | html-demos | design-guidelines | accessibility) | ||||||||||||
| source: react | ||||||||||||
| # If you use typescript, the name of the interface to display props for | ||||||||||||
| # These are found through the sourceProps function provided in patternfly-docs.source.js | ||||||||||||
| propComponents: ['Tearsheet', 'TearsheetHeader', 'TearsheetBody', 'TearsheetFooter', 'TearsheetGroup'] | ||||||||||||
| sourceLink: https://github.com/patternfly/react-component-groups/blob/main/packages/module/patternfly-docs/content/extensions/component-groups/examples/Tearsheet/Tearsheet.md | ||||||||||||
| --- | ||||||||||||
|
|
||||||||||||
| import { Fragment, useState } from 'react'; | ||||||||||||
| import spacing from '@patternfly/react-styles/css/utilities/Spacing/spacing'; | ||||||||||||
| import TearsheetGroup from '@patternfly/react-component-groups/dist/dynamic/TearsheetGroup'; | ||||||||||||
| import Tearsheet from '@patternfly/react-component-groups/dist/dynamic/Tearsheet'; | ||||||||||||
| import TearsheetHeader from '@patternfly/react-component-groups/dist/dynamic/TearsheetHeader'; | ||||||||||||
| import TearsheetBody from '@patternfly/react-component-groups/dist/dynamic/TearsheetBody'; | ||||||||||||
| import TearsheetFooter from '@patternfly/react-component-groups/dist/dynamic/TearsheetFooter'; | ||||||||||||
|
|
||||||||||||
| **Tearsheet** are a full-screen extension of the `<Modal>` component allowing more complex experiences to be provided to the user. | ||||||||||||
| While the biggest Modal size (`ModalVariant.large`) may work for some cases, tearsheets allow near the entire real-estate to be leveraged. | ||||||||||||
| This component extends the [modal component](/components/modal) allowing any use of its properties to be provided. | ||||||||||||
|
|
||||||||||||
| ## Examples | ||||||||||||
|
|
||||||||||||
| ### Basic | ||||||||||||
|
|
||||||||||||
| Typical tearsheets should make use of the entire area, for this basic case some sample text is rendered. | ||||||||||||
|
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.
Suggested change
|
||||||||||||
|
|
||||||||||||
| ```ts file="./TearsheetBasic.tsx" | ||||||||||||
| ``` | ||||||||||||
|
|
||||||||||||
| ### Tearsheet layouts | ||||||||||||
|
|
||||||||||||
| Tearsheets should allow various sorts of layouts to be rendered. | ||||||||||||
|
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.
Suggested change
|
||||||||||||
| The `<TearsheetBody>` component will handle scrolling for long content. | ||||||||||||
|
|
||||||||||||
| ```ts file="./TearsheetLayouts.tsx" | ||||||||||||
| ``` | ||||||||||||
|
|
||||||||||||
| ### Stacked | ||||||||||||
|
|
||||||||||||
| One special use case with tearsheets is stacking. | ||||||||||||
| When a user is using a tearsheet, if another one needs to open it can open one level "on-top" of it in a new stack. | ||||||||||||
| Tearsheets offer 3 stack levels (0,1,2). | ||||||||||||
| A special stack level -1 allows a tearsheet to hide behind others. | ||||||||||||
|
Comment on lines
+48
to
+51
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.
Suggested change
|
||||||||||||
|
|
||||||||||||
| ```ts file="./TearsheetStacked.tsx" | ||||||||||||
| ``` | ||||||||||||
|
|
||||||||||||
| ### Tearsheet group (infinite stacking) | ||||||||||||
|
|
||||||||||||
| Use a `TearsheetGroup` to manage an unbounded number of stacked tearsheets. | ||||||||||||
| `children` rendering order determines stacking priority with later children stacking in front of earlier ones. | ||||||||||||
| Only the top 3 open tearsheets are visible; earlier ones hide behind the stack and reappear as front tearsheets are closed. | ||||||||||||
|
|
||||||||||||
| ```ts file="./TearsheetGroup.tsx" | ||||||||||||
|
Comment on lines
+56
to
+62
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. From a design standpoint, I don't think its a good idea to recommend infinite stacking. I would advise against including this as an example so we dont encourage users to stack more than 4 sheets. I think it could be useful to include some explicit text in the stacking section that says something like "Limit stacked tearsheets to a maximum of three. Flows requiring four or more levels should be redesigned using multi-step wizard or dedicates page to prevent loss of user context." Hiding an unbounded number of sheets behind the visible top 3 tends to break the user's mental model of where they are on the page, and forces "click-to-close" repetition to get back to the main view. |
||||||||||||
| ``` | ||||||||||||
|
|
||||||||||||
| ### Tearsheets vs Modals | ||||||||||||
|
|
||||||||||||
|
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.
Suggested change
|
||||||||||||
| To illustrate the difference between a tearsheet and a modal, this example showcases a complex use case with a search bar, side panel, and a number of cards. | ||||||||||||
| In a modal the content is crammed and is not as usable as if it were on a bigger area like the tearsheet. | ||||||||||||
|
|
||||||||||||
| ```ts file="./TearsheetComparison.tsx" | ||||||||||||
| ``` | ||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { Fragment, useState } from 'react'; | ||
| import { Button } from '@patternfly/react-core'; | ||
| import Tearsheet from '@patternfly/react-component-groups/dist/dynamic/Tearsheet'; | ||
| import TearsheetHeader from '@patternfly/react-component-groups/dist/dynamic/TearsheetHeader'; | ||
| import TearsheetBody from '@patternfly/react-component-groups/dist/dynamic/TearsheetBody'; | ||
| import TearsheetFooter from '@patternfly/react-component-groups/dist/dynamic/TearsheetFooter'; | ||
|
|
||
| export const TearsheetBasic: React.FunctionComponent = () => { | ||
| const [ isTearsheetOpen, setIsTearsheetOpen ] = useState(false); | ||
|
|
||
| const toggleTearsheet = (_event: React.MouseEvent<Element, MouseEvent> | KeyboardEvent | MouseEvent) => { | ||
| setIsTearsheetOpen(!isTearsheetOpen); | ||
| }; | ||
|
|
||
| return ( | ||
| <Fragment> | ||
| <Button variant="primary" onClick={toggleTearsheet}> | ||
| Show Tearsheet | ||
| </Button> | ||
| <Tearsheet | ||
| isOpen={isTearsheetOpen} | ||
| onClose={(e: React.MouseEvent<Element, MouseEvent> | KeyboardEvent | MouseEvent) => toggleTearsheet(e)} | ||
| > | ||
| <TearsheetHeader title="Tearsheet Header" labelId="basic-modal-title" /> | ||
| <TearsheetBody> | ||
| Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore | ||
| magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo | ||
| consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla | ||
| pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id | ||
| est laborum. | ||
| </TearsheetBody> | ||
| <TearsheetFooter> | ||
| <Button key="confirm" variant="primary" onClick={toggleTearsheet}> | ||
| Confirm | ||
| </Button> | ||
| <Button key="cancel" variant="link" onClick={toggleTearsheet}> | ||
| Cancel | ||
| </Button> | ||
| </TearsheetFooter> | ||
| </Tearsheet> | ||
| </Fragment> | ||
| ); | ||
| }; |
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.
Let's remove these comments and just leave the property value pairs