UNPKG

@guardian/threads

Version:
83 lines 3.96 kB
import { __assign, __extends } from "tslib"; import React, { Component, createRef } from 'react'; import { DateChip } from './DateChip'; import { SelectChip } from './SelectChip'; import { SelectAsyncChip } from './SelectAsyncChip'; import { TextChip } from './TextChip'; import { UnknownChip } from './UnknownChip'; import { FilterHelpers } from '../../Filter'; var styles = require('./ChipWrapper.module.css'); export var stagedForDeletionKey = 'data-staged-for-deletion'; var ChipWrapper = /** @class */ (function (_super) { __extends(ChipWrapper, _super); function ChipWrapper() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.controlRef = createRef(); _this.focus = function (focusEnd) { var current = _this.controlRef.current; if (current) { current.focus(focusEnd); } }; _this.select = function () { var current = _this.controlRef.current; if (current) { current.select(); } }; _this.onDeleteClicked = function () { _this.props.onDeleteClicked(_this.props.index); }; _this.onNegateClicked = function () { _this.props.onNegateClicked(_this.props.index); }; _this.renderControl = function () { var _a = _this.props, value = _a.value, label = _a.label, index = _a.index, filter = _a.filter, focusElement = _a.focusElement, deleteChip = _a.deleteChip, onUpdate = _a.onUpdate; var sharedProps = { ref: _this.controlRef, index: index, value: value, focusElement: focusElement, onUpdate: onUpdate, deleteChip: deleteChip, }; if (FilterHelpers.isText(filter)) { switch (filter.type) { case 'text': return React.createElement(TextChip, __assign({}, sharedProps)); case 'date': return React.createElement(DateChip, __assign({ dateMode: "from_start" }, sharedProps)); case 'date_ex': return React.createElement(DateChip, __assign({ dateMode: "from_end" }, sharedProps)); default: } } else if (FilterHelpers.isSelect(filter)) { return React.createElement(SelectChip, __assign({ options: filter.options }, sharedProps)); } else if (FilterHelpers.isSelectAsync(filter)) { return (React.createElement(SelectAsyncChip, __assign({ onInputChange: filter.onInputChange, label: label }, sharedProps))); } // Boolean chips currently not supported return React.createElement(UnknownChip, __assign({}, sharedProps)); }; return _this; } ChipWrapper.prototype.render = function () { var _a; var stagedForDeletion = this.props.stagedForDeletion; return (React.createElement("div", __assign({ className: styles.chipWrapper }, (_a = {}, _a[stagedForDeletionKey] = stagedForDeletion ? stagedForDeletion : null, _a)), React.createElement("button", { className: styles.chipNegateButton, onClick: this.onNegateClicked }, React.createElement("div", null, this.props.negate ? '−' : '+')), React.createElement("div", { className: styles.chipBody }, React.createElement("span", { className: styles.chipName }, this.props.filter.name), this.renderControl()), React.createElement("button", { className: styles.chipDeleteButton, onClick: this.onDeleteClicked }, React.createElement("div", null, "\u00D7")))); }; return ChipWrapper; }(Component)); export { ChipWrapper }; //# sourceMappingURL=ChipWrapper.js.map