UNPKG

4.08 kBJavaScriptView Raw
1'use client';
2
3import * as React from 'react';
4import PropTypes from 'prop-types';
5import clsx from 'clsx';
6import composeClasses from '@mui/utils/composeClasses';
7import { styled } from "../zero-styled/index.js";
8import { useDefaultProps } from "../DefaultPropsProvider/index.js";
9import ButtonBase from "../ButtonBase/index.js";
10import StepLabel from "../StepLabel/index.js";
11import isMuiElement from "../utils/isMuiElement.js";
12import StepperContext from "../Stepper/StepperContext.js";
13import StepContext from "../Step/StepContext.js";
14import stepButtonClasses, { getStepButtonUtilityClass } from "./stepButtonClasses.js";
15import { jsx as _jsx } from "react/jsx-runtime";
16const useUtilityClasses = ownerState => {
17 const {
18 classes,
19 orientation
20 } = ownerState;
21 const slots = {
22 root: ['root', orientation],
23 touchRipple: ['touchRipple']
24 };
25 return composeClasses(slots, getStepButtonUtilityClass, classes);
26};
27const StepButtonRoot = styled(ButtonBase, {
28 name: 'MuiStepButton',
29 slot: 'Root',
30 overridesResolver: (props, styles) => {
31 const {
32 ownerState
33 } = props;
34 return [{
35 [`& .${stepButtonClasses.touchRipple}`]: styles.touchRipple
36 }, styles.root, styles[ownerState.orientation]];
37 }
38})({
39 width: '100%',
40 padding: '24px 16px',
41 margin: '-24px -16px',
42 boxSizing: 'content-box',
43 [`& .${stepButtonClasses.touchRipple}`]: {
44 color: 'rgba(0, 0, 0, 0.3)'
45 },
46 variants: [{
47 props: {
48 orientation: 'vertical'
49 },
50 style: {
51 justifyContent: 'flex-start',
52 padding: '8px',
53 margin: '-8px'
54 }
55 }]
56});
57const StepButton = /*#__PURE__*/React.forwardRef(function StepButton(inProps, ref) {
58 const props = useDefaultProps({
59 props: inProps,
60 name: 'MuiStepButton'
61 });
62 const {
63 children,
64 className,
65 icon,
66 optional,
67 ...other
68 } = props;
69 const {
70 disabled,
71 active
72 } = React.useContext(StepContext);
73 const {
74 orientation
75 } = React.useContext(StepperContext);
76 const ownerState = {
77 ...props,
78 orientation
79 };
80 const classes = useUtilityClasses(ownerState);
81 const childProps = {
82 icon,
83 optional
84 };
85 const child = isMuiElement(children, ['StepLabel']) ? (/*#__PURE__*/React.cloneElement(children, childProps)) : /*#__PURE__*/_jsx(StepLabel, {
86 ...childProps,
87 children: children
88 });
89 return /*#__PURE__*/_jsx(StepButtonRoot, {
90 focusRipple: true,
91 disabled: disabled,
92 TouchRippleProps: {
93 className: classes.touchRipple
94 },
95 className: clsx(classes.root, className),
96 ref: ref,
97 ownerState: ownerState,
98 "aria-current": active ? 'step' : undefined,
99 ...other,
100 children: child
101 });
102});
103process.env.NODE_ENV !== "production" ? StepButton.propTypes /* remove-proptypes */ = {
104 // ┌────────────────────────────── Warning ──────────────────────────────┐
105 // │ These PropTypes are generated from the TypeScript type definitions. │
106 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
107 // └─────────────────────────────────────────────────────────────────────┘
108 /**
109 * Can be a `StepLabel` or a node to place inside `StepLabel` as children.
110 */
111 children: PropTypes.node,
112 /**
113 * Override or extend the styles applied to the component.
114 */
115 classes: PropTypes.object,
116 /**
117 * @ignore
118 */
119 className: PropTypes.string,
120 /**
121 * The icon displayed by the step label.
122 */
123 icon: PropTypes.node,
124 /**
125 * The optional node to display.
126 */
127 optional: PropTypes.node,
128 /**
129 * The system prop that allows defining system overrides as well as additional CSS styles.
130 */
131 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
132} : void 0;
133export default StepButton;
\No newline at end of file