1 | 'use client';
|
2 |
|
3 |
|
4 | import * as React from 'react';
|
5 | import PropTypes from 'prop-types';
|
6 | import clsx from 'clsx';
|
7 | import composeClasses from '@mui/utils/composeClasses';
|
8 | import { useRtl } from '@mui/system/RtlProvider';
|
9 | import useSlotProps from '@mui/utils/useSlotProps';
|
10 | import KeyboardArrowLeft from "../internal/svg-icons/KeyboardArrowLeft.js";
|
11 | import KeyboardArrowRight from "../internal/svg-icons/KeyboardArrowRight.js";
|
12 | import ButtonBase from "../ButtonBase/index.js";
|
13 | import { styled } from "../zero-styled/index.js";
|
14 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
15 | import tabScrollButtonClasses, { getTabScrollButtonUtilityClass } from "./tabScrollButtonClasses.js";
|
16 | import { jsx as _jsx } from "react/jsx-runtime";
|
17 | const useUtilityClasses = ownerState => {
|
18 | const {
|
19 | classes,
|
20 | orientation,
|
21 | disabled
|
22 | } = ownerState;
|
23 | const slots = {
|
24 | root: ['root', orientation, disabled && 'disabled']
|
25 | };
|
26 | return composeClasses(slots, getTabScrollButtonUtilityClass, classes);
|
27 | };
|
28 | const TabScrollButtonRoot = styled(ButtonBase, {
|
29 | name: 'MuiTabScrollButton',
|
30 | slot: 'Root',
|
31 | overridesResolver: (props, styles) => {
|
32 | const {
|
33 | ownerState
|
34 | } = props;
|
35 | return [styles.root, ownerState.orientation && styles[ownerState.orientation]];
|
36 | }
|
37 | })({
|
38 | width: 40,
|
39 | flexShrink: 0,
|
40 | opacity: 0.8,
|
41 | [`&.${tabScrollButtonClasses.disabled}`]: {
|
42 | opacity: 0
|
43 | },
|
44 | variants: [{
|
45 | props: {
|
46 | orientation: 'vertical'
|
47 | },
|
48 | style: {
|
49 | width: '100%',
|
50 | height: 40,
|
51 | '& svg': {
|
52 | transform: 'var(--TabScrollButton-svgRotate)'
|
53 | }
|
54 | }
|
55 | }]
|
56 | });
|
57 | const TabScrollButton = React.forwardRef(function TabScrollButton(inProps, ref) {
|
58 | const props = useDefaultProps({
|
59 | props: inProps,
|
60 | name: 'MuiTabScrollButton'
|
61 | });
|
62 | const {
|
63 | className,
|
64 | slots = {},
|
65 | slotProps = {},
|
66 | direction,
|
67 | orientation,
|
68 | disabled,
|
69 | ...other
|
70 | } = props;
|
71 | const isRtl = useRtl();
|
72 | const ownerState = {
|
73 | isRtl,
|
74 | ...props
|
75 | };
|
76 | const classes = useUtilityClasses(ownerState);
|
77 | const StartButtonIcon = slots.StartScrollButtonIcon ?? KeyboardArrowLeft;
|
78 | const EndButtonIcon = slots.EndScrollButtonIcon ?? KeyboardArrowRight;
|
79 | const startButtonIconProps = useSlotProps({
|
80 | elementType: StartButtonIcon,
|
81 | externalSlotProps: slotProps.startScrollButtonIcon,
|
82 | additionalProps: {
|
83 | fontSize: 'small'
|
84 | },
|
85 | ownerState
|
86 | });
|
87 | const endButtonIconProps = useSlotProps({
|
88 | elementType: EndButtonIcon,
|
89 | externalSlotProps: slotProps.endScrollButtonIcon,
|
90 | additionalProps: {
|
91 | fontSize: 'small'
|
92 | },
|
93 | ownerState
|
94 | });
|
95 | return _jsx(TabScrollButtonRoot, {
|
96 | component: "div",
|
97 | className: clsx(classes.root, className),
|
98 | ref: ref,
|
99 | role: null,
|
100 | ownerState: ownerState,
|
101 | tabIndex: null,
|
102 | ...other,
|
103 | style: {
|
104 | ...other.style,
|
105 | ...(orientation === 'vertical' && {
|
106 | '--TabScrollButton-svgRotate': `rotate(${isRtl ? -90 : 90}deg)`
|
107 | })
|
108 | },
|
109 | children: direction === 'left' ? _jsx(StartButtonIcon, {
|
110 | ...startButtonIconProps
|
111 | }) : _jsx(EndButtonIcon, {
|
112 | ...endButtonIconProps
|
113 | })
|
114 | });
|
115 | });
|
116 | process.env.NODE_ENV !== "production" ? TabScrollButton.propTypes = {
|
117 |
|
118 |
|
119 |
|
120 |
|
121 | |
122 |
|
123 |
|
124 | children: PropTypes.node,
|
125 | |
126 |
|
127 |
|
128 | classes: PropTypes.object,
|
129 | |
130 |
|
131 |
|
132 | className: PropTypes.string,
|
133 | |
134 |
|
135 |
|
136 | direction: PropTypes.oneOf(['left', 'right']).isRequired,
|
137 | |
138 |
|
139 |
|
140 |
|
141 | disabled: PropTypes.bool,
|
142 | |
143 |
|
144 |
|
145 | orientation: PropTypes.oneOf(['horizontal', 'vertical']).isRequired,
|
146 | |
147 |
|
148 |
|
149 |
|
150 |
|
151 | slotProps: PropTypes.shape({
|
152 | endScrollButtonIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
153 | startScrollButtonIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
154 | }),
|
155 | |
156 |
|
157 |
|
158 |
|
159 | slots: PropTypes.shape({
|
160 | EndScrollButtonIcon: PropTypes.elementType,
|
161 | StartScrollButtonIcon: PropTypes.elementType
|
162 | }),
|
163 | |
164 |
|
165 |
|
166 | style: PropTypes.object,
|
167 | |
168 |
|
169 |
|
170 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
171 | } : void 0;
|
172 | export default TabScrollButton; |
\ | No newline at end of file |