baseui
Version:
A React Component library implementing the Base design language
91 lines (86 loc) • 3.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var React = _interopRequireWildcard(require("react"));
var _styles = require("../styles");
var _columnCategorical = require("./column-categorical");
var _column = _interopRequireDefault(require("./column"));
var _constants = require("./constants");
var _locale = require("../locale");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
/*
Copyright (c) Uber Technologies, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
function mapSelection(selection, transform) {
const coercedSelection = new Set();
selection.forEach(item => coercedSelection.add(transform(item)));
return coercedSelection;
}
// @ts-ignore
function BooleanFilter(props) {
const locale = React.useContext(_locale.LocaleContext);
let selectionString = new Set();
if (props.filterParams && props.filterParams.selection) {
selectionString = mapSelection(props.filterParams.selection, i => i ? locale.datatable.booleanFilterTrue : locale.datatable.booleanFilterFalse);
}
return /*#__PURE__*/React.createElement(_columnCategorical.CategoricalFilter, {
close: props.close,
data: [locale.datatable.booleanFilterTrue, locale.datatable.booleanFilterFalse],
filterParams: props.filterParams ? {
selection: selectionString,
description: props.filterParams.description,
exclude: props.filterParams.exclude
} : undefined,
setFilter: params => {
props.setFilter({
selection: mapSelection(params.selection, i => i === locale.datatable.booleanFilterTrue),
exclude: params.exclude,
description: params.description
});
}
});
}
// @ts-ignore
function BooleanCell(props) {
const [css, theme] = (0, _styles.useStyletron)();
const locale = React.useContext(_locale.LocaleContext);
return /*#__PURE__*/React.createElement("div", {
className: css({
textAlign: props.value ? 'right' : 'left',
minWidth: theme.sizing.scale1400,
width: '100%'
})
}, props.value ? locale.datatable.booleanColumnTrueShort : locale.datatable.booleanColumnFalseShort);
}
function BooleanColumn(options) {
return (0, _column.default)({
kind: _constants.COLUMNS.BOOLEAN,
buildFilter: function (params) {
return function (data) {
const included = params.selection.has(data);
return params.exclude ? !included : included;
};
},
cellBlockAlign: options.cellBlockAlign,
fillWidth: options.fillWidth,
filterable: options.filterable === undefined ? true : options.filterable,
mapDataToValue: options.mapDataToValue,
maxWidth: options.maxWidth,
minWidth: options.minWidth,
renderCell: BooleanCell,
renderFilter: BooleanFilter,
sortable: options.sortable === undefined ? true : options.sortable,
sortFn: function (a, b) {
if (a === b) return 0;
return a ? -1 : 1;
},
title: options.title
});
}
var _default = exports.default = BooleanColumn;