UNPKG

semantic-ui-calendar-react

Version:
112 lines (111 loc) 5.58 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) t[p[i]] = s[p[i]]; return t; }; Object.defineProperty(exports, "__esModule", { value: true }); var _ = require("lodash"); var React = require("react"); var semantic_ui_react_1 = require("semantic-ui-react"); var lib_1 = require("../lib"); var popupStyle = { padding: '0', filter: 'none', }; var FormInputWithRef = /** @class */ (function (_super) { __extends(FormInputWithRef, _super); function FormInputWithRef() { return _super !== null && _super.apply(this, arguments) || this; } FormInputWithRef.prototype.render = function () { var _a = this.props, value = _a.value, clearable = _a.clearable, icon = _a.icon, clearIcon = _a.clearIcon, onClear = _a.onClear, rest = __rest(_a, ["value", "clearable", "icon", "clearIcon", "onClear"]); var ClearIcon = _.isString(clearIcon) ? React.createElement(semantic_ui_react_1.Icon, { name: clearIcon, link: true, onClick: onClear }) : React.createElement(clearIcon.type, __assign({}, clearIcon.props, { link: true, onClick: onClear })); return (React.createElement(semantic_ui_react_1.Form.Input, __assign({}, rest, { value: value, icon: value && clearable ? ClearIcon : icon }))); }; return FormInputWithRef; }(React.Component)); var InputView = /** @class */ (function (_super) { __extends(InputView, _super); function InputView() { return _super !== null && _super.apply(this, arguments) || this; } InputView.prototype.componentDidMount = function () { if (this.props.onMount) { this.props.onMount(this.inputNode); } this.initialInputNode = this.inputNode; }; InputView.prototype.componentDidUpdate = function () { // TODO: find actual root of the problem. // Sometimes input node reference passed // to this.props.onMount stales. // this.inputNode referes to // different DOM object than it was after first // component render. // InputView component doesn't unmount it just // gets different underlying input node. // In order to keep input node reference fresh // we make this check. if (this.inputNode !== this.initialInputNode) { this.initialInputNode = this.inputNode; this.props.onMount(this.inputNode); } }; InputView.prototype.render = function () { var _this = this; var _a = this.props, render = _a.render, popupPosition = _a.popupPosition, inline = _a.inline, value = _a.value, closeOnMouseLeave = _a.closeOnMouseLeave, onChange = _a.onChange, onClear = _a.onClear, children = _a.children, inlineLabel = _a.inlineLabel, popupIsClosed = _a.popupIsClosed, mountNode = _a.mountNode, tabIndex = _a.tabIndex, onMount = _a.onMount, rest = __rest(_a, ["render", "popupPosition", "inline", "value", "closeOnMouseLeave", "onChange", "onClear", "children", "inlineLabel", "popupIsClosed", "mountNode", "tabIndex", "onMount"]); var inputElement = (React.createElement(FormInputWithRef, __assign({}, rest, { ref: function (e) { var node = lib_1.findHTMLElement(e); _this.inputNode = node && node.querySelector('input'); }, value: value, tabIndex: tabIndex, inline: inlineLabel, onClear: function (e) { return (onClear || onChange)(e, __assign({}, rest, { value: '' })); }, onChange: onChange }))); if (inline) { return render({ tabIndex: tabIndex, }); } return (React.createElement(semantic_ui_react_1.Popup, { position: popupPosition, open: popupIsClosed ? false : undefined, trigger: inputElement, hoverable: closeOnMouseLeave, flowing: true, mountNode: mountNode, style: popupStyle, hideOnScroll: true, on: 'focus' }, render({ tabIndex: -1, }))); }; InputView.defaultProps = { inline: false, closeOnMouseLeave: true, tabIndex: '0', clearable: false, icon: 'calendar', clearIcon: 'remove', }; return InputView; }(React.Component)); exports.default = InputView;