forked from patternfly/react-component-groups
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeckExample.tsx
More file actions
87 lines (81 loc) · 2.15 KB
/
DeckExample.tsx
File metadata and controls
87 lines (81 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* 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');
}}
/>
);
};