Skip to content

Commit

Permalink
fix(ApplicationLauncher): Allow custom icon for application launcher …
Browse files Browse the repository at this point in the history
…toggle
  • Loading branch information
jeff-phillips-18 committed Jul 9, 2019
1 parent 79aa23f commit 1088eed
Show file tree
Hide file tree
Showing 4 changed files with 765 additions and 16 deletions.
Expand Up @@ -8,6 +8,7 @@ Note: Application launcher is built on Dropdown, for extended API go to [`Dropdo
To add a tooltip, use the `tooltip` prop and optionally add more tooltip props by using `tooltipProps`. For more tooltip information go to [`Tooltip`](/components/tooltip/).

import { ApplicationLauncher, ApplicationLauncherIcon, ApplicationLauncherText, ApplicationLauncherItem, ApplicationLauncherGroup, ApplicationLauncherSeparator } from '@patternfly/react-core';
import { HelpIcon } from '@patternfly/react-icons';
import pfIcon from './examples/pf-logo-small.svg';

## Simple application launcher
Expand Down Expand Up @@ -180,4 +181,57 @@ class ApplicationLauncherSections extends React.Component {
);
}
}
```
```

## Application launcher w/ custom icon
```js
import React from 'react';
import { ApplicationLauncher, ApplicationLauncherItem } from '@patternfly/react-core';
import { HelpIcon } from '@patternfly/react-icons';

class ApplicationLauncheIcon extends React.Component {
constructor(props) {
super(props);
this.state = {
isOpen: false
};
this.onToggle = isOpen => {
this.setState({
isOpen
});
};
this.onSelect = event => {
this.setState({
isOpen: !this.state.isOpen
});
};
}

render() {
const { isOpen } = this.state;
const appLauncherItems = [
<ApplicationLauncherItem key="application_1a" href="#">
Application 1 (anchor link)
</ApplicationLauncherItem>,
<ApplicationLauncherItem key="application_2a" onClick={() => alert('Clicked item 2')}>
Application 2 (div with onClick)
</ApplicationLauncherItem>,
<ApplicationLauncherItem key="application_3a" onClick={() => alert('Clicked item 3')}>
Application 3 (div with onClick)
</ApplicationLauncherItem>,
<ApplicationLauncherItem key="disabled_application_4a" isDisabled>
Unavailable Application
</ApplicationLauncherItem>
];
return (
<ApplicationLauncher
onSelect={this.onSelect}
onToggle={this.onToggle}
isOpen={isOpen}
items={appLauncherItems}
toggleIcon={<HelpIcon />}
/>
);
}
}
```
@@ -1,5 +1,6 @@
import React from 'react';
import { mount } from 'enzyme';
import { HelpIcon } from '@patternfly/react-icons';
import { ApplicationLauncher } from './ApplicationLauncher';
import DropdownItem from '../Dropdown/DropdownItem';

Expand Down Expand Up @@ -55,4 +56,11 @@ describe('ApplicationLauncher', () => {
const view = mount(<ApplicationLauncher dropdownItems={dropdownItems} isOpen />);
expect(view).toMatchSnapshot();
});

test('custom icon', () => {
const view = mount(
<ApplicationLauncher dropdownItems={dropdownItems} isOpen toggleIcon={<HelpIcon id="test-icon" />} />
);
expect(view).toMatchSnapshot();
});
});
Expand Up @@ -6,32 +6,34 @@ import { DropdownWithContext } from '../Dropdown/Dropdown';

export interface ApplicationLauncherProps extends React.HTMLProps<HTMLDivElement> {
/** Additional element css classes */
className: string;
className?: string;
/** Display menu above or below dropdown toggle */
direction: DropdownDirection;
/**
direction?: DropdownDirection;
/**
* @deprecated
* Use the items prop instead
*
*
* Array of DropdownItem nodes that will be rendered in the dropdown Menu list
*/
dropdownItems: React.ReactNode[];
dropdownItems?: React.ReactNode[];
/** Array of application launcher items */
items: React.ReactNode[];
items?: React.ReactNode[];
/** Render Application launcher toggle as disabled icon */
isDisabled: boolean;
isDisabled?: boolean;
/** open bool */
isOpen: boolean;
isOpen?: boolean;
/** Indicates where menu will be alligned horizontally */
position: DropdownPosition;
position?: DropdownPosition;
/** Function callback called when user selects item */
onSelect: (event: any) => void;
onSelect?: (event: any) => void;
/** Callback called when application launcher toggle is clicked */
onToggle?: (value: boolean) => void;
/** Adds accessible text to the button. Required for plain buttons */
'aria-label': string;
'aria-label'?: string;
/** Flag to indicate if application launcher has groups */
isGrouped: boolean;
isGrouped?: boolean;
/** Toggle Icon, optional to override the icon used for the toggle */
toggleIcon?: React.ReactNode
}

export class ApplicationLauncher extends React.Component<ApplicationLauncherProps> {
Expand All @@ -46,10 +48,23 @@ export class ApplicationLauncher extends React.Component<ApplicationLauncherProp
onSelect: (_event: any): any => undefined,
onToggle: (_value: boolean): any => undefined,
'aria-label': 'Application launcher',
isGrouped: false
isGrouped: false,
toggleIcon: <ThIcon />
};
render() {
const { 'aria-label': ariaLabel, isOpen, onToggle, onSelect, isDisabled, className, isGrouped, dropdownItems, items, ...props } = this.props;
const {
'aria-label': ariaLabel,
isOpen,
onToggle,
toggleIcon,
onSelect,
isDisabled,
className,
isGrouped,
dropdownItems,
items,
...props
} = this.props;
return (
<DropdownContext.Provider value={{
onSelect,
Expand Down Expand Up @@ -79,7 +94,7 @@ export class ApplicationLauncher extends React.Component<ApplicationLauncherProp
isDisabled={isDisabled}
aria-label={ariaLabel}
>
<ThIcon />
{toggleIcon}
</DropdownToggle>
}
isGrouped={isGrouped}
Expand Down

0 comments on commit 1088eed

Please sign in to comment.