@up-group/react-controls
Version:
We know that there are a ton of react UI library projects to choose from. Our hope with this one is to provide the next generation of react components that you can use to bootstrap your next project, or as a reference for building a UIKit. Read on to get
174 lines • 7.25 kB
JavaScript
"use strict";
var __extends = (this && this.__extends) || (function () {
var 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 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) || 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;
};
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 React = require("react");
var classnames = require("classnames");
var styles_1 = require("./styles");
var Tooltip_1 = require("../../Display/Tooltip");
var theming_1 = require("../../../Common/theming");
var utils_1 = require("../../../Common/utils");
var typestyle_1 = require("typestyle");
var UpButton = (function (_super) {
__extends(UpButton, _super);
function UpButton(props) {
var _this = _super.call(this, props) || this;
_this.handleClick = function (e) {
if (_this.props.disabled !== true) {
_this.props.onClick(e);
if (_this.props.dropDown != 'none') {
_this.setState({ isToggled: !_this.state.isToggled });
}
}
e.preventDefault();
e.stopPropagation();
};
_this.collapse = function () {
if (_this.props.dropDown != 'none') {
_this.setState({ isToggled: false });
}
};
_this.handleActionClick = function (action) {
action.onClick(null);
_this.collapse();
};
_this.handleClick = _this.handleClick.bind(_this);
_this.state = {
isToggled: false
};
return _this;
}
UpButton.prototype.isSeparator = function (element) {
return element.size !== undefined;
};
UpButton.prototype.render = function () {
var _this = this;
var _a = this.props, children = _a.children, tooltip = _a.tooltip, onClick = _a.onClick, iconName = _a.iconName, iconPosition = _a.iconPosition, others = __rest(_a, ["children", "tooltip", "onClick", "iconName", "iconPosition"]);
var BtnList = typestyle_1.style({
display: this.state.isToggled ? "block" : "none",
position: "absolute",
top: "35px",
zIndex: 1000,
listStyle: "none",
backgroundColor: "#ffffff",
minWidth: 160,
margin: 0,
paddingTop: 10,
paddingBottom: 10,
paddingLeft: 0,
borderRadius: 4,
boxShadow: "0 6px 12px rgba(0, 0, 0, .175)",
height: this.state.isToggled ? 'auto' : '0px',
transition: this.state.isToggled ? "height 2s ease-in" : "height 2s ease-out",
transform: this.state.isToggled ? "scaleY(1)" : "scaleY(0)",
transformOrigin: "top"
});
var buttonElement = typestyle_1.style({
cursor: "pointer",
padding: "8px",
$nest: {
'&:hover': { backgroundColor: "#f5f5f5" },
}
});
var separatorElement = typestyle_1.style({
height: "1px",
margin: "9px 0",
overflow: "hidden",
backgroundColor: '#e5e5e5'
});
var buttonWrapper = typestyle_1.style({
display: "inline-block",
position: "relative"
});
var icon = iconName;
if (icon === false && this.props.dropDown != 'none') {
if (this.props.dropDown == 'up') {
icon = 'caret-up';
}
else if (this.props.dropDown == 'down') {
icon = 'caret-down';
}
}
var position = iconPosition;
if (position === 'none' && this.props.dropDown != 'none') {
position = 'right';
}
else if (position === 'none' && icon === false) {
position = 'left';
}
var _tooltip = null;
if (tooltip) {
if (utils_1.isString(tooltip)) {
_tooltip = {
content: tooltip
};
}
else {
_tooltip = tooltip;
}
}
return (React.createElement("div", { className: classnames('up-btn-wrapper', buttonWrapper) },
tooltip === null ?
React.createElement(styles_1.BaseButton, __assign({ iconName: icon, iconPosition: position, onClick: this.handleClick, isToggled: this.state.isToggled }, others), children != null &&
React.createElement("span", null, children))
:
React.createElement(Tooltip_1.default, __assign({}, _tooltip),
React.createElement(styles_1.BaseButton, __assign({ iconName: icon, iconPosition: position, onClick: this.handleClick, isToggled: this.state.isToggled }, others), children != null &&
React.createElement("span", null, children))),
this.props.dropDown != 'none' && this.state.isToggled &&
React.createElement("ul", { tabIndex: 0, className: BtnList }, this.props.extraActions.map(function (v, i) {
var isSeparator = _this.isSeparator(v);
if (!isSeparator) {
return React.createElement("li", { tabIndex: i + 1, key: i, className: buttonElement, onMouseDown: _this.handleActionClick.bind(_this, v) }, v.libelle);
}
else {
return React.createElement("li", { tabIndex: i + 1, role: "separator", key: i, className: separatorElement });
}
}))));
};
UpButton.defaultProps = {
backgroundColor: '',
borderColor: '',
fontSize: 'large',
disabled: false,
shadow: false,
iconName: false,
iconPosition: 'none',
iconSize: 20,
intent: 'default',
width: 'auto',
height: 'normal',
tooltip: null,
dropDown: 'none',
onClick: function (e) { },
theme: theming_1.default
};
return UpButton;
}(React.Component));
exports.default = UpButton;
//# sourceMappingURL=UpButton.js.map