Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-floater

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-floater - npm Package Compare versions

Comparing version 0.9.0 to 0.9.1

4

dist/index.d.ts

@@ -1,2 +0,2 @@

import * as react_jsx_runtime from 'react/jsx-runtime';
import * as React from 'react';
import { CSSProperties, MouseEventHandler, ReactNode, FunctionComponent, ReactElement } from 'react';

@@ -144,3 +144,3 @@ import { RequireExactlyOne, PartialDeep } from 'type-fest';

declare function ReactFloater(props: Props): react_jsx_runtime.JSX.Element;
declare function ReactFloater(props: Props): React.JSX.Element;
declare namespace ReactFloater {

@@ -147,0 +147,0 @@ var defaultProps: {

@@ -36,3 +36,3 @@ "use strict";

module.exports = __toCommonJS(src_exports);
var React6 = __toESM(require("react"));
var React8 = __toESM(require("react"));
var import_core = require("@popperjs/core");

@@ -43,6 +43,6 @@ var import_is_lite5 = __toESM(require("is-lite"));

// src/components/Floater/index.tsx
var React3 = __toESM(require("react"));
var React5 = __toESM(require("react"));
// src/components/Floater/Arrow.tsx
var import_jsx_runtime = require("react/jsx-runtime");
var React = __toESM(require("react"));
function FloaterArrow(props) {

@@ -70,3 +70,3 @@ const { arrowRef, placement, styles } = props;

}
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { ref: arrowRef, className: "__floater__arrow", style: arrowStyles, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { height: y, version: "1.1", width: x, xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("polygon", { fill: color, points }) }) });
return /* @__PURE__ */ React.createElement("span", { ref: arrowRef, className: "__floater__arrow", style: arrowStyles }, /* @__PURE__ */ React.createElement("svg", { height: y, version: "1.1", width: x, xmlns: "http://www.w3.org/2000/svg" }, /* @__PURE__ */ React.createElement("polygon", { fill: color, points })));
}

@@ -76,10 +76,10 @@ var Arrow_default = FloaterArrow;

// src/components/Floater/Container.tsx
var React = __toESM(require("react"));
var React3 = __toESM(require("react"));
var import_is_lite = __toESM(require("is-lite"));
// src/components/Floater/CloseButton.tsx
var import_jsx_runtime2 = require("react/jsx-runtime");
var React2 = __toESM(require("react"));
function FloaterCloseButton({ onClick, styles }) {
const { color, height, width, ...style } = styles;
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { "aria-label": "close", onClick, style, type: "button", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
return /* @__PURE__ */ React2.createElement("button", { "aria-label": "close", onClick, style, type: "button" }, /* @__PURE__ */ React2.createElement(
"svg",

@@ -92,12 +92,12 @@ {

width: `${width}px`,
xmlns: "http://www.w3.org/2000/svg",
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("g", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
"path",
{
d: "M8.13911129,9.00268191 L0.171521827,17.0258467 C-0.0498027049,17.248715 -0.0498027049,17.6098394 0.171521827,17.8327545 C0.28204354,17.9443526 0.427188206,17.9998706 0.572051765,17.9998706 C0.71714958,17.9998706 0.862013139,17.9443526 0.972581703,17.8327545 L9.0000937,9.74924618 L17.0276057,17.8327545 C17.1384085,17.9443526 17.2832721,17.9998706 17.4281356,17.9998706 C17.5729992,17.9998706 17.718097,17.9443526 17.8286656,17.8327545 C18.0499901,17.6098862 18.0499901,17.2487618 17.8286656,17.0258467 L9.86135722,9.00268191 L17.8340066,0.973848225 C18.0553311,0.750979934 18.0553311,0.389855532 17.8340066,0.16694039 C17.6126821,-0.0556467968 17.254037,-0.0556467968 17.0329467,0.16694039 L9.00042166,8.25611765 L0.967006424,0.167268345 C0.745681892,-0.0553188426 0.387317931,-0.0553188426 0.165993399,0.167268345 C-0.0553311331,0.390136635 -0.0553311331,0.751261038 0.165993399,0.974176179 L8.13920499,9.00268191 L8.13911129,9.00268191 Z",
fill: color
}
) })
}
) });
xmlns: "http://www.w3.org/2000/svg"
},
/* @__PURE__ */ React2.createElement("g", null, /* @__PURE__ */ React2.createElement(
"path",
{
d: "M8.13911129,9.00268191 L0.171521827,17.0258467 C-0.0498027049,17.248715 -0.0498027049,17.6098394 0.171521827,17.8327545 C0.28204354,17.9443526 0.427188206,17.9998706 0.572051765,17.9998706 C0.71714958,17.9998706 0.862013139,17.9443526 0.972581703,17.8327545 L9.0000937,9.74924618 L17.0276057,17.8327545 C17.1384085,17.9443526 17.2832721,17.9998706 17.4281356,17.9998706 C17.5729992,17.9998706 17.718097,17.9443526 17.8286656,17.8327545 C18.0499901,17.6098862 18.0499901,17.2487618 17.8286656,17.0258467 L9.86135722,9.00268191 L17.8340066,0.973848225 C18.0553311,0.750979934 18.0553311,0.389855532 17.8340066,0.16694039 C17.6126821,-0.0556467968 17.254037,-0.0556467968 17.0329467,0.16694039 L9.00042166,8.25611765 L0.967006424,0.167268345 C0.745681892,-0.0553188426 0.387317931,-0.0553188426 0.165993399,0.167268345 C-0.0553311331,0.390136635 -0.0553311331,0.751261038 0.165993399,0.974176179 L8.13920499,9.00268191 L8.13911129,9.00268191 Z",
fill: color
}
))
));
}

@@ -107,23 +107,17 @@ var CloseButton_default = FloaterCloseButton;

// src/components/Floater/Container.tsx
var import_jsx_runtime3 = require("react/jsx-runtime");
function FloaterContainer(props) {
const { content, footer, onClick, open, positionWrapper, showCloseButton, styles, title } = props;
const output = {
content: React.isValidElement(content) ? content : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "__floater__content", style: styles.content, children: content })
content: React3.isValidElement(content) ? content : /* @__PURE__ */ React3.createElement("div", { className: "__floater__content", style: styles.content }, content)
};
if (title) {
output.title = React.isValidElement(title) ? title : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "__floater__title", style: styles.title, children: title });
output.title = React3.isValidElement(title) ? title : /* @__PURE__ */ React3.createElement("div", { className: "__floater__title", style: styles.title }, title);
}
if (footer) {
output.footer = React.isValidElement(footer) ? footer : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "__floater__footer", style: styles.footer, children: footer });
output.footer = React3.isValidElement(footer) ? footer : /* @__PURE__ */ React3.createElement("div", { className: "__floater__footer", style: styles.footer }, footer);
}
if ((showCloseButton || positionWrapper) && !import_is_lite.default.boolean(open)) {
output.close = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CloseButton_default, { onClick, styles: styles.close });
output.close = /* @__PURE__ */ React3.createElement(CloseButton_default, { onClick, styles: styles.close });
}
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "__floater__container", style: styles.container, children: [
output.close,
output.title,
output.content,
output.footer
] });
return /* @__PURE__ */ React3.createElement("div", { className: "__floater__container", style: styles.container }, output.close, output.title, output.content, output.footer);
}

@@ -145,3 +139,3 @@ var Container_default = FloaterContainer;

// src/modules/helpers.ts
var React2 = __toESM(require("react"));
var React4 = __toESM(require("react"));
var import_deepmerge_ts = require("deepmerge-ts");

@@ -218,3 +212,3 @@ var import_is_lite2 = __toESM(require("is-lite"));

function isValidElement3(object) {
return React2.isValidElement(object);
return React4.isValidElement(object);
}

@@ -264,3 +258,2 @@ function log({ data, debug = false, title }) {

// src/components/Floater/index.tsx
var import_jsx_runtime4 = require("react/jsx-runtime");
function Floater(props) {

@@ -278,3 +271,3 @@ const {

} = props;
const style = React3.useMemo(() => {
const style = React5.useMemo(() => {
const {

@@ -320,5 +313,5 @@ arrow: { length },

const componentProps = { closeFn, ...baseProps };
output.content = isValidElement3(component) ? React3.cloneElement(component, componentProps) : component(componentProps);
output.content = isValidElement3(component) ? React5.cloneElement(component, componentProps) : component(componentProps);
} else {
output.content = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Container_default, { ...props, content });
output.content = /* @__PURE__ */ React5.createElement(Container_default, { ...props, content });
}

@@ -329,3 +322,3 @@ if (status === STATUS.OPEN) {

if (!hideArrow) {
output.arrow = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Arrow_default, { ...props });
output.arrow = /* @__PURE__ */ React5.createElement(Arrow_default, { ...props });
}

@@ -335,11 +328,8 @@ if (!shouldRender) {

}
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { ref: floaterRef, style: { zIndex: styles.options.zIndex }, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: classes.join(" "), style, ...baseProps, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "__floater__body", children: [
output.content,
output.arrow
] }) }) });
return /* @__PURE__ */ React5.createElement("div", { ref: floaterRef, style: { zIndex: styles.options.zIndex } }, /* @__PURE__ */ React5.createElement("div", { className: classes.join(" "), style, ...baseProps }, /* @__PURE__ */ React5.createElement("div", { className: "__floater__body" }, output.content, output.arrow)));
}
var Floater_default = React3.memo(Floater);
var Floater_default = React5.memo(Floater);
// src/components/Portal.tsx
var React4 = __toESM(require("react"));
var React6 = __toESM(require("react"));
var import_react_dom = require("react-dom");

@@ -384,4 +374,4 @@ var import_is_lite3 = __toESM(require("is-lite"));

const { children, hasChildren, internalId, placement, portalElement, target, zIndex } = props;
const node = React4.useRef(null);
const initialize = React4.useCallback(() => {
const node = React6.useRef(null);
const initialize = React6.useCallback(() => {
if (!canUseDOM()) {

@@ -422,3 +412,3 @@ return;

});
React4.useEffect(() => {
React6.useEffect(() => {
initialize();

@@ -456,5 +446,4 @@ }, [initialize]);

// src/components/Wrapper.tsx
var React5 = __toESM(require("react"));
var React7 = __toESM(require("react"));
var import_is_lite4 = __toESM(require("is-lite"));
var import_jsx_runtime5 = require("react/jsx-runtime");
function FloaterWrapper(props) {

@@ -482,3 +471,3 @@ const {

...style,
...React5.isValidElement(children) ? children.props.style : void 0
...React7.isValidElement(children) ? children.props.style : void 0
};

@@ -501,10 +490,10 @@ let wrapperProps = {

if (children) {
if (React5.Children.count(children) === 1 && React5.isValidElement(children) && children.type !== React5.Fragment) {
if (React7.Children.count(children) === 1 && React7.isValidElement(children) && children.type !== React7.Fragment) {
if (import_is_lite4.default.function(children.type)) {
element = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { ref: wrapperRef, children: React5.cloneElement(React5.Children.only(children), {
element = /* @__PURE__ */ React7.createElement("span", { ref: wrapperRef }, React7.cloneElement(React7.Children.only(children), {
innerRef: childRef,
...wrapperProps
}) });
}));
} else {
element = React5.cloneElement(React5.Children.only(children), {
element = React7.cloneElement(React7.Children.only(children), {
ref: wrapperRef,

@@ -515,3 +504,3 @@ ...wrapperProps

} else {
element = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { ref: wrapperRef, ...wrapperProps, children });
element = /* @__PURE__ */ React7.createElement("span", { ref: wrapperRef, ...wrapperProps }, children);
}

@@ -521,3 +510,3 @@ }

}
var Wrapper_default = React5.memo(FloaterWrapper);
var Wrapper_default = React7.memo(FloaterWrapper);

@@ -625,3 +614,2 @@ // src/modules/styles.ts

// src/index.tsx
var import_jsx_runtime6 = require("react/jsx-runtime");
function ReactFloater(props) {

@@ -655,3 +643,3 @@ const {

} = enhanceProps(props);
const [state, setState] = React6.useReducer(
const [state, setState] = React8.useReducer(
(previousState, nextState) => ({

@@ -668,17 +656,17 @@ ...previousState,

);
const arrowRef = React6.useRef(null);
const childRef = React6.useRef(null);
const eventDelayTimer = React6.useRef();
const floaterRef = React6.useRef(null);
const internalId = React6.useRef(randomId());
const isMounted = React6.useRef(false);
const popperRef = React6.useRef();
const stateRef = React6.useRef(state);
const wrapperPopper = React6.useRef();
const wrapperRef = React6.useRef(null);
const wrapperStyles = React6.useRef({});
const arrowRef = React8.useRef(null);
const childRef = React8.useRef(null);
const eventDelayTimer = React8.useRef();
const floaterRef = React8.useRef(null);
const internalId = React8.useRef(randomId());
const isMounted = React8.useRef(false);
const popperRef = React8.useRef();
const stateRef = React8.useRef(state);
const wrapperPopper = React8.useRef();
const wrapperRef = React8.useRef(null);
const wrapperStyles = React8.useRef({});
const { currentPlacement, positionWrapper, status, statusWrapper } = state;
const { changed } = (0, import_tree_changes_hook.default)(state);
const { changed: changedProps } = (0, import_tree_changes_hook.default)(props);
const updateState = React6.useCallback(
const updateState = React8.useCallback(
(nextState, callback_) => {

@@ -695,3 +683,3 @@ if (isMounted.current) {

);
const toggle = React6.useCallback(
const toggle = React8.useCallback(
(forceStatus) => {

@@ -709,3 +697,3 @@ let nextStatus = stateRef.current.status === STATUS.OPEN ? STATUS.CLOSING : STATUS.RENDER;

);
const targetElement = React6.useRef(() => {
const targetElement = React8.useRef(() => {
if (!canUseDOM()) {

@@ -722,6 +710,6 @@ return null;

});
const currentDebug = React6.useMemo(() => {
const currentDebug = React8.useMemo(() => {
return canUseDOM() && (debug || !!window.ReactFloaterDebug);
}, [debug]);
const currentEvent = React6.useMemo(() => {
const currentEvent = React8.useMemo(() => {
if (event === "hover" && isMobile() && !disableHoverToClick) {

@@ -732,3 +720,3 @@ return "click";

}, [disableHoverToClick, event]);
const currentStyles = React6.useMemo(() => {
const currentStyles = React8.useMemo(() => {
const nextStyles = getStyles(styles);

@@ -774,3 +762,3 @@ const element = targetElement.current();

}, [positionWrapper, status, statusWrapper, styles]);
const initPopper = React6.useRef(() => {
const initPopper = React8.useRef(() => {
const nextStatus = stateRef.current.status === STATUS.RENDER ? STATUS.OPENING : STATUS.IDLE;

@@ -915,3 +903,3 @@ const element = targetElement.current();

});
const handleLoad = React6.useRef(() => {
const handleLoad = React8.useRef(() => {
if (popperRef.current) {

@@ -924,3 +912,3 @@ popperRef.current.forceUpdate();

});
const handleTransitionEnd = React6.useRef(() => {
const handleTransitionEnd = React8.useRef(() => {
if (wrapperPopper.current) {

@@ -940,3 +928,3 @@ wrapperPopper.current.forceUpdate();

});
const handleClick = React6.useCallback(() => {
const handleClick = React8.useCallback(() => {
if (import_is_lite5.default.boolean(open)) {

@@ -954,3 +942,3 @@ return;

}, [currentDebug, currentEvent, event, open, positionWrapper, status, toggle]);
const handleMouseEnter = React6.useCallback(() => {
const handleMouseEnter = React8.useCallback(() => {
if (import_is_lite5.default.boolean(open) || isMobile() || currentEvent !== "hover") {

@@ -970,3 +958,3 @@ return;

}, [currentDebug, currentEvent, event, open, status, toggle]);
const handleMouseLeave = React6.useCallback(() => {
const handleMouseLeave = React8.useCallback(() => {
if (import_is_lite5.default.boolean(open) || isMobile()) {

@@ -995,3 +983,3 @@ return;

}, [currentDebug, currentEvent, event, eventDelay, open, positionWrapper, status, toggle]);
const handleWrapperMount = React6.useCallback(() => {
const handleWrapperMount = React8.useCallback(() => {
if (positionWrapper) {

@@ -1073,3 +1061,3 @@ initPopper.current();

});
const wrapper = /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
const wrapper = /* @__PURE__ */ React8.createElement(
Wrapper_default,

@@ -1087,42 +1075,37 @@ {

styles: currentStyles.wrapper,
wrapperRef,
children
}
wrapperRef
},
children
);
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
Portal_default,
return /* @__PURE__ */ React8.createElement(React8.Fragment, null, /* @__PURE__ */ React8.createElement(
Portal_default,
{
hasChildren: !!children,
internalId: internalId.current,
placement: currentPlacement,
portalElement,
target,
zIndex: currentStyles.options.zIndex
},
/* @__PURE__ */ React8.createElement(
Floater_default,
{
hasChildren: !!children,
internalId: internalId.current,
arrowRef,
component,
content,
floaterRef,
footer,
hideArrow: hideArrow || currentPlacement === "center",
id: id ?? internalId.current,
onClick: handleClick,
placement: currentPlacement,
portalElement,
target,
zIndex: currentStyles.options.zIndex,
children: [
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
Floater_default,
{
arrowRef,
component,
content,
floaterRef,
footer,
hideArrow: hideArrow || currentPlacement === "center",
id: id ?? internalId.current,
onClick: handleClick,
placement: currentPlacement,
positionWrapper,
showCloseButton,
status,
styles: currentStyles,
title
}
),
positionWrapper && wrapper
]
positionWrapper,
showCloseButton,
status,
styles: currentStyles,
title
}
),
!positionWrapper && wrapper
] });
positionWrapper && wrapper
), !positionWrapper && wrapper);
}

@@ -1129,0 +1112,0 @@ ReactFloater.defaultProps = {

{
"name": "react-floater",
"version": "0.9.0",
"version": "0.9.1",
"description": "Floaters everywhere!",

@@ -46,4 +46,4 @@ "author": "Gil Barbara <gilbarbara@gmail.com>",

"deepmerge-ts": "^5.1.0",
"is-lite": "^0.9.3",
"tree-changes-hook": "^0.10.0"
"is-lite": "^1.2.0",
"tree-changes-hook": "^0.11.1"
},

@@ -53,16 +53,16 @@ "devDependencies": {

"@emotion/styled": "^11.11.0",
"@gilbarbara/eslint-config": "^0.5.4",
"@gilbarbara/eslint-config": "^0.7.1",
"@gilbarbara/prettier-config": "^1.0.0",
"@gilbarbara/tsconfig": "^0.2.3",
"@gilbarbara/types": "^0.2.2",
"@size-limit/preset-small-lib": "^9.0.0",
"@swc/core": "^1.3.92",
"@size-limit/preset-small-lib": "^10.0.2",
"@swc/core": "^1.3.96",
"@testing-library/dom": "^9.3.3",
"@testing-library/jest-dom": "^6.1.3",
"@testing-library/react": "^14.0.0",
"@types/exenv": "^1.2.0",
"@types/jest": "^29.5.5",
"@types/node": "^20.8.3",
"@types/react": "^18.2.25",
"@types/react-dom": "^18.2.11",
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/react": "^14.1.0",
"@types/exenv": "^1.2.2",
"@types/jest": "^29.5.8",
"@types/node": "^20.9.0",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"del-cli": "^5.1.0",

@@ -75,3 +75,3 @@ "disable-scroll": "^0.6.0",

"jest-environment-jsdom": "^29.7.0",
"jest-extended": "^4.0.1",
"jest-extended": "^4.0.2",
"jest-serializer-html": "^7.1.0",

@@ -82,10 +82,9 @@ "jest-watch-typeahead": "^2.2.2",

"react-use": "^17.4.0",
"repo-tools": "^0.2.2",
"size-limit": "^9.0.0",
"repo-tools": "^0.3.1",
"size-limit": "^10.0.2",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"tsup": "^7.2.0",
"type-fest": "^4.4.0",
"typescript": "^5.2.2",
"webpack": "^5.88.2"
"type-fest": "^4.7.1",
"typescript": "^5.2.2"
},

@@ -123,3 +122,5 @@ "scripts": {

"extends": [
"@gilbarbara/eslint-config"
"@gilbarbara/eslint-config",
"@gilbarbara/eslint-config/jest",
"@gilbarbara/eslint-config/testing-library"
],

@@ -126,0 +127,0 @@ "rules": {

@@ -26,6 +26,5 @@ import { DependencyList, EffectCallback, useEffect, useRef } from 'react';

// update the ref each render so if it change the newest callback will be invoked
// update the ref each render so if it changes the newest callback will be invoked
fnRef.current = fn;
// eslint-disable-next-line unicorn/consistent-function-scoping
useEffectOnce(() => () => fnRef.current());

@@ -32,0 +31,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc