UNPKG

@hypothesis/frontend-shared

Version:

Shared components, styles and utilities for Hypothesis projects

41 lines 1.58 kB
var _jsxFileName = "/home/runner/work/frontend-shared/frontend-shared/src/components/input/CloseButton.tsx"; import { useContext } from 'preact/hooks'; import { downcastRef } from '../../util/typing'; import CloseableContext from '../CloseableContext'; import { CancelIcon } from '../icons'; import IconButton from './IconButton'; import { jsxDEV as _jsxDEV } from "preact/jsx-dev-runtime"; /** * Render a close button. Use provided `onClick` or check for a CloseableContext * with a close handler. */ export default function CloseButton({ children, classes, elementRef, title, onClick, ...iconButtonProps }) { var _ref; const closeableContext = useContext(CloseableContext); // Provided `title` and `onClick` are prioritized, but fall back to values // from the `CloseableContext` const buttonTitle = (_ref = title !== null && title !== void 0 ? title : closeableContext === null || closeableContext === void 0 ? void 0 : closeableContext.title) !== null && _ref !== void 0 ? _ref : 'Close'; const closeHandler = onClick !== null && onClick !== void 0 ? onClick : closeableContext === null || closeableContext === void 0 ? void 0 : closeableContext.onClose; return _jsxDEV(IconButton, { "data-component": "CloseButton", elementRef: downcastRef(elementRef), icon: CancelIcon, title: buttonTitle, classes: classes, ...iconButtonProps, onClick: closeHandler, children: children }, void 0, false, { fileName: _jsxFileName, lineNumber: 36, columnNumber: 5 }, this); } //# sourceMappingURL=CloseButton.js.map