This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useCallback, useLayoutEffect, useRef, useState } from 'react' | |
import PropTypes from 'prop-types' | |
import usePortal from '@viclafouch/usePortal' | |
import { Styled } from './tooltip.styled' | |
import styled from 'styled-components' | |
const Styled = styled.div` | |
color: #ffffff; | |
padding: 4px 8px; | |
font-size: 1rem; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useRef, useEffect, useCallback } from 'react' | |
import { createPortal } from 'react-dom' | |
export default function usePortal() { | |
const [isOpen, setIsOpen] = useState(false) | |
const portal = useRef(null) | |
const openPortal = useCallback((callback) => { | |
if (!portal.current) { | |
portal.current = document.createElement('div') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function scrollTop(nodeElement = window) { | |
try { | |
// The new API | |
nodeElement.scroll({ | |
top: 0, | |
left: 0, | |
behavior: 'smooth' | |
}) | |
} catch (error) { | |
// For olders browsers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { forwardRef } from "react"; | |
// Declare a type that works with | |
// generic components | |
type FixedForwardRef = <T, P = {}>( | |
render: (props: P, ref: React.Ref<T>) => React.ReactNode | |
) => (props: P & React.RefAttributes<T>) => React.ReactNode; | |
// Cast the old forwardRef to the new one | |
export const fixedForwardRef = |
OlderNewer