UNPKG

5.39 kBJavaScriptView Raw
1'use client';
2
3/* eslint-disable jsx-a11y/aria-role */
4import * as React from 'react';
5import PropTypes from 'prop-types';
6import clsx from 'clsx';
7import composeClasses from '@mui/utils/composeClasses';
8import { useRtl } from '@mui/system/RtlProvider';
9import useSlotProps from '@mui/utils/useSlotProps';
10import KeyboardArrowLeft from "../internal/svg-icons/KeyboardArrowLeft.js";
11import KeyboardArrowRight from "../internal/svg-icons/KeyboardArrowRight.js";
12import ButtonBase from "../ButtonBase/index.js";
13import { styled } from "../zero-styled/index.js";
14import { useDefaultProps } from "../DefaultPropsProvider/index.js";
15import tabScrollButtonClasses, { getTabScrollButtonUtilityClass } from "./tabScrollButtonClasses.js";
16import { jsx as _jsx } from "react/jsx-runtime";
17const 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};
28const 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});
57const TabScrollButton = /*#__PURE__*/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 /*#__PURE__*/_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' ? /*#__PURE__*/_jsx(StartButtonIcon, {
110 ...startButtonIconProps
111 }) : /*#__PURE__*/_jsx(EndButtonIcon, {
112 ...endButtonIconProps
113 })
114 });
115});
116process.env.NODE_ENV !== "production" ? TabScrollButton.propTypes /* remove-proptypes */ = {
117 // ┌────────────────────────────── Warning ──────────────────────────────┐
118 // │ These PropTypes are generated from the TypeScript type definitions. │
119 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
120 // └─────────────────────────────────────────────────────────────────────┘
121 /**
122 * The content of the component.
123 */
124 children: PropTypes.node,
125 /**
126 * Override or extend the styles applied to the component.
127 */
128 classes: PropTypes.object,
129 /**
130 * @ignore
131 */
132 className: PropTypes.string,
133 /**
134 * The direction the button should indicate.
135 */
136 direction: PropTypes.oneOf(['left', 'right']).isRequired,
137 /**
138 * If `true`, the component is disabled.
139 * @default false
140 */
141 disabled: PropTypes.bool,
142 /**
143 * The component orientation (layout flow direction).
144 */
145 orientation: PropTypes.oneOf(['horizontal', 'vertical']).isRequired,
146 /**
147 * The extra props for the slot components.
148 * You can override the existing props or add new ones.
149 * @default {}
150 */
151 slotProps: PropTypes.shape({
152 endScrollButtonIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
153 startScrollButtonIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
154 }),
155 /**
156 * The components used for each slot inside.
157 * @default {}
158 */
159 slots: PropTypes.shape({
160 EndScrollButtonIcon: PropTypes.elementType,
161 StartScrollButtonIcon: PropTypes.elementType
162 }),
163 /**
164 * @ignore
165 */
166 style: PropTypes.object,
167 /**
168 * The system prop that allows defining system overrides as well as additional CSS styles.
169 */
170 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
171} : void 0;
172export default TabScrollButton;
\No newline at end of file