How to use the @magento/peregrine.useEventListener function in @magento/peregrine

To help you get started, we’ve selected a few @magento/peregrine examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / venia-concept / src / components / MiniCart / kebab.js View on Github external
const classes = mergeClasses(defaultClasses, props.classes);
    const toggleClass = isOpen ? classes.dropdown_active : classes.dropdown;

    const handleKebabClick = useCallback(() => {
        setIsOpen(!isOpen);
    }, [isOpen]);
    const handleOutsideKebabClick = useCallback(event => {
        // Ensure we're truly outside of the kebab.
        if (!kebabRef.current.contains(event.target)) {
            setIsOpen(false);
        }
    }, []);

    useEventListener(document, 'mousedown', handleOutsideKebabClick);
    useEventListener(document, 'touchend', handleOutsideKebabClick);

    return (
        <div>
            <button>
                
            </button>
            <ul>{children}</ul>
        </div>
    );
};
github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / venia-concept / src / components / MiniCart / kebab.js View on Github external
const [isOpen, setIsOpen] = useState(false);

    const classes = mergeClasses(defaultClasses, props.classes);
    const toggleClass = isOpen ? classes.dropdown_active : classes.dropdown;

    const handleKebabClick = useCallback(() =&gt; {
        setIsOpen(!isOpen);
    }, [isOpen]);
    const handleOutsideKebabClick = useCallback(event =&gt; {
        // Ensure we're truly outside of the kebab.
        if (!kebabRef.current.contains(event.target)) {
            setIsOpen(false);
        }
    }, []);

    useEventListener(document, 'mousedown', handleOutsideKebabClick);
    useEventListener(document, 'touchend', handleOutsideKebabClick);

    return (
        <div>
            <button>
                
            </button>
            <ul>{children}</ul>
        </div>
    );
};