1 | 'use client';
|
2 |
|
3 | import composeClasses from '@mui/utils/composeClasses';
|
4 | import clsx from 'clsx';
|
5 | import PropTypes from 'prop-types';
|
6 | import * as React from 'react';
|
7 | import ButtonBase from "../ButtonBase/index.js";
|
8 | import ArrowDownwardIcon from "../internal/svg-icons/ArrowDownward.js";
|
9 | import { styled } from "../zero-styled/index.js";
|
10 | import memoTheme from "../utils/memoTheme.js";
|
11 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
12 | import capitalize from "../utils/capitalize.js";
|
13 | import tableSortLabelClasses, { getTableSortLabelUtilityClass } from "./tableSortLabelClasses.js";
|
14 | import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
15 | const useUtilityClasses = ownerState => {
|
16 | const {
|
17 | classes,
|
18 | direction,
|
19 | active
|
20 | } = ownerState;
|
21 | const slots = {
|
22 | root: ['root', active && 'active', `direction${capitalize(direction)}`],
|
23 | icon: ['icon', `iconDirection${capitalize(direction)}`]
|
24 | };
|
25 | return composeClasses(slots, getTableSortLabelUtilityClass, classes);
|
26 | };
|
27 | const TableSortLabelRoot = styled(ButtonBase, {
|
28 | name: 'MuiTableSortLabel',
|
29 | slot: 'Root',
|
30 | overridesResolver: (props, styles) => {
|
31 | const {
|
32 | ownerState
|
33 | } = props;
|
34 | return [styles.root, ownerState.active && styles.active];
|
35 | }
|
36 | })(memoTheme(({
|
37 | theme
|
38 | }) => ({
|
39 | cursor: 'pointer',
|
40 | display: 'inline-flex',
|
41 | justifyContent: 'flex-start',
|
42 | flexDirection: 'inherit',
|
43 | alignItems: 'center',
|
44 | '&:focus': {
|
45 | color: (theme.vars || theme).palette.text.secondary
|
46 | },
|
47 | '&:hover': {
|
48 | color: (theme.vars || theme).palette.text.secondary,
|
49 | [`& .${tableSortLabelClasses.icon}`]: {
|
50 | opacity: 0.5
|
51 | }
|
52 | },
|
53 | [`&.${tableSortLabelClasses.active}`]: {
|
54 | color: (theme.vars || theme).palette.text.primary,
|
55 | [`& .${tableSortLabelClasses.icon}`]: {
|
56 | opacity: 1,
|
57 | color: (theme.vars || theme).palette.text.secondary
|
58 | }
|
59 | }
|
60 | })));
|
61 | const TableSortLabelIcon = styled('span', {
|
62 | name: 'MuiTableSortLabel',
|
63 | slot: 'Icon',
|
64 | overridesResolver: (props, styles) => {
|
65 | const {
|
66 | ownerState
|
67 | } = props;
|
68 | return [styles.icon, styles[`iconDirection${capitalize(ownerState.direction)}`]];
|
69 | }
|
70 | })(memoTheme(({
|
71 | theme
|
72 | }) => ({
|
73 | fontSize: 18,
|
74 | marginRight: 4,
|
75 | marginLeft: 4,
|
76 | opacity: 0,
|
77 | transition: theme.transitions.create(['opacity', 'transform'], {
|
78 | duration: theme.transitions.duration.shorter
|
79 | }),
|
80 | userSelect: 'none',
|
81 | variants: [{
|
82 | props: {
|
83 | direction: 'desc'
|
84 | },
|
85 | style: {
|
86 | transform: 'rotate(0deg)'
|
87 | }
|
88 | }, {
|
89 | props: {
|
90 | direction: 'asc'
|
91 | },
|
92 | style: {
|
93 | transform: 'rotate(180deg)'
|
94 | }
|
95 | }]
|
96 | })));
|
97 |
|
98 |
|
99 |
|
100 |
|
101 | const TableSortLabel = React.forwardRef(function TableSortLabel(inProps, ref) {
|
102 | const props = useDefaultProps({
|
103 | props: inProps,
|
104 | name: 'MuiTableSortLabel'
|
105 | });
|
106 | const {
|
107 | active = false,
|
108 | children,
|
109 | className,
|
110 | direction = 'asc',
|
111 | hideSortIcon = false,
|
112 | IconComponent = ArrowDownwardIcon,
|
113 | ...other
|
114 | } = props;
|
115 | const ownerState = {
|
116 | ...props,
|
117 | active,
|
118 | direction,
|
119 | hideSortIcon,
|
120 | IconComponent
|
121 | };
|
122 | const classes = useUtilityClasses(ownerState);
|
123 | return _jsxs(TableSortLabelRoot, {
|
124 | className: clsx(classes.root, className),
|
125 | component: "span",
|
126 | disableRipple: true,
|
127 | ownerState: ownerState,
|
128 | ref: ref,
|
129 | ...other,
|
130 | children: [children, hideSortIcon && !active ? null : _jsx(TableSortLabelIcon, {
|
131 | as: IconComponent,
|
132 | className: clsx(classes.icon),
|
133 | ownerState: ownerState
|
134 | })]
|
135 | });
|
136 | });
|
137 | process.env.NODE_ENV !== "production" ? TableSortLabel.propTypes = {
|
138 |
|
139 |
|
140 |
|
141 |
|
142 | |
143 |
|
144 |
|
145 |
|
146 | active: PropTypes.bool,
|
147 | |
148 |
|
149 |
|
150 | children: PropTypes.node,
|
151 | |
152 |
|
153 |
|
154 | classes: PropTypes.object,
|
155 | |
156 |
|
157 |
|
158 | className: PropTypes.string,
|
159 | |
160 |
|
161 |
|
162 |
|
163 | direction: PropTypes.oneOf(['asc', 'desc']),
|
164 | |
165 |
|
166 |
|
167 |
|
168 | hideSortIcon: PropTypes.bool,
|
169 | |
170 |
|
171 |
|
172 |
|
173 | IconComponent: PropTypes.elementType,
|
174 | |
175 |
|
176 |
|
177 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
178 | } : void 0;
|
179 | export default TableSortLabel; |
\ | No newline at end of file |