nice-ui
Version:
React design system, components, and utilities
48 lines (47 loc) • 2.24 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.PopupControlled = void 0;
const React = require("react");
const nano_theme_1 = require("nano-theme");
const BasicTooltip_1 = require("../BasicTooltip");
const PositionPopup_1 = require("../../utils/popup/PositionPopup");
const useClickAway_1 = require("../../hooks/useClickAway");
const blockClass = (0, nano_theme_1.rule)({
d: 'flex',
pos: 'relative',
});
const buttonClass = (0, nano_theme_1.rule)({
d: 'inline-flex',
ta: 'inherit',
position: 'relative',
bg: 'none',
pad: 0,
mar: 0,
out: 0,
trs: 'box-shadow .15s',
});
const roundClass = (0, nano_theme_1.rule)({
bdrad: '50%',
});
const PopupControlled = (props) => {
const { renderContext, children, round, open = false, prerender, tooltip, fadeIn, block, onHeadClick, onClickAway = () => { }, onEsc, refToggle, ...rest } = props;
const clickAwayRef = (0, useClickAway_1.useClickAway)(onClickAway);
const childrenWithTooltip = tooltip ? (React.createElement(BasicTooltip_1.BasicTooltip, { ...tooltip, ...(open ? { renderTooltip: undefined } : null) }, children)) : (children);
const dropdown = (open || prerender) && (React.createElement(PositionPopup_1.PositionPopup, { fadeIn: fadeIn },
React.createElement("span", { style: {
visibility: open ? 'visible' : 'hidden',
} }, renderContext({ open }))));
const toggle = (React.createElement("span", { ref: refToggle, className: buttonClass + (round ? roundClass : ''), style: { display: block ? 'block' : undefined, width: block ? '100%' : undefined }, onClick: onHeadClick }, childrenWithTooltip));
return (React.createElement("span", { ...rest, ref: clickAwayRef, className: props.className + '' + blockClass, style: { display: block ? 'block' : undefined, width: block ? '100%' : undefined, ...(props.style || {}) }, onKeyDown: !onEsc
? void 0
: (e) => {
if (e.key === 'Escape') {
e.stopPropagation();
e.preventDefault();
onEsc();
}
} },
toggle,
dropdown));
};
exports.PopupControlled = PopupControlled;
;