1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import composeClasses from '../composeClasses';
|
6 | import { getButtonUtilityClass } from './buttonClasses';
|
7 | import useButton from '../useButton';
|
8 | import { useSlotProps } from '../utils';
|
9 | import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
10 | import { jsx as _jsx } from "react/jsx-runtime";
|
11 | var useUtilityClasses = function useUtilityClasses(ownerState) {
|
12 | var active = ownerState.active,
|
13 | disabled = ownerState.disabled,
|
14 | focusVisible = ownerState.focusVisible;
|
15 | var slots = {
|
16 | root: ['root', disabled && 'disabled', focusVisible && 'focusVisible', active && 'active']
|
17 | };
|
18 | return composeClasses(slots, useClassNamesOverride(getButtonUtilityClass));
|
19 | };
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | var Button = React.forwardRef(function Button(props, forwardedRef) {
|
32 | var _slots$root;
|
33 | var action = props.action,
|
34 | children = props.children,
|
35 | disabled = props.disabled,
|
36 | _props$focusableWhenD = props.focusableWhenDisabled,
|
37 | focusableWhenDisabled = _props$focusableWhenD === void 0 ? false : _props$focusableWhenD,
|
38 | onFocusVisible = props.onFocusVisible,
|
39 | _props$slotProps = props.slotProps,
|
40 | slotProps = _props$slotProps === void 0 ? {} : _props$slotProps,
|
41 | _props$slots = props.slots,
|
42 | slots = _props$slots === void 0 ? {} : _props$slots,
|
43 | other = _objectWithoutProperties(props, ["action", "children", "disabled", "focusableWhenDisabled", "onFocusVisible", "slotProps", "slots"]);
|
44 | var buttonRef = React.useRef();
|
45 | var _useButton = useButton(_extends({}, props, {
|
46 | focusableWhenDisabled: focusableWhenDisabled
|
47 | })),
|
48 | active = _useButton.active,
|
49 | focusVisible = _useButton.focusVisible,
|
50 | setFocusVisible = _useButton.setFocusVisible,
|
51 | getRootProps = _useButton.getRootProps;
|
52 | React.useImperativeHandle(action, function () {
|
53 | return {
|
54 | focusVisible: function focusVisible() {
|
55 | setFocusVisible(true);
|
56 | buttonRef.current.focus();
|
57 | }
|
58 | };
|
59 | }, [setFocusVisible]);
|
60 | var ownerState = _extends({}, props, {
|
61 | active: active,
|
62 | focusableWhenDisabled: focusableWhenDisabled,
|
63 | focusVisible: focusVisible
|
64 | });
|
65 | var classes = useUtilityClasses(ownerState);
|
66 | var defaultElement = other.href || other.to ? 'a' : 'button';
|
67 | var Root = (_slots$root = slots.root) != null ? _slots$root : defaultElement;
|
68 | var rootProps = useSlotProps({
|
69 | elementType: Root,
|
70 | getSlotProps: getRootProps,
|
71 | externalForwardedProps: other,
|
72 | externalSlotProps: slotProps.root,
|
73 | additionalProps: {
|
74 | ref: forwardedRef
|
75 | },
|
76 | ownerState: ownerState,
|
77 | className: classes.root
|
78 | });
|
79 | return _jsx(Root, _extends({}, rootProps, {
|
80 | children: children
|
81 | }));
|
82 | });
|
83 | process.env.NODE_ENV !== "production" ? Button.propTypes = {
|
84 |
|
85 |
|
86 |
|
87 |
|
88 | |
89 |
|
90 |
|
91 | action: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
92 | current: PropTypes.shape({
|
93 | focusVisible: PropTypes.func.isRequired
|
94 | })
|
95 | })]),
|
96 | |
97 |
|
98 |
|
99 | children: PropTypes.node,
|
100 | |
101 |
|
102 |
|
103 |
|
104 | disabled: PropTypes.bool,
|
105 | |
106 |
|
107 |
|
108 |
|
109 | focusableWhenDisabled: PropTypes.bool,
|
110 | |
111 |
|
112 |
|
113 | href: PropTypes.string,
|
114 | |
115 |
|
116 |
|
117 | onFocusVisible: PropTypes.func,
|
118 | |
119 |
|
120 |
|
121 |
|
122 | slotProps: PropTypes.shape({
|
123 | root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
124 | }),
|
125 | |
126 |
|
127 |
|
128 |
|
129 |
|
130 | slots: PropTypes.shape({
|
131 | root: PropTypes.elementType
|
132 | }),
|
133 | |
134 |
|
135 |
|
136 | to: PropTypes.string
|
137 | } : void 0;
|
138 | export default Button; |
\ | No newline at end of file |