UNPKG

@formant/ava-react

Version:

React components of AVA.

49 lines 2.48 kB
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } import React from 'react'; import { isFunction } from 'lodash'; import { INSIGHT_CARD_PREFIX_CLS } from "../constants"; import { DEFAULT_TOOLS } from "./constants"; import { BaseIconButton, getDefaultTool } from "./defaultTools"; export var Toolbar = function Toolbar(_ref) { var _ref$tools = _ref.tools, tools = _ref$tools === void 0 ? [] : _ref$tools, data = _ref.data; var getDefaultIconProps = function getDefaultIconProps(type) { if (DEFAULT_TOOLS.includes(type)) { return getDefaultTool(type); } return null; }; var toolButtons = tools === null || tools === void 0 ? void 0 : tools.map(function (tool) { if (tool !== null && tool !== void 0 && tool.type) { var _customProps$icon, _customProps$descript; var type = tool.type, icon = tool.icon, description = tool.description, onClick = tool.onClick; var onClickIconButton = function onClickIconButton(event) { onClick === null || onClick === void 0 || onClick(event, type, data); }; var defaultIconProps = getDefaultIconProps(type); var customProps = { icon: isFunction(icon) ? icon(type, data) : icon, description: isFunction(description) ? description(type, data) : description }; var iconButtonProps = { icon: (_customProps$icon = customProps.icon) !== null && _customProps$icon !== void 0 ? _customProps$icon : defaultIconProps === null || defaultIconProps === void 0 ? void 0 : defaultIconProps.icon, description: (_customProps$descript = customProps.description) !== null && _customProps$descript !== void 0 ? _customProps$descript : defaultIconProps === null || defaultIconProps === void 0 ? void 0 : defaultIconProps.description, onClick: onClickIconButton }; return /*#__PURE__*/React.createElement(BaseIconButton, _extends({}, iconButtonProps, { key: type })); } return tool; }); return tools.length ? /*#__PURE__*/React.createElement("div", { className: "".concat(INSIGHT_CARD_PREFIX_CLS, "-toolbar"), style: { display: 'inline-block' } }, toolButtons) : null; };