mirror of
https://github.com/azaion/ui.git
synced 2026-06-21 15:41:10 +00:00
Refactor project structure and dependencies; rename package to azaion-ui, update version to 0.0.1, and remove unused files. Introduce new routing and authentication features in App component.
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
|
||||
export function useDebounce<T>(value: T, delay: number): T {
|
||||
const [debounced, setDebounced] = useState(value)
|
||||
|
||||
useEffect(() => {
|
||||
const timer = setTimeout(() => setDebounced(value), delay)
|
||||
return () => clearTimeout(timer)
|
||||
}, [value, delay])
|
||||
|
||||
return debounced
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { useState, useCallback, useRef, useEffect } from 'react'
|
||||
|
||||
export function useResizablePanel(initialWidth: number, min = 100, max = 600) {
|
||||
const [width, setWidth] = useState(initialWidth)
|
||||
const dragging = useRef(false)
|
||||
const startX = useRef(0)
|
||||
const startWidth = useRef(0)
|
||||
|
||||
const onMouseDown = useCallback((e: React.MouseEvent) => {
|
||||
dragging.current = true
|
||||
startX.current = e.clientX
|
||||
startWidth.current = width
|
||||
e.preventDefault()
|
||||
}, [width])
|
||||
|
||||
useEffect(() => {
|
||||
const onMouseMove = (e: MouseEvent) => {
|
||||
if (!dragging.current) return
|
||||
const delta = e.clientX - startX.current
|
||||
setWidth(Math.min(max, Math.max(min, startWidth.current + delta)))
|
||||
}
|
||||
const onMouseUp = () => { dragging.current = false }
|
||||
window.addEventListener('mousemove', onMouseMove)
|
||||
window.addEventListener('mouseup', onMouseUp)
|
||||
return () => {
|
||||
window.removeEventListener('mousemove', onMouseMove)
|
||||
window.removeEventListener('mouseup', onMouseUp)
|
||||
}
|
||||
}, [min, max])
|
||||
|
||||
return { width, onMouseDown, setWidth }
|
||||
}
|
||||
Reference in New Issue
Block a user