FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(Dropdown): Added support for dropdown with primary button toggle by rebeccaalpert · Pull Request #2857 · patternfly/patternfly-react · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .md  (1) .snap  (7) .tsx  (3) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
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
Expand Up @@ -262,6 +262,7 @@ exports[`ApplicationLauncher custom icon 1`] = `
isHovered={false}
isOpen={true}
isPlain={false}
isPrimary={false}
isSplitButton={false}
onEnter={[Function]}
onToggle={[Function]}
Expand Down Expand Up @@ -926,6 +927,7 @@ exports[`ApplicationLauncher dropup + right aligned 1`] = `
isHovered={false}
isOpen={false}
isPlain={false}
isPrimary={false}
isSplitButton={false}
onEnter={[Function]}
onToggle={[Function]}
Expand Down Expand Up @@ -1185,6 +1187,7 @@ exports[`ApplicationLauncher dropup 1`] = `
isHovered={false}
isOpen={false}
isPlain={false}
isPrimary={false}
isSplitButton={false}
onEnter={[Function]}
onToggle={[Function]}
Expand Down Expand Up @@ -1531,6 +1534,7 @@ exports[`ApplicationLauncher expanded 1`] = `
isHovered={false}
isOpen={true}
isPlain={false}
isPrimary={false}
isSplitButton={false}
onEnter={[Function]}
onToggle={[Function]}
Expand Down Expand Up @@ -2192,6 +2196,7 @@ exports[`ApplicationLauncher regular 1`] = `
isHovered={false}
isOpen={false}
isPlain={false}
isPrimary={false}
isSplitButton={false}
onEnter={[Function]}
onToggle={[Function]}
Expand Down Expand Up @@ -2451,6 +2456,7 @@ exports[`ApplicationLauncher right aligned 1`] = `
isHovered={false}
isOpen={false}
isPlain={false}
isPrimary={false}
isSplitButton={false}
onEnter={[Function]}
onToggle={[Function]}
Expand Down
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
Expand Up @@ -240,6 +240,62 @@ class DisabledDropdown extends React.Component {
}
```

## Dropdown (primary toggle)

```js
import React from 'react';
import { Dropdown, DropdownToggle, DropdownItem, DropdownSeparator, DropdownPosition, DropdownDirection } from '@patternfly/react-core';
import { ThIcon, CaretDownIcon } from '@patternfly/react-icons';

class PrimaryDropdown 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 dropdownItems = [
<DropdownItem key="link">Link</DropdownItem>,
<DropdownItem key="action" component="button">
Action
</DropdownItem>,
<DropdownItem key="disabled link" isDisabled>
Disabled Link
</DropdownItem>,
<DropdownItem key="disabled action" isDisabled component="button">
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={this.onSelect}
toggle={<DropdownToggle onToggle={this.onToggle} iconComponent={CaretDownIcon} isPrimary>Dropdown</DropdownToggle>}
isOpen={isOpen}
dropdownItems={dropdownItems}
/>
);
}
}
```

## Dropdown (position right)

```js
Expand Down
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
Expand Up @@ -78,6 +78,16 @@ describe('dropdown', () => {
expect(view).toMatchSnapshot();
});

test('primary', () => {
const view = mount(
<Dropdown
dropdownItems={dropdownItems}
toggle={<DropdownToggle id="Dropdown Toggle" isPrimary>Dropdown</DropdownToggle>}
/>
);
expect(view).toMatchSnapshot();
});

test('basic', () => {
const view = mount(
<Dropdown isOpen toggle={<DropdownToggle id="Dropdown Toggle">Dropdown</DropdownToggle>}>
Expand Down
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
Expand Up @@ -28,6 +28,8 @@ export interface DropdownToggleProps extends React.HTMLProps<HTMLButtonElement>
isPlain?: boolean;
/** Whether or not the <div> has a disabled state */
isDisabled?: boolean;
/** Whether or not the dropdown toggle button should have primary button styling */
isPrimary?: boolean;
/** The icon to display for the toggle. Defaults to CaretDownIcon. Set to null to not show an icon. */
iconComponent?: React.ElementType | null;
/** Elements to display before the toggle button. When included, renders the toggle as a split button. */
Expand All @@ -51,6 +53,7 @@ export const DropdownToggle: React.FunctionComponent<DropdownToggleProps> = ({
isActive = false,
isDisabled = false,
isPlain = false,
isPrimary = false,
onToggle = (_isOpen: boolean) => undefined as any,
iconComponent: IconComponent = CaretDownIcon,
splitButtonItems,
Expand All @@ -72,6 +75,7 @@ export const DropdownToggle: React.FunctionComponent<DropdownToggleProps> = ({
isActive={isActive}
isDisabled={isDisabled}
isPlain={isPlain}
isPrimary={isPrimary}
onToggle={onToggle}
ariaHasPopup={ariaHasPopup}
{...splitButtonItems && { "isSplitButton": true, 'aria-label': props['aria-label'] || 'Select' }}>
Expand Down
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
Expand Up @@ -31,6 +31,8 @@ export interface ToggleProps {
isDisabled?: boolean;
/** Display the toggle with no border or background */
isPlain?: boolean;
/** Display the toggle with a primary button style */
isPrimary?: boolean;
/** Style the toggle as a child of a split button */
isSplitButton?: boolean;
/** Flag for aria popup */
Expand All @@ -48,6 +50,7 @@ export class Toggle extends React.Component<ToggleProps> {
isActive: false,
isDisabled: false,
isPlain: false,
isPrimary: false,
isSplitButton: false,
onToggle: Function.prototype,
onEnter: Function.prototype
Expand Down Expand Up @@ -107,6 +110,7 @@ export class Toggle extends React.Component<ToggleProps> {
isHovered,
isDisabled,
isPlain,
isPrimary,
isSplitButton,
ariaHasPopup,
onToggle,
Expand All @@ -130,6 +134,7 @@ export class Toggle extends React.Component<ToggleProps> {
isActive && styles.modifiers.active,
isPlain && styles.modifiers.plain,
isDisabled && styles.modifiers.disabled,
isPrimary && styles.modifiers.primary,
className
)}
type={type || 'button'}
Expand Down
Loading

Back | FazBrowse Home | New Git URL