@orfeas126/box-ui-elements
Version:
Box UI Elements
49 lines • 2.56 kB
JavaScript
const _excluded = ["className", "onViewModeChange", "intl", "viewMode"];
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
import * as React from 'react';
import { injectIntl } from 'react-intl';
import classNames from 'classnames';
import noop from 'lodash/noop';
import Button from '../../../components/button';
import IconGridViewInverted from '../../../icons/general/IconGridViewInverted';
import IconListView from '../../../icons/general/IconListView';
import messages from '../messages';
import Tooltip from '../Tooltip';
import { VIEW_MODE_GRID, VIEW_MODE_LIST } from '../../../constants';
import { bdlGray65 } from '../../../styles/variables';
import './ViewModeChangeButton.scss';
const ViewModeChangeButton = _ref => {
let {
className = '',
onViewModeChange = noop,
intl,
viewMode
} = _ref,
rest = _objectWithoutProperties(_ref, _excluded);
const isGridView = viewMode === VIEW_MODE_GRID;
const viewMessage = isGridView ? intl.formatMessage(messages.listView) : intl.formatMessage(messages.gridView);
const onClick = () => {
onViewModeChange(isGridView ? VIEW_MODE_LIST : VIEW_MODE_GRID);
};
return /*#__PURE__*/React.createElement(Tooltip, {
text: viewMessage
}, /*#__PURE__*/React.createElement(Button, _extends({
"aria-label": viewMessage,
"data-testid": "view-mode-change-button",
className: classNames('bdl-ViewModeChangeButton', className),
type: "button",
onClick: onClick
}, rest), isGridView ? /*#__PURE__*/React.createElement(IconListView, {
color: bdlGray65,
width: 17,
height: 17
}) : /*#__PURE__*/React.createElement(IconGridViewInverted, {
color: bdlGray65,
width: 17,
height: 17
})));
};
export default injectIntl(ViewModeChangeButton);
//# sourceMappingURL=ViewModeChangeButton.js.map