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

feat(Dropdown): add split button action variant by kmcfaul · Pull Request #3307 · patternfly/patternfly-react · GitHub

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 @@ -615,6 +615,7 @@ exports[`ApplicationLauncher custom icon 1`] = `
tabIndex={-1}
tooltip={null}
tooltipProps={Object {}}
variant="item"
>
<li
className={null}
Expand Down Expand Up @@ -662,6 +663,7 @@ exports[`ApplicationLauncher custom icon 1`] = `
tabIndex={-1}
tooltip={null}
tooltipProps={Object {}}
variant="item"
>
<li
className={null}
Expand Down Expand Up @@ -710,6 +712,7 @@ exports[`ApplicationLauncher custom icon 1`] = `
tabIndex={-1}
tooltip={null}
tooltipProps={Object {}}
variant="item"
>
<li
className={null}
Expand Down Expand Up @@ -758,6 +761,7 @@ exports[`ApplicationLauncher custom icon 1`] = `
tabIndex={-1}
tooltip={null}
tooltipProps={Object {}}
variant="item"
>
<li
className={null}
Expand Down Expand Up @@ -803,6 +807,7 @@ exports[`ApplicationLauncher custom icon 1`] = `
onSelect={[Function]}
role="separator"
tooltipProps={Object {}}
variant="item"
>
<li
className={null}
Expand Down Expand Up @@ -845,6 +850,7 @@ exports[`ApplicationLauncher custom icon 1`] = `
tabIndex={-1}
tooltip={null}
tooltipProps={Object {}}
variant="item"
>
<li
className={null}
Expand Down Expand Up @@ -892,6 +898,7 @@ exports[`ApplicationLauncher custom icon 1`] = `
tabIndex={-1}
tooltip={null}
tooltipProps={Object {}}
variant="item"
>
<li
className={null}
Expand Down Expand Up @@ -2298,6 +2305,7 @@ exports[`ApplicationLauncher expanded 1`] = `
tabIndex={-1}
tooltip={null}
tooltipProps={Object {}}
variant="item"
>
<li
className={null}
Expand Down Expand Up @@ -2345,6 +2353,7 @@ exports[`ApplicationLauncher expanded 1`] = `
tabIndex={-1}
tooltip={null}
tooltipProps={Object {}}
variant="item"
>
<li
className={null}
Expand Down Expand Up @@ -2393,6 +2402,7 @@ exports[`ApplicationLauncher expanded 1`] = `
tabIndex={-1}
tooltip={null}
tooltipProps={Object {}}
variant="item"
>
<li
className={null}
Expand Down Expand Up @@ -2441,6 +2451,7 @@ exports[`ApplicationLauncher expanded 1`] = `
tabIndex={-1}
tooltip={null}
tooltipProps={Object {}}
variant="item"
>
<li
className={null}
Expand Down Expand Up @@ -2486,6 +2497,7 @@ exports[`ApplicationLauncher expanded 1`] = `
onSelect={[Function]}
role="separator"
tooltipProps={Object {}}
variant="item"
>
<li
className={null}
Expand Down Expand Up @@ -2528,6 +2540,7 @@ exports[`ApplicationLauncher expanded 1`] = `
tabIndex={-1}
tooltip={null}
tooltipProps={Object {}}
variant="item"
>
<li
className={null}
Expand Down Expand Up @@ -2575,6 +2588,7 @@ exports[`ApplicationLauncher expanded 1`] = `
tabIndex={-1}
tooltip={null}
tooltipProps={Object {}}
variant="item"
>
<li
className={null}
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 @@ -11,6 +11,8 @@ export interface DropdownItemProps extends InternalDropdownItemProps {
listItemClassName?: string;
/** Indicates which component will be used as dropdown item */
component?: React.ReactNode;
/** Variant of the item. The 'icon' variant should use DropdownItemIcon to wrap contained icons or images. */
variant?: 'item' | 'icon';
/** Render dropdown item as disabled option */
isDisabled?: boolean;
/** Forces display of the hover state of the element */
Expand All @@ -27,6 +29,7 @@ export const DropdownItem: React.FunctionComponent<DropdownItemProps> = ({
children = null,
className = '',
component = 'a',
variant = 'item',
isDisabled = false,
isHovered = false,
href = '',
Expand All @@ -46,6 +49,7 @@ export const DropdownItem: React.FunctionComponent<DropdownItemProps> = ({
children={children}
className={className}
component={component}
variant={variant}
isDisabled={isDisabled}
isHovered={isHovered}
href={href}
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
@@ -0,0 +1,20 @@
import * as React from 'react';
import { css } from '@patternfly/react-styles';
import styles from '@patternfly/react-styles/css/components/Dropdown/dropdown';

export interface DropdownItemIconProps extends React.HTMLProps<HTMLAnchorElement> {
/** Icon to be rendered in the dropdown item */
children?: React.ReactNode;
/** Classes applied to span element of dropdown icon item */
className?: string;
}

export const DropdownItemIcon: React.FunctionComponent<DropdownItemIconProps> = ({
children,
className = '',
...props
}: DropdownItemIconProps) => (
<span className={css(styles.dropdownMenuItemIcon, className)} {...props}>
{children}
</span>
);
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 @@ -34,6 +34,8 @@ export interface DropdownToggleProps extends React.HTMLProps<HTMLButtonElement>
iconComponent?: React.ElementType | null;
/** Elements to display before the toggle button. When included, renders the toggle as a split button. */
splitButtonItems?: React.ReactNode[];
/** Variant of split button toggle */
splitButtonVariant?: 'action' | 'checkbox';
/** Accessible label for the dropdown toggle button */
'aria-label'?: string;
/** Accessibility property to indicate correct has popup */
Expand All @@ -59,6 +61,7 @@ export const DropdownToggle: React.FunctionComponent<DropdownToggleProps> = ({
onToggle = (_isOpen: boolean) => undefined as any,
iconComponent: IconComponent = CaretDownIcon,
splitButtonItems,
splitButtonVariant = 'checkbox',
ariaHasPopup,
ref, // Types of Ref are different for React.FC vs React.Component
...props
Expand Down Expand Up @@ -92,7 +95,12 @@ export const DropdownToggle: React.FunctionComponent<DropdownToggleProps> = ({
if (splitButtonItems) {
return (
<div
className={css(styles.dropdownToggle, styles.modifiers.splitButton, isDisabled && styles.modifiers.disabled)}
className={css(
styles.dropdownToggle,
styles.modifiers.splitButton,
splitButtonVariant === 'action' && styles.modifiers.action,
isDisabled && styles.modifiers.disabled
)}
>
{splitButtonItems}
{toggle}
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
@@ -0,0 +1,25 @@
import * as React from 'react';
import { shallow, mount } from 'enzyme';
import { DropdownToggleAction } from './DropdownToggleAction';

test('renders with text', () => {
const view = shallow(<DropdownToggleAction id="action" aria-label="action" />);
expect(view).toMatchSnapshot();
});

test('isDisabled', () => {
const view = shallow(<DropdownToggleAction id="action" aria-label="action" isDisabled />);
expect(view).toMatchSnapshot();
});

test('passing class', () => {
const view = shallow(<DropdownToggleAction id="action" aria-label="action" className="abc" />);
expect(view).toMatchSnapshot();
});

test('checkbox passes value and event to onClick handler', () => {
const onClickMock = jest.fn();
const view = mount(<DropdownToggleAction id="action" aria-label="acton" onClick={onClickMock} />);
view.find('button').simulate('click');
expect(onClickMock).toBeCalled();
});
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
@@ -0,0 +1,42 @@
import * as React from 'react';
import styles from '@patternfly/react-styles/css/components/Dropdown/dropdown';
import { css } from '@patternfly/react-styles';

export interface DropdownToggleActionProps {
/** Additional classes added to the DropdownToggleAction */
className?: string;
/** Flag to show if the action button is disabled */
isDisabled?: boolean;
/** A callback for when the action button is clicked */
onClick?(event: React.MouseEvent<HTMLButtonElement>): void;
/** Element to be rendered inside the <button> */
children?: React.ReactNode;
/** Id of the action button */
id?: string;
/** Aria-label of the action button */
'aria-label'?: string;
}

export class DropdownToggleAction extends React.Component<DropdownToggleActionProps> {
static defaultProps = {
className: '',
isDisabled: false,
onClick: Function.prototype
};

render() {
const { id, className, onClick, isDisabled, children, ...props } = this.props;

return (
<button
id={id}
className={css(styles.dropdownToggleButton, className)}
onClick={onClick}
{...(isDisabled && { disabled: true, 'aria-disabled': true })}
{...props}
>
{children}
</button>
);
}
}
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 @@ -3,6 +3,7 @@ import { css } from '@patternfly/react-styles';
import { DropdownContext } from './dropdownConstants';
import { KEY_CODES, KEYHANDLER_DIRECTION } from '../../helpers/constants';
import { Tooltip } from '../Tooltip';
import styles from '@patternfly/react-styles/css/components/Dropdown/dropdown';

export interface InternalDropdownItemProps extends React.HTMLProps<HTMLAnchorElement> {
/** Anything which can be rendered as dropdown item */
Expand All @@ -13,6 +14,8 @@ export interface InternalDropdownItemProps extends React.HTMLProps<HTMLAnchorEle
listItemClassName?: string;
/** Indicates which component will be used as dropdown item */
component?: React.ReactNode | string;
/** Variant of the item. The 'icon' variant should use DropdownItemIcon to wrap contained icons or images. */
variant?: 'item' | 'icon';
/** Role for the item */
role?: string;
/** Render dropdown item as disabled option */
Expand Down Expand Up @@ -45,6 +48,7 @@ export class InternalDropdownItem extends React.Component<InternalDropdownItemPr
className: '',
isHovered: false,
component: 'a',
variant: 'item',
role: 'none',
isDisabled: false,
href: '',
Expand All @@ -57,7 +61,7 @@ export class InternalDropdownItem extends React.Component<InternalDropdownItemPr
sendRef: Function.prototype
},
id: '',
componentID: '',
componentID: ''
};

componentDidMount() {
Expand Down Expand Up @@ -96,6 +100,7 @@ export class InternalDropdownItem extends React.Component<InternalDropdownItemPr
context,
onClick,
component,
variant,
role,
isDisabled,
index,
Expand Down Expand Up @@ -157,13 +162,17 @@ export class InternalDropdownItem extends React.Component<InternalDropdownItemPr
isComponentReactElement ? (
React.cloneElement(Component as React.ReactHTMLElement<any>, {
...additionalProps,
className: css(classes, itemClass)
className: css(classes, itemClass, variant === 'icon' && styles.modifiers.icon)
})
) : (
<Component
{...additionalProps}
href={href || null}
className={css(classes, this.props.role !== 'separator' && itemClass)}
className={css(
classes,
this.props.role !== 'separator' && itemClass,
variant === 'icon' && styles.modifiers.icon
)}
id={componentID}
>
{children}
Expand Down
Loading

Back | FazBrowse Home | New Git URL