@i-novus/ui-core
Version:
Базовые UI компоненты
19 lines (18 loc) • 988 B
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { useEffect, useRef } from 'react';
import { Button } from '../../../../general/Button';
const OUTLINE_WIDTH = 3;
export const Option = ({ isSelected, parentContainerRef, prefix, children, onClick, name, id, className, ...rest }) => {
const optionRef = useRef(null);
useEffect(() => {
if (isSelected) {
const parentRect = parentContainerRef.current?.getBoundingClientRect();
const optionRect = optionRef.current?.getBoundingClientRect();
if (optionRect && parentRect) {
const scrollTop = Math.abs(parentRect.top) - Math.abs(optionRect.top) + OUTLINE_WIDTH;
parentContainerRef.current?.scrollTo(0, Math.abs(scrollTop));
}
}
}, [parentContainerRef, isSelected]);
return (_jsx(Button, { ...rest, id: id, name: name, variant: "link-cancel", ref: optionRef, className: className, onClick: onClick, children: children }));
};