-
Notifications
You must be signed in to change notification settings - Fork 31
Add deck component #827
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
Add deck component #827
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
45 changes: 45 additions & 0 deletions
45
...odule/patternfly-docs/content/extensions/component-groups/examples/Deck/Deck.md
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,45 @@ | ||
| --- | ||
| # Sidenav top-level section | ||
| # should be the same for all markdown files | ||
| section: Component groups | ||
| subsection: Content containers | ||
| # Sidenav secondary level section | ||
| # should be the same for all markdown files | ||
| id: Deck | ||
| # 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: ['Deck', 'DeckPage', 'DeckButton', 'ModalDeck'] | ||
| sourceLink: https://github.com/patternfly/react-component-groups/blob/main/packages/module/patternfly-docs/content/extensions/component-groups/examples/Deck/Deck.md | ||
| --- | ||
|
|
||
| import Deck from '@patternfly/react-component-groups/dist/dynamic/Deck'; | ||
| import { ModalDeck } from '@patternfly/react-component-groups/dist/dynamic/ModalDeck'; | ||
| import { FunctionComponent, useState } from 'react'; | ||
|
|
||
| The **deck** component is a compact, sequential container for presenting a suite of static announcements or an informational walkthrough. It is not intended for task completion or form-filling workflows. | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Basic deck | ||
|
|
||
| This example demonstrates the basic deck with automatic navigation. Buttons can use the `navigation` prop to automatically handle page changes: | ||
| - `navigation: 'next'` - Advances to the next page | ||
| - `navigation: 'previous'` - Goes back to the previous page | ||
| - `navigation: 'close'` - Triggers the onClose callback | ||
|
|
||
| You can also add custom `onClick` handlers for analytics, validation, or other logic. The custom `onClick` will be called **before** the automatic navigation occurs. | ||
|
|
||
| ```ts file="./DeckExample.tsx" | ||
|
|
||
| ``` | ||
|
|
||
| ### Modal deck | ||
|
|
||
| Display the deck in a modal dialog. The `ModalDeck` component wraps the Deck in a PatternFly Modal without a close button or extra padding, ideal for guided walkthroughs that require user interaction. | ||
|
|
||
| ```ts file="./ModalDeckExample.tsx" | ||
|
|
||
| ``` | ||
|
|
26 changes: 26 additions & 0 deletions
26
.../patternfly-docs/content/extensions/component-groups/examples/Deck/DeckDemos.md
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,26 @@ | ||
| --- | ||
| # Sidenav top-level section | ||
| # should be the same for all markdown files | ||
| section: Component groups | ||
| subsection: Content containers | ||
| # Sidenav secondary level section | ||
| # should be the same for all markdown files | ||
| id: Deck | ||
| # Tab (react | react-demos | html | html-demos | design-guidelines | accessibility) | ||
| source: react-demos | ||
| sourceLink: https://github.com/patternfly/react-component-groups/blob/main/packages/module/patternfly-docs/content/extensions/component-groups/examples/Deck/DeckDemos.md | ||
| --- | ||
| import { FunctionComponent, useState } from 'react'; | ||
|
|
||
| import Deck from '@patternfly/react-component-groups/dist/dynamic/Deck'; | ||
| import { ModalDeck } from '@patternfly/react-component-groups/dist/dynamic/ModalDeck'; | ||
|
|
||
| ## Demos | ||
|
|
||
| ### Onboarding modal deck | ||
|
|
||
| A complete onboarding experience using ModalDeck to guide users through key product features. This demo demonstrates a multi-step walkthrough with custom styling, labels, and content. | ||
|
|
||
| ```ts file="./OnboardingModalDeckDemo.tsx" | ||
|
|
||
| ``` |
87 changes: 87 additions & 0 deletions
87
.../module/patternfly-docs/content/extensions/component-groups/examples/Deck/DeckExample.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,87 @@ | ||
| /* eslint-disable no-console */ | ||
| import { FunctionComponent, useState } from 'react'; | ||
| import Deck, { DeckButton } from '@patternfly/react-component-groups/dist/dynamic/Deck'; | ||
| import { ButtonVariant } from '@patternfly/react-core'; | ||
|
|
||
| export const BasicExample: FunctionComponent = () => { | ||
| const [ deckKey, setDeckKey ] = useState(0); | ||
|
|
||
| // Simulated analytics function | ||
| const trackEvent = (eventName, data) => { | ||
| console.log('Analytics:', eventName, data); | ||
| }; | ||
|
|
||
| const restartDeck = () => { | ||
| setDeckKey(prev => prev + 1); | ||
| trackEvent('deck_restarted', {}); | ||
| }; | ||
|
|
||
| const pages = [ | ||
| { | ||
| content: ( | ||
| <div> | ||
| <p>This is the first page of your informational walkthrough.</p> | ||
| </div> | ||
| ), | ||
| buttons: [ | ||
| { | ||
| children: 'Next', | ||
| variant: ButtonVariant.primary, | ||
| navigation: 'next', | ||
| // Custom onClick for analytics - called before navigation | ||
| onClick: () => trackEvent('deck_next_clicked', { fromPage: 1 }) | ||
| } | ||
| ] as DeckButton[] | ||
| }, | ||
| { | ||
| content: ( | ||
| <div> | ||
| <p>Continue through your walkthrough.</p> | ||
| </div> | ||
| ), | ||
| buttons: [ | ||
| { | ||
| children: 'Next', | ||
| variant: ButtonVariant.primary, | ||
| navigation: 'next', | ||
| onClick: () => trackEvent('deck_next_clicked', { fromPage: 2 }) | ||
| } | ||
| ] as DeckButton[] | ||
| }, | ||
| { | ||
| content: ( | ||
| <div> | ||
| <p>You've reached the end of the deck.</p> | ||
| </div> | ||
| ), | ||
| buttons: [ | ||
| { | ||
| children: 'Restart', | ||
| variant: ButtonVariant.primary, | ||
| // Restart the deck for demo purposes | ||
| onClick: () => { | ||
| trackEvent('deck_completed', { totalPages: 3 }); | ||
| console.log('Deck completed! Restarting...'); | ||
| restartDeck(); | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ]; | ||
|
|
||
| return ( | ||
| <Deck | ||
| key={deckKey} | ||
| pages={pages} | ||
| onPageChange={(index) => { | ||
| console.log('Current page:', index); | ||
| trackEvent('deck_page_changed', { page: index + 1 }); | ||
| }} | ||
| onClose={() => { | ||
| trackEvent('deck_closed', {}); | ||
| console.log('Deck closed'); | ||
| }} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
78 changes: 78 additions & 0 deletions
78
...le/patternfly-docs/content/extensions/component-groups/examples/Deck/ModalDeckExample.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,78 @@ | ||
| /* eslint-disable no-console */ | ||
| import { FunctionComponent, useState } from 'react'; | ||
| import Deck, { DeckButton } from '@patternfly/react-component-groups/dist/dynamic/Deck'; | ||
| import { ModalDeck } from '@patternfly/react-component-groups/dist/dynamic/ModalDeck'; | ||
| import { Button, ButtonVariant } from '@patternfly/react-core'; | ||
|
|
||
| export const ModalDeckExample: FunctionComponent = () => { | ||
| const [ isModalOpen, setIsModalOpen ] = useState(false); | ||
|
|
||
| const handleClose = () => { | ||
| setIsModalOpen(false); | ||
| console.log('Modal deck closed'); | ||
| }; | ||
|
|
||
| const pages = [ | ||
| { | ||
| content: ( | ||
| <div> | ||
| <h2>Welcome to the Modal Deck</h2> | ||
| <p>This deck is displayed in a modal dialog.</p> | ||
| </div> | ||
| ), | ||
| buttons: [ | ||
| { | ||
| children: 'Next', | ||
| variant: ButtonVariant.primary, | ||
| navigation: 'next' | ||
| } | ||
| ] as DeckButton[] | ||
| }, | ||
| { | ||
| content: ( | ||
| <div> | ||
| <h2>Page 2</h2> | ||
| <p>Navigate through the walkthrough.</p> | ||
| </div> | ||
| ), | ||
| buttons: [ | ||
| { | ||
| children: 'Next', | ||
| variant: ButtonVariant.primary, | ||
| navigation: 'next' | ||
| } | ||
| ] as DeckButton[] | ||
| }, | ||
| { | ||
| content: ( | ||
| <div> | ||
| <h2>Final Page</h2> | ||
| <p>Click Close to finish.</p> | ||
| </div> | ||
| ), | ||
| buttons: [ | ||
| { | ||
| children: 'Close', | ||
| variant: ButtonVariant.primary, | ||
| navigation: 'close' | ||
| } | ||
| ] as DeckButton[] | ||
| } | ||
| ]; | ||
|
|
||
| return ( | ||
| <> | ||
| <Button onClick={() => setIsModalOpen(true)}> | ||
| Launch modal deck | ||
| </Button> | ||
| <ModalDeck isOpen={isModalOpen} onClose={handleClose}> | ||
| <Deck | ||
| pages={pages} | ||
| onClose={handleClose} | ||
| onPageChange={(index) => console.log('Page changed to:', index + 1)} | ||
| /> | ||
| </ModalDeck> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
130 changes: 130 additions & 0 deletions
130
...ernfly-docs/content/extensions/component-groups/examples/Deck/OnboardingModalDeckDemo.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,130 @@ | ||
| /* eslint-disable no-console */ | ||
| import { FunctionComponent, useState } from 'react'; | ||
| import Deck, { DeckButton } from '@patternfly/react-component-groups/dist/dynamic/Deck'; | ||
| import { ModalDeck } from '@patternfly/react-component-groups/dist/dynamic/ModalDeck'; | ||
| import { Button, ButtonVariant, Label, Title, Stack, StackItem, Content } from '@patternfly/react-core'; | ||
|
|
||
| export const OnboardingModalDeckDemo: FunctionComponent = () => { | ||
| const [ isModalOpen, setIsModalOpen ] = useState(false); | ||
|
|
||
| const handleClose = () => { | ||
| setIsModalOpen(false); | ||
| console.log('Onboarding completed or skipped'); | ||
| }; | ||
|
|
||
| // Placeholder for illustration - in a real app, replace with actual images | ||
| const placeholderImage = ( | ||
| <div | ||
| style={{ | ||
| width: '256px', | ||
| height: '256px', | ||
| borderRadius: '8px', | ||
| background: 'repeating-linear-gradient(45deg, #f3f4f6, #f3f4f6 10px, #e5e7eb 10px, #e5e7eb 20px)', | ||
| opacity: 0.25, | ||
| margin: 'auto' | ||
| }} | ||
| /> | ||
| ); | ||
|
|
||
| const pages = [ | ||
| { | ||
| content: ( | ||
| <Stack hasGutter> | ||
| <StackItem>{placeholderImage}</StackItem> | ||
| <StackItem> | ||
| <Title headingLevel="h2" size="2xl">Welcome to [Product Name]</Title> | ||
| </StackItem> | ||
| <StackItem> | ||
| <Content component="p"> | ||
| Harness the full potential of the hybrid cloud, simply by asking. | ||
| </Content> | ||
| </StackItem> | ||
| </Stack> | ||
| ), | ||
| buttons: [ | ||
| { | ||
| children: 'Continue', | ||
| variant: ButtonVariant.primary, | ||
| navigation: 'next' | ||
| } | ||
| ] as DeckButton[] | ||
| }, | ||
| { | ||
| content: ( | ||
| <Stack hasGutter> | ||
| <StackItem>{placeholderImage}</StackItem> | ||
| <StackItem><Label color="grey">AI Command Center</Label></StackItem> | ||
| <StackItem><Title headingLevel="h2" size="2xl">Intelligence at your command</Title></StackItem> | ||
| <StackItem><Content component="p">Ask anything. Get answers. Troubleshoot, analyze, and understand your entire fleet just by asking. It's the power of your data, in plain language.</Content></StackItem> | ||
| </Stack> | ||
| ), | ||
| buttons: [ | ||
| { | ||
| children: 'Continue', | ||
| variant: ButtonVariant.primary, | ||
| navigation: 'next' | ||
| } | ||
| ] as DeckButton[] | ||
| }, | ||
| { | ||
| content: ( | ||
| <Stack hasGutter> | ||
| <StackItem>{placeholderImage}</StackItem> | ||
| <StackItem><Label color="grey">Canvas Mode</Label></StackItem> | ||
| <StackItem><Title headingLevel="h2" size="2xl">Go from conversation to clarity.</Title></StackItem> | ||
| <StackItem><Content component="p">Transform answers into custom dashboards. In Canvas Mode, you can effortlessly arrange, customize, and build the precise view you need to monitor what matters most.</Content></StackItem> | ||
| </Stack> | ||
| ), | ||
| buttons: [ | ||
| { | ||
| children: 'Continue', | ||
| variant: ButtonVariant.primary, | ||
| navigation: 'next' | ||
| } | ||
| ] as DeckButton[] | ||
| }, | ||
| { | ||
| content: ( | ||
| <Stack hasGutter> | ||
| <StackItem>{placeholderImage}</StackItem> | ||
| <StackItem><Label color="grey">Sharing</Label></StackItem> | ||
| <StackItem><Title headingLevel="h2" size="2xl">Share your vision. Instantly.</Title></StackItem> | ||
| <StackItem><Content component="p">An insight is only powerful when it’s shared. Save any view to your library and share it with your team in a single click. Drive decisions, together.</Content></StackItem> | ||
| </Stack> | ||
| ), | ||
| buttons: [ | ||
| { | ||
| children: 'Get started', | ||
| variant: ButtonVariant.primary, | ||
| navigation: 'close' | ||
| } | ||
| ] as DeckButton[] | ||
| } | ||
| ]; | ||
|
|
||
| return ( | ||
| <> | ||
| <Button onClick={() => setIsModalOpen(true)}> | ||
| Launch onboarding | ||
| </Button> | ||
| <ModalDeck | ||
| isOpen={isModalOpen} | ||
| modalProps={{ | ||
| 'aria-label': 'Product onboarding walkthrough' | ||
| }} | ||
| > | ||
| <Deck | ||
| pages={pages} | ||
| onClose={handleClose} | ||
| onPageChange={(index) => console.log('Onboarding page:', index + 1)} | ||
| ariaLabel="Product onboarding" | ||
| ariaRoleDescription="onboarding walkthrough" | ||
| contentFlexProps={{ | ||
| spaceItems: { default: 'spaceItemsXl' } | ||
| }} | ||
| /> | ||
| </ModalDeck> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
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.
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.