UNPKG

4.79 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
5var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
7Object.defineProperty(exports, "__esModule", {
8 value: true
9});
10exports.default = exports.styles = void 0;
11
12var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
14var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
15
16var React = _interopRequireWildcard(require("react"));
17
18var _propTypes = _interopRequireDefault(require("prop-types"));
19
20var _clsx = _interopRequireDefault(require("clsx"));
21
22var _ArrowDownward = _interopRequireDefault(require("../internal/svg-icons/ArrowDownward"));
23
24var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
25
26var _ButtonBase = _interopRequireDefault(require("../ButtonBase"));
27
28var _capitalize = _interopRequireDefault(require("../utils/capitalize"));
29
30var styles = function styles(theme) {
31 return {
32 /* Styles applied to the root element. */
33 root: {
34 cursor: 'pointer',
35 display: 'inline-flex',
36 justifyContent: 'flex-start',
37 flexDirection: 'inherit',
38 alignItems: 'center',
39 '&:focus': {
40 color: theme.palette.text.secondary
41 },
42 '&:hover': {
43 color: theme.palette.text.secondary,
44 '& $icon': {
45 opacity: 0.5
46 }
47 },
48 '&$active': {
49 color: theme.palette.text.primary,
50 // && instead of & is a workaround for https://github.com/cssinjs/jss/issues/1045
51 '&& $icon': {
52 opacity: 1,
53 color: theme.palette.text.secondary
54 }
55 }
56 },
57
58 /* Pseudo-class applied to the root element if `active={true}`. */
59 active: {},
60
61 /* Styles applied to the icon component. */
62 icon: {
63 fontSize: 18,
64 marginRight: 4,
65 marginLeft: 4,
66 opacity: 0,
67 transition: theme.transitions.create(['opacity', 'transform'], {
68 duration: theme.transitions.duration.shorter
69 }),
70 userSelect: 'none'
71 },
72
73 /* Styles applied to the icon component if `direction="desc"`. */
74 iconDirectionDesc: {
75 transform: 'rotate(0deg)'
76 },
77
78 /* Styles applied to the icon component if `direction="asc"`. */
79 iconDirectionAsc: {
80 transform: 'rotate(180deg)'
81 }
82 };
83};
84/**
85 * A button based label for placing inside `TableCell` for column sorting.
86 */
87
88
89exports.styles = styles;
90var TableSortLabel = /*#__PURE__*/React.forwardRef(function TableSortLabel(props, ref) {
91 var _props$active = props.active,
92 active = _props$active === void 0 ? false : _props$active,
93 children = props.children,
94 classes = props.classes,
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 ? _ArrowDownward.default : _props$IconComponent,
102 other = (0, _objectWithoutProperties2.default)(props, ["active", "children", "classes", "className", "direction", "hideSortIcon", "IconComponent"]);
103 return /*#__PURE__*/React.createElement(_ButtonBase.default, (0, _extends2.default)({
104 className: (0, _clsx.default)(classes.root, className, active && classes.active),
105 component: "span",
106 disableRipple: true,
107 ref: ref
108 }, other), children, hideSortIcon && !active ? null : /*#__PURE__*/React.createElement(IconComponent, {
109 className: (0, _clsx.default)(classes.icon, classes["iconDirection".concat((0, _capitalize.default)(direction))])
110 }));
111});
112process.env.NODE_ENV !== "production" ? TableSortLabel.propTypes = {
113 /**
114 * If `true`, the label will have the active styling (should be true for the sorted column).
115 */
116 active: _propTypes.default.bool,
117
118 /**
119 * Label contents, the arrow will be appended automatically.
120 */
121 children: _propTypes.default.node,
122
123 /**
124 * Override or extend the styles applied to the component.
125 * See [CSS API](#css) below for more details.
126 */
127 classes: _propTypes.default.object.isRequired,
128
129 /**
130 * @ignore
131 */
132 className: _propTypes.default.string,
133
134 /**
135 * The current sort direction.
136 */
137 direction: _propTypes.default.oneOf(['asc', 'desc']),
138
139 /**
140 * Hide sort icon when active is false.
141 */
142 hideSortIcon: _propTypes.default.bool,
143
144 /**
145 * Sort icon to use.
146 */
147 IconComponent: _propTypes.default.elementType
148} : void 0;
149
150var _default = (0, _withStyles.default)(styles, {
151 name: 'MuiTableSortLabel'
152})(TableSortLabel);
153
154exports.default = _default;
\No newline at end of file