-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
/
Copy pathTabScrollButton.js
182 lines (167 loc) · 5.17 KB
/
TabScrollButton.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
'use client';
/* eslint-disable jsx-a11y/aria-role */
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import composeClasses from '@mui/utils/composeClasses';
import { useRtl } from '@mui/system/RtlProvider';
import useSlotProps from '@mui/utils/useSlotProps';
import KeyboardArrowLeft from '../internal/svg-icons/KeyboardArrowLeft';
import KeyboardArrowRight from '../internal/svg-icons/KeyboardArrowRight';
import ButtonBase from '../ButtonBase';
import { styled } from '../zero-styled';
import { useDefaultProps } from '../DefaultPropsProvider';
import tabScrollButtonClasses, { getTabScrollButtonUtilityClass } from './tabScrollButtonClasses';
const useUtilityClasses = (ownerState) => {
const { classes, orientation, disabled } = ownerState;
const slots = {
root: ['root', orientation, disabled && 'disabled'],
};
return composeClasses(slots, getTabScrollButtonUtilityClass, classes);
};
const TabScrollButtonRoot = styled(ButtonBase, {
name: 'MuiTabScrollButton',
slot: 'Root',
overridesResolver: (props, styles) => {
const { ownerState } = props;
return [styles.root, ownerState.orientation && styles[ownerState.orientation]];
},
})({
width: 40,
flexShrink: 0,
opacity: 0.8,
[`&.${tabScrollButtonClasses.disabled}`]: {
opacity: 0,
},
variants: [
{
props: {
orientation: 'vertical',
},
style: {
width: '100%',
height: 40,
'& svg': {
transform: 'var(--TabScrollButton-svgRotate)',
},
},
},
],
});
const TabScrollButton = React.forwardRef(function TabScrollButton(inProps, ref) {
const props = useDefaultProps({ props: inProps, name: 'MuiTabScrollButton' });
const {
className,
slots = {},
slotProps = {},
direction,
orientation,
disabled,
...other
} = props;
const isRtl = useRtl();
const ownerState = { isRtl, ...props };
const classes = useUtilityClasses(ownerState);
const StartButtonIcon = slots.StartScrollButtonIcon ?? KeyboardArrowLeft;
const EndButtonIcon = slots.EndScrollButtonIcon ?? KeyboardArrowRight;
const startButtonIconProps = useSlotProps({
elementType: StartButtonIcon,
externalSlotProps: slotProps.startScrollButtonIcon,
additionalProps: {
fontSize: 'small',
},
ownerState,
});
const endButtonIconProps = useSlotProps({
elementType: EndButtonIcon,
externalSlotProps: slotProps.endScrollButtonIcon,
additionalProps: {
fontSize: 'small',
},
ownerState,
});
return (
<TabScrollButtonRoot
component="div"
className={clsx(classes.root, className)}
ref={ref}
role={null}
ownerState={ownerState}
tabIndex={null}
{...other}
style={{
...other.style,
...(orientation === 'vertical' && {
'--TabScrollButton-svgRotate': `rotate(${isRtl ? -90 : 90}deg)`,
}),
}}
>
{direction === 'left' ? (
<StartButtonIcon {...startButtonIconProps} />
) : (
<EndButtonIcon {...endButtonIconProps} />
)}
</TabScrollButtonRoot>
);
});
TabScrollButton.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the d.ts file and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* The content of the component.
*/
children: PropTypes.node,
/**
* Override or extend the styles applied to the component.
*/
classes: PropTypes.object,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The direction the button should indicate.
*/
direction: PropTypes.oneOf(['left', 'right']).isRequired,
/**
* If `true`, the component is disabled.
* @default false
*/
disabled: PropTypes.bool,
/**
* The component orientation (layout flow direction).
*/
orientation: PropTypes.oneOf(['horizontal', 'vertical']).isRequired,
/**
* The extra props for the slot components.
* You can override the existing props or add new ones.
* @default {}
*/
slotProps: PropTypes.shape({
endScrollButtonIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
startScrollButtonIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
}),
/**
* The components used for each slot inside.
* @default {}
*/
slots: PropTypes.shape({
EndScrollButtonIcon: PropTypes.elementType,
StartScrollButtonIcon: PropTypes.elementType,
}),
/**
* @ignore
*/
style: PropTypes.object,
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])),
PropTypes.func,
PropTypes.object,
]),
};
export default TabScrollButton;