Debian Codegraph @

node/@patternfly/react-core/src/components/Tabs/examples/TabsHelp.tsx

raw
1 import { createRef, useState } from 'react';
2 import { Tabs, Tab, TabTitleText, TabAction, Popover } from '@patternfly/react-core';
3 import HelpIcon from '@patternfly/react-icons/dist/esm/icons/help-icon';
4
5 export const TabsHelp: React.FunctionComponent = () => {
6 const [activeTabKey, setActiveTabKey] = useState<number>(0);
7
8 const tabs = ['Users', 'Containers', 'Database', 'Disabled', 'ARIA disabled', 'Help disabled'];
9
10 const helpPopover = (header: string, popoverRef: React.RefObject<any>) => (
11 <Popover
12 headerContent={<div>{header}</div>}
13 bodyContent={
14 <div>
15 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id feugiat augue, nec fringilla turpis.
16 </div>
17 }
18 footerContent="Popover footer"
19 triggerRef={popoverRef}
20 />
21 );
22
23 return (
24 <Tabs
25 activeKey={activeTabKey}
26 onSelect={(event: any, tabIndex: string | number) => setActiveTabKey(tabIndex as number)}
27 aria-label="Tabs in the help action example"
28 role="region"
29 >
30 {tabs.map((tab, index) => {
31 const ref = createRef<HTMLElement>();
32
33 return (
34 <Tab
35 key={index}
36 eventKey={index}
37 aria-label={`Help action content - ${tab}`}
38 title={<TabTitleText>{tab}</TabTitleText>}
39 {...(tab === 'Disabled' && { isDisabled: true })}
40 {...(tab === 'ARIA disabled' && { isAriaDisabled: true })}
41 actions={
42 <>
43 <TabAction
44 aria-label={`Help action for ${tab}`}
45 ref={ref}
46 {...(tab === 'Help disabled' && { isDisabled: true })}
47 >
48 <HelpIcon />
49 </TabAction>
50 {helpPopover(`Help popover for ${tab}`, ref)}
51 </>
52 }
53 >
54 {tab}
55 </Tab>
56 );
57 })}
58 </Tabs>
59 );
60 };