Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function Box({ focused, color, children, onFocus, onBlur, path }: Props) {
const { setFocus } = useSunbeam()
const prevFocused = usePrevious(focused, focused)
useEffect(() => {
if (prevFocused === focused) return
if (focused && onFocus) {
onFocus()
return
}
if (onBlur) onBlur()
}, [prevFocused, focused, onFocus, onBlur])
const onClick = useCallback(() => {
setFocus(path)
}, [path])
export function FocusableItem({ children, style, focusKey, onFocus }: Props) {
const elementRef = useRef(null)
const { focused, path } = useFocusable(focusKey, elementRef)
const { setFocus } = useSunbeam()
const prevFocused = usePrevious(focused, focused)
useEffect(() => {
if (prevFocused !== focused && focused && onFocus) {
onFocus({ element: elementRef.current, focusPath: path })
}
})
const handleClick = useCallback(() => {
setFocus(path)
}, [path])
return (
<div style="{typeof">
{children}
</div>
const newScrollX = ensureScrollXWithinBounds(scrollX + deltaScrollX)
function ensureScrollXWithinBounds(value: number): number {
const minScrollX = 0
const maxScrollX = trackRef.current.scrollWidth - viewportWidth
if (value < minScrollX) return minScrollX
if (value > maxScrollX) return maxScrollX
return value
}
if (newScrollX !== scrollX) setScrollX(newScrollX)
onItemFocus(event)
},
[scrollX]
)
const { setFocus } = useSunbeam()
const handleItemClick = useCallback((itemFocusPath: ReadonlyArray) => {
setFocus(itemFocusPath)
}, [])
return (
<div style="{{">
<div style="{{"></div></div>