UNPKG

@chayns-components/core

Version:

A set of beautiful React components for developing your own applications with chayns.

64 lines (63 loc) 3.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _useKeyboardFocusHighlighting = require("../../hooks/useKeyboardFocusHighlighting"); var _ColorSchemeProvider = require("../color-scheme-provider/ColorSchemeProvider"); var _Icon = _interopRequireDefault(require("../icon/Icon")); var _SharingBar = require("./SharingBar.styles"); var _SharingContextMenu = _interopRequireDefault(require("../sharing-context-menu/SharingContextMenu")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } const SharingBar = ({ label, link, popupAlignment, container, shouldEnableKeyboardHighlighting }) => { const colorScheme = (0, _ColorSchemeProvider.useColorScheme)(); const shouldEnableKeyboardHighlightingEffective = shouldEnableKeyboardHighlighting ?? (colorScheme === null || colorScheme === void 0 ? void 0 : colorScheme.shouldEnableKeyboardHighlighting) ?? false; const contextMenuRef = (0, _react.useRef)(null); const shouldShowKeyboardHighlighting = (0, _useKeyboardFocusHighlighting.useKeyboardFocusHighlighting)(shouldEnableKeyboardHighlightingEffective); const showContextMenu = (0, _react.useCallback)(() => { var _contextMenuRef$curre; (_contextMenuRef$curre = contextMenuRef.current) === null || _contextMenuRef$curre === void 0 || _contextMenuRef$curre.show(); }, []); const handleSharingBarClick = (0, _react.useCallback)(event => { event.preventDefault(); event.stopPropagation(); showContextMenu(); }, [showContextMenu]); const handleKeyDown = (0, _react.useCallback)(event => { if (event.currentTarget !== event.target) { return; } if (event.key !== 'Enter' && event.key !== ' ') { return; } event.preventDefault(); event.stopPropagation(); showContextMenu(); }, [showContextMenu]); return /*#__PURE__*/_react.default.createElement(_SharingBar.StyledSharingBar, { onClick: handleSharingBarClick, onKeyDown: shouldEnableKeyboardHighlightingEffective ? handleKeyDown : undefined, tabIndex: shouldEnableKeyboardHighlightingEffective ? 0 : undefined, role: shouldEnableKeyboardHighlightingEffective ? 'button' : undefined, "data-should-show-keyboard-highlighting": shouldShowKeyboardHighlighting ? 'true' : undefined }, /*#__PURE__*/_react.default.createElement(_SharingBar.StyledSharingBarIconWrapper, null, /*#__PURE__*/_react.default.createElement(_Icon.default, { icons: ['fa fa-share-nodes'] })), /*#__PURE__*/_react.default.createElement(_SharingContextMenu.default, { link: link, ref: contextMenuRef, alignment: popupAlignment, container: container, shouldDisableClick: true }, null), /*#__PURE__*/_react.default.createElement(_SharingBar.StyledSharingBarText, null, label)); }; SharingBar.displayName = 'SharingBar'; var _default = exports.default = SharingBar; //# sourceMappingURL=SharingBar.js.map