@talend/react-components
Version:
Set of react components.
81 lines (80 loc) • 2.72 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = AppSwitcher;
var _reactI18next = require("react-i18next");
var _propTypes = _interopRequireDefault(require("prop-types"));
var _Action = _interopRequireDefault(require("../Actions/Action"));
var _ActionDropdown = _interopRequireDefault(require("../Actions/ActionDropdown"));
var _constants = _interopRequireDefault(require("../constants"));
var _Inject = _interopRequireDefault(require("../Inject"));
var _theme = require("../theme");
var _AppSwitcherModule = _interopRequireDefault(require("./AppSwitcher.module.scss"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const theme = (0, _theme.getTheme)(_AppSwitcherModule.default);
function AppSwitcher({
label,
isSeparated,
onClick,
getComponent,
iconUrl,
...props
}) {
const {
t
} = (0, _reactI18next.useTranslation)(_constants.default);
const Renderers = _Inject.default.getAll(getComponent, {
Action: _Action.default,
ActionDropdown: _ActionDropdown.default
});
const className = theme('tc-app-switcher-action', {
separated: isSeparated,
hasIcon: !!iconUrl
});
let ActionComponent;
let clickAction;
let ariaLabel;
if (props && props.items && props.items.length) {
ActionComponent = Renderers.ActionDropdown;
ariaLabel = t('APP_SWITCHER', {
defaultValue: 'Switch to another application. Current application: {{appName}}.',
appName: label
});
} else {
ActionComponent = Renderers.Action;
clickAction = onClick;
}
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
role: "presentation",
className: className,
children: [iconUrl && /*#__PURE__*/(0, _jsxRuntime.jsx)("style", {
children: `.tc-app-switcher-action [role='heading'] span:first-child:before {
-webkit-mask-image: url('${iconUrl}');
mask-image: url('${iconUrl}');
}`
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
role: "heading",
"aria-level": "1",
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ActionComponent, {
bsStyle: "link",
className: theme('tc-app-switcher'),
tooltipPlacement: "bottom",
label: label,
"aria-label": ariaLabel,
onClick: clickAction,
...props
})
})]
});
}
AppSwitcher.propTypes = {
label: _propTypes.default.string,
isSeparated: _propTypes.default.bool,
items: _propTypes.default.arrayOf(_propTypes.default.object),
iconUrl: _propTypes.default.string,
onClick: _propTypes.default.func,
getComponent: _propTypes.default.func
};
//# sourceMappingURL=AppSwitcher.component.js.map