UNPKG

@hitachivantara/uikit-react-core

Version:

Core React components for the NEXT Design System.

118 lines (117 loc) 4.11 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const jsxRuntime = require("react/jsx-runtime"); const React = require("react"); const uikitStyles = require("@hitachivantara/uikit-styles"); const useUniqueId = require("../../hooks/useUniqueId.cjs"); const icons = require("../../icons.cjs"); const Action_styles = require("./Action.styles.cjs"); const Avatar = require("../../Avatar/Avatar.cjs"); const ListItem = require("../../ListContainer/ListItem/ListItem.cjs"); const Typography = require("../../Typography/Typography.cjs"); const OverflowTooltip = require("../../OverflowTooltip/OverflowTooltip.cjs"); const Tooltip = require("../../Tooltip/Tooltip.cjs"); const HvAppSwitcherAction = ({ id, className, classes: classesProp, application, onClickCallback = () => { }, isSelectedCallback = () => false }) => { const { classes, cx } = Action_styles.useClasses(classesProp); const { name, description, disabled, iconElement, iconUrl, url, target } = application; const color = uikitStyles.getColor( disabled ? "textDisabled" : application?.color, "text" ); const [validIconUrl, setValidIconUrl] = React.useState(true); const renderApplicationIcon = () => { if (iconElement) { return iconElement; } if (iconUrl && validIconUrl) { return /* @__PURE__ */ jsxRuntime.jsx( "img", { className: classes.iconUrl, src: iconUrl, onError: () => { setValidIconUrl(false); }, alt: description } ); } const brokenTitle = name.split(" "); const initials = brokenTitle[0].substring(0, 1) + (brokenTitle[1] ? brokenTitle[1].substring(0, 1) : ""); return /* @__PURE__ */ jsxRuntime.jsx(Avatar.HvAvatar, { size: "sm", backgroundColor: color, variant: "square", "aria-hidden": true, children: initials }); }; const isSelected = isSelectedCallback(application); const handleOnClick = React.useCallback( (event) => { if (disabled) { event.preventDefault(); return; } onClickCallback?.(event, { ...application, isSelected }); }, [application, disabled, isSelected, onClickCallback] ); const isLink = url != null; const descriptionElementId = useUniqueId.useUniqueId(id); return /* @__PURE__ */ jsxRuntime.jsx( ListItem.HvListItem, { id, interactive: true, tabIndex: 0, selected: isSelected, disabled, className: cx( classes.root, { [classes.disabled]: disabled, [classes.selected]: isSelected }, className ), children: /* @__PURE__ */ jsxRuntime.jsxs( Typography.HvTypography, { component: "button", className: classes.typography, onClick: handleOnClick, style: { borderColor: color }, "aria-label": name, ...description && { "aria-describedby": descriptionElementId }, ...isLink && { component: "a", href: url, target: target || "_top" }, children: [ /* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.icon, children: renderApplicationIcon() }), /* @__PURE__ */ jsxRuntime.jsx( OverflowTooltip.HvOverflowTooltip, { paragraphOverflow: true, className: classes.title, placement: "top-start", data: name, classes: { tooltipAnchorParagraph: classes.titleAnchor } } ), description && /* @__PURE__ */ jsxRuntime.jsx(Tooltip.HvTooltip, { title: description, children: /* @__PURE__ */ jsxRuntime.jsx( icons.HvIcon, { name: "Info", compact: true, className: classes.iconInfo, id: descriptionElementId } ) }) ] } ) } ); }; exports.appSwitcherActionClasses = Action_styles.staticClasses; exports.HvAppSwitcherAction = HvAppSwitcherAction;