| 1 |
import { __rest } from "tslib"; |
| 2 |
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; |
| 3 |
import { Component, forwardRef, isValidElement } from 'react'; |
| 4 |
import styles from '@patternfly/react-styles/css/components/MenuToggle/menu-toggle.mjs'; |
| 5 |
import { css } from '@patternfly/react-styles'; |
| 6 |
import RhMicronsCaretDownFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-microns-caret-down-fill-icon'; |
| 7 |
import RhUiSettingsFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-settings-fill-icon'; |
| 8 |
import RhUiCheckCircleFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-check-circle-fill-icon'; |
| 9 |
import RhUiErrorFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-error-fill-icon'; |
| 10 |
import RhUiWarningFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-warning-fill-icon'; |
| 11 |
import { getOUIAProps } from '../../helpers'; |
| 12 |
import { SSRSafeIds } from '../../helpers/SSRSafeIds/SSRSafeIds'; |
| 13 |
export var MenuToggleStatus; |
| 14 |
(function (MenuToggleStatus) { |
| 15 |
MenuToggleStatus["success"] = "success"; |
| 16 |
MenuToggleStatus["danger"] = "danger"; |
| 17 |
MenuToggleStatus["warning"] = "warning"; |
| 18 |
})(MenuToggleStatus || (MenuToggleStatus = {})); |
| 19 |
export var MenuToggleSize; |
| 20 |
(function (MenuToggleSize) { |
| 21 |
MenuToggleSize["default"] = "default"; |
| 22 |
MenuToggleSize["sm"] = "sm"; |
| 23 |
})(MenuToggleSize || (MenuToggleSize = {})); |
| 24 |
class MenuToggleBase extends Component { |
| 25 |
constructor() { |
| 26 |
super(...arguments); |
| 27 |
this.displayName = 'MenuToggleBase'; |
| 28 |
} |
| 29 |
render() { |
| 30 |
const _a = this.props, { children, className, icon, badge, isExpanded, isDisabled, isFullHeight, isFullWidth, isInForm, isPlaceholder, isCircle, isSettings, isDocked, isTextExpanded, splitButtonItems, variant, status, statusIcon, innerRef, onClick, 'aria-label': ariaLabel, ouiaId, ouiaSafe, size } = _a, otherProps = __rest(_a, ["children", "className", "icon", "badge", "isExpanded", "isDisabled", "isFullHeight", "isFullWidth", "isInForm", "isPlaceholder", "isCircle", "isSettings", "isDocked", "isTextExpanded", "splitButtonItems", "variant", "status", "statusIcon", "innerRef", "onClick", 'aria-label', "ouiaId", "ouiaSafe", "size"]); |
| 31 |
const isPlain = variant === 'plain'; |
| 32 |
const isPlainText = variant === 'plainText'; |
| 33 |
const isTypeahead = variant === 'typeahead'; |
| 34 |
return (_jsx(SSRSafeIds, { prefix: "pf-", ouiaComponentType: `MenuToggle${variant ? `-${variant}` : ''}`, children: (_, generatedOuiaId) => { |
| 35 |
const ouiaProps = getOUIAProps(MenuToggle.displayName, ouiaId !== null && ouiaId !== void 0 ? ouiaId : generatedOuiaId, ouiaSafe); |
| 36 |
let _statusIcon = statusIcon; |
| 37 |
if (!statusIcon) { |
| 38 |
switch (status) { |
| 39 |
case MenuToggleStatus.success: |
| 40 |
_statusIcon = _jsx(RhUiCheckCircleFillIcon, {}); |
| 41 |
break; |
| 42 |
case MenuToggleStatus.warning: |
| 43 |
_statusIcon = _jsx(RhUiWarningFillIcon, {}); |
| 44 |
break; |
| 45 |
case MenuToggleStatus.danger: |
| 46 |
_statusIcon = _jsx(RhUiErrorFillIcon, {}); |
| 47 |
break; |
| 48 |
} |
| 49 |
} |
| 50 |
const toggleControls = (_jsxs("span", { className: css(styles.menuToggleControls), children: [status !== undefined && _jsx("span", { className: css(styles.menuToggleStatusIcon), children: _statusIcon }), _jsx("span", { className: css(styles.menuToggleToggleIcon), children: _jsx(RhMicronsCaretDownFillIcon, {}) })] })); |
| 51 |
const content = (_jsxs(_Fragment, { children: [(icon || isSettings) && (_jsx("span", { className: css(styles.menuToggleIcon), children: isSettings ? _jsx(RhUiSettingsFillIcon, {}) : icon })), isTypeahead ? children : children && _jsx("span", { className: css(styles.menuToggleText), children: children }), isValidElement(badge) && _jsx("span", { className: css(styles.menuToggleCount), children: badge }), isTypeahead ? (_jsx("button", Object.assign({ type: "button", className: css(styles.menuToggleButton), "aria-expanded": isExpanded, onClick: onClick, "aria-label": ariaLabel || 'Menu toggle', tabIndex: -1 }, ouiaProps, { children: toggleControls }))) : (!isPlain && toggleControls)] })); |
| 52 |
const commonStyles = css(styles.menuToggle, isExpanded && styles.modifiers.expanded, variant === 'primary' && styles.modifiers.primary, variant === 'secondary' && styles.modifiers.secondary, status && styles.modifiers[status], (isPlain || isPlainText) && styles.modifiers.plain, isPlainText && styles.modifiers.text, isFullHeight && styles.modifiers.fullHeight, isFullWidth && styles.modifiers.fullWidth, isInForm && styles.modifiers.form, isDisabled && styles.modifiers.disabled, isPlaceholder && styles.modifiers.placeholder, isSettings && styles.modifiers.settings, isDocked && styles.modifiers.docked, isDocked && isTextExpanded && styles.modifiers.textExpanded, size === MenuToggleSize.sm && styles.modifiers.small, className); |
| 53 |
const componentProps = Object.assign(Object.assign({ children: content }, (isDisabled && { disabled: true })), otherProps); |
| 54 |
if (isTypeahead) { |
| 55 |
return (_jsx("div", Object.assign({ ref: innerRef, className: css(commonStyles, styles.modifiers.typeahead) }, componentProps))); |
| 56 |
} |
| 57 |
if (splitButtonItems) { |
| 58 |
return (_jsxs("div", { ref: innerRef, className: css(commonStyles, styles.modifiers.splitButton), children: [splitButtonItems, _jsxs("button", Object.assign({ className: css(styles.menuToggleButton, children && styles.modifiers.text), type: "button", "aria-expanded": isExpanded, "aria-label": ariaLabel, disabled: isDisabled, onClick: onClick }, otherProps, ouiaProps, { children: [children && _jsx("span", { className: css(styles.menuToggleText), children: children }), toggleControls] }))] })); |
| 59 |
} |
| 60 |
return (_jsx("button", Object.assign({ className: css(commonStyles, isCircle && isPlain && styles.modifiers.circle), type: "button", "aria-label": ariaLabel, "aria-expanded": isExpanded, ref: innerRef, disabled: isDisabled, onClick: onClick }, componentProps, ouiaProps))); |
| 61 |
} })); |
| 62 |
} |
| 63 |
} |
| 64 |
MenuToggleBase.defaultProps = { |
| 65 |
className: '', |
| 66 |
isExpanded: false, |
| 67 |
isDisabled: false, |
| 68 |
isFullWidth: false, |
| 69 |
isFullHeight: false, |
| 70 |
isInForm: false, |
| 71 |
isPlaceholder: false, |
| 72 |
isCircle: false, |
| 73 |
isDocked: false, |
| 74 |
isTextExpanded: false, |
| 75 |
size: 'default', |
| 76 |
ouiaSafe: true |
| 77 |
}; |
| 78 |
export const MenuToggle = forwardRef((props, ref) => (_jsx(MenuToggleBase, Object.assign({ innerRef: ref }, props)))); |
| 79 |
MenuToggle.displayName = 'MenuToggle'; |
| 80 |
//# sourceMappingURL=MenuToggle.js.map |