Skip to content

Instantly share code, notes, and snippets.

View viclafouch's full-sized avatar
🎯
Focusing

Victor de la Fouchardière viclafouch

🎯
Focusing
View GitHub Profile
@viclafouch
viclafouch / tooltip.jsx
Created December 18, 2020 10:52
An implementation of a Tooltip Component with React Hooks !
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;
@viclafouch
viclafouch / styles.css
Last active June 23, 2020 16:43
A custom React Hook to help you implement a "light/dark mode" component for your application.
html[data-theme='dark'] {
--text-color: #f0F0F0;
--background-body: #1C1C1C;
--other-var: #111111;
}
html[data-theme='light'] {
--text-color: #111111;
--background-body: #FAFAFA;
--other-var: #ffffff;
@viclafouch
viclafouch / use-viewport.js
Last active June 17, 2020 19:17
A custom React Hook for tracking the window width and to get the current viewport.
// hooks/use-viewport.js
import { useState, useEffect } from 'react'
export const MOBILE = 'MOBILE'
export const TABLET = 'TABLET'
export const DESKTOP = 'DESKTOP'
const getDevice = width => {
if (width < 768) return MOBILE
else if (width < 992) return TABLET
@viclafouch
viclafouch / use-scroll.js
Last active June 17, 2020 19:15
A custom React Hook to handle the scroll of a DOM element.
// hooks/use-scroll.js
import { useEffect, useRef, useCallback, useState } from 'react'
function useScroll({ threshold = 450, isWindow = false, smooth = true } = {}) {
const [isAtBottom, setIsAtBottom] = useState(false)
const ref = useRef(isWindow ? window : null)
const goTop = useCallback(() => {
const element = ref.current
element.scrollTo({