1 | import { __rest } from "tslib";
|
2 | import * as React from 'react';
|
3 | import styles from '@patternfly/react-styles/css/components/Button/button';
|
4 | import { css } from '@patternfly/react-styles';
|
5 | import { Spinner, spinnerSize } from '../Spinner';
|
6 | import { useOUIAProps } from '../../helpers';
|
7 | export var ButtonVariant;
|
8 | (function (ButtonVariant) {
|
9 | ButtonVariant["primary"] = "primary";
|
10 | ButtonVariant["secondary"] = "secondary";
|
11 | ButtonVariant["tertiary"] = "tertiary";
|
12 | ButtonVariant["danger"] = "danger";
|
13 | ButtonVariant["warning"] = "warning";
|
14 | ButtonVariant["link"] = "link";
|
15 | ButtonVariant["plain"] = "plain";
|
16 | ButtonVariant["control"] = "control";
|
17 | })(ButtonVariant || (ButtonVariant = {}));
|
18 | export var ButtonType;
|
19 | (function (ButtonType) {
|
20 | ButtonType["button"] = "button";
|
21 | ButtonType["submit"] = "submit";
|
22 | ButtonType["reset"] = "reset";
|
23 | })(ButtonType || (ButtonType = {}));
|
24 | const ButtonBase = (_a) => {
|
25 | var { children = null, className = '', component = 'button', isActive = false, isBlock = false, isDisabled = false, isAriaDisabled = false, isLoading = null, isDanger = false, spinnerAriaValueText, spinnerAriaLabelledBy, spinnerAriaLabel, isSmall = false, isLarge = false, inoperableEvents = ['onClick', 'onKeyPress'], isInline = false, type = ButtonType.button, variant = ButtonVariant.primary, iconPosition = 'left', 'aria-label': ariaLabel = null, icon = null, ouiaId, ouiaSafe = true, tabIndex = null, innerRef } = _a, props = __rest(_a, ["children", "className", "component", "isActive", "isBlock", "isDisabled", "isAriaDisabled", "isLoading", "isDanger", "spinnerAriaValueText", "spinnerAriaLabelledBy", "spinnerAriaLabel", "isSmall", "isLarge", "inoperableEvents", "isInline", "type", "variant", "iconPosition", 'aria-label', "icon", "ouiaId", "ouiaSafe", "tabIndex", "innerRef"]);
|
26 | const ouiaProps = useOUIAProps(Button.displayName, ouiaId, ouiaSafe, variant);
|
27 | const Component = component;
|
28 | const isButtonElement = Component === 'button';
|
29 | const isInlineSpan = isInline && Component === 'span';
|
30 | const preventedEvents = inoperableEvents.reduce((handlers, eventToPrevent) => (Object.assign(Object.assign({}, handlers), { [eventToPrevent]: (event) => {
|
31 | event.preventDefault();
|
32 | } })), {});
|
33 | const getDefaultTabIdx = () => {
|
34 | if (isDisabled) {
|
35 | return isButtonElement ? null : -1;
|
36 | }
|
37 | else if (isAriaDisabled) {
|
38 | return null;
|
39 | }
|
40 | else if (isInlineSpan) {
|
41 | return 0;
|
42 | }
|
43 | };
|
44 | return (React.createElement(Component, Object.assign({}, props, (isAriaDisabled ? preventedEvents : null), { "aria-disabled": isDisabled || isAriaDisabled, "aria-label": ariaLabel, className: css(styles.button, styles.modifiers[variant], isBlock && styles.modifiers.block, isDisabled && styles.modifiers.disabled, isAriaDisabled && styles.modifiers.ariaDisabled, isActive && styles.modifiers.active, isInline && variant === ButtonVariant.link && styles.modifiers.inline, isDanger && (variant === ButtonVariant.secondary || variant === ButtonVariant.link) && styles.modifiers.danger, isLoading !== null && children !== null && styles.modifiers.progress, isLoading && styles.modifiers.inProgress, isSmall && styles.modifiers.small, isLarge && styles.modifiers.displayLg, className), disabled: isButtonElement ? isDisabled : null, tabIndex: tabIndex !== null ? tabIndex : getDefaultTabIdx(), type: isButtonElement || isInlineSpan ? type : null, role: isInlineSpan ? 'button' : null, ref: innerRef }, ouiaProps),
|
45 | isLoading && (React.createElement("span", { className: css(styles.buttonProgress) },
|
46 | React.createElement(Spinner, { size: spinnerSize.md, "aria-valuetext": spinnerAriaValueText, "aria-label": spinnerAriaLabel, "aria-labelledby": spinnerAriaLabelledBy }))),
|
47 | variant === ButtonVariant.plain && children === null && icon ? icon : null,
|
48 | variant !== ButtonVariant.plain && icon && iconPosition === 'left' && (React.createElement("span", { className: css(styles.buttonIcon, styles.modifiers.start) }, icon)),
|
49 | children,
|
50 | variant !== ButtonVariant.plain && icon && iconPosition === 'right' && (React.createElement("span", { className: css(styles.buttonIcon, styles.modifiers.end) }, icon))));
|
51 | };
|
52 | export const Button = React.forwardRef((props, ref) => (React.createElement(ButtonBase, Object.assign({ innerRef: ref }, props))));
|
53 | Button.displayName = 'Button';
|
54 |
|
\ | No newline at end of file |