UNPKG

5.32 kBJavaScriptView Raw
1'use client';
2
3import composeClasses from '@mui/utils/composeClasses';
4import clsx from 'clsx';
5import PropTypes from 'prop-types';
6import * as React from 'react';
7import ButtonBase from "../ButtonBase/index.js";
8import ArrowDownwardIcon from "../internal/svg-icons/ArrowDownward.js";
9import { styled } from "../zero-styled/index.js";
10import memoTheme from "../utils/memoTheme.js";
11import { useDefaultProps } from "../DefaultPropsProvider/index.js";
12import capitalize from "../utils/capitalize.js";
13import tableSortLabelClasses, { getTableSortLabelUtilityClass } from "./tableSortLabelClasses.js";
14import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
15const 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};
27const 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})));
61const 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 * A button based label for placing inside `TableCell` for column sorting.
100 */
101const TableSortLabel = /*#__PURE__*/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 /*#__PURE__*/_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 : /*#__PURE__*/_jsx(TableSortLabelIcon, {
131 as: IconComponent,
132 className: clsx(classes.icon),
133 ownerState: ownerState
134 })]
135 });
136});
137process.env.NODE_ENV !== "production" ? TableSortLabel.propTypes /* remove-proptypes */ = {
138 // ┌────────────────────────────── Warning ──────────────────────────────┐
139 // │ These PropTypes are generated from the TypeScript type definitions. │
140 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
141 // └─────────────────────────────────────────────────────────────────────┘
142 /**
143 * If `true`, the label will have the active styling (should be true for the sorted column).
144 * @default false
145 */
146 active: PropTypes.bool,
147 /**
148 * Label contents, the arrow will be appended automatically.
149 */
150 children: PropTypes.node,
151 /**
152 * Override or extend the styles applied to the component.
153 */
154 classes: PropTypes.object,
155 /**
156 * @ignore
157 */
158 className: PropTypes.string,
159 /**
160 * The current sort direction.
161 * @default 'asc'
162 */
163 direction: PropTypes.oneOf(['asc', 'desc']),
164 /**
165 * Hide sort icon when active is false.
166 * @default false
167 */
168 hideSortIcon: PropTypes.bool,
169 /**
170 * Sort icon to use.
171 * @default ArrowDownwardIcon
172 */
173 IconComponent: PropTypes.elementType,
174 /**
175 * The system prop that allows defining system overrides as well as additional CSS styles.
176 */
177 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
178} : void 0;
179export default TableSortLabel;
\No newline at end of file