@eccenca/gui-elements
Version:
GUI elements based on other libraries, usable in React application, written in Typescript.
67 lines • 3.48 kB
JavaScript
;
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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Button = void 0;
const react_1 = __importDefault(require("react"));
const core_1 = require("@blueprintjs/core");
const constants_1 = require("../../configuration/constants");
const Icon_1 = __importDefault(require("../Icon/Icon"));
const Badge_1 = __importDefault(require("./../Badge/Badge"));
const Tooltip_1 = __importDefault(require("./../Tooltip/Tooltip"));
/**
* Display a button element to enable user interaction.
* It normally should trigger action when clicked.
*/
const Button = (_a) => {
var { children, className = "", affirmative = false, disruptive = false, elevated = false, icon, rightIcon, tooltip = null, tooltipProps, badge, badgeProps = { size: "small", position: "top-right", maxLength: 2 }, intent } = _a, restProps = __rest(_a, ["children", "className", "affirmative", "disruptive", "elevated", "icon", "rightIcon", "tooltip", "tooltipProps", "badge", "badgeProps", "intent"]);
let intentByFunction;
switch (true) {
case affirmative || elevated:
intentByFunction = "accent";
break;
case disruptive:
intentByFunction = core_1.Intent.DANGER;
break;
default:
break;
}
const ButtonType = restProps.href ? core_1.AnchorButton : core_1.Button;
const button = (react_1.default.createElement(ButtonType, Object.assign({}, restProps, { className: `${constants_1.CLASSPREFIX}-button ` + className, intent: (intent || intentByFunction), icon: typeof icon === "string" ? react_1.default.createElement(Icon_1.default, { name: icon }) : icon, rightIcon: typeof rightIcon === "string" ? react_1.default.createElement(Icon_1.default, { name: rightIcon }) : rightIcon }),
children,
badge && (react_1.default.createElement(Badge_1.default, Object.assign({ children: badge }, constructBadgeProperties({
intent,
minimal: restProps.minimal,
outlined: restProps.outlined,
badgeProps,
}))))));
return tooltip && !restProps.loading ? (react_1.default.createElement(Tooltip_1.default, Object.assign({ content: tooltip }, tooltipProps),
react_1.default.createElement("span", null, button))) : (button);
};
exports.Button = Button;
const constructBadgeProperties = ({ intent, minimal, outlined, badgeProps = {} }) => {
if (badgeProps.intent)
return badgeProps;
if (intent)
badgeProps["intent"] = intent;
if (!badgeProps.tagProps || typeof badgeProps.tagProps.minimal === "undefined") {
if (!minimal && !outlined) {
badgeProps["tagProps"] = Object.assign(Object.assign({}, badgeProps.tagProps), { minimal: true });
}
}
return badgeProps;
};
exports.default = exports.Button;
//# sourceMappingURL=Button.js.map