-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Ability to add custom toolbar items to main page nav bar
* core.ts * Adds optional toolbarItems property to plugin interface * HawtioHeader.tsx * Picks up the plugins from the context and find the plugin that is currently being displayed. If this plugin has a toolbar item property then pick up the components into a custom toolbar group
- Loading branch information
1 parent
8e9ffee
commit bf4c67b
Showing
5 changed files
with
122 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,91 @@ | ||
import React from 'react' | ||
import { Button, Dropdown, DropdownItem, DropdownSeparator, DropdownToggle, Modal } from '@patternfly/react-core' | ||
|
||
export const ToolbarItemComp1: React.FunctionComponent = () => { | ||
const [isModalOpen, setIsModalOpen] = React.useState(false) | ||
|
||
const handleModalToggle = () => { | ||
setIsModalOpen(!isModalOpen) | ||
} | ||
|
||
return ( | ||
<React.Fragment> | ||
<Button variant='primary' onClick={handleModalToggle}> | ||
Click Me! | ||
</Button> | ||
|
||
<Modal | ||
title='Basic modal' | ||
isOpen={isModalOpen} | ||
onClose={handleModalToggle} | ||
actions={[ | ||
<Button key='confirm' variant='primary' onClick={handleModalToggle}> | ||
Confirm | ||
</Button>, | ||
<Button key='cancel' variant='link' onClick={handleModalToggle}> | ||
Cancel | ||
</Button>, | ||
]} | ||
> | ||
Hello World! | ||
</Modal> | ||
</React.Fragment> | ||
) | ||
} | ||
|
||
export const ToolbarItemComp2: React.FunctionComponent = () => { | ||
const [isOpen, setIsOpen] = React.useState(false) | ||
|
||
const onToggle = (isOpen: boolean) => { | ||
setIsOpen(isOpen) | ||
} | ||
|
||
const onFocus = () => { | ||
const element = document.getElementById('toggle-basic') | ||
element?.focus() | ||
} | ||
|
||
const onSelect = () => { | ||
setIsOpen(false) | ||
onFocus() | ||
} | ||
|
||
const dropdownItems = [ | ||
<DropdownItem key='link' tooltip='Tooltip for enabled link'> | ||
Link | ||
</DropdownItem>, | ||
<DropdownItem key='action' component='button' tooltip='Tooltip for enabled button'> | ||
Action | ||
</DropdownItem>, | ||
<DropdownItem key='disabled link' isDisabled href='www.google.com'> | ||
Disabled link | ||
</DropdownItem>, | ||
<DropdownItem | ||
key='disabled action' | ||
isAriaDisabled | ||
component='button' | ||
tooltip='Tooltip for disabled item' | ||
tooltipProps={{ position: 'top' }} | ||
> | ||
Disabled action | ||
</DropdownItem>, | ||
<DropdownSeparator key='separator' />, | ||
<DropdownItem key='separated link'>Separated link</DropdownItem>, | ||
<DropdownItem key='separated action' component='button'> | ||
Separated action | ||
</DropdownItem>, | ||
] | ||
|
||
return ( | ||
<Dropdown | ||
onSelect={onSelect} | ||
toggle={ | ||
<DropdownToggle id='toggle-basic' onToggle={onToggle}> | ||
Dropdown | ||
</DropdownToggle> | ||
} | ||
isOpen={isOpen} | ||
dropdownItems={dropdownItems} | ||
/> | ||
) | ||
} |
This file contains 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 |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { hawtio, HawtioPlugin } from '@hawtio/react' | ||
import { Example3 } from './Example3' | ||
import { ToolbarItemComp1, ToolbarItemComp2 } from './ToolbarItemComp' | ||
|
||
export const registerExample3: HawtioPlugin = () => { | ||
hawtio.addPlugin({ | ||
id: 'example3', | ||
title: 'Example 3', | ||
path: '/example3', | ||
component: Example3, | ||
headerItems: [ToolbarItemComp1, ToolbarItemComp2], | ||
isActive: async () => true, | ||
}) | ||
} |
This file contains 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
This file contains 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