@bigbinary/neetoui
Version:
neetoUI drives the experience at all neeto products
102 lines (96 loc) • 4.3 kB
JavaScript
'use strict';
var _extends = require('@babel/runtime/helpers/extends');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var React = require('react');
var classnames = require('classnames');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var neetoIcons = require('@bigbinary/neeto-icons');
var Button = require('./Button.js');
var Popover = require('./Popover.js');
var Tooltip = require('./Tooltip.js');
var Typography = require('./Typography.js');
require('@babel/runtime/helpers/slicedToArray');
require('@tippyjs/react');
require('tippy.js');
require('react-router-dom');
require('./Spinner.js');
var _excluded$2 = ["onClick", "className", "icon"];
var HelpIcon = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
var onClick = _ref.onClick,
className = _ref.className,
icon = _ref.icon,
otherProps = _objectWithoutProperties(_ref, _excluded$2);
var HelpIcon = icon || neetoIcons.Help;
return /*#__PURE__*/React.createElement("span", {
onClick: onClick,
ref: ref,
className: classnames("neeto-ui-label__help-icon-wrap", _defineProperty({}, className, className))
}, /*#__PURE__*/React.createElement(HelpIcon, _extends({
size: 16
}, otherProps)));
});
HelpIcon.displayName = "HelpIcon";
var _excluded$1 = ["tooltipProps", "popoverProps"],
_excluded2 = ["title", "description", "helpLinkProps"];
var HelpContent = function HelpContent(_ref) {
var helpIconProps = _ref.helpIconProps;
var popoverReferenceElement = React.useRef();
var _ref2 = helpIconProps || {},
tooltipProps = _ref2.tooltipProps,
popoverProps = _ref2.popoverProps,
otherHelpIconProps = _objectWithoutProperties(_ref2, _excluded$1);
if (tooltipProps) {
return /*#__PURE__*/React.createElement(Tooltip, tooltipProps, /*#__PURE__*/React.createElement(HelpIcon, otherHelpIconProps));
}
if (popoverProps) {
var title = popoverProps.title,
description = popoverProps.description,
helpLinkProps = popoverProps.helpLinkProps,
otherPopoverProps = _objectWithoutProperties(popoverProps, _excluded2);
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(HelpIcon, _extends({}, otherHelpIconProps, {
ref: popoverReferenceElement
})), /*#__PURE__*/React.createElement(Popover, _extends({
reference: popoverReferenceElement
}, otherPopoverProps), /*#__PURE__*/React.createElement("div", {
className: "neeto-ui-flex neeto-ui-flex-col"
}, title && /*#__PURE__*/React.createElement(Popover.Title, {
"data-cy": "help-popover-title",
"data-testid": "help-popover-title"
}, title), typeof description === "string" ? /*#__PURE__*/React.createElement(Typography, {
"data-cy": "help-popover-description",
"data-testid": "help-popover-description",
lineHeight: "normal",
style: "body2",
weight: "normal"
}, description) : description, helpLinkProps && /*#__PURE__*/React.createElement(Button, _extends({
className: "neeto-ui-mt-3",
"data-cy": "help-popover-link-button",
size: "small"
}, helpLinkProps, {
"data-testid": "help-popover-link-button",
style: "link",
target: "_blank"
})))));
}
return /*#__PURE__*/React.createElement(HelpIcon, otherHelpIconProps);
};
var _excluded = ["children", "className", "required", "helpIconProps"];
var Label = function Label(_ref) {
var children = _ref.children,
_ref$className = _ref.className,
className = _ref$className === void 0 ? "" : _ref$className,
_ref$required = _ref.required,
required = _ref$required === void 0 ? false : _ref$required,
_ref$helpIconProps = _ref.helpIconProps,
helpIconProps = _ref$helpIconProps === void 0 ? null : _ref$helpIconProps,
props = _objectWithoutProperties(_ref, _excluded);
return /*#__PURE__*/React.createElement("label", _extends({
className: classnames("neeto-ui-label neeto-ui-flex neeto-ui-items-center", className)
}, props), children, required && /*#__PURE__*/React.createElement("span", {
"aria-hidden": true
}, "*"), helpIconProps && /*#__PURE__*/React.createElement(HelpContent, {
helpIconProps: helpIconProps
}));
};
module.exports = Label;
//# sourceMappingURL=Label.js.map