UNPKG

@razorpay/blade

Version:

The Design System that powers Razorpay

131 lines (128 loc) 6.54 kB
import _defineProperty from '@babel/runtime/helpers/defineProperty'; import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties'; import 'react'; import styled from 'styled-components'; import { ComponentIds } from './componentIds.js'; import { tableToolbar } from './tokens.js'; import { useTableContext } from './TableContext.js'; import '../Box/BaseBox/index.js'; import '../Typography/index.js'; import '../../utils/assignWithoutSideEffects/index.js'; import '../Divider/index.js'; import '../Link/index.js'; import '../Box/styledProps/index.js'; import '../../utils/index.js'; import '../BladeProvider/index.js'; import getIn from '../../utils/lodashButBetter/get.js'; import '../../utils/makeAnalyticsAttribute/index.js'; import { jsx, jsxs } from 'react/jsx-runtime'; import useTheme from '../BladeProvider/useTheme.js'; import { BaseBox } from '../Box/BaseBox/BaseBox.web.js'; import { getStyledProps } from '../Box/styledProps/getStyledProps.js'; import { makeAnalyticsAttribute } from '../../utils/makeAnalyticsAttribute/makeAnalyticsAttribute.js'; import { assignWithoutSideEffects } from '../../utils/assignWithoutSideEffects/assignWithoutSideEffects.js'; import { makeMotionTime } from '../../utils/makeMotionTime/makeMotionTime.web.js'; import Link from '../Link/Link/Link.js'; import { Text } from '../Typography/Text/Text.js'; import { Divider } from '../Divider/Divider.js'; var _excluded = ["children"], _excluded2 = ["children", "title", "selectedTitle"]; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } var _TableToolbarActions = function _TableToolbarActions(_ref) { var children = _ref.children, rest = _objectWithoutProperties(_ref, _excluded); var _useTheme = useTheme(), platform = _useTheme.platform; var onMobile = platform === 'onMobile'; return /*#__PURE__*/jsx(BaseBox, _objectSpread(_objectSpread(_objectSpread({ display: "flex", flex: onMobile ? 1 : 0, justifyContent: onMobile ? 'flex-start' : 'flex-end' }, getStyledProps(rest)), makeAnalyticsAttribute(rest)), {}, { children: children })); }; var TableToolbarActions = /*#__PURE__*/assignWithoutSideEffects(_TableToolbarActions, { componentId: ComponentIds.TableToolbarActions }); var ToolbarWrapper = /*#__PURE__*/styled(BaseBox).withConfig({ displayName: "TableToolbarweb__ToolbarWrapper", componentId: "sc-15cjj2g-0" })(function (_ref2) { var theme = _ref2.theme; return { transition: "background-color ".concat(makeMotionTime(getIn(theme.motion, tableToolbar.backgroundColorMotionDuration)), " ").concat(getIn(theme.motion, tableToolbar.backgroundColorMotionEasing)) }; }); var _TableToolbar = function _TableToolbar(_ref3) { var _ref4; var children = _ref3.children, title = _ref3.title, controlledSelectedTitle = _ref3.selectedTitle, rest = _objectWithoutProperties(_ref3, _excluded2); var _useTableContext = useTableContext(), selectedRows = _useTableContext.selectedRows, deselectAllRows = _useTableContext.deselectAllRows, currentPaginationState = _useTableContext.currentPaginationState, totalItems = _useTableContext.totalItems, backgroundColor = _useTableContext.backgroundColor; var _useTheme2 = useTheme(), platform = _useTheme2.platform; var isSelected = selectedRows && selectedRows.length > 0; var defaultTitle = currentPaginationState ? "Showing ".concat(currentPaginationState.page * currentPaginationState.size + 1, "-").concat(currentPaginationState.page * currentPaginationState.size + currentPaginationState.size, " Items") : "Showing 1-".concat(totalItems, " Items"); var selectedItemsCount = selectedRows ? selectedRows.length : 0; var selectedTitle = isSelected ? controlledSelectedTitle !== null && controlledSelectedTitle !== void 0 ? controlledSelectedTitle : "".concat(selectedRows.length, " ").concat(selectedItemsCount === 1 ? 'Item' : 'Items', " Selected") : null; var onMobile = platform === 'onMobile'; var deselectButton = /*#__PURE__*/jsx(Link, { marginLeft: "spacing.5", variant: "button", onClick: function onClick() { return deselectAllRows(); }, children: "Deselect" }); return /*#__PURE__*/jsx(BaseBox, _objectSpread(_objectSpread({ backgroundColor: backgroundColor }, makeAnalyticsAttribute(rest)), {}, { children: /*#__PURE__*/jsxs(ToolbarWrapper, { display: "flex", backgroundColor: isSelected ? tableToolbar.backgroundColorSelected : tableToolbar.backgroundColor, padding: "spacing.4", flexWrap: "wrap", flexDirection: onMobile ? 'column' : 'row', gap: "spacing.5", children: [/*#__PURE__*/jsxs(BaseBox, { display: "flex", alignItems: "center", flex: 1, children: [/*#__PURE__*/jsx(BaseBox, { children: /*#__PURE__*/jsx(Text, { size: "medium", weight: "medium", color: isSelected ? 'surface.text.gray.normal' : 'surface.text.gray.subtle', children: (_ref4 = selectedTitle !== null && selectedTitle !== void 0 ? selectedTitle : title) !== null && _ref4 !== void 0 ? _ref4 : defaultTitle }) }), isSelected && !onMobile && /*#__PURE__*/jsxs(BaseBox, { display: "flex", marginLeft: "spacing.5", height: "100%", children: [/*#__PURE__*/jsx(Divider, { orientation: "vertical", thickness: "thick" }), deselectButton] }), isSelected && onMobile && /*#__PURE__*/jsx(BaseBox, { display: "flex", flex: 1, justifyContent: "flex-end", children: deselectButton })] }), children] }) })); }; var TableToolbar = /*#__PURE__*/assignWithoutSideEffects(_TableToolbar, { componentId: ComponentIds.TableToolbar }); export { TableToolbar, TableToolbarActions }; //# sourceMappingURL=TableToolbar.web.js.map