@eccenca/gui-elements
Version:
GUI elements based on other libraries, usable in React application, written in Typescript.
72 lines • 3.9 kB
JavaScript
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 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import React from "react";
import { AnchorButton as BlueprintAnchorButton, Button as BlueprintButton, Intent as BlueprintIntent, } from "@blueprintjs/core";
import { CLASSPREFIX as eccgui } from "../../configuration/constants.js";
import Icon from "../Icon/Icon.js";
import Badge from "./../Badge/Badge.js";
import Tooltip from "./../Tooltip/Tooltip.js";
/**
* Display a button element to enable user interaction.
* It normally should trigger action when clicked.
*/
export var Button = function (_a) {
var children = _a.children, _b = _a.className, className = _b === void 0 ? "" : _b, _c = _a.affirmative, affirmative = _c === void 0 ? false : _c, _d = _a.disruptive, disruptive = _d === void 0 ? false : _d, _e = _a.elevated, elevated = _e === void 0 ? false : _e, icon = _a.icon, rightIcon = _a.rightIcon, _f = _a.tooltip, tooltip = _f === void 0 ? null : _f, tooltipProps = _a.tooltipProps, badge = _a.badge, _g = _a.badgeProps, badgeProps = _g === void 0 ? { size: "small", position: "top-right", maxLength: 2 } : _g, intent = _a.intent, restProps = __rest(_a, ["children", "className", "affirmative", "disruptive", "elevated", "icon", "rightIcon", "tooltip", "tooltipProps", "badge", "badgeProps", "intent"]);
var intentByFunction;
switch (true) {
case affirmative || elevated:
intentByFunction = "accent";
break;
case disruptive:
intentByFunction = BlueprintIntent.DANGER;
break;
default:
break;
}
var ButtonType = restProps.href ? BlueprintAnchorButton : BlueprintButton;
var button = (React.createElement(ButtonType, __assign({}, restProps, { className: "".concat(eccgui, "-button ") + className, intent: (intent || intentByFunction), icon: typeof icon === "string" ? React.createElement(Icon, { name: icon }) : icon, rightIcon: typeof rightIcon === "string" ? React.createElement(Icon, { name: rightIcon }) : rightIcon }),
children,
badge && (React.createElement(Badge, __assign({ children: badge }, constructBadgeProperties({
intent: intent,
minimal: restProps.minimal,
outlined: restProps.outlined,
badgeProps: badgeProps,
}))))));
return tooltip && !restProps.loading ? (React.createElement(Tooltip, __assign({ content: tooltip }, tooltipProps),
React.createElement("span", null, button))) : (button);
};
var constructBadgeProperties = function (_a) {
var intent = _a.intent, minimal = _a.minimal, outlined = _a.outlined, _b = _a.badgeProps, badgeProps = _b === void 0 ? {} : _b;
if (badgeProps.intent)
return badgeProps;
if (intent)
badgeProps["intent"] = intent;
if (!badgeProps.tagProps || typeof badgeProps.tagProps.minimal === "undefined") {
if (!minimal && !outlined) {
badgeProps["tagProps"] = __assign(__assign({}, badgeProps.tagProps), { minimal: true });
}
}
return badgeProps;
};
export default Button;
//# sourceMappingURL=Button.js.map