@blueprintjs/core
Version:
Core styles & components
107 lines (106 loc) • 4.14 kB
JavaScript
/*
* Copyright 2016 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the terms of the LICENSE file distributed with this project.
*/
import * as tslib_1 from "tslib";
// HACKHACK: these components should go in separate files
// tslint:disable max-classes-per-file
// we need some empty interfaces to show up in docs
// tslint:disable no-empty-interface
import * as classNames from "classnames";
import * as React from "react";
import * as Classes from "../../common/classes";
import { removeNonHTMLProps } from "../../common/props";
import { safeInvoke } from "../../common/utils";
var INVALID_PROPS = [
// we spread props to `<input>` but render `children` as its sibling
"children",
"defaultIndeterminate",
"indeterminate",
"labelElement",
];
/** Base Component class for all Controls */
var Control = (function (_super) {
tslib_1.__extends(Control, _super);
function Control() {
return _super !== null && _super.apply(this, arguments) || this;
}
// generates control markup for given input type.
// optional inputRef in case the component needs reference for itself (don't forget to invoke the prop!).
Control.prototype.renderControl = function (type, typeClassName, inputRef) {
if (inputRef === void 0) { inputRef = this.props.inputRef; }
var className = classNames(Classes.CONTROL, typeClassName, (_a = {},
_a[Classes.DISABLED] = this.props.disabled,
_a[Classes.INLINE] = this.props.inline,
_a), this.props.className);
var inputProps = removeNonHTMLProps(this.props, INVALID_PROPS, true);
return (React.createElement("label", { className: className, style: this.props.style },
React.createElement("input", tslib_1.__assign({}, inputProps, { ref: inputRef, type: type })),
React.createElement("span", { className: Classes.CONTROL_INDICATOR }),
this.props.label,
this.props.labelElement,
this.props.children));
var _a;
};
return Control;
}(React.Component));
export { Control };
var Checkbox = (function (_super) {
tslib_1.__extends(Checkbox, _super);
function Checkbox() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.handleInputRef = function (ref) {
_this.input = ref;
safeInvoke(_this.props.inputRef, ref);
};
return _this;
}
Checkbox.prototype.render = function () {
return this.renderControl("checkbox", "pt-checkbox", this.handleInputRef);
};
Checkbox.prototype.componentDidMount = function () {
if (this.props.defaultIndeterminate != null) {
this.input.indeterminate = this.props.defaultIndeterminate;
}
this.updateIndeterminate();
};
Checkbox.prototype.componentDidUpdate = function () {
this.updateIndeterminate();
};
Checkbox.prototype.updateIndeterminate = function () {
if (this.props.indeterminate != null) {
this.input.indeterminate = this.props.indeterminate;
}
};
Checkbox.displayName = "Blueprint.Checkbox";
return Checkbox;
}(Control));
export { Checkbox };
var Switch = (function (_super) {
tslib_1.__extends(Switch, _super);
function Switch() {
return _super !== null && _super.apply(this, arguments) || this;
}
Switch.prototype.render = function () {
return this.renderControl("checkbox", "pt-switch");
};
Switch.displayName = "Blueprint.Switch";
return Switch;
}(Control));
export { Switch };
var Radio = (function (_super) {
tslib_1.__extends(Radio, _super);
function Radio() {
return _super !== null && _super.apply(this, arguments) || this;
}
Radio.prototype.render = function () {
return this.renderControl("radio", "pt-radio");
};
Radio.displayName = "Blueprint.Radio";
return Radio;
}(Control));
export { Radio };
export var CheckboxFactory = React.createFactory(Checkbox);
export var SwitchFactory = React.createFactory(Switch);
export var RadioFactory = React.createFactory(Radio);