UNPKG

6.23 kBJavaScriptView Raw
1'use client';
2
3import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4import _extends from "@babel/runtime/helpers/esm/extends";
5import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
6import composeClasses from '@mui/utils/composeClasses';
7import clsx from 'clsx';
8import PropTypes from 'prop-types';
9import * as React from 'react';
10import ButtonBase from '../ButtonBase';
11import ArrowDownwardIcon from '../internal/svg-icons/ArrowDownward';
12import styled from '../styles/styled';
13import { useDefaultProps } from '../DefaultPropsProvider';
14import capitalize from '../utils/capitalize';
15import tableSortLabelClasses, { getTableSortLabelUtilityClass } from './tableSortLabelClasses';
16import { jsx as _jsx } from "react/jsx-runtime";
17import { jsxs as _jsxs } from "react/jsx-runtime";
18var useUtilityClasses = function useUtilityClasses(ownerState) {
19 var classes = ownerState.classes,
20 direction = ownerState.direction,
21 active = ownerState.active;
22 var slots = {
23 root: ['root', active && 'active'],
24 icon: ['icon', "iconDirection".concat(capitalize(direction))]
25 };
26 return composeClasses(slots, getTableSortLabelUtilityClass, classes);
27};
28var TableSortLabelRoot = styled(ButtonBase, {
29 name: 'MuiTableSortLabel',
30 slot: 'Root',
31 overridesResolver: function overridesResolver(props, styles) {
32 var ownerState = props.ownerState;
33 return [styles.root, ownerState.active && styles.active];
34 }
35})(function (_ref) {
36 var theme = _ref.theme;
37 return _defineProperty({
38 cursor: 'pointer',
39 display: 'inline-flex',
40 justifyContent: 'flex-start',
41 flexDirection: 'inherit',
42 alignItems: 'center',
43 '&:focus': {
44 color: (theme.vars || theme).palette.text.secondary
45 },
46 '&:hover': _defineProperty({
47 color: (theme.vars || theme).palette.text.secondary
48 }, "& .".concat(tableSortLabelClasses.icon), {
49 opacity: 0.5
50 })
51 }, "&.".concat(tableSortLabelClasses.active), _defineProperty({
52 color: (theme.vars || theme).palette.text.primary
53 }, "& .".concat(tableSortLabelClasses.icon), {
54 opacity: 1,
55 color: (theme.vars || theme).palette.text.secondary
56 }));
57});
58var TableSortLabelIcon = styled('span', {
59 name: 'MuiTableSortLabel',
60 slot: 'Icon',
61 overridesResolver: function overridesResolver(props, styles) {
62 var ownerState = props.ownerState;
63 return [styles.icon, styles["iconDirection".concat(capitalize(ownerState.direction))]];
64 }
65})(function (_ref3) {
66 var theme = _ref3.theme,
67 ownerState = _ref3.ownerState;
68 return _extends({
69 fontSize: 18,
70 marginRight: 4,
71 marginLeft: 4,
72 opacity: 0,
73 transition: theme.transitions.create(['opacity', 'transform'], {
74 duration: theme.transitions.duration.shorter
75 }),
76 userSelect: 'none'
77 }, ownerState.direction === 'desc' && {
78 transform: 'rotate(0deg)'
79 }, ownerState.direction === 'asc' && {
80 transform: 'rotate(180deg)'
81 });
82});
83
84/**
85 * A button based label for placing inside `TableCell` for column sorting.
86 */
87var TableSortLabel = /*#__PURE__*/React.forwardRef(function TableSortLabel(inProps, ref) {
88 var props = useDefaultProps({
89 props: inProps,
90 name: 'MuiTableSortLabel'
91 });
92 var _props$active = props.active,
93 active = _props$active === void 0 ? false : _props$active,
94 children = props.children,
95 className = props.className,
96 _props$direction = props.direction,
97 direction = _props$direction === void 0 ? 'asc' : _props$direction,
98 _props$hideSortIcon = props.hideSortIcon,
99 hideSortIcon = _props$hideSortIcon === void 0 ? false : _props$hideSortIcon,
100 _props$IconComponent = props.IconComponent,
101 IconComponent = _props$IconComponent === void 0 ? ArrowDownwardIcon : _props$IconComponent,
102 other = _objectWithoutProperties(props, ["active", "children", "className", "direction", "hideSortIcon", "IconComponent"]);
103 var ownerState = _extends({}, props, {
104 active: active,
105 direction: direction,
106 hideSortIcon: hideSortIcon,
107 IconComponent: IconComponent
108 });
109 var classes = useUtilityClasses(ownerState);
110 return /*#__PURE__*/_jsxs(TableSortLabelRoot, _extends({
111 className: clsx(classes.root, className),
112 component: "span",
113 disableRipple: true,
114 ownerState: ownerState,
115 ref: ref
116 }, other, {
117 children: [children, hideSortIcon && !active ? null : /*#__PURE__*/_jsx(TableSortLabelIcon, {
118 as: IconComponent,
119 className: clsx(classes.icon),
120 ownerState: ownerState
121 })]
122 }));
123});
124process.env.NODE_ENV !== "production" ? TableSortLabel.propTypes /* remove-proptypes */ = {
125 // ┌────────────────────────────── Warning ──────────────────────────────┐
126 // │ These PropTypes are generated from the TypeScript type definitions. │
127 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
128 // └─────────────────────────────────────────────────────────────────────┘
129 /**
130 * If `true`, the label will have the active styling (should be true for the sorted column).
131 * @default false
132 */
133 active: PropTypes.bool,
134 /**
135 * Label contents, the arrow will be appended automatically.
136 */
137 children: PropTypes.node,
138 /**
139 * Override or extend the styles applied to the component.
140 */
141 classes: PropTypes.object,
142 /**
143 * @ignore
144 */
145 className: PropTypes.string,
146 /**
147 * The current sort direction.
148 * @default 'asc'
149 */
150 direction: PropTypes.oneOf(['asc', 'desc']),
151 /**
152 * Hide sort icon when active is false.
153 * @default false
154 */
155 hideSortIcon: PropTypes.bool,
156 /**
157 * Sort icon to use.
158 * @default ArrowDownwardIcon
159 */
160 IconComponent: PropTypes.elementType,
161 /**
162 * The system prop that allows defining system overrides as well as additional CSS styles.
163 */
164 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
165} : void 0;
166export default TableSortLabel;
\No newline at end of file